mirror of
https://github.com/leanote/leanote-android.git
synced 2026-01-13 07:03:54 +08:00
init notebook id when create new note, resolve #11
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user