From 11a06dadc01979273e1c443b608b3e6d5d0a00c9 Mon Sep 17 00:00:00 2001 From: houxg Date: Wed, 22 Feb 2017 11:52:38 +0800 Subject: [PATCH] when in notebook mode, use current notebook as deafault for create a note, otherwise use recent notebook --- .../org/houxg/leamonax/ui/MainActivity.java | 17 ++++++++++++++--- .../java/org/houxg/leamonax/ui/Navigation.java | 4 ++++ 2 files changed, 18 insertions(+), 3 deletions(-) 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 a980eff..79fa71e 100644 --- a/app/src/main/java/org/houxg/leamonax/ui/MainActivity.java +++ b/app/src/main/java/org/houxg/leamonax/ui/MainActivity.java @@ -35,6 +35,7 @@ import org.houxg.leamonax.utils.ToastUtils; import java.util.Collections; import java.util.List; +import java.util.Locale; import butterknife.BindView; import butterknife.ButterKnife; @@ -156,9 +157,19 @@ public class MainActivity extends BaseActivity implements Navigation.Callback { 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()); + Notebook notebook; + Navigation.Mode currentMode = mNavigation.getCurrentMode(); + if (currentMode == Navigation.Mode.NOTEBOOK) { + notebook = AppDataBase.getNotebookByLocalId(currentMode.notebookId); + } else { + notebook = AppDataBase.getRecentNoteBook(AccountService.getCurrent().getUserId()); + } + if (notebook != null) { + newNote.setNoteBookId(notebook.getNotebookId()); + } else { + Exception exception = new IllegalStateException( + String.format(Locale.US, "notebook is null, mode:%s, notebookLocalId:%d", currentMode, currentMode.notebookId)); + CrashReport.postCatchedException(exception); } newNote.setIsMarkDown(account.getDefaultEditor() == Account.EDITOR_MARKDOWN); newNote.save(); diff --git a/app/src/main/java/org/houxg/leamonax/ui/Navigation.java b/app/src/main/java/org/houxg/leamonax/ui/Navigation.java index e26beef..993f574 100644 --- a/app/src/main/java/org/houxg/leamonax/ui/Navigation.java +++ b/app/src/main/java/org/houxg/leamonax/ui/Navigation.java @@ -366,6 +366,10 @@ public class Navigation { } } + public Mode getCurrentMode() { + return mCurrentMode; + } + public void refresh() { refreshUserInfo(AccountService.getCurrent()); mAccountAdapter.load(AccountService.getAccountList());