diff --git a/src/main/java/net/micode/notes/model/WorkingNote.java b/src/main/java/net/micode/notes/model/WorkingNote.java index 4e5a4e7..caaed12 100644 --- a/src/main/java/net/micode/notes/model/WorkingNote.java +++ b/src/main/java/net/micode/notes/model/WorkingNote.java @@ -187,16 +187,24 @@ public class WorkingNote { return new WorkingNote(context, id, 0); } - public synchronized boolean saveNote() { - if (isWorthSaving()) { - if (!existInDatabase()) { + public synchronized boolean saveNote() {// TODO: 2023/12/19 要仔细溯源看看 + /** + * @method: saveNote + * @description: 保存工作便签,当保存成功时,返回true,保存失败() + * @date: 2023/12/19 23:44 + * @author: zhoukexing + * @param: [] + * @return: boolean + */ + if (isWorthSaving()) { // 判断是否有新内容-->是否值得注释 @zhoukexing 2023/12/19 23:45 + if (!existInDatabase()) { // 判断是否在数据库里存在==是新便签还是已有便签 @zhoukexing 2023/12/19 23:45 if ((mNoteId = Note.getNewNoteId(mContext, mFolderId)) == 0) { Log.e(TAG, "Create new note fail with id:" + mNoteId); return false; } } - mNote.syncNote(mContext, mNoteId); + mNote.syncNote(mContext, mNoteId); // 和远程同步 @zhoukexing 2023/12/19 23:46 /** * Update widget content if there exist any widget of this note @@ -208,7 +216,7 @@ public class WorkingNote { } return true; } else { - return false; + return false; // 没有需要保存的,就返回false @zhoukexing 2023/12/19 23:46 } } diff --git a/src/main/java/net/micode/notes/ui/NoteEditActivity.java b/src/main/java/net/micode/notes/ui/NoteEditActivity.java index 619e70b..03aef1b 100644 --- a/src/main/java/net/micode/notes/ui/NoteEditActivity.java +++ b/src/main/java/net/micode/notes/ui/NoteEditActivity.java @@ -557,8 +557,17 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但 @Override public boolean onOptionsItemSelected(MenuItem item) { + /** + * @method: onOptionsItemSelected + * @description: 覆写了Activity.java里的onOptionsItemSelected,路线是menu-->item, + * 这里就是处理识别到的item + * @date: 2023/12/19 23:35 + * @author: zhoukexing + * @param: [item] + * @return: boolean + */ int itemId = item.getItemId(); - if (itemId == R.id.menu_new_note) { + if (itemId == R.id.menu_new_note) { // 从item到itemid,用itemid导向对应的不同的动作 @zhoukexing 2023/12/19 23:38 createNewNote(); } else if (itemId == R.id.menu_delete) { AlertDialog.Builder builder = new AlertDialog.Builder(this); @@ -623,13 +632,23 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但 } private void createNewNote() { + /** + * @method: createNewNote + * @description: 从编辑页面,点击“add note”会进入这个创建便签的方法。 + * 此方法会保存并结束当前便签,用NoteEditActivity类实例化一个新的intent(活动意图), + * 设置行为和指定报错对象后,启动intent活动意图 + * @date: 2023/12/19 23:03 + * @author: zhoukexing + * @param: [] + * @return: void + */ // Firstly, save current editing notes saveNote(); // For safety, start a new NoteEditActivity finish(); Intent intent = new Intent(this, NoteEditActivity.class); //Q: 在类的内部,还没有实现完全时,启动这个类自己?@zkx 2023/12/17 - intent.setAction(Intent.ACTION_INSERT_OR_EDIT); + intent.setAction(Intent.ACTION_INSERT_OR_EDIT); // 创建便签后,要插入或者编辑。Q: 为什么要插入 @zhoukexing 2023/12/19 22:57 intent.putExtra(Notes.INTENT_EXTRA_FOLDER_ID, mWorkingNote.getFolderId()); startActivity(intent); } @@ -865,8 +884,16 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但 } private boolean saveNote() { + /** + * @method: saveNote + * @description: 获取工作文本,调用真正的保存便签的方法,设置便签在list界面的位置 + * @date: 2023/12/19 23:50 + * @author: zhoukexing + * @param: [] + * @return: boolean + */ getWorkingText(); - boolean saved = mWorkingNote.saveNote(); + boolean saved = mWorkingNote.saveNote();// TODO: 2023/12/19 工作便签下的saveNote if (saved) { /** * There are two modes from List view to edit view, open one note, @@ -875,7 +902,8 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但 * new node requires to the top of the list. This code * {@link #RESULT_OK} is used to identify the create/edit state */ - setResult(RESULT_OK); + setResult(RESULT_OK); // RESULT_OK指示将该便签保存到list界面的顶端(因为这是新建的便签) @zhoukexing 2023/12/19 23:41 + //Q: 这个setResult只在这里调用了,怎么实现的 @zkx 2023/12/19 } return saved; }