Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/src/main/java/org/houxg/leamonax/ui/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ public void onBackPressed() {
if (mNavigation.isOpen()) {
mNavigation.close();
} else {
super.onBackPressed();
if (mNoteFragment.canGoBack()) {
mNoteFragment.goBack();
} else {
super.onBackPressed();
}
}
}

Expand Down
26 changes: 26 additions & 0 deletions app/src/main/java/org/houxg/leamonax/ui/NoteFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down