mirror of
https://github.com/ankidroid/Anki-Android.git
synced 2024-09-20 20:03:05 +02:00
Merge pull request #748 from timrae/reload-card-after-note-edit
Always reload newest card of stack after performing an operation in note editor
This commit is contained in:
commit
59b7bfb9c9
@ -1128,6 +1128,11 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity {
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if (!AnkiDroidApp.colIsOpen()) {
|
||||
Timber.e("onActivityResult -- Collection is not open... aborting");
|
||||
return;
|
||||
}
|
||||
|
||||
if (resultCode == DeckPicker.RESULT_DB_ERROR) {
|
||||
closeReviewer(DeckPicker.RESULT_DB_ERROR, false);
|
||||
}
|
||||
@ -1136,21 +1141,24 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity {
|
||||
finishNoStorageAvailable();
|
||||
}
|
||||
if (requestCode == EDIT_CURRENT_CARD) {
|
||||
// If the card was rescheduled, we need to remove it from the top of the queue as it is
|
||||
// no longer positioned there. Use a "fake" answer for this by passing a null card.
|
||||
if (data != null && data.hasExtra("rescheduled")) {
|
||||
if (resultCode == RESULT_CANCELED && !(data!=null && data.hasExtra("reloadRequired"))) {
|
||||
// If note not saved and no reload required then simply redraw the flashcard
|
||||
fillFlashcard();
|
||||
} else {
|
||||
// Save the note if required
|
||||
if (resultCode == RESULT_OK) {
|
||||
Timber.i("AbstractFlashcardViewer:: Saving card...");
|
||||
DeckTask.launchDeckTask(DeckTask.TASK_TYPE_UPDATE_FACT, mUpdateCardHandler, new DeckTask.TaskData(
|
||||
mSched, mCurrentCard, true));
|
||||
}
|
||||
|
||||
/* Reset the schedule and reload the latest card off the top of the stack.
|
||||
This always needs to be done, as the card could have been rescheduled, the deck could
|
||||
have changed, or a change of note type could have lead to the card being deleted */
|
||||
getCol().getSched().reset();
|
||||
DeckTask.launchDeckTask(DeckTask.TASK_TYPE_ANSWER_CARD, mAnswerCardHandler, new DeckTask.TaskData(
|
||||
mSched, null, 0));
|
||||
}
|
||||
// Modification of the note is independent of rescheduling, so we still need to save it if it
|
||||
// happened.
|
||||
if (resultCode != RESULT_CANCELED) {
|
||||
Timber.i("AbstractFlashcardViewer:: Saving card...");
|
||||
DeckTask.launchDeckTask(DeckTask.TASK_TYPE_UPDATE_FACT, mUpdateCardHandler, new DeckTask.TaskData(
|
||||
mSched, mCurrentCard, true));
|
||||
} else {
|
||||
fillFlashcard();
|
||||
}
|
||||
}
|
||||
if (!mDisableClipboard) {
|
||||
clipboardSetText("");
|
||||
|
@ -154,7 +154,7 @@ public class NoteEditor extends AnkiActivity {
|
||||
|
||||
private boolean mChanged = false;
|
||||
private boolean mFieldEdited = false;
|
||||
private boolean mRescheduled = false;
|
||||
private boolean mReloadRequired = false;
|
||||
|
||||
|
||||
/**
|
||||
@ -808,10 +808,10 @@ public class NoteEditor extends AnkiActivity {
|
||||
private void changeNoteType(JSONObject oldModel, JSONObject newModel) throws ConfirmModSchemaException {
|
||||
final long [] nids = {mEditorNote.getId()};
|
||||
getCol().getModels().change(oldModel, nids, newModel, mModelChangeFieldMap, mModelChangeCardMap);
|
||||
// refresh the note & card objects to reflect the database changes
|
||||
mCurrentEditedCard.load();
|
||||
mEditorNote = mCurrentEditedCard.note();
|
||||
// refresh the note object to reflect the database changes
|
||||
mEditorNote.load();
|
||||
// close note editor
|
||||
mReloadRequired = true;
|
||||
closeNoteEditor();
|
||||
}
|
||||
|
||||
@ -1005,12 +1005,13 @@ public class NoteEditor extends AnkiActivity {
|
||||
} else {
|
||||
result = RESULT_CANCELED;
|
||||
}
|
||||
if (mRescheduled) {
|
||||
if (mReloadRequired) {
|
||||
if (intent == null) {
|
||||
intent = new Intent();
|
||||
}
|
||||
intent.putExtra("rescheduled", true);
|
||||
intent.putExtra("reloadRequired", true);
|
||||
}
|
||||
|
||||
closeNoteEditor(result, intent);
|
||||
}
|
||||
|
||||
@ -1088,7 +1089,7 @@ public class NoteEditor extends AnkiActivity {
|
||||
Timber.i("NoteEditor:: OK button pressed");
|
||||
getCol().getSched().forgetCards(new long[] { mCurrentEditedCard.getId() });
|
||||
getCol().reset();
|
||||
mRescheduled = true;
|
||||
mReloadRequired = true;
|
||||
Themes.showThemedToast(NoteEditor.this,
|
||||
getResources().getString(R.string.reset_card_dialog_acknowledge), true);
|
||||
}
|
||||
@ -1112,7 +1113,7 @@ public class NoteEditor extends AnkiActivity {
|
||||
int days = Integer.parseInt(((EditText) rescheduleEditText).getText().toString());
|
||||
getCol().getSched().reschedCards(new long[] { mCurrentEditedCard.getId() }, days, days);
|
||||
getCol().reset();
|
||||
mRescheduled = true;
|
||||
mReloadRequired = true;
|
||||
Themes.showThemedToast(NoteEditor.this,
|
||||
getResources().getString(R.string.reschedule_card_dialog_acknowledge), true);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user