when in notebook mode, use current notebook as deafault for create a note, otherwise use recent notebook

This commit is contained in:
houxg
2017-02-22 11:52:38 +08:00
parent 4eea3edf4d
commit 11a06dadc0
2 changed files with 18 additions and 3 deletions

View File

@@ -35,6 +35,7 @@ import org.houxg.leamonax.utils.ToastUtils;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Locale;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
@@ -156,9 +157,19 @@ public class MainActivity extends BaseActivity implements Navigation.Callback {
Account account = AccountService.getCurrent(); Account account = AccountService.getCurrent();
Note newNote = new Note(); Note newNote = new Note();
newNote.setUserId(account.getUserId()); newNote.setUserId(account.getUserId());
Notebook recentNotebook = AppDataBase.getRecentNoteBook(AccountService.getCurrent().getUserId()); Notebook notebook;
if (recentNotebook != null) { Navigation.Mode currentMode = mNavigation.getCurrentMode();
newNote.setNoteBookId(recentNotebook.getNotebookId()); 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.setIsMarkDown(account.getDefaultEditor() == Account.EDITOR_MARKDOWN);
newNote.save(); newNote.save();

View File

@@ -366,6 +366,10 @@ public class Navigation {
} }
} }
public Mode getCurrentMode() {
return mCurrentMode;
}
public void refresh() { public void refresh() {
refreshUserInfo(AccountService.getCurrent()); refreshUserInfo(AccountService.getCurrent());
mAccountAdapter.load(AccountService.getAccountList()); mAccountAdapter.load(AccountService.getAccountList());