package net.coding.program.model;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;

/**
 * Created by yangzhen on 2014/10/25.
 */
public class AttachmentFolderObject implements Serializable {
    public long created_at;//创建时间
    public String file_id = "";//文件ID
    public String name = "";//文件名称
    public String owner_id = "";//
    public String parent_id = "";//
    public int type;//文件类型
    public long updated_at;//更新时间
    public int count;//文件数量
    public boolean isSelected = false;

    public static final String SHARE_FOLDER_ID = "-1";

    public ArrayList<AttachmentFolderObject> sub_folders = new ArrayList<>();
    public AttachmentFolderObject parent;

    public AttachmentFolderObject() {
        this.name = "默认文件夹";
        this.file_id = "0";
    }

    public AttachmentFolderObject(JSONObject json) throws JSONException {
        created_at = json.optLong("created_at");
        file_id = json.optString("file_id");
        name = json.optString("name");
        owner_id = json.optString("owner_id");
        parent_id = json.optString("parent_id");
        type = json.optInt("type");
        updated_at = json.optLong("updated_at");

        JSONArray subFolders = json.optJSONArray("sub_folders");
        for (int i = 0; i < subFolders.length(); i++) {
            JSONObject subFolderObject = subFolders.getJSONObject(i);
            AttachmentFolderObject subFolder = new AttachmentFolderObject(subFolderObject);
            subFolder.parent = this;
            sub_folders.add(subFolder);
        }
    }

    public int getCount() {
        return count;
    }

    public void setCount(Integer count) {
        if (count != null) {
            this.count = count;
        }
    }

    /**
     * @return 当前目录文件总数，包括子目录中的文件数
     */
    public int getTotelCount() {
        int subFolderCount = 0;
        for (AttachmentFolderObject subFolder : this.sub_folders) {
            subFolderCount += subFolder.getTotelCount();
        }
        return this.count + subFolderCount;
        //return this.count;
    }

    public String getNameCount() {
        return String.format("%s (%s)", this.name, getTotelCount());
    }

    /**
     * @return 文件夹是否能被删除
     */
    public boolean isDeleteable() {
        return (!file_id.equals("0") && count == 0);
    }
}

@@ -414,32 +414,37 @@
 owner_id = %22%22;//
+%E5%88%9B%E5%BB%BA%E8%80%85ID
 %0A    public Stri
@@ -463,16 +463,21 @@
  = %22%22;//
+%E6%96%87%E4%BB%B6%E5%A4%B9ID
 %0A    pub

添加文件owner_id,parent_id注释