0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-19 19:42:17 +02:00

Fix CardBrowser shows wrong deck

(cherry picked from commit c84cf4b151)
This commit is contained in:
tda1009 2021-07-10 15:02:57 +07:00 committed by Mike Hardy
parent 4845c885a3
commit 7bb570d131
No known key found for this signature in database
GPG Key ID: 2FB9315A0E38FF42
4 changed files with 23 additions and 11 deletions

View File

@ -128,6 +128,7 @@ public class CardBrowser extends NavigationDrawerActivity implements
}
long deckId = deck.getDeckId();
mDeckSpinnerSelection.initializeActionBarDeckSpinner();
mDeckSpinnerSelection.selectDeckById(deckId, true);
selectDeckAndSave(deckId);
}
@ -762,14 +763,14 @@ public class CardBrowser extends NavigationDrawerActivity implements
if (getLastDeckId() != null && getLastDeckId() == ALL_DECKS_ID) {
selectAllDecks();
} else if (getLastDeckId() != null && getCol().getDecks().get(getLastDeckId(), false) != null) {
mDeckSpinnerSelection.selectDeckById(getLastDeckId());
mDeckSpinnerSelection.selectDeckById(getLastDeckId(), false);
} else {
mDeckSpinnerSelection.selectDeckById(getCol().getDecks().selected());
mDeckSpinnerSelection.selectDeckById(getCol().getDecks().selected(), false);
}
}
public void selectDeckAndSave(long deckId) {
mDeckSpinnerSelection.selectDeckById(deckId);
mDeckSpinnerSelection.selectDeckById(deckId, true);
if (deckId == ALL_DECKS_ID) {
mRestrictOnDeck = "";
} else {

View File

@ -174,21 +174,32 @@ public class DeckSpinnerSelection {
return mSpinner;
}
// Iterates the drop down decks, and selects the one matching the given id
public boolean selectDeckById(long deckId) {
/**
* Iterates the drop down decks, and selects the one matching the given id.
* @param deckId The deck id to be selected.
* @param setAsCurrentDeck If true, deckId will be set as the current deck id of Collection
* (this means the deck selected here will continue to appear in any future Activity whose
* display data is loaded from Collection's current deck). If false, deckId will not be set as
* the current deck id of Collection.
* @return True if a deck with deckId exists, false otherwise.
*/
public boolean selectDeckById(long deckId, boolean setAsCurrentDeck) {
if (deckId == ALL_DECKS_ID) {
selectAllDecks();
return true;
}
return searchInList(deckId);
return searchInList(deckId, setAsCurrentDeck);
}
private boolean searchInList(long deckId) {
private boolean searchInList(long deckId, boolean setAsCurrentDeck) {
for (int dropDownDeckIdx = 0; dropDownDeckIdx < mAllDeckIds.size(); dropDownDeckIdx++) {
if (mAllDeckIds.get(dropDownDeckIdx) == deckId) {
int position = mShowAllDecks ? dropDownDeckIdx + 1 : dropDownDeckIdx;
selectDropDownItem(position);
if (setAsCurrentDeck) {
mContext.getCol().getDecks().select(deckId);
}
return true;
}
}

View File

@ -269,7 +269,7 @@ public class NoteEditor extends AnkiActivity implements
}
mCurrentDid = deck.getDeckId();
mDeckSpinnerSelection.initializeNoteEditorDeckSpinner(mCurrentEditedCard, mAddNote);
mDeckSpinnerSelection.selectDeckById(deck.getDeckId());
mDeckSpinnerSelection.selectDeckById(deck.getDeckId(), false);
}
@Override
@ -1899,7 +1899,7 @@ public class NoteEditor extends AnkiActivity implements
} else {
mCurrentDid = mCurrentEditedCard.getDid();
}
mDeckSpinnerSelection.selectDeckById(mCurrentDid);
mDeckSpinnerSelection.selectDeckById(mCurrentDid, false);
}

View File

@ -132,7 +132,7 @@ public class Statistics extends NavigationDrawerActivity implements
mDeckSpinnerSelection = new DeckSpinnerSelection(this, R.id.toolbar_spinner);
mDeckSpinnerSelection.initializeActionBarDeckSpinner();
mDeckSpinnerSelection.setShowAllDecks(true);
mDeckSpinnerSelection.selectDeckById(deckId);
mDeckSpinnerSelection.selectDeckById(deckId, false);
mTaskHandler.setDeckId(deckId);
mViewPager.getAdapter().notifyDataSetChanged();
}
@ -235,7 +235,7 @@ public class Statistics extends NavigationDrawerActivity implements
return;
}
mDeckSpinnerSelection.initializeActionBarDeckSpinner();
mDeckSpinnerSelection.selectDeckById(deck.getDeckId());
mDeckSpinnerSelection.selectDeckById(deck.getDeckId(), true);
mTaskHandler.setDeckId(deck.getDeckId());
mViewPager.getAdapter().notifyDataSetChanged();
}