添加代码注释

MRD
MRD 2 months ago
parent 1cdafabdb1
commit 05a1a73226

@ -1,17 +1,9 @@
/* /*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Apache2.0
* 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获取
*
* 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.
*/ */
package net.micode.notes.ui; 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.data.Notes.NoteColumns;
import net.micode.notes.tool.DataUtils; import net.micode.notes.tool.DataUtils;
/**
*
* 访
*
*/
public class NoteItemData { public class NoteItemData {
static final String [] PROJECTION = new String [] { // 数据库查询投影:指定要查询的列
NoteColumns.ID, static final String[] PROJECTION = new String[]{
NoteColumns.ALERTED_DATE, NoteColumns.ID, // 笔记ID
NoteColumns.BG_COLOR_ID, NoteColumns.ALERTED_DATE, // 提醒日期
NoteColumns.CREATED_DATE, NoteColumns.BG_COLOR_ID, // 背景颜色ID
NoteColumns.HAS_ATTACHMENT, NoteColumns.CREATED_DATE, // 创建日期
NoteColumns.MODIFIED_DATE, NoteColumns.HAS_ATTACHMENT, // 是否有附件
NoteColumns.NOTES_COUNT, NoteColumns.MODIFIED_DATE, // 修改日期
NoteColumns.PARENT_ID, NoteColumns.NOTES_COUNT, // 子笔记数量(用于文件夹)
NoteColumns.SNIPPET, NoteColumns.PARENT_ID, // 父文件夹ID
NoteColumns.TYPE, NoteColumns.SNIPPET, // 笔记摘要
NoteColumns.WIDGET_ID, NoteColumns.TYPE, // 笔记类型
NoteColumns.WIDGET_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 ID_COLUMN = 0; // 笔记ID列索引
private static final int BG_COLOR_ID_COLUMN = 2; private static final int ALERTED_DATE_COLUMN = 1; // 提醒日期列索引
private static final int CREATED_DATE_COLUMN = 3; private static final int BG_COLOR_ID_COLUMN = 2; // 背景颜色ID列索引
private static final int HAS_ATTACHMENT_COLUMN = 4; private static final int CREATED_DATE_COLUMN = 3; // 创建日期列索引
private static final int MODIFIED_DATE_COLUMN = 5; private static final int HAS_ATTACHMENT_COLUMN = 4; // 附件标志列索引
private static final int NOTES_COUNT_COLUMN = 6; private static final int MODIFIED_DATE_COLUMN = 5; // 修改日期列索引
private static final int PARENT_ID_COLUMN = 7; private static final int NOTES_COUNT_COLUMN = 6; // 子笔记数量列索引
private static final int SNIPPET_COLUMN = 8; private static final int PARENT_ID_COLUMN = 7; // 父文件夹ID列索引
private static final int TYPE_COLUMN = 9; private static final int SNIPPET_COLUMN = 8; // 摘要列索引
private static final int WIDGET_ID_COLUMN = 10; private static final int TYPE_COLUMN = 9; // 类型列索引
private static final int WIDGET_TYPE_COLUMN = 11; private static final int WIDGET_ID_COLUMN = 10; // 小部件ID列索引
private static final int WIDGET_TYPE_COLUMN = 11; // 小部件类型列索引
private long mId;
private long mAlertDate; // 笔记基本信息
private int mBgColorId; private long mId; // 笔记ID
private long mCreatedDate; private long mAlertDate; // 提醒日期
private boolean mHasAttachment; private int mBgColorId; // 背景颜色ID
private long mModifiedDate; private long mCreatedDate; // 创建日期
private int mNotesCount; private boolean mHasAttachment; // 是否有附件
private long mParentId; private long mModifiedDate; // 修改日期
private String mSnippet; private int mNotesCount; // 子笔记数量(文件夹)
private int mType; private long mParentId; // 父文件夹ID
private int mWidgetId; private String mSnippet; // 笔记摘要
private int mWidgetType; private int mType; // 笔记类型
private String mName; private int mWidgetId; // 桌面小部件ID
private String mPhoneNumber; private int mWidgetType; // 桌面小部件类型
private String mName; // 联系人名称(通话记录笔记)
private boolean mIsLastItem; private String mPhoneNumber; // 电话号码(通话记录笔记)
private boolean mIsFirstItem;
private boolean mIsOnlyOneItem; // 列表位置标识
private boolean mIsOneNoteFollowingFolder; private boolean mIsLastItem; // 是否为列表最后一项
private boolean mIsMultiNotesFollowingFolder; private boolean mIsFirstItem; // 是否为列表第一项
private boolean mIsOnlyOneItem; // 是否为列表唯一一项
private boolean mIsOneNoteFollowingFolder; // 是否为文件夹后的单条笔记
private boolean mIsMultiNotesFollowingFolder; // 是否为文件夹后的多条笔记
/**
*
* @param context
* @param cursor
*/
public NoteItemData(Context context, Cursor cursor) { public NoteItemData(Context context, Cursor cursor) {
// 从游标中获取基本笔记信息
mId = cursor.getLong(ID_COLUMN); mId = cursor.getLong(ID_COLUMN);
mAlertDate = cursor.getLong(ALERTED_DATE_COLUMN); mAlertDate = cursor.getLong(ALERTED_DATE_COLUMN);
mBgColorId = cursor.getInt(BG_COLOR_ID_COLUMN); mBgColorId = cursor.getInt(BG_COLOR_ID_COLUMN);
@ -86,13 +92,17 @@ public class NoteItemData {
mNotesCount = cursor.getInt(NOTES_COUNT_COLUMN); mNotesCount = cursor.getInt(NOTES_COUNT_COLUMN);
mParentId = cursor.getLong(PARENT_ID_COLUMN); mParentId = cursor.getLong(PARENT_ID_COLUMN);
mSnippet = cursor.getString(SNIPPET_COLUMN); mSnippet = cursor.getString(SNIPPET_COLUMN);
// 处理清单模式标签
mSnippet = mSnippet.replace(NoteEditActivity.TAG_CHECKED, "").replace( mSnippet = mSnippet.replace(NoteEditActivity.TAG_CHECKED, "").replace(
NoteEditActivity.TAG_UNCHECKED, ""); NoteEditActivity.TAG_UNCHECKED, "");
mType = cursor.getInt(TYPE_COLUMN); mType = cursor.getInt(TYPE_COLUMN);
mWidgetId = cursor.getInt(WIDGET_ID_COLUMN); mWidgetId = cursor.getInt(WIDGET_ID_COLUMN);
mWidgetType = cursor.getInt(WIDGET_TYPE_COLUMN); mWidgetType = cursor.getInt(WIDGET_TYPE_COLUMN);
mPhoneNumber = ""; mPhoneNumber = "";
// 处理通话记录笔记
if (mParentId == Notes.ID_CALL_RECORD_FOLDER) { if (mParentId == Notes.ID_CALL_RECORD_FOLDER) {
mPhoneNumber = DataUtils.getCallNumberByNoteId(context.getContentResolver(), mId); mPhoneNumber = DataUtils.getCallNumberByNoteId(context.getContentResolver(), mId);
if (!TextUtils.isEmpty(mPhoneNumber)) { if (!TextUtils.isEmpty(mPhoneNumber)) {
@ -106,9 +116,14 @@ public class NoteItemData {
if (mName == null) { if (mName == null) {
mName = ""; mName = "";
} }
// 检查并设置列表位置标识
checkPostion(cursor); checkPostion(cursor);
} }
/**
*
* @param cursor
*/
private void checkPostion(Cursor cursor) { private void checkPostion(Cursor cursor) {
mIsLastItem = cursor.isLast() ? true : false; mIsLastItem = cursor.isLast() ? true : false;
mIsFirstItem = cursor.isFirst() ? true : false; mIsFirstItem = cursor.isFirst() ? true : false;
@ -116,6 +131,7 @@ public class NoteItemData {
mIsMultiNotesFollowingFolder = false; mIsMultiNotesFollowingFolder = false;
mIsOneNoteFollowingFolder = false; mIsOneNoteFollowingFolder = false;
// 检查是否为文件夹后的笔记项
if (mType == Notes.TYPE_NOTE && !mIsFirstItem) { if (mType == Notes.TYPE_NOTE && !mIsFirstItem) {
int position = cursor.getPosition(); int position = cursor.getPosition();
if (cursor.moveToPrevious()) { if (cursor.moveToPrevious()) {
@ -134,91 +150,180 @@ public class NoteItemData {
} }
} }
/**
*
* @return true
*/
public boolean isOneFollowingFolder() { public boolean isOneFollowingFolder() {
return mIsOneNoteFollowingFolder; return mIsOneNoteFollowingFolder;
} }
/**
*
* @return true
*/
public boolean isMultiFollowingFolder() { public boolean isMultiFollowingFolder() {
return mIsMultiNotesFollowingFolder; return mIsMultiNotesFollowingFolder;
} }
/**
*
* @return true
*/
public boolean isLast() { public boolean isLast() {
return mIsLastItem; return mIsLastItem;
} }
/**
*
* @return
*/
public String getCallName() { public String getCallName() {
return mName; return mName;
} }
/**
*
* @return true
*/
public boolean isFirst() { public boolean isFirst() {
return mIsFirstItem; return mIsFirstItem;
} }
/**
*
* @return true
*/
public boolean isSingle() { public boolean isSingle() {
return mIsOnlyOneItem; return mIsOnlyOneItem;
} }
/**
* ID
* @return ID
*/
public long getId() { public long getId() {
return mId; return mId;
} }
/**
*
* @return ()
*/
public long getAlertDate() { public long getAlertDate() {
return mAlertDate; return mAlertDate;
} }
/**
*
* @return ()
*/
public long getCreatedDate() { public long getCreatedDate() {
return mCreatedDate; return mCreatedDate;
} }
/**
*
* @return true
*/
public boolean hasAttachment() { public boolean hasAttachment() {
return mHasAttachment; return mHasAttachment;
} }
/**
*
* @return ()
*/
public long getModifiedDate() { public long getModifiedDate() {
return mModifiedDate; return mModifiedDate;
} }
/**
* ID
* @return ID
*/
public int getBgColorId() { public int getBgColorId() {
return mBgColorId; return mBgColorId;
} }
/**
* ID
* @return ID
*/
public long getParentId() { public long getParentId() {
return mParentId; return mParentId;
} }
/**
* ()
* @return
*/
public int getNotesCount() { public int getNotesCount() {
return mNotesCount; return mNotesCount;
} }
public long getFolderId () { /**
* ID(ID)
* @return ID
*/
public long getFolderId() {
return mParentId; return mParentId;
} }
/**
*
* @return
*/
public int getType() { public int getType() {
return mType; return mType;
} }
/**
*
* @return
*/
public int getWidgetType() { public int getWidgetType() {
return mWidgetType; return mWidgetType;
} }
/**
* ID
* @return ID
*/
public int getWidgetId() { public int getWidgetId() {
return mWidgetId; return mWidgetId;
} }
/**
*
* @return
*/
public String getSnippet() { public String getSnippet() {
return mSnippet; return mSnippet;
} }
/**
*
* @return true
*/
public boolean hasAlert() { public boolean hasAlert() {
return (mAlertDate > 0); return (mAlertDate > 0);
} }
/**
*
* @return true
*/
public boolean isCallRecord() { public boolean isCallRecord() {
return (mParentId == Notes.ID_CALL_RECORD_FOLDER && !TextUtils.isEmpty(mPhoneNumber)); return (mParentId == Notes.ID_CALL_RECORD_FOLDER && !TextUtils.isEmpty(mPhoneNumber));
} }
/**
*
* @param cursor
* @return
*/
public static int getNoteType(Cursor cursor) { public static int getNoteType(Cursor cursor) {
return cursor.getInt(TYPE_COLUMN); return cursor.getInt(TYPE_COLUMN);
} }
} }
Loading…
Cancel
Save