Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import com.ichi2.anki.R
import com.ichi2.anki.analytics.AnalyticsDialogFragment
import com.ichi2.anki.common.utils.annotation.KotlinCleanup
import com.ichi2.anki.dialogs.DeckSelectionDialog.DecksArrayAdapter.DecksFilter
import com.ichi2.anki.dialogs.DeckSelectionDialog.SelectableDeck
import com.ichi2.anki.launchCatchingTask
import com.ichi2.anki.showThemedToast
import com.ichi2.annotations.NeedsTest
Expand Down Expand Up @@ -247,23 +246,22 @@ open class DeckSelectionDialog : AnalyticsDialogFragment() {
if (field != null) {
return field
}
val parentFragment = parentFragment
if (parentFragment is DeckSelectionListener) {
return parentFragment
}
val activity: Activity = requireActivity()
if (activity is DeckSelectionListener) {
return activity
}
val parentFragment = parentFragment
if (parentFragment is DeckSelectionListener) {
return parentFragment
} else {
// try to find inside the activity an active fragment that is a DeckSelectionListener
val foundAvailableFragments =
parentFragmentManager.fragments.filter {
it.isResumed && it is DeckSelectionListener
}
if (foundAvailableFragments.isNotEmpty()) {
// if we found at least one resumed candidate fragment use it
return foundAvailableFragments[0] as DeckSelectionListener
// try to find inside the activity an active fragment that is a DeckSelectionListener
val foundAvailableFragments =
parentFragmentManager.fragments.filter {
it.isResumed && it is DeckSelectionListener
}
if (foundAvailableFragments.isNotEmpty()) {
// if we found at least one resumed candidate fragment use it
return foundAvailableFragments[0] as DeckSelectionListener
}
throw IllegalStateException("Neither activity or any fragment in the activity were a selection listener")
}
Expand Down