package net.micode.notes.model; import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.text.TextUtils; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; import java.util.List; /** * 笔记模板数据模型类,用于存储和管理笔记模板 */ public class NoteTemplate { public static final String TYPE_SYSTEM = "system"; public static final String TYPE_CUSTOM = "custom"; private long id; private String name; private String content; private String type; private long createTime; private long updateTime; public NoteTemplate() { this.createTime = System.currentTimeMillis(); this.updateTime = System.currentTimeMillis(); } public NoteTemplate(long id, String name, String content, String type, long createTime, long updateTime) { this.id = id; this.name = name; this.content = content; this.type = type; this.createTime = createTime; this.updateTime = updateTime; } // Getters and Setters public long getId() { return id; } public void setId(long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getContent() { return content; } public void setContent(String content) { this.content = content; } public String getType() { return type; } public void setType(String type) { this.type = type; } public long getCreateTime() { return createTime; } public void setCreateTime(long createTime) { this.createTime = createTime; } public long getUpdateTime() { return updateTime; } public void setUpdateTime(long updateTime) { this.updateTime = updateTime; } /** * 将模板对象转换为JSON对象 */ public JSONObject toJson() throws JSONException { JSONObject json = new JSONObject(); json.put("id", id); json.put("name", name); json.put("content", content); json.put("type", type); json.put("createTime", createTime); json.put("updateTime", updateTime); return json; } /** * 从JSON对象创建模板对象 */ public static NoteTemplate fromJson(JSONObject json) throws JSONException { NoteTemplate template = new NoteTemplate(); template.setId(json.getLong("id")); template.setName(json.getString("name")); template.setContent(json.getString("content")); template.setType(json.getString("type")); template.setCreateTime(json.getLong("createTime")); template.setUpdateTime(json.getLong("updateTime")); return template; } }