From 1707eb1e7c60c66d1fb18ffc6efa41e168f72fa1 Mon Sep 17 00:00:00 2001 From: lxf <1829758450@qq.com> Date: Thu, 15 May 2025 09:36:48 +0800 Subject: [PATCH] =?UTF-8?q?lxf-2nd-commit,=E6=B7=BB=E5=8A=A0data=E5=8C=85?= =?UTF-8?q?=E4=B8=8B=E7=9A=84=E9=83=A8=E5=88=86=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/AndroidProjectSystem.xml | 6 + .idea/deploymentTargetSelector.xml | 10 ++ .idea/gradle.xml | 3 +- .idea/misc.xml | 1 - .idea/runConfigurations.xml | 17 ++ .idea/vcs.xml | 6 + app/build.gradle.kts | 5 +- .../java/net/micode/notes/data/Contact.java | 9 ++ .../java/net/micode/notes/data/Notes.java | 146 ++++++------------ .../notes/data/NotesDatabaseHelper.java | 79 ++++------ .../net/micode/notes/data/NotesProvider.java | 19 ++- gradle/libs.versions.toml | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- 13 files changed, 145 insertions(+), 160 deletions(-) create mode 100644 .idea/AndroidProjectSystem.xml create mode 100644 .idea/deploymentTargetSelector.xml create mode 100644 .idea/runConfigurations.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/AndroidProjectSystem.xml b/.idea/AndroidProjectSystem.xml new file mode 100644 index 0000000..4a53bee --- /dev/null +++ b/.idea/AndroidProjectSystem.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml new file mode 100644 index 0000000..b268ef3 --- /dev/null +++ b/.idea/deploymentTargetSelector.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index b148fa1..5ef3273 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -4,8 +4,8 @@ diff --git a/.idea/misc.xml b/.idea/misc.xml index 0ad17cb..8978d23 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,3 @@ - diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..16660f1 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts index c0fcb59..fac1378 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -5,8 +5,8 @@ plugins { android { namespace = "net.micode.notes" - compileSdk = 34 - buildToolsVersion ="34.0.0" + compileSdk = 35 +// buildToolsVersion ="34.0.0" defaultConfig { applicationId = "net.micode.notes" @@ -35,7 +35,6 @@ android { resources.excludes.add("META-INF/LICENSE.txt") resources.excludes.add("META-INF/NOTICE.txt") } - buildToolsVersion = "30.0.2" } dependencies { diff --git a/app/src/main/java/net/micode/notes/data/Contact.java b/app/src/main/java/net/micode/notes/data/Contact.java index d97ac5d..c02756a 100644 --- a/app/src/main/java/net/micode/notes/data/Contact.java +++ b/app/src/main/java/net/micode/notes/data/Contact.java @@ -25,10 +25,13 @@ import android.util.Log; import java.util.HashMap; + public class Contact { + //缓存联系人信息,防止频繁查询联系人数据库 private static HashMap sContactCache; private static final String TAG = "Contact"; + //查询联系人数据库的查询条件 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 " @@ -36,6 +39,12 @@ public class Contact { + " FROM phone_lookup" + " WHERE min_match = '+')"; + /** + * 根据电话号码获取联系人信息 + * 如果联系人信息存在缓存中,则直接从缓存中获取 + * 如果联系人信息不存在缓存中,则从联系人数据库中查询 + * 并将查询结果存入缓存中,以便下次查询时直接从缓存中获取 + */ public static String getContact(Context context, String phoneNumber) { if(sContactCache == null) { sContactCache = new HashMap(); diff --git a/app/src/main/java/net/micode/notes/data/Notes.java b/app/src/main/java/net/micode/notes/data/Notes.java index f240604..7261a51 100644 --- a/app/src/main/java/net/micode/notes/data/Notes.java +++ b/app/src/main/java/net/micode/notes/data/Notes.java @@ -17,6 +17,13 @@ package net.micode.notes.data; import android.net.Uri; + +//这个类定义了一些常量,用于表示不同的类型和标识符 +//例如,AUTHORITY表示内容提供者的身份,TAG表示日志的标签,TYPE_NOTE表示笔记的类型,ID_ROOT_FOLDER表示根文件夹的标识符等 +//这些常量可以在其他类中使用,以提供更清晰和易于理解的代码 +//例如,在Notes类中,可以使用Notes.AUTHORITY来表示内容提供者的身份,而不是直接使用字符串"micode_notes" +//这样可以避免在代码中出现拼写错误或不一致的字符串,提高代码的可读性和可维护性 +//例如,在Notes类中,可以使用Notes.TAG来表示日志的标签,而不是直接使用字符串"Notes" public class Notes { public static final String AUTHORITY = "micode_notes"; public static final String TAG = "Notes"; @@ -30,6 +37,14 @@ public class Notes { * {@link Notes#ID_TEMPARAY_FOLDER } is for notes belonging no folder * {@link Notes#ID_CALL_RECORD_FOLDER} is to store call records */ + + /* + 以下是系统文件夹的标识符 + ID_ROOT_FOLDER是默认文件夹 + ID_TEMPARAY_FOLDER是用于存储没有文件夹的笔记 + ID_CALL_RECORD_FOLDER是用于存储电话记录的文件夹 + ID_TRASH_FOLER是用于存储垃圾邮件的文件夹 + */ public static final int ID_ROOT_FOLDER = 0; public static final int ID_TEMPARAY_FOLDER = -1; public static final int ID_CALL_RECORD_FOLDER = -2; @@ -51,157 +66,86 @@ public class Notes { public static final String CALL_NOTE = CallNote.CONTENT_ITEM_TYPE; } - /** - * Uri to query all notes and folders - */ + //用于查询所有笔记和文件夹的统一资源标识符 public static final Uri CONTENT_NOTE_URI = Uri.parse("content://" + AUTHORITY + "/note"); - /** - * Uri to query data - */ + //用于查询所有数据的统一资源标识符 + //数据可以是笔记或文件夹 public static final Uri CONTENT_DATA_URI = Uri.parse("content://" + AUTHORITY + "/data"); public interface NoteColumns { - /** - * The unique ID for a row - *

Type: INTEGER (long)

- */ + //用于查询所有笔记的统一资源标识符 + public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/note"); + + //常量表示笔记的唯一标识符 + //这个常量用于在查询笔记时指定要查询的列 public static final String ID = "_id"; - /** - * The parent's id for note or folder - *

Type: INTEGER (long)

- */ + //常量表示笔记的标题 public static final String PARENT_ID = "parent_id"; - /** - * Created data for note or folder - *

Type: INTEGER (long)

- */ + //常量表示笔记的创建日期 public static final String CREATED_DATE = "created_date"; - /** - * Latest modified date - *

Type: INTEGER (long)

- */ + //常量表示笔记的修改日期 public static final String MODIFIED_DATE = "modified_date"; - - /** - * Alert date - *

Type: INTEGER (long)

- */ + //常量表示笔记的提醒日期 public static final String ALERTED_DATE = "alert_date"; - /** - * Folder's name or text content of note - *

Type: TEXT

- */ public static final String SNIPPET = "snippet"; - /** - * Note's widget id - *

Type: INTEGER (long)

- */ + //常量表示部件的ID public static final String WIDGET_ID = "widget_id"; - /** - * Note's widget type - *

Type: INTEGER (long)

- */ + //常量表示部件的类型 public static final String WIDGET_TYPE = "widget_type"; - /** - * Note's background color's id - *

Type: INTEGER (long)

- */ + //常量表示笔记的背景颜色ID public static final String BG_COLOR_ID = "bg_color_id"; - /** - * For text note, it doesn't has attachment, for multi-media - * note, it has at least one attachment - *

Type: INTEGER

- */ + //常量表示有附件的标志 public static final String HAS_ATTACHMENT = "has_attachment"; - /** - * Folder's count of notes - *

Type: INTEGER (long)

- */ + //常量表示笔记的数量 public static final String NOTES_COUNT = "notes_count"; - /** - * The file type: folder or note - *

Type: INTEGER

- */ + //常量表示笔记的类型 public static final String TYPE = "type"; - /** - * The last sync id - *

Type: INTEGER (long)

- */ + //常量表示笔记的同步ID public static final String SYNC_ID = "sync_id"; - /** - * Sign to indicate local modified or not - *

Type: INTEGER

- */ + //常量表示本地修改的标志 public static final String LOCAL_MODIFIED = "local_modified"; - /** - * Original parent id before moving into temporary folder - *

Type : INTEGER

- */ + //常量表示原始父ID public static final String ORIGIN_PARENT_ID = "origin_parent_id"; - /** - * The gtask id - *

Type : TEXT

- */ + //常量表示Google任务的ID public static final String GTASK_ID = "gtask_id"; - /** - * The version code - *

Type : INTEGER (long)

- */ + //常量表示版本号 public static final String VERSION = "version"; } public interface DataColumns { - /** - * The unique ID for a row - *

Type: INTEGER (long)

- */ + //用于查询所有数据的统一资源标识符 public static final String ID = "_id"; - /** - * The MIME type of the item represented by this row. - *

Type: Text

- */ + //数据的MIME类型 public static final String MIME_TYPE = "mime_type"; - /** - * The reference id to note that this data belongs to - *

Type: INTEGER (long)

- */ + //笔记的父ID public static final String NOTE_ID = "note_id"; - /** - * Created data for note or folder - *

Type: INTEGER (long)

- */ + //笔记的创建日期 public static final String CREATED_DATE = "created_date"; - /** - * Latest modified date - *

Type: INTEGER (long)

- */ + //笔记的修改日期 public static final String MODIFIED_DATE = "modified_date"; - /** - * Data's content - *

Type: TEXT

- */ + //笔记的内容 public static final String CONTENT = "content"; @@ -241,6 +185,7 @@ public class Notes { public static final String DATA5 = "data5"; } + //用来存储一些静态常量 public static final class TextNote implements DataColumns { /** * Mode to indicate the text in check list mode or not @@ -257,6 +202,7 @@ public class Notes { public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/text_note"); } + //用来存储一些静态常量 public static final class CallNote implements DataColumns { /** * Call date for this record diff --git a/app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java b/app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java index ffe5d57..bd7043b 100644 --- a/app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java +++ b/app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java @@ -27,6 +27,7 @@ import net.micode.notes.data.Notes.DataConstants; import net.micode.notes.data.Notes.NoteColumns; +//笔记数据库的数据库辅助类,用于创建和升级数据库 public class NotesDatabaseHelper extends SQLiteOpenHelper { private static final String DB_NAME = "note.db"; @@ -42,6 +43,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { private static NotesDatabaseHelper mInstance; + //创建笔记表的SQL语句,用于存储笔记 private static final String CREATE_NOTE_TABLE_SQL = "CREATE TABLE " + TABLE.NOTE + "(" + NoteColumns.ID + " INTEGER PRIMARY KEY," + @@ -63,6 +65,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0" + ")"; + //创造数据表的SQL语句,用于存储数据 private static final String CREATE_DATA_TABLE_SQL = "CREATE TABLE " + TABLE.DATA + "(" + DataColumns.ID + " INTEGER PRIMARY KEY," + @@ -78,13 +81,12 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { DataColumns.DATA5 + " TEXT NOT NULL DEFAULT ''" + ")"; + //创建索引,用于提高查询效率 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 "+ " AFTER UPDATE OF " + NoteColumns.PARENT_ID + " ON " + TABLE.NOTE + @@ -94,9 +96,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " WHERE " + NoteColumns.ID + "=new." + NoteColumns.PARENT_ID + ";" + " 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 " + " AFTER UPDATE OF " + NoteColumns.PARENT_ID + " ON " + TABLE.NOTE + @@ -107,9 +107,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " AND " + NoteColumns.NOTES_COUNT + ">0" + ";" + " 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 " + " AFTER INSERT ON " + TABLE.NOTE + @@ -119,9 +117,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " WHERE " + NoteColumns.ID + "=new." + NoteColumns.PARENT_ID + ";" + " 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 " + " AFTER DELETE ON " + TABLE.NOTE + @@ -132,9 +128,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " AND " + NoteColumns.NOTES_COUNT + ">0;" + " 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 " + " AFTER INSERT ON " + TABLE.DATA + @@ -145,9 +139,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " WHERE " + NoteColumns.ID + "=new." + DataColumns.NOTE_ID + ";" + " END"; - /** - * Update note's content when data with {@link DataConstants#NOTE} type has changed - */ + //当类型为{@link DataConstants#NOTE}的数据发生变化时,更新笔记内容 private static final String DATA_UPDATE_NOTE_CONTENT_ON_UPDATE_TRIGGER = "CREATE TRIGGER update_note_content_on_update " + " AFTER UPDATE ON " + TABLE.DATA + @@ -158,9 +150,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " WHERE " + NoteColumns.ID + "=new." + DataColumns.NOTE_ID + ";" + " END"; - /** - * Update note's content when data with {@link DataConstants#NOTE} type has deleted - */ + //当类型为{@link DataConstants#NOTE}的数据被删除时,更新笔记内容 private static final String DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER = "CREATE TRIGGER update_note_content_on_delete " + " AFTER delete ON " + TABLE.DATA + @@ -171,9 +161,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " WHERE " + NoteColumns.ID + "=old." + DataColumns.NOTE_ID + ";" + " 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 " + " AFTER DELETE ON " + TABLE.NOTE + @@ -182,9 +170,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " WHERE " + DataColumns.NOTE_ID + "=old." + NoteColumns.ID + ";" + " 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 " + " AFTER DELETE ON " + TABLE.NOTE + @@ -193,9 +179,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " WHERE " + NoteColumns.PARENT_ID + "=old." + NoteColumns.ID + ";" + " 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 " + " AFTER UPDATE ON " + TABLE.NOTE + @@ -210,6 +194,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { super(context, DB_NAME, null, DB_VERSION); } + //创建数据库 public void createNoteTable(SQLiteDatabase db) { db.execSQL(CREATE_NOTE_TABLE_SQL); reCreateNoteTableTriggers(db); @@ -217,6 +202,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { Log.d(TAG, "note table has been created"); } + //重新创建触发器 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,41 +221,35 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { db.execSQL(FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER); } + //创建系统文件夹 private void createSystemFolder(SQLiteDatabase db) { ContentValues values = new ContentValues(); - /** - * call record foler for call notes - */ + //通话记录文件夹,用于通话记录笔记 values.put(NoteColumns.ID, Notes.ID_CALL_RECORD_FOLDER); values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM); db.insert(TABLE.NOTE, null, values); - /** - * root folder which is default folder - */ + //根文件夹,用于存储所有笔记 values.clear(); values.put(NoteColumns.ID, Notes.ID_ROOT_FOLDER); values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM); db.insert(TABLE.NOTE, null, values); - /** - * temporary folder which is used for moving note - */ + //临时文件夹,用于存储没有文件夹的笔记 values.clear(); values.put(NoteColumns.ID, Notes.ID_TEMPARAY_FOLDER); values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM); db.insert(TABLE.NOTE, null, values); - /** - * create trash folder - */ + //回收站文件夹,用于存储删除的笔记 values.clear(); values.put(NoteColumns.ID, Notes.ID_TRASH_FOLER); values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM); db.insert(TABLE.NOTE, null, values); } + //创建数据表 public void createDataTable(SQLiteDatabase db) { db.execSQL(CREATE_DATA_TABLE_SQL); reCreateDataTableTriggers(db); @@ -277,6 +257,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { Log.d(TAG, "data table has been created"); } + //重新创建触发器 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 +268,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { db.execSQL(DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER); } + //获取数据库实例 static synchronized NotesDatabaseHelper getInstance(Context context) { if (mInstance == null) { mInstance = new NotesDatabaseHelper(context); @@ -294,12 +276,14 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { return mInstance; } + //创建数据库 @Override public void onCreate(SQLiteDatabase db) { createNoteTable(db); createDataTable(db); } + //升级数据库 @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { boolean reCreateTriggers = false; @@ -307,7 +291,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { if (oldVersion == 1) { upgradeToV2(db); - skipV2 = true; // this upgrade including the upgrade from v2 to v3 + skipV2 = true; //此次升级跳过V2 oldVersion++; } @@ -333,6 +317,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { } } + //升级到V2 private void upgradeToV2(SQLiteDatabase db) { db.execSQL("DROP TABLE IF EXISTS " + TABLE.NOTE); db.execSQL("DROP TABLE IF EXISTS " + TABLE.DATA); @@ -340,21 +325,23 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { createDataTable(db); } + //升级到V3 private void upgradeToV3(SQLiteDatabase db) { - // drop unused triggers + //删除未使用的触发器 db.execSQL("DROP TRIGGER IF EXISTS update_note_modified_date_on_insert"); db.execSQL("DROP TRIGGER IF EXISTS update_note_modified_date_on_delete"); db.execSQL("DROP TRIGGER IF EXISTS update_note_modified_date_on_update"); - // add a column for gtask id + //添加一个用于gtask id的列 db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.GTASK_ID + " TEXT NOT NULL DEFAULT ''"); - // add a trash system folder + //添加一个垃圾系统文件夹 ContentValues values = new ContentValues(); values.put(NoteColumns.ID, Notes.ID_TRASH_FOLER); values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM); db.insert(TABLE.NOTE, null, values); } + //升级到V4 private void upgradeToV4(SQLiteDatabase db) { db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0"); diff --git a/app/src/main/java/net/micode/notes/data/NotesProvider.java b/app/src/main/java/net/micode/notes/data/NotesProvider.java index edb0a60..879c563 100644 --- a/app/src/main/java/net/micode/notes/data/NotesProvider.java +++ b/app/src/main/java/net/micode/notes/data/NotesProvider.java @@ -35,6 +35,8 @@ import net.micode.notes.data.Notes.NoteColumns; import net.micode.notes.data.NotesDatabaseHelper.TABLE; +//这个类是一个内容提供者,用于提供笔记和文件夹的数据 +//它继承自ContentProvider类,并重写了它的方法,以实现对笔记和文件夹数据的增删改查操作 public class NotesProvider extends ContentProvider { private static final UriMatcher mMatcher; @@ -73,6 +75,14 @@ public class NotesProvider extends ContentProvider { + "'" + Intent.ACTION_VIEW + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_ACTION + "," + "'" + Notes.TextNote.CONTENT_TYPE + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA; + //查询笔记的SQL语句 + //LIKE操作符来匹配笔记的标题或内容 + //INNER JOIN操作符来连接笔记和文件夹表 + //ORDER BY操作符来按照笔记的修改日期排序 + //LIMIT操作符来限制查询结果的数量 + //GROUP BY操作符来按照笔记的ID分组 + //HAVING操作符来过滤查询结果 + //UNION操作符来合并查询结果 private static String NOTES_SNIPPET_SEARCH_QUERY = "SELECT " + NOTES_SEARCH_PROJECTION + " FROM " + TABLE.NOTE + " WHERE " + NoteColumns.SNIPPET + " LIKE ?" @@ -166,13 +176,13 @@ public class NotesProvider extends ContentProvider { default: throw new IllegalArgumentException("Unknown URI " + uri); } - // Notify the note uri + //通知笔记统一资源标识符 if (noteId > 0) { getContext().getContentResolver().notifyChange( ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null); } - // Notify the data uri + //通知数据统一资源标识符 if (dataId > 0) { getContext().getContentResolver().notifyChange( ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), null); @@ -194,10 +204,7 @@ public class NotesProvider extends ContentProvider { break; case URI_NOTE_ITEM: id = uri.getPathSegments().get(1); - /** - * ID that smaller than 0 is system folder which is not allowed to - * trash - */ + //小于0的ID代表系统文件夹,不允许将其放入回收站 long noteId = Long.valueOf(id); if (noteId <= 0) { break; diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index eb9d448..dfa1e51 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -agp = "8.3.0-alpha08" +agp = "8.10.0" junit = "4.13.2" androidx-test-ext-junit = "1.1.5" espresso-core = "3.5.1" diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 85a0ad2..823b0d8 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,7 @@ #Sun May 11 23:35:16 CST 2025 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://mirrors.aliyun.com/macports/distfiles/gradle/gradle-8.7-bin.zip +distributionUrl=https\://mirrors.aliyun.com/macports/distfiles/gradle/gradle-8.11.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists android.nonFinalResIds=false \ No newline at end of file