From 12f847dd18de96dfb483d27b82a5f82d2b53e62c Mon Sep 17 00:00:00 2001 From: xingxing Date: Fri, 18 May 2018 22:27:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E7=BA=A7=E7=AC=94=E8=AE=B0=E6=9C=AC?= =?UTF-8?q?=E5=AD=90=E7=9B=AE=E5=BD=95=E5=8F=AF=E4=BB=A5=E5=9B=9E=E9=80=80?= =?UTF-8?q?=E5=88=B0=E4=B8=8A=E7=BA=A7=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/houxg/leamonax/ui/MainActivity.java | 6 ++++- .../org/houxg/leamonax/ui/NoteFragment.java | 26 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) 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()) {