Skip to content

Commit 01553a2

Browse files
david-allisonBrayanDSO
authored andcommitted
fix(card-browser): note editor fragment updated browser deck
Prefer the parent fragment over the activity when finding `DeckSelectionListener` Fixes 18462
1 parent 5b182d3 commit 01553a2

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

AnkiDroid/src/main/java/com/ichi2/anki/dialogs/DeckSelectionDialog.kt

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import com.ichi2.anki.R
4444
import com.ichi2.anki.analytics.AnalyticsDialogFragment
4545
import com.ichi2.anki.common.utils.annotation.KotlinCleanup
4646
import com.ichi2.anki.dialogs.DeckSelectionDialog.DecksArrayAdapter.DecksFilter
47-
import com.ichi2.anki.dialogs.DeckSelectionDialog.SelectableDeck
4847
import com.ichi2.anki.launchCatchingTask
4948
import com.ichi2.anki.showThemedToast
5049
import com.ichi2.annotations.NeedsTest
@@ -247,23 +246,22 @@ open class DeckSelectionDialog : AnalyticsDialogFragment() {
247246
if (field != null) {
248247
return field
249248
}
249+
val parentFragment = parentFragment
250+
if (parentFragment is DeckSelectionListener) {
251+
return parentFragment
252+
}
250253
val activity: Activity = requireActivity()
251254
if (activity is DeckSelectionListener) {
252255
return activity
253256
}
254-
val parentFragment = parentFragment
255-
if (parentFragment is DeckSelectionListener) {
256-
return parentFragment
257-
} else {
258-
// try to find inside the activity an active fragment that is a DeckSelectionListener
259-
val foundAvailableFragments =
260-
parentFragmentManager.fragments.filter {
261-
it.isResumed && it is DeckSelectionListener
262-
}
263-
if (foundAvailableFragments.isNotEmpty()) {
264-
// if we found at least one resumed candidate fragment use it
265-
return foundAvailableFragments[0] as DeckSelectionListener
257+
// try to find inside the activity an active fragment that is a DeckSelectionListener
258+
val foundAvailableFragments =
259+
parentFragmentManager.fragments.filter {
260+
it.isResumed && it is DeckSelectionListener
266261
}
262+
if (foundAvailableFragments.isNotEmpty()) {
263+
// if we found at least one resumed candidate fragment use it
264+
return foundAvailableFragments[0] as DeckSelectionListener
267265
}
268266
throw IllegalStateException("Neither activity or any fragment in the activity were a selection listener")
269267
}

0 commit comments

Comments
 (0)