Merge pull request 'data和gtask-data' (#13) from dongjiaqi_branch into main

pull/17/head
ps249eph7 11 months ago
commit f849e02ce4

@ -25,19 +25,39 @@ import android.util.Log;
import java.util.HashMap;
/**
* @Package: net.micode.notes.data
* @ClassName: Contact
* @Description:
* ContactgetContact
* 使
* @Author: Dong Jiaqi
* @CreateDate: 12/21/2023 19:31 PM
*/
public class Contact {
private static HashMap<String, String> sContactCache;
private static final String TAG = "Contact";
private static HashMap<String, String> sContactCache;//定义了一个静态的HashMap变量sContactCache
private static final String TAG = "Contact";//定义了一个静态的字符串常量TAG
private static final String CALLER_ID_SELECTION = "PHONE_NUMBERS_EQUAL(" + Phone.NUMBER
+ ",?) AND " + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'"
+ " AND " + Data.RAW_CONTACT_ID + " IN "
+ "(SELECT raw_contact_id "
+ " FROM phone_lookup"
+ " WHERE min_match = '+')";
/*
*CALLER_ID_SELECTION,
*使PHONE_NUMBERS_EQUAL,使ID.
*/
/**
* getContact,
* getContact2contextphoneNumber,Context,访;
* 3sContactCache.get(phoneNumber)sContactCacheHashMap
* name; nullIndexOutOfBoundsException
*/
public static String getContact(Context context, String phoneNumber) {
if(sContactCache == null) {
if(sContactCache == null) {//确保HashMap对象不会空始终指向一个实例化的HashMap对象
sContactCache = new HashMap<String, String>();
}
@ -46,21 +66,36 @@ public class Contact {
}
String selection = CALLER_ID_SELECTION.replace("+",
PhoneNumberUtils.toCallerIDMinMatch(phoneNumber));
PhoneNumberUtils.toCallerIDMinMatch(phoneNumber)); //获取电话号码的最小匹配形式比如字母换数字然后用replace方发将CALLER_ID_SELECTION中的"+"替换为最小匹配后的电话号码
Cursor cursor = context.getContentResolver().query(
Data.CONTENT_URI,
new String [] { Phone.DISPLAY_NAME },
selection,
new String[] { phoneNumber },
null);
/*
*context.getContentResolver()query()
*Data.CONTENT_URIData.CONTENT_URIURI
*new String []{Phone.DISPLAY_NAME}
*selection
*new String[] {phoneNumber}
*null
*/
//如果查询结果不为空将第一个结果的显示名称存储在缓存中并返回该名称否则记录到错误日志并返回null。
if (cursor != null && cursor.moveToFirst()) {
/*
* namesContactCache
* IndexOutOfBoundsExceptiondebug
* 使try-catch-finally
*
*/
try {
String name = cursor.getString(0);
sContactCache.put(phoneNumber, name);
return name;
} catch (IndexOutOfBoundsException e) {
Log.e(TAG, " Cursor get string error " + e.toString());
Log.e(TAG, " Cursor get string error " + e.toString());//调用Log.e()方法,把错误信息写到日志。
return null;
} finally {
cursor.close();

@ -17,6 +17,18 @@
package net.micode.notes.data;
import android.net.Uri;
/**
* @Package: net.micode.notes.data
* @ClassName: Notes
* @Description:
* NotesURI
*
*
* ID IDID
* URI 便
* @Author: Dong Jiaqi
* @CreateDate: 12/22/2023 0:53 AM
*/
public class Notes {
public static final String AUTHORITY = "micode_notes";
public static final String TAG = "Notes";
@ -46,6 +58,7 @@ public class Notes {
public static final int TYPE_WIDGET_2X = 0;
public static final int TYPE_WIDGET_4X = 1;
//定义了一个静态内部类DataConstants包含2个变量NOTE和CALL_NOTE前者用于表示数据类型为文本笔记类型后者用于表示数据类型为通话类型
public static class DataConstants {
public static final String NOTE = TextNote.CONTENT_ITEM_TYPE;
public static final String CALL_NOTE = CallNote.CONTENT_ITEM_TYPE;
@ -61,6 +74,10 @@ public class Notes {
*/
public static final Uri CONTENT_DATA_URI = Uri.parse("content://" + AUTHORITY + "/data");
/**
* NoteColumns
* 使便访
*/
public interface NoteColumns {
/**
* The unique ID for a row
@ -167,6 +184,10 @@ public class Notes {
public static final String VERSION = "version";
}
/**
* DataColumns
* 访使便
*/
public interface DataColumns {
/**
* The unique ID for a row
@ -241,28 +262,34 @@ public class Notes {
public static final String DATA5 = "data5";
}
/**
* TextNoteDataColumns
*/
public static final class TextNote implements DataColumns {
/**
* Mode to indicate the text in check list mode or not
* <P> Type: Integer 1:check list mode 0: normal mode </P>
*/
public static final String MODE = DATA1;
public static final String MODE = DATA1;//表示文本笔记的模式用来指示是否处于检查模式当中值为1表示检查模式为0表示普通模式
public static final int MODE_CHECK_LIST = 1;
public static final int MODE_CHECK_LIST = 1;//表示检查列表模式的常量值。
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/text_note";
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/text_note";
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/text_note");
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/text_note");//表示文本笔记的内容URI用来访问和操作笔记中的数值是两者拼合成的URI
}
/**
* CallNoteDataColumns
*/
public static final class CallNote implements DataColumns {
/**
* Call date for this record
* <P> Type: INTEGER (long) </P>
*/
public static final String CALL_DATE = DATA1;
public static final String CALL_DATE = DATA1;//表示通话笔记的通话日期
/**
* Phone number for this record

@ -26,7 +26,17 @@ import net.micode.notes.data.Notes.DataColumns;
import net.micode.notes.data.Notes.DataConstants;
import net.micode.notes.data.Notes.NoteColumns;
/**
* @Package: net.micode.notes.data
* @ClassName: NotesDatabaseHelper
* @Description:
* 便NotesDatabaseHelper,SQLiteOpenHelper
* ,便
* 5
* 便
* @Author: Dong Jiaqi
* @CreateDate: 12/23/2023 0:44 AM
*/
public class NotesDatabaseHelper extends SQLiteOpenHelper {
private static final String DB_NAME = "note.db";
@ -61,7 +71,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
NoteColumns.ORIGIN_PARENT_ID + " INTEGER NOT NULL DEFAULT 0," +
NoteColumns.GTASK_ID + " TEXT NOT NULL DEFAULT ''," +
NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0" +
")";
")";//这是用于创建便签表的SQL语句定义了便签表的结构包含便签各种属性和字段存储了用户创建的所有便签的信息。
private static final String CREATE_DATA_TABLE_SQL =
"CREATE TABLE " + TABLE.DATA + "(" +
@ -76,14 +86,14 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
DataColumns.DATA3 + " TEXT NOT NULL DEFAULT ''," +
DataColumns.DATA4 + " TEXT NOT NULL DEFAULT ''," +
DataColumns.DATA5 + " TEXT NOT NULL DEFAULT ''" +
")";
")";//这是用于定义数据表结构的SQL语句存储了与便签相关的数据信息包括了各种附加数据用来扩展便签功能。
private static final String CREATE_DATA_NOTE_ID_INDEX_SQL =
"CREATE INDEX IF NOT EXISTS note_id_index ON " +
TABLE.DATA + "(" + DataColumns.NOTE_ID + ");";
/**
* Increase folder's note count when move note to the folder
* 便便
*/
private static final String NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER =
"CREATE TRIGGER increase_folder_count_on_update "+
@ -95,7 +105,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";
/**
* Decrease folder's note count when move note from folder
* 便便
*/
private static final String NOTE_DECREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER =
"CREATE TRIGGER decrease_folder_count_on_update " +
@ -108,7 +118,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";
/**
* Increase folder's note count when insert new note to the folder
* 便便
*/
private static final String NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER =
"CREATE TRIGGER increase_folder_count_on_insert " +
@ -120,7 +130,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";
/**
* Decrease folder's note count when delete note from the folder
* 便便
*/
private static final String NOTE_DECREASE_FOLDER_COUNT_ON_DELETE_TRIGGER =
"CREATE TRIGGER decrease_folder_count_on_delete " +
@ -133,7 +143,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";
/**
* Update note's content when insert data with type {@link DataConstants#NOTE}
* 便{@link DataConstants#NOTE}
*/
private static final String DATA_UPDATE_NOTE_CONTENT_ON_INSERT_TRIGGER =
"CREATE TRIGGER update_note_content_on_insert " +
@ -172,7 +182,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";
/**
* Delete datas belong to note which has been deleted
* 便
*/
private static final String NOTE_DELETE_DATA_ON_DELETE_TRIGGER =
"CREATE TRIGGER delete_data_on_delete " +
@ -183,7 +193,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";
/**
* Delete notes belong to folder which has been deleted
* 便
*/
private static final String FOLDER_DELETE_NOTES_ON_DELETE_TRIGGER =
"CREATE TRIGGER folder_delete_notes_on_delete " +
@ -194,7 +204,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";
/**
* Move notes belong to folder which has been moved to trash folder
* 便
*/
private static final String FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER =
"CREATE TRIGGER folder_move_notes_on_trash " +
@ -210,6 +220,10 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
super(context, DB_NAME, null, DB_VERSION);
}
/**
* 便
* @param SQLiteDatabasedb便
*/
public void createNoteTable(SQLiteDatabase db) {
db.execSQL(CREATE_NOTE_TABLE_SQL);
reCreateNoteTableTriggers(db);
@ -217,6 +231,10 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
Log.d(TAG, "note table has been created");
}
/**
* 便便
* @param db
*/
private void reCreateNoteTableTriggers(SQLiteDatabase db) {
db.execSQL("DROP TRIGGER IF EXISTS increase_folder_count_on_update");
db.execSQL("DROP TRIGGER IF EXISTS decrease_folder_count_on_update");
@ -235,6 +253,10 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.execSQL(FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER);
}
/**
*
* @param db
*/
private void createSystemFolder(SQLiteDatabase db) {
ContentValues values = new ContentValues();
@ -277,6 +299,10 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
Log.d(TAG, "data table has been created");
}
/**
* 33
* @param db
*/
private void reCreateDataTableTriggers(SQLiteDatabase db) {
db.execSQL("DROP TRIGGER IF EXISTS update_note_content_on_insert");
db.execSQL("DROP TRIGGER IF EXISTS update_note_content_on_update");
@ -287,6 +313,15 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.execSQL(DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER);
}
/**
* NotesDatabaseHelper
* 访便使访
* @param context Context
* ,Context contextNoteDatabaseHelper
*
* @return mInstancenull
* mInstance
*/
static synchronized NotesDatabaseHelper getInstance(Context context) {
if (mInstance == null) {
mInstance = new NotesDatabaseHelper(context);
@ -300,11 +335,21 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
createDataTable(db);
}
/**
* ,,
* @param db
* @param oldVersion
* @param newVersion
*/
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
boolean reCreateTriggers = false;
boolean skipV2 = false;
/**
*
*
*/
if (oldVersion == 1) {
upgradeToV2(db);
skipV2 = true; // this upgrade including the upgrade from v2 to v3

@ -34,7 +34,15 @@ import net.micode.notes.data.Notes.DataColumns;
import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.data.NotesDatabaseHelper.TABLE;
/**
* @Package: net.micode.notes.data
* @ClassName: NotesProvider
* @Description:
* ContentProvider,便,
*
* @Author: Dong Jiaqi
* @CreateDate: 12/23/2023 2327 PM
*/
public class NotesProvider extends ContentProvider {
private static final UriMatcher mMatcher;
@ -50,6 +58,10 @@ public class NotesProvider extends ContentProvider {
private static final int URI_SEARCH = 5;
private static final int URI_SEARCH_SUGGEST = 6;
/**
* UriMatcher
* addURI()mMatcherUriMatcher
*/
static {
mMatcher = new UriMatcher(UriMatcher.NO_MATCH);
mMatcher.addURI(Notes.AUTHORITY, "note", URI_NOTE);
@ -79,18 +91,36 @@ public class NotesProvider extends ContentProvider {
+ " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER
+ " AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE;
/**
* onCreate()
* @return true
*/
@Override
public boolean onCreate() {
mHelper = NotesDatabaseHelper.getInstance(getContext());
return true;
}
/**
* query(),URI,
* @param uri URI
* @param projection
* @param selection
* @param selectionArgs selection
* @param sortOrder
* @return (Cursor)(c)
*/
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder) {
Cursor c = null;
SQLiteDatabase db = mHelper.getReadableDatabase();
String id = null;
/**
* switchURI
* 3URIURIILLegalArgumentExceptionURI
* URIURIAndroid ContentProvider
*/
switch (mMatcher.match(uri)) {
case URI_NOTE:
c = db.query(TABLE.NOTE, projection, selection, selectionArgs, null, null,
@ -130,6 +160,11 @@ public class NotesProvider extends ContentProvider {
return null;
}
/**
* URI_SEARCH URI_SEARCH_SUGGEST rawQuery Cursor
* IllegalStateException Log.e() 便
*
*/
try {
searchString = String.format("%%%s%%", searchString);
c = db.rawQuery(NOTES_SNIPPET_SEARCH_QUERY,
@ -147,6 +182,12 @@ public class NotesProvider extends ContentProvider {
return c;
}
/**
* URI
* @param uri URI
* @param values
* @return URIContentUris.withAppendedId(uri, insertedId)
*/
@Override
public Uri insert(Uri uri, ContentValues values) {
SQLiteDatabase db = mHelper.getWritableDatabase();
@ -181,6 +222,13 @@ public class NotesProvider extends ContentProvider {
return ContentUris.withAppendedId(uri, insertedId);
}
/**
* URI
* @param uri URI
* @param selection
* @param selectionArgs selection
* @return
*/
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
int count = 0;
@ -227,12 +275,25 @@ public class NotesProvider extends ContentProvider {
return count;
}
/**
* URI
* @param uri URI
* @param values
* @param selection
* @param selectionArgs selection
* @return
*/
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
int count = 0;
String id = null;
SQLiteDatabase db = mHelper.getWritableDatabase();
boolean updateData = false;
/**
* URIUniform Resource Identifier
* URI URI
* switch-case URI
*/
switch (mMatcher.match(uri)) {
case URI_NOTE:
increaseNoteVersion(-1, selection, selectionArgs);
@ -267,10 +328,21 @@ public class NotesProvider extends ContentProvider {
return count;
}
/**
* SQLWHERE
* @param selection
* @return
*/
private String parseSelection(String selection) {
return (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : "");
}
/**
* 便
* @param id 便ID
* @param selection 便
* @param selectionArgs
*/
private void increaseNoteVersion(long id, String selection, String[] selectionArgs) {
StringBuilder sql = new StringBuilder(120);
sql.append("UPDATE ");
@ -296,6 +368,10 @@ public class NotesProvider extends ContentProvider {
mHelper.getWritableDatabase().execSQL(sql.toString());
}
/**
*
* @param uri URI
*/
@Override
public String getType(Uri uri) {
// TODO Auto-generated method stub

@ -24,13 +24,33 @@ import net.micode.notes.tool.GTaskStringUtils;
import org.json.JSONException;
import org.json.JSONObject;
/**
* @Package: net.micode.notes.gtask.data
* @ClassName: MetaData
* @Description:
* MetaData Task
* GID JSON
* 访使
* @Author: Dong Jiaqi
* @CreateDate: 12/24/2023 9:53 AM
*/
public class MetaData extends Task {
private final static String TAG = MetaData.class.getSimpleName();
private String mRelatedGid = null;
/**
* GID
* @param gid Global Task ID
* @param metaInfo JSONObject
*/
public void setMeta(String gid, JSONObject metaInfo) {
/**
* metaInfo JSONObject GTaskStringUtils.META_HEAD_GTASK_ID gid
* 使 try-catch JSONException
*
* Java JSONObject put JSONException put 使 try-catch
*/
try {
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
} catch (JSONException e) {
@ -40,19 +60,29 @@ public class MetaData extends Task {
setName(GTaskStringUtils.META_NOTE_NAME);
}
//作用是获取任务的相关 GID并返回其字符串形式。
public String getRelatedGid() {
return mRelatedGid;
return mRelatedGid;//返回值是一个字符串类型的变量 mRelatedGid表示相关 GIDGlobal Task ID。mRelatedGid 是一个成员变量,它保存了在任务的元数据信息中提取出来的相关 GID。
}
//作用是判断任务是否值得保存。它通过检查任务的注释信息是否为null来确定任务是否值得保存。
@Override
public boolean isWorthSaving() {
return getNotes() != null;
return getNotes() != null;//如果注释信息不为null则返回true表示任务值得保存反之如果注释信息为null则返回false表示任务不值得保存。
}
/**
* JSON Task
* @param js JSONObject
*/
@Override
public void setContentByRemoteJSON(JSONObject js) {
super.setContentByRemoteJSON(js);
if (getNotes() != null) {
/**
* GID mRelatedGid
* 使try-catch
*/
try {
JSONObject metaInfo = new JSONObject(getNotes().trim());
mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID);
@ -66,7 +96,7 @@ public class MetaData extends Task {
@Override
public void setContentByLocalJSON(JSONObject js) {
// this function should not be called
throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");
throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");//抛出一个IllegalAccessError异常并且提供异常的详细描述信息
}
@Override

@ -20,24 +20,33 @@ import android.database.Cursor;
import org.json.JSONObject;
/**
* @Package: net.micode.notes.gtask.data
* @ClassName: Node
* @Description:
* Node
* *
* @Author: Dong Jiaqi
* @CreateDate: 12/24/2023 10:23 AM
*/
public abstract class Node {
public static final int SYNC_ACTION_NONE = 0;
public static final int SYNC_ACTION_NONE = 0;//表示没有同步操作。
public static final int SYNC_ACTION_ADD_REMOTE = 1;
public static final int SYNC_ACTION_ADD_REMOTE = 1;//表示远程添加操作。
public static final int SYNC_ACTION_ADD_LOCAL = 2;
public static final int SYNC_ACTION_ADD_LOCAL = 2;//表示本地添加操作。
public static final int SYNC_ACTION_DEL_REMOTE = 3;
public static final int SYNC_ACTION_DEL_REMOTE = 3;//表示远程删除操作。
public static final int SYNC_ACTION_DEL_LOCAL = 4;
public static final int SYNC_ACTION_DEL_LOCAL = 4;//表示本地删除操作。
public static final int SYNC_ACTION_UPDATE_REMOTE = 5;
public static final int SYNC_ACTION_UPDATE_REMOTE = 5;//表示远程更新操作。
public static final int SYNC_ACTION_UPDATE_LOCAL = 6;
public static final int SYNC_ACTION_UPDATE_LOCAL = 6;//表示本地更新操作。
public static final int SYNC_ACTION_UPDATE_CONFLICT = 7;
public static final int SYNC_ACTION_UPDATE_CONFLICT = 7;//表示更新冲突操作。
public static final int SYNC_ACTION_ERROR = 8;
public static final int SYNC_ACTION_ERROR = 8;//表示同步错误操作。
private String mGid;
@ -66,34 +75,66 @@ public abstract class Node {
public abstract int getSyncAction(Cursor c);
/**
* gid
* @param gid
*/
public void setGid(String gid) {
this.mGid = gid;
}
/**
* name mName
* @param name
*/
public void setName(String name) {
this.mName = name;
}
/**
* lastModified mLastModified
* @param lastModified
*/
public void setLastModified(long lastModified) {
this.mLastModified = lastModified;
}
/**
* deleted mDeleted
* @param deleted true false
*/
public void setDeleted(boolean deleted) {
this.mDeleted = deleted;
}
/**
* gid mGid
* @return this.mGid
*/
public String getGid() {
return this.mGid;
}
/**
* mName
* @return this.mName
*/
public String getName() {
return this.mName;
}
/**
* mLastModified
* @return this.mLastModified
*/
public long getLastModified() {
return this.mLastModified;
}
/**
* mDeleted
* @return true false
*/
public boolean getDeleted() {
return this.mDeleted;
}

@ -34,26 +34,33 @@ import net.micode.notes.gtask.exception.ActionFailureException;
import org.json.JSONException;
import org.json.JSONObject;
/**
* @Package: net.micode.notes.gtask.data
* @ClassName: SqlData
* @Description:
*
* @Author: Dong Jiaqi
* @CreateDate: 12/24/2023 10:58 AM
*/
public class SqlData {
private static final String TAG = SqlData.class.getSimpleName();
private static final int INVALID_ID = -99999;
private static final int INVALID_ID = -99999;//定义了一个名为 INVALID_ID 的私有静态整型常量,并赋值为 -99999被用来表示无效的 ID 值。
public static final String[] PROJECTION_DATA = new String[] {
DataColumns.ID, DataColumns.MIME_TYPE, DataColumns.CONTENT, DataColumns.DATA1,
DataColumns.DATA3
};
};//定义了一个名为 PROJECTION_DATA 的字符串数组,其中包含了一组列名
public static final int DATA_ID_COLUMN = 0;
public static final int DATA_ID_COLUMN = 0;//表示数据的 ID 在数据列中的索引位置,即第一列。
public static final int DATA_MIME_TYPE_COLUMN = 1;
public static final int DATA_MIME_TYPE_COLUMN = 1;//表示数据的 MIME 类型在数据列中的索引位置,即第二列。
public static final int DATA_CONTENT_COLUMN = 2;
public static final int DATA_CONTENT_COLUMN = 2;//表示数据的内容在数据列中的索引位置,即第三列。
public static final int DATA_CONTENT_DATA_1_COLUMN = 3;
public static final int DATA_CONTENT_DATA_1_COLUMN = 3;//表示数据的内容数据1在数据列中的索引位置即第四列。
public static final int DATA_CONTENT_DATA_3_COLUMN = 4;
public static final int DATA_CONTENT_DATA_3_COLUMN = 4;//表示数据的内容数据3在数据列中的索引位置即第五列。
private ContentResolver mContentResolver;
@ -71,36 +78,54 @@ public class SqlData {
private ContentValues mDiffDataValues;
/**
* Context
* @param context 便
*/
public SqlData(Context context) {
mContentResolver = context.getContentResolver();
mContentResolver = context.getContentResolver();//这是构造方法的定义,表明这是一个公共的构造方法,并且接受一个 Context 类型的参数。
mIsCreate = true;
mDataId = INVALID_ID;
mDataMimeType = DataConstants.NOTE;
mDataContent = "";
mDataContent = "";//成员变量初始化
mDataContentData1 = 0;
mDataContentData3 = "";
mDiffDataValues = new ContentValues();
mDiffDataValues = new ContentValues();//创建新的ContentValues对象
}
/**
* ContextCursorCursor
* @param context 便
* @param c Cursor
*/
public SqlData(Context context, Cursor c) {
mContentResolver = context.getContentResolver();
mIsCreate = false;
loadFromCursor(c);
loadFromCursor(c);//调用 loadFromCursor() 方法,将传入的 Cursor 对象作为参数,以从 Cursor 对象中加载数据库中的数据到 SqlData 对象的成员变量中。
mDiffDataValues = new ContentValues();
}
/**
* Cursor SqlData
* @param c Cursor
*/
private void loadFromCursor(Cursor c) {
mDataId = c.getLong(DATA_ID_COLUMN);
mDataMimeType = c.getString(DATA_MIME_TYPE_COLUMN);
mDataId = c.getLong(DATA_ID_COLUMN);//从 Cursor 对象中获取指定列索引为 DATA_ID_COLUMN 的长整型数据,并赋值给 mDataId 成员变量。
mDataMimeType = c.getString(DATA_MIME_TYPE_COLUMN);//从 Cursor 对象中获取指定列索引为 DATA_MIME_TYPE_COLUMN 的字符串数据,并赋值给 mDataMimeType 成员变量。
mDataContent = c.getString(DATA_CONTENT_COLUMN);
mDataContentData1 = c.getLong(DATA_CONTENT_DATA_1_COLUMN);
mDataContentData3 = c.getString(DATA_CONTENT_DATA_3_COLUMN);
}
/**
* JSONJSONmDiffDataValues
* @param js JSONObject
* @throws JSONException
*/
public void setContent(JSONObject js) throws JSONException {
long dataId = js.has(DataColumns.ID) ? js.getLong(DataColumns.ID) : INVALID_ID;
if (mIsCreate || mDataId != dataId) {
mDiffDataValues.put(DataColumns.ID, dataId);
long dataId = js.has(DataColumns.ID) ? js.getLong(DataColumns.ID) : INVALID_ID;//检查 JSON 对象 js 中是否包含名为 DataColumns.ID 的字段,如果包含则将其转换为 long 类型并赋给 dataId否则将 INVALID_ID 赋给 dataId。
if (mIsCreate || mDataId != dataId) {//检查是否正在创建新数据mIsCreate 为 true或者已有数据的 dataId 是否与新获取的 dataId 不同。
mDiffDataValues.put(DataColumns.ID, dataId);//如果满足条件,则将 DataColumns.ID 和对应的 dataId 放入 mDiffDataValues 中。
}
mDataId = dataId;
@ -130,42 +155,53 @@ public class SqlData {
mDataContentData3 = dataContentData3;
}
/**
* JSON
* @return JSONObject SqlData 使 null
* @throws JSONException
*/
public JSONObject getContent() throws JSONException {
if (mIsCreate) {
Log.e(TAG, "it seems that we haven't created this in database yet");
return null;
}
JSONObject js = new JSONObject();
js.put(DataColumns.ID, mDataId);
js.put(DataColumns.MIME_TYPE, mDataMimeType);
js.put(DataColumns.ID, mDataId);//将类的成员变量 mDataId 的值存储到 js 对象中,使用键名 DataColumns.ID。
js.put(DataColumns.MIME_TYPE, mDataMimeType);//将类的成员变量 mDataMimeType 的值存储到 js 对象中,使用键名 DataColumns.MIME_TYPE
js.put(DataColumns.CONTENT, mDataContent);
js.put(DataColumns.DATA1, mDataContentData1);
js.put(DataColumns.DATA3, mDataContentData3);
return js;
}
/**
* IDmDiffDataValues
* @param noteId 便ID便ID
* @param validateVersion
* @param version
*/
public void commit(long noteId, boolean validateVersion, long version) {
if (mIsCreate) {
if (mIsCreate) {//如果数据是新创建的
if (mDataId == INVALID_ID && mDiffDataValues.containsKey(DataColumns.ID)) {
mDiffDataValues.remove(DataColumns.ID);
}
mDiffDataValues.put(DataColumns.NOTE_ID, noteId);
Uri uri = mContentResolver.insert(Notes.CONTENT_DATA_URI, mDiffDataValues);
mDiffDataValues.put(DataColumns.NOTE_ID, noteId); //设置便签的ID
Uri uri = mContentResolver.insert(Notes.CONTENT_DATA_URI, mDiffDataValues);//向数据库中插入数据
try {
mDataId = Long.valueOf(uri.getPathSegments().get(1));
} catch (NumberFormatException e) {
Log.e(TAG, "Get note id error :" + e.toString());
throw new ActionFailureException("create note failed");
}
} else {
} else {//如果不是新创建的数据
if (mDiffDataValues.size() > 0) {
int result = 0;
if (!validateVersion) {
if (!validateVersion) {//如果不用验证版本,直接更新数据
result = mContentResolver.update(ContentUris.withAppendedId(
Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues, null, null);
} else {
} else {//如果要验证版本,根据版本号更新数据
result = mContentResolver.update(ContentUris.withAppendedId(
Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues,
" ? in (SELECT " + NoteColumns.ID + " FROM " + TABLE.NOTE
@ -179,10 +215,14 @@ public class SqlData {
}
}
mDiffDataValues.clear();
mDiffDataValues.clear();//提交后清空数据
mIsCreate = false;
}
/**
* mDataId
* @return ID
*/
public long getId() {
return mDataId;
}

@ -37,7 +37,14 @@ import org.json.JSONObject;
import java.util.ArrayList;
/**
* @Package: net.micode.notes.gtask.data
* @ClassName: SqlNote
* @Description:
* SqlNote便便
* @Author: Dong Jiaqi
* @CreateDate: 12/24/2023 1718 PM
*/
public class SqlNote {
private static final String TAG = SqlNote.class.getSimpleName();
@ -52,9 +59,9 @@ public class SqlNote {
NoteColumns.VERSION
};
public static final int ID_COLUMN = 0;
public static final int ID_COLUMN = 0;//便签的ID列的索引为0
public static final int ALERTED_DATE_COLUMN = 1;
public static final int ALERTED_DATE_COLUMN = 1;//提醒日期列的索引为1
public static final int BG_COLOR_ID_COLUMN = 2;
@ -120,8 +127,12 @@ public class SqlNote {
private ContentValues mDiffNoteValues;
private ArrayList<SqlData> mDataList;
private ArrayList<SqlData> mDataList;//用Java中的ArrayList类定义了一个SqlData对象 mDataList用于存储从数据库查询中返回的便签数据
/**
* SqlNote SqlNote
* @param context 使
*/
public SqlNote(Context context) {
mContext = context;
mContentResolver = context.getContentResolver();
@ -143,6 +154,11 @@ public class SqlNote {
mDataList = new ArrayList<SqlData>();
}
/**
* SqlNote Cursor
* @param context 使
* @param c
*/
public SqlNote(Context context, Cursor c) {
mContext = context;
mContentResolver = context.getContentResolver();
@ -154,6 +170,11 @@ public class SqlNote {
mDiffNoteValues = new ContentValues();
}
/**
* SqlNote ID
* @param context 使
* @param id 便ID
*/
public SqlNote(Context context, long id) {
mContext = context;
mContentResolver = context.getContentResolver();
@ -166,8 +187,17 @@ public class SqlNote {
}
/**
* ID 便 SqlNote
* @param id 便 ID
*/
private void loadFromCursor(long id) {
Cursor c = null;
/**
* try-finally
*
* finally
*/
try {
c = mContentResolver.query(Notes.CONTENT_NOTE_URI, PROJECTION_NOTE, "(_id=?)",
new String[] {
@ -185,6 +215,10 @@ public class SqlNote {
}
}
/**
* 便 SqlNote
* @param c
*/
private void loadFromCursor(Cursor c) {
mId = c.getLong(ID_COLUMN);
mAlertDate = c.getLong(ALERTED_DATE_COLUMN);
@ -200,9 +234,17 @@ public class SqlNote {
mVersion = c.getLong(VERSION_COLUMN);
}
/**
* ID
* 便
*/
private void loadDataContent() {
Cursor c = null;
mDataList.clear();
/**
* ID mDataList
*
*/
try {
c = mContentResolver.query(Notes.CONTENT_DATA_URI, SqlData.PROJECTION_DATA,
"(note_id=?)", new String[] {
@ -226,7 +268,19 @@ public class SqlNote {
}
}
/**
* JSONObject
* JSONObjectmDiffNoteValues
* @param js JSONObject
* @return truefalse
*/
public boolean setContent(JSONObject js) {
/**
* tryJSONJSONExceptioncatch
* catchfalse
*
*/
try {
JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_SYSTEM) {
@ -237,14 +291,14 @@ public class SqlNote {
.getString(NoteColumns.SNIPPET) : "";
if (mIsCreate || !mSnippet.equals(snippet)) {
mDiffNoteValues.put(NoteColumns.SNIPPET, snippet);
}
}//判断是否需要更新笔记的摘要snippet。它通过比较当前对象的mSnippet属性和传入的参数snippet如果两者不相等则将新的摘要值存储在mDiffNoteValues中。
mSnippet = snippet;
int type = note.has(NoteColumns.TYPE) ? note.getInt(NoteColumns.TYPE)
: Notes.TYPE_NOTE;
if (mIsCreate || mType != type) {
mDiffNoteValues.put(NoteColumns.TYPE, type);
}
}//检查是否正在创建新的笔记mIsCreate为true或者当前笔记的类型与传入的类型值不相等mType != type。如果满足其中一个条件就会将新的类型值存储在mDiffNoteValues中。
mType = type;
} else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_NOTE) {
JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA);
@ -359,6 +413,10 @@ public class SqlNote {
return true;
}
/**
* JSON
* @return JSONObject
*/
public JSONObject getContent() {
try {
JSONObject js = new JSONObject();
@ -407,39 +465,74 @@ public class SqlNote {
return null;
}
/**
* IDmDiffNoteValues
* @param id longID
*/
public void setParentId(long id) {
mParentId = id;
mDiffNoteValues.put(NoteColumns.PARENT_ID, id);
}
/**
* Google TasksIDgidmDiffNoteValues便
* @param gid Google TasksID
*/
public void setGtaskId(String gid) {
mDiffNoteValues.put(NoteColumns.GTASK_ID, gid);
}
/**
* IDsyncIdmDiffNoteValues便
* @param syncId longID
*/
public void setSyncId(long syncId) {
mDiffNoteValues.put(NoteColumns.SYNC_ID, syncId);
}
/**
*
*/
public void resetLocalModified() {
mDiffNoteValues.put(NoteColumns.LOCAL_MODIFIED, 0);
}
/**
* ID
* @return ID
*/
public long getId() {
return mId;
}
/**
* ID
* @return ID
*/
public long getParentId() {
return mParentId;
}
/**
*
* @return
*/
public String getSnippet() {
return mSnippet;
}
/**
* 便
* @return 便便truefalse
*/
public boolean isNoteType() {
return mType == Notes.TYPE_NOTE;
}
/**
*
* @param validateVersion true
*/
public void commit(boolean validateVersion) {
if (mIsCreate) {
if (mId == INVALID_ID && mDiffNoteValues.containsKey(NoteColumns.ID)) {

@ -31,7 +31,16 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/**
* @Package: net.micode.notes.gtask.data
* @ClassName: Task
* @Description:
* TaskNodeGoogle使
*
* JSON便Google
* @Author: Dong Jiaqi
* @CreateDate: 12/24/2023 1948 PM
*/
public class Task extends Node {
private static final String TAG = Task.class.getSimpleName();
@ -45,17 +54,27 @@ public class Task extends Node {
private TaskList mParent;
/**
*
* null
*/
public Task() {
super();
mCompleted = false;
mNotes = null;
mPriorSibling = null;
mParent = null;
mMetaInfo = null;
super();//调用父类Node的构造方法确保父类的属性得到正确初始化
mCompleted = false;//任务完成状态设置为未完成
mNotes = null;//暂时没有便签笔记
mPriorSibling = null;//当前任务没有前节点
mParent = null;//当前任务没有父节点
mMetaInfo = null;//当前任务没有元数据信息
}
/**
* JSON
* JSONActionFailureException
* @param actionId
* @return JSONObject
*/
public JSONObject getCreateAction(int actionId) {
JSONObject js = new JSONObject();
JSONObject js = new JSONObject();//创建一个空的JSONObject对象。
try {
// action_type
@ -97,12 +116,17 @@ public class Task extends Node {
} catch (JSONException e) {
Log.e(TAG, e.toString());
e.printStackTrace();
throw new ActionFailureException("fail to generate task-create jsonobject");
throw new ActionFailureException("fail to generate task-create jsonobject");//抛出异常
}
return js;
}
/**
* JSON
* @param actionId
* @return JSONObject
*/
public JSONObject getUpdateAction(int actionId) {
JSONObject js = new JSONObject();
@ -135,6 +159,11 @@ public class Task extends Node {
return js;
}
/**
* JSONObject
* JSON
* @param js JSONObject
*/
public void setContentByRemoteJSON(JSONObject js) {
if (js != null) {
try {
@ -175,17 +204,25 @@ public class Task extends Node {
}
}
/**
* JSONObject
* @param js
*/
public void setContentByLocalJSON(JSONObject js) {
if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)
|| !js.has(GTaskStringUtils.META_HEAD_DATA)) {
Log.w(TAG, "setContentByLocalJSON: nothing is avaiable");
}
/**
* JSONObject
* 便便
*/
try {
JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA);
if (note.getInt(NoteColumns.TYPE) != Notes.TYPE_NOTE) {
if (note.getInt(NoteColumns.TYPE) != Notes.TYPE_NOTE) {//检查便签类型是不是普通便签
Log.e(TAG, "invalid type");
return;
}
@ -204,6 +241,11 @@ public class Task extends Node {
}
}
/**
* JSONObject
* @return JSONObjectjs
* mMetaInfo
*/
public JSONObject getLocalJSONFromContent() {
String name = getName();
try {
@ -247,6 +289,10 @@ public class Task extends Node {
}
}
/**
*
* @param metaData MetaData
*/
public void setMetaInfo(MetaData metaData) {
if (metaData != null && metaData.getNotes() != null) {
try {
@ -258,6 +304,16 @@ public class Task extends Node {
}
}
/**
* Cursor
* @param c Cursorc
* @return
* SYNC_ACTION_NONE
* SYNC_ACTION_UPDATE_LOCAL
* SYNC_ACTION_UPDATE_REMOTE
* SYNC_ACTION_UPDATE_CONFLICT
* SYNC_ACTION_ERROR
*/
public int getSyncAction(Cursor c) {
try {
JSONObject noteInfo = null;
@ -311,39 +367,80 @@ public class Task extends Node {
return SYNC_ACTION_ERROR;
}
/**
*
* @return booleantruefalse
*/
public boolean isWorthSaving() {
return mMetaInfo != null || (getName() != null && getName().trim().length() > 0)
|| (getNotes() != null && getNotes().trim().length() > 0);
}
/**
*
* 便
* @param completed boolean
*/
public void setCompleted(boolean completed) {
this.mCompleted = completed;
}
/**
*
* 便
* @param notes String
*/
public void setNotes(String notes) {
this.mNotes = notes;
}
/**
*
*
* @param priorSibling Task
*/
public void setPriorSibling(Task priorSibling) {
this.mPriorSibling = priorSibling;
}
/**
*
*
* @param parent TaskList
*/
public void setParent(TaskList parent) {
this.mParent = parent;
}
/**
*
* 便
* @return booleantruefalse
*/
public boolean getCompleted() {
return this.mCompleted;
}
/**
*
* @return String
*/
public String getNotes() {
return this.mNotes;
}
/**
*
* @return Tasknull
*/
public Task getPriorSibling() {
return this.mPriorSibling;
}
/**
*
* @return TaskListnull
*/
public TaskList getParent() {
return this.mParent;
}

@ -30,19 +30,36 @@ import org.json.JSONObject;
import java.util.ArrayList;
/**
* @Package: net.micode.notes.gtask.data
* @ClassName: TaskList
* @Description:
* TaskListNode
* JSON
* @Author: Dong Jiaqi
* @CreateDate: 12/24/2023 2048 PM
*/
public class TaskList extends Node {
private static final String TAG = TaskList.class.getSimpleName();
private static final String TAG = TaskList.class.getSimpleName();//私有静态常量,用于在日志和调试中标识类名。
private int mIndex;
private int mIndex;//私有整型变量,表示任务列表的索引。
private ArrayList<Task> mChildren;
private ArrayList<Task> mChildren;//私有ArrayList存储Task对象表示该任务列表下的子任务列表。
/**
* mChildrenTaskmIndex1
*/
public TaskList() {
super();
mChildren = new ArrayList<Task>();
mIndex = 1;
}
/**
* actionIdJSONObject
* @param actionId ID
* @return JSONObject
*/
public JSONObject getCreateAction(int actionId) {
JSONObject js = new JSONObject();
@ -74,6 +91,11 @@ public class TaskList extends Node {
return js;
}
/**
* actionIdJSONObject
* @param actionId ID
* @return JSONObject
*/
public JSONObject getUpdateAction(int actionId) {
JSONObject js = new JSONObject();
@ -103,6 +125,10 @@ public class TaskList extends Node {
return js;
}
/**
* JSON
* @param js JSONObject
*/
public void setContentByRemoteJSON(JSONObject js) {
if (js != null) {
try {
@ -129,6 +155,10 @@ public class TaskList extends Node {
}
}
/**
* JSON
* @param js JSONObject
*/
public void setContentByLocalJSON(JSONObject js) {
if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)) {
Log.w(TAG, "setContentByLocalJSON: nothing is avaiable");
@ -157,6 +187,10 @@ public class TaskList extends Node {
}
}
/**
* JSON
* @return JSONObject
*/
public JSONObject getLocalJSONFromContent() {
try {
JSONObject js = new JSONObject();
@ -183,6 +217,17 @@ public class TaskList extends Node {
}
}
/**
*
* @param c Cursor
* @return
* SYNC_ACTION_NONE
* SYNC_ACTION_UPDATE_LOCAL
* SYNC_ACTION_ERROR
* SYNC_ACTION_UPDATE_REMOTEID,
* SYNC_ACTION_UPDATE_REMOTEID,
* SYNC_ACTION_ERROR
*/
public int getSyncAction(Cursor c) {
try {
if (c.getInt(SqlNote.LOCAL_MODIFIED_COLUMN) == 0) {
@ -216,10 +261,19 @@ public class TaskList extends Node {
return SYNC_ACTION_ERROR;
}
/**
*
* @return
*/
public int getChildTaskCount() {
return mChildren.size();
}
/**
*
* @param task
* @return boolean:truefalse
*/
public boolean addChildTask(Task task) {
boolean ret = false;
if (task != null && !mChildren.contains(task)) {
@ -234,6 +288,12 @@ public class TaskList extends Node {
return ret;
}
/**
*
* @param task
* @param index 0
* @return boolean:truefalse
*/
public boolean addChildTask(Task task, int index) {
if (index < 0 || index > mChildren.size()) {
Log.e(TAG, "add child task: invalid index");
@ -260,6 +320,11 @@ public class TaskList extends Node {
return true;
}
/**
*
* @param task
* @return boolean:truefalse
*/
public boolean removeChildTask(Task task) {
boolean ret = false;
int index = mChildren.indexOf(task);
@ -281,6 +346,12 @@ public class TaskList extends Node {
return ret;
}
/**
*
* @param task
* @param index 0
* @return boolean:truefalse
*/
public boolean moveChildTask(Task task, int index) {
if (index < 0 || index >= mChildren.size()) {
@ -299,6 +370,11 @@ public class TaskList extends Node {
return (removeChildTask(task) && addChildTask(task, index));
}
/**
*
* @param gid gid()
* @return Taskgidnull
*/
public Task findChildTaskByGid(String gid) {
for (int i = 0; i < mChildren.size(); i++) {
Task t = mChildren.get(i);
@ -309,10 +385,20 @@ public class TaskList extends Node {
return null;
}
/**
*
* @param task
* @return int:0-1
*/
public int getChildTaskIndex(Task task) {
return mChildren.indexOf(task);
}
/**
*
* @param index 0
* @return Tasknull
*/
public Task getChildTaskByIndex(int index) {
if (index < 0 || index >= mChildren.size()) {
Log.e(TAG, "getTaskByIndex: invalid index");
@ -321,6 +407,11 @@ public class TaskList extends Node {
return mChildren.get(index);
}
/**
*
* @param gid gid
* @return Taskgidnull
*/
public Task getChilTaskByGid(String gid) {
for (Task task : mChildren) {
if (task.getGid().equals(gid))
@ -329,14 +420,26 @@ public class TaskList extends Node {
return null;
}
/**
*
* @return ArrayList<Task>ArrayList
*/
public ArrayList<Task> getChildTaskList() {
return this.mChildren;
}
/**
*
* @param index
*/
public void setIndex(int index) {
this.mIndex = index;
}
/**
*
* @return
*/
public int getIndex() {
return this.mIndex;
}

Loading…
Cancel
Save