fix can’t save changes when clicked navigation button

This commit is contained in:
houxg
2016-12-21 16:38:20 +08:00
parent 9c0fe8b9c8
commit 13d34e5590

View File

@@ -106,8 +106,9 @@ public class NoteEditActivity extends BaseActivity implements EditorFragment.Edi
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
public boolean onOptionsItemSelected(final MenuItem item) {
switch (item.getItemId()) {
case
case R.id.action_save:
filterUnchanged()
.doOnNext(new Action1<Wrapper>() {
@@ -159,6 +160,34 @@ public class NoteEditActivity extends BaseActivity implements EditorFragment.Edi
case R.id.action_settings:
mPager.setCurrentItem(FRAG_SETTINGS);
return true;
case android.R.id.home:
if (mPager.getCurrentItem() > FRAG_EDITOR) {
mPager.setCurrentItem(FRAG_EDITOR);
} else {
filterUnchanged()
.observeOn(AndroidSchedulers.mainThread())
.doOnCompleted(new Action0() {
@Override
public void call() {
NoteEditActivity.super.onOptionsItemSelected(item);
}
})
.subscribe(new Action1<Wrapper>() {
@Override
public void call(Wrapper wrapper) {
setResult(RESULT_OK);
Log.i(TAG, wrapper.toString());
if (mIsNewNote && isTitleContentEmpty(wrapper.note)) {
Log.i(TAG, "remove empty note, id=" + wrapper.note.getId());
AppDataBase.deleteNoteByLocalId(wrapper.note.getId());
} else {
saveAsDraft(wrapper);
}
}
});
}
return true;
}
return super.onOptionsItemSelected(item);
}