init notebook id when create new note, resolve #11

This commit is contained in:
houxg
2016-12-22 15:11:19 +08:00
parent f98bd432a0
commit 2aba1d6d31
2 changed files with 21 additions and 2 deletions

View File

@@ -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<Note> 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))

View File

@@ -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);