From 05a1a73226be8dfbcfc1767d8388eab472d892a0 Mon Sep 17 00:00:00 2001 From: MRD <1259303886@qq.com> Date: Fri, 13 Jun 2025 17:36:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BB=A3=E7=A0=81=E6=B3=A8?= =?UTF-8?q?=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/micode/notes/ui/NoteItemData.java | 227 +++++++++++++----- 1 file changed, 166 insertions(+), 61 deletions(-) diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/ui/NoteItemData.java b/src/Notes-master/app/src/main/java/net/micode/notes/ui/NoteItemData.java index 0f5a878..74bf0c7 100644 --- a/src/Notes-master/app/src/main/java/net/micode/notes/ui/NoteItemData.java +++ b/src/Notes-master/app/src/main/java/net/micode/notes/ui/NoteItemData.java @@ -1,17 +1,9 @@ /* * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * 版权声明:本代码受Apache许可证2.0版本保护 + * 您可以在遵守许可证的前提下使用、修改和分发本代码 + * 许可证全文可在http://www.apache.org/licenses/LICENSE-2.0获取 */ package net.micode.notes.ui; @@ -25,58 +17,72 @@ import net.micode.notes.data.Notes; import net.micode.notes.data.Notes.NoteColumns; import net.micode.notes.tool.DataUtils; - +/** + * 笔记项数据类 + * 功能:封装笔记列表项的数据模型,提供笔记信息的存储和访问接口 + * 特点:包含笔记基本信息、位置标识、类型判断等功能 + */ public class NoteItemData { - static final String [] PROJECTION = new String [] { - NoteColumns.ID, - NoteColumns.ALERTED_DATE, - NoteColumns.BG_COLOR_ID, - NoteColumns.CREATED_DATE, - NoteColumns.HAS_ATTACHMENT, - NoteColumns.MODIFIED_DATE, - NoteColumns.NOTES_COUNT, - NoteColumns.PARENT_ID, - NoteColumns.SNIPPET, - NoteColumns.TYPE, - NoteColumns.WIDGET_ID, - NoteColumns.WIDGET_TYPE, + // 数据库查询投影:指定要查询的列 + static final String[] PROJECTION = new String[]{ + NoteColumns.ID, // 笔记ID + NoteColumns.ALERTED_DATE, // 提醒日期 + NoteColumns.BG_COLOR_ID, // 背景颜色ID + NoteColumns.CREATED_DATE, // 创建日期 + NoteColumns.HAS_ATTACHMENT, // 是否有附件 + NoteColumns.MODIFIED_DATE, // 修改日期 + NoteColumns.NOTES_COUNT, // 子笔记数量(用于文件夹) + NoteColumns.PARENT_ID, // 父文件夹ID + NoteColumns.SNIPPET, // 笔记摘要 + NoteColumns.TYPE, // 笔记类型 + NoteColumns.WIDGET_ID, // 桌面小部件ID + NoteColumns.WIDGET_TYPE, // 桌面小部件类型 }; - private static final int ID_COLUMN = 0; - private static final int ALERTED_DATE_COLUMN = 1; - private static final int BG_COLOR_ID_COLUMN = 2; - private static final int CREATED_DATE_COLUMN = 3; - private static final int HAS_ATTACHMENT_COLUMN = 4; - private static final int MODIFIED_DATE_COLUMN = 5; - private static final int NOTES_COUNT_COLUMN = 6; - private static final int PARENT_ID_COLUMN = 7; - private static final int SNIPPET_COLUMN = 8; - private static final int TYPE_COLUMN = 9; - private static final int WIDGET_ID_COLUMN = 10; - private static final int WIDGET_TYPE_COLUMN = 11; - - private long mId; - private long mAlertDate; - private int mBgColorId; - private long mCreatedDate; - private boolean mHasAttachment; - private long mModifiedDate; - private int mNotesCount; - private long mParentId; - private String mSnippet; - private int mType; - private int mWidgetId; - private int mWidgetType; - private String mName; - private String mPhoneNumber; - - private boolean mIsLastItem; - private boolean mIsFirstItem; - private boolean mIsOnlyOneItem; - private boolean mIsOneNoteFollowingFolder; - private boolean mIsMultiNotesFollowingFolder; - + // 列索引常量,便于代码引用 + private static final int ID_COLUMN = 0; // 笔记ID列索引 + private static final int ALERTED_DATE_COLUMN = 1; // 提醒日期列索引 + private static final int BG_COLOR_ID_COLUMN = 2; // 背景颜色ID列索引 + private static final int CREATED_DATE_COLUMN = 3; // 创建日期列索引 + private static final int HAS_ATTACHMENT_COLUMN = 4; // 附件标志列索引 + private static final int MODIFIED_DATE_COLUMN = 5; // 修改日期列索引 + private static final int NOTES_COUNT_COLUMN = 6; // 子笔记数量列索引 + private static final int PARENT_ID_COLUMN = 7; // 父文件夹ID列索引 + private static final int SNIPPET_COLUMN = 8; // 摘要列索引 + private static final int TYPE_COLUMN = 9; // 类型列索引 + private static final int WIDGET_ID_COLUMN = 10; // 小部件ID列索引 + private static final int WIDGET_TYPE_COLUMN = 11; // 小部件类型列索引 + + // 笔记基本信息 + private long mId; // 笔记ID + private long mAlertDate; // 提醒日期 + private int mBgColorId; // 背景颜色ID + private long mCreatedDate; // 创建日期 + private boolean mHasAttachment; // 是否有附件 + private long mModifiedDate; // 修改日期 + private int mNotesCount; // 子笔记数量(文件夹) + private long mParentId; // 父文件夹ID + private String mSnippet; // 笔记摘要 + private int mType; // 笔记类型 + private int mWidgetId; // 桌面小部件ID + private int mWidgetType; // 桌面小部件类型 + private String mName; // 联系人名称(通话记录笔记) + private String mPhoneNumber; // 电话号码(通话记录笔记) + + // 列表位置标识 + private boolean mIsLastItem; // 是否为列表最后一项 + private boolean mIsFirstItem; // 是否为列表第一项 + private boolean mIsOnlyOneItem; // 是否为列表唯一一项 + private boolean mIsOneNoteFollowingFolder; // 是否为文件夹后的单条笔记 + private boolean mIsMultiNotesFollowingFolder; // 是否为文件夹后的多条笔记 + + /** + * 构造函数 + * @param context 上下文对象 + * @param cursor 包含笔记数据的数据库游标 + */ public NoteItemData(Context context, Cursor cursor) { + // 从游标中获取基本笔记信息 mId = cursor.getLong(ID_COLUMN); mAlertDate = cursor.getLong(ALERTED_DATE_COLUMN); mBgColorId = cursor.getInt(BG_COLOR_ID_COLUMN); @@ -86,13 +92,17 @@ public class NoteItemData { mNotesCount = cursor.getInt(NOTES_COUNT_COLUMN); mParentId = cursor.getLong(PARENT_ID_COLUMN); mSnippet = cursor.getString(SNIPPET_COLUMN); + + // 处理清单模式标签 mSnippet = mSnippet.replace(NoteEditActivity.TAG_CHECKED, "").replace( NoteEditActivity.TAG_UNCHECKED, ""); + mType = cursor.getInt(TYPE_COLUMN); mWidgetId = cursor.getInt(WIDGET_ID_COLUMN); mWidgetType = cursor.getInt(WIDGET_TYPE_COLUMN); mPhoneNumber = ""; + // 处理通话记录笔记 if (mParentId == Notes.ID_CALL_RECORD_FOLDER) { mPhoneNumber = DataUtils.getCallNumberByNoteId(context.getContentResolver(), mId); if (!TextUtils.isEmpty(mPhoneNumber)) { @@ -106,9 +116,14 @@ public class NoteItemData { if (mName == null) { mName = ""; } + // 检查并设置列表位置标识 checkPostion(cursor); } + /** + * 检查并设置笔记在列表中的位置标识 + * @param cursor 数据库游标 + */ private void checkPostion(Cursor cursor) { mIsLastItem = cursor.isLast() ? true : false; mIsFirstItem = cursor.isFirst() ? true : false; @@ -116,6 +131,7 @@ public class NoteItemData { mIsMultiNotesFollowingFolder = false; mIsOneNoteFollowingFolder = false; + // 检查是否为文件夹后的笔记项 if (mType == Notes.TYPE_NOTE && !mIsFirstItem) { int position = cursor.getPosition(); if (cursor.moveToPrevious()) { @@ -134,91 +150,180 @@ public class NoteItemData { } } + /** + * 判断是否为文件夹后的单条笔记 + * @return true表示是文件夹后的单条笔记 + */ public boolean isOneFollowingFolder() { return mIsOneNoteFollowingFolder; } + /** + * 判断是否为文件夹后的多条笔记 + * @return true表示是文件夹后的多条笔记 + */ public boolean isMultiFollowingFolder() { return mIsMultiNotesFollowingFolder; } + /** + * 判断是否为列表最后一项 + * @return true表示是列表最后一项 + */ public boolean isLast() { return mIsLastItem; } + /** + * 获取通话记录的联系人名称 + * @return 联系人名称或电话号码 + */ public String getCallName() { return mName; } + /** + * 判断是否为列表第一项 + * @return true表示是列表第一项 + */ public boolean isFirst() { return mIsFirstItem; } + /** + * 判断是否为列表唯一一项 + * @return true表示是列表唯一一项 + */ public boolean isSingle() { return mIsOnlyOneItem; } + /** + * 获取笔记ID + * @return 笔记ID + */ public long getId() { return mId; } + /** + * 获取提醒日期 + * @return 提醒日期(毫秒值) + */ public long getAlertDate() { return mAlertDate; } + /** + * 获取创建日期 + * @return 创建日期(毫秒值) + */ public long getCreatedDate() { return mCreatedDate; } + /** + * 判断是否有附件 + * @return true表示有附件 + */ public boolean hasAttachment() { return mHasAttachment; } + /** + * 获取修改日期 + * @return 修改日期(毫秒值) + */ public long getModifiedDate() { return mModifiedDate; } + /** + * 获取背景颜色ID + * @return 背景颜色ID + */ public int getBgColorId() { return mBgColorId; } + /** + * 获取父文件夹ID + * @return 父文件夹ID + */ public long getParentId() { return mParentId; } + /** + * 获取子笔记数量(用于文件夹) + * @return 子笔记数量 + */ public int getNotesCount() { return mNotesCount; } - public long getFolderId () { + /** + * 获取文件夹ID(与父文件夹ID相同) + * @return 文件夹ID + */ + public long getFolderId() { return mParentId; } + /** + * 获取笔记类型 + * @return 笔记类型 + */ public int getType() { return mType; } + /** + * 获取桌面小部件类型 + * @return 小部件类型 + */ public int getWidgetType() { return mWidgetType; } + /** + * 获取桌面小部件ID + * @return 小部件ID + */ public int getWidgetId() { return mWidgetId; } + /** + * 获取笔记摘要 + * @return 笔记摘要 + */ public String getSnippet() { return mSnippet; } + /** + * 判断是否设置了提醒 + * @return true表示设置了提醒 + */ public boolean hasAlert() { return (mAlertDate > 0); } + /** + * 判断是否为通话记录笔记 + * @return true表示是通话记录笔记 + */ public boolean isCallRecord() { return (mParentId == Notes.ID_CALL_RECORD_FOLDER && !TextUtils.isEmpty(mPhoneNumber)); } + /** + * 从游标中获取笔记类型 + * @param cursor 数据库游标 + * @return 笔记类型 + */ public static int getNoteType(Cursor cursor) { return cursor.getInt(TYPE_COLUMN); } -} +} \ No newline at end of file