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 87c35c9..a31da0a 100644 --- a/app/src/main/java/org/houxg/leamonax/ui/MainActivity.java +++ b/app/src/main/java/org/houxg/leamonax/ui/MainActivity.java @@ -137,7 +137,11 @@ public void onBackPressed() { if (mNavigation.isOpen()) { mNavigation.close(); } else { - super.onBackPressed(); + if (mNoteFragment.canGoBack()) { + mNoteFragment.goBack(); + } else { + super.onBackPressed(); + } } } diff --git a/app/src/main/java/org/houxg/leamonax/ui/NoteFragment.java b/app/src/main/java/org/houxg/leamonax/ui/NoteFragment.java index e4efda3..7870250 100644 --- a/app/src/main/java/org/houxg/leamonax/ui/NoteFragment.java +++ b/app/src/main/java/org/houxg/leamonax/ui/NoteFragment.java @@ -7,6 +7,7 @@ import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v7.widget.RecyclerView; +import android.text.TextUtils; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; @@ -19,8 +20,10 @@ import org.houxg.leamonax.R; import org.houxg.leamonax.adapter.NoteAdapter; import org.houxg.leamonax.database.NoteDataStore; +import org.houxg.leamonax.database.NotebookDataStore; import org.houxg.leamonax.model.Account; import org.houxg.leamonax.model.Note; +import org.houxg.leamonax.model.Notebook; import org.houxg.leamonax.service.NoteService; import org.houxg.leamonax.utils.ActionModeHandler; import org.houxg.leamonax.utils.CollectionUtils; @@ -155,6 +158,29 @@ public void setMode(Mode mode) { } } + public boolean canGoBack() { + if (mCurrentMode == Mode.NOTEBOOK) { + Notebook notebook = NotebookDataStore.getByLocalId(mCurrentMode.notebookId); + if (!TextUtils.isEmpty(notebook.getParentNotebookId())) { + return true; + } + return false; + } + return false; + } + + public void goBack() { + if (mCurrentMode == Mode.NOTEBOOK) { + Notebook notebook = NotebookDataStore.getByLocalId(mCurrentMode.notebookId); + long localId = NotebookDataStore.getByServerId(notebook.getParentNotebookId()).getId(); + Mode mode = Mode.NOTEBOOK; + mode.setNotebookId(localId); + setMode(mode); + } + } + + + @Override public void onClickNote(Note note) { if (mActionModeHandler.isActionMode()) {