From 2aba1d6d313475bad65bfb4e759cfb9054d136e2 Mon Sep 17 00:00:00 2001 From: houxg Date: Thu, 22 Dec 2016 15:11:19 +0800 Subject: [PATCH] init notebook id when create new note, resolve #11 --- .../houxg/leamonax/database/AppDataBase.java | 19 +++++++++++++++++-- .../org/houxg/leamonax/ui/MainActivity.java | 4 ++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/houxg/leamonax/database/AppDataBase.java b/app/src/main/java/org/houxg/leamonax/database/AppDataBase.java index 30889a3..a7395af 100644 --- a/app/src/main/java/org/houxg/leamonax/database/AppDataBase.java +++ b/app/src/main/java/org/houxg/leamonax/database/AppDataBase.java @@ -24,6 +24,7 @@ import org.houxg.leamonax.model.RelationshipOfNoteTag; import org.houxg.leamonax.model.RelationshipOfNoteTag_Table; import org.houxg.leamonax.model.Tag; import org.houxg.leamonax.model.Tag_Table; +import org.houxg.leamonax.utils.CollectionUtils; import java.util.ArrayList; import java.util.Collection; @@ -60,7 +61,7 @@ public class AppDataBase { if (TextUtils.isEmpty(tagText)) { continue; } - Tag tagModel = SQLite.select() + Tag tagModel = SQLite.select() .from(Tag.class) .where(Tag_Table.userId.eq(uid)) .and(Tag_Table.text.eq(tagText)) @@ -149,7 +150,21 @@ public class AppDataBase { } public static Notebook getRecentNoteBook(String userId) { - //FIXME:get recent notebook + List recentNotes = SQLite.select() + .from(Note.class) + .where(Note_Table.userId.eq(userId)) + .and(Note_Table.notebookId.notEq("")) + .orderBy(Note_Table.updatedTime, false) + .queryList(); + + if (CollectionUtils.isNotEmpty(recentNotes)) { + for (Note note : recentNotes) { + Notebook notebook = getNotebookByServerId(note.getNoteBookId()); + if (!notebook.isDeleted()) { + return notebook; + } + } + } return SQLite.select() .from(Notebook.class) .where(Notebook_Table.userId.eq(userId)) diff --git a/app/src/main/java/org/houxg/leamonax/ui/MainActivity.java b/app/src/main/java/org/houxg/leamonax/ui/MainActivity.java index 8908184..10c8c3d 100644 --- a/app/src/main/java/org/houxg/leamonax/ui/MainActivity.java +++ b/app/src/main/java/org/houxg/leamonax/ui/MainActivity.java @@ -256,6 +256,10 @@ public class MainActivity extends BaseActivity implements NotebookAdapter.Notebo Account account = AccountService.getCurrent(); Note newNote = new Note(); newNote.setUserId(account.getUserId()); + Notebook recentNotebook = AppDataBase.getRecentNoteBook(AccountService.getCurrent().getUserId()); + if (recentNotebook != null) { + newNote.setNoteBookId(recentNotebook.getNotebookId()); + } newNote.setIsMarkDown(account.getDefaultEditor() == Account.EDITOR_MARKDOWN); newNote.save(); Intent intent = NoteEditActivity.getOpenIntent(this, newNote.getId(), true);