|
|
|
|
@ -29,7 +29,9 @@ import net.micode.notes.data.Notes.DataColumns;
|
|
|
|
|
import net.micode.notes.data.Notes.DataConstants;
|
|
|
|
|
import net.micode.notes.data.Notes.NoteColumns;
|
|
|
|
|
import net.micode.notes.data.Notes.TextNote;
|
|
|
|
|
import net.micode.notes.tool.DataUtils;
|
|
|
|
|
import net.micode.notes.tool.ResourceParser.NoteBgResources;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -331,6 +333,7 @@ public class WorkingNote {
|
|
|
|
|
* <p>
|
|
|
|
|
* 将当前工作笔记保存到数据库中。如果笔记不存在,则创建新笔记;
|
|
|
|
|
* 如果笔记已存在,则更新现有笔记。
|
|
|
|
|
* 如果笔记内容为空且已存在于数据库,则删除该笔记。
|
|
|
|
|
* </p>
|
|
|
|
|
*
|
|
|
|
|
* @return 保存成功返回true,否则返回false
|
|
|
|
|
@ -356,6 +359,15 @@ public class WorkingNote {
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
// 添加删除逻辑:如果笔记内容为空且已存在于数据库,则删除该笔记
|
|
|
|
|
if (existInDatabase() && TextUtils.isEmpty(mContent)) {
|
|
|
|
|
HashSet<Long> ids = new HashSet<Long>();
|
|
|
|
|
ids.add(mNoteId);
|
|
|
|
|
if (!DataUtils.batchDeleteNotes(mContext.getContentResolver(), ids)) {
|
|
|
|
|
Log.e(TAG, "Delete empty note error");
|
|
|
|
|
}
|
|
|
|
|
mIsDeleted = true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -376,13 +388,13 @@ public class WorkingNote {
|
|
|
|
|
* 检查笔记是否值得保存
|
|
|
|
|
* <p>
|
|
|
|
|
* 检查当前工作笔记是否值得保存到数据库中。如果笔记已删除、
|
|
|
|
|
* 内容为空且不存在于数据库中,或者存在于数据库但未修改,则不值得保存。
|
|
|
|
|
* 内容为空,或者存在于数据库但未修改,则不值得保存。
|
|
|
|
|
* </p>
|
|
|
|
|
*
|
|
|
|
|
* @return 值得保存返回true,否则返回false
|
|
|
|
|
*/
|
|
|
|
|
private boolean isWorthSaving() {
|
|
|
|
|
if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent))
|
|
|
|
|
if (mIsDeleted || TextUtils.isEmpty(mContent)
|
|
|
|
|
|| (existInDatabase() && !mNote.isLocalModified())) {
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
|