多级笔记本子目录可以回退到上级目录

This commit is contained in:
xingxing
2018-05-18 22:27:31 +08:00
parent eaa038e308
commit 12f847dd18
2 changed files with 31 additions and 1 deletions

View File

@@ -137,7 +137,11 @@ public class MainActivity extends BaseActivity implements Navigation.Callback {
if (mNavigation.isOpen()) {
mNavigation.close();
} else {
super.onBackPressed();
if (mNoteFragment.canGoBack()) {
mNoteFragment.goBack();
} else {
super.onBackPressed();
}
}
}

View File

@@ -7,6 +7,7 @@ import android.os.Bundle;
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.Leamonax;
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 class NoteFragment extends Fragment implements NoteAdapter.NoteAdapterLis
}
}
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()) {