mirror of
https://github.com/ankidroid/Anki-Android.git
synced 2024-09-20 20:03:05 +02:00
Fix bug in #748
Only do sched.reset() when really necessary after closing note editor, and also reload card list in browser when reloadRequired flag is sent
This commit is contained in:
parent
05c5fc46c0
commit
371f525cee
@ -1128,11 +1128,6 @@ 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);
|
||||
}
|
||||
@ -1140,25 +1135,31 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity {
|
||||
if (resultCode == DeckPicker.RESULT_MEDIA_EJECTED) {
|
||||
finishNoStorageAvailable();
|
||||
}
|
||||
if (requestCode == EDIT_CURRENT_CARD) {
|
||||
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 */
|
||||
if (!AnkiDroidApp.colIsOpen()) {
|
||||
Timber.e("onActivityResult -- Collection is not open... aborting");
|
||||
return;
|
||||
}
|
||||
|
||||
if (requestCode == EDIT_CURRENT_CARD) {
|
||||
/* Reset the schedule and reload the latest card off the top of the stack if required.
|
||||
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 */
|
||||
if (data!=null && data.hasExtra("reloadRequired")) {
|
||||
getCol().getSched().reset();
|
||||
DeckTask.launchDeckTask(DeckTask.TASK_TYPE_ANSWER_CARD, mAnswerCardHandler, new DeckTask.TaskData(
|
||||
mSched, null, 0));
|
||||
}
|
||||
|
||||
if (resultCode == RESULT_OK) {
|
||||
// content of note was changed so update the note and current card
|
||||
Timber.i("AbstractFlashcardViewer:: Saving card...");
|
||||
DeckTask.launchDeckTask(DeckTask.TASK_TYPE_UPDATE_FACT, mUpdateCardHandler, new DeckTask.TaskData(
|
||||
mSched, mCurrentCard, true));
|
||||
} else if (resultCode == RESULT_CANCELED && !(data!=null && data.hasExtra("reloadRequired"))) {
|
||||
// nothing was changed by the note editor so just redraw the card
|
||||
fillFlashcard();
|
||||
}
|
||||
}
|
||||
if (!mDisableClipboard) {
|
||||
clipboardSetText("");
|
||||
|
@ -569,6 +569,11 @@ public class CardBrowser extends NavigationDrawerActivity implements ActionBar.O
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (requestCode == EDIT_CARD && data!=null && data.hasExtra("reloadRequired")) {
|
||||
// if reloadRequired flag was sent from note editor then reload card list
|
||||
searchCards();
|
||||
}
|
||||
}
|
||||
|
||||
private DialogFragment showDialogFragment(int id) {
|
||||
|
@ -154,6 +154,10 @@ public class NoteEditor extends AnkiActivity {
|
||||
|
||||
private boolean mChanged = false;
|
||||
private boolean mFieldEdited = false;
|
||||
|
||||
/**
|
||||
* Flag which forces the calling activity to rebuild it's definition of current card from scratch
|
||||
*/
|
||||
private boolean mReloadRequired = false;
|
||||
|
||||
|
||||
@ -719,6 +723,7 @@ public class NoteEditor extends AnkiActivity {
|
||||
final JSONObject newModel = getCurrentlySelectedModel();
|
||||
final JSONObject oldModel = mCurrentEditedCard.model();
|
||||
if (!newModel.equals(oldModel)) {
|
||||
mReloadRequired = true;
|
||||
if (mModelChangeCardMap.size() < mEditorNote.cards().size() || mModelChangeCardMap.containsKey(null)) {
|
||||
// If cards will be lost via the new mapping then show a confirmation dialog before proceeding with the change
|
||||
ConfirmationDialog dialog = new ConfirmationDialog () {
|
||||
@ -740,6 +745,7 @@ public class NoteEditor extends AnkiActivity {
|
||||
boolean modified = false;
|
||||
// changed did? this has to be done first as remFromDyn() involves a direct write to the database
|
||||
if (mCurrentEditedCard.getDid() != mCurrentDid) {
|
||||
mReloadRequired = true;
|
||||
// remove card from filtered deck first (if relevant)
|
||||
AnkiDroidApp.getCol().getSched().remFromDyn(new long[] { mCurrentEditedCard.getId() });
|
||||
// refresh the card object to reflect the database changes in remFromDyn()
|
||||
@ -811,7 +817,6 @@ public class NoteEditor extends AnkiActivity {
|
||||
// refresh the note object to reflect the database changes
|
||||
mEditorNote.load();
|
||||
// close note editor
|
||||
mReloadRequired = true;
|
||||
closeNoteEditor();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user