Skip to content

Commit

Permalink
Fix browser displayed deck when selected from DeckPicker's context menu
Browse files Browse the repository at this point in the history
CardBrowser uses LastDeckIdRepository to get the last selected deck id
but this wasn't updated in DeckPicker when selecting the browse option
in the context menu.

The fix extracts the SharedPreferencesLastDeckIdReporitory instance to the
application app where it can behave as a singleton available to
CardBrowser and DeckPicker.
  • Loading branch information
lukstbit authored and mikehardy committed Feb 3, 2024
1 parent 2ccbb28 commit 846cf2b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/AnkiDroidApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import androidx.lifecycle.MutableLiveData
import com.ichi2.anki.CrashReportService.sendExceptionReport
import com.ichi2.anki.UIUtils.showThemedToast
import com.ichi2.anki.analytics.UsageAnalytics
import com.ichi2.anki.browser.SharedPreferencesLastDeckIdRepository
import com.ichi2.anki.contextmenu.AnkiCardContextMenu
import com.ichi2.anki.contextmenu.CardBrowserContextMenu
import com.ichi2.anki.exception.StorageAccessException
Expand Down Expand Up @@ -73,6 +74,7 @@ open class AnkiDroidApp : Application() {
private val notifications = MutableLiveData<Void?>()

lateinit var activityAgnosticDialogs: ActivityAgnosticDialogs
val sharedPrefsLastDeckIdRepository = SharedPreferencesLastDeckIdRepository()

/** Used to avoid showing extra progress dialogs when one already shown. */
var progressDialogShown = false
Expand Down
2 changes: 1 addition & 1 deletion AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1891,7 +1891,7 @@ open class CardBrowser :
*/
private fun createViewModel() = ViewModelProvider(
viewModelStore,
CardBrowserViewModel.factory(SharedPreferencesLastDeckIdRepository()),
CardBrowserViewModel.factory(AnkiDroidApp.instance.sharedPrefsLastDeckIdRepository),
defaultViewModelCreationExtras
)[CardBrowserViewModel::class.java]

Expand Down
1 change: 1 addition & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ open class DeckPicker :
DeckPickerContextMenuOption.BROWSE_CARDS -> {
Timber.i("ContextMenu: Browse cards")
getColUnsafe.decks.select(deckId)
AnkiDroidApp.instance.sharedPrefsLastDeckIdRepository.lastDeckId = deckId
val intent = Intent(this, CardBrowser::class.java)
startActivity(intent)
dismissAllDialogFragments()
Expand Down

0 comments on commit 846cf2b

Please sign in to comment.