Skip to content

Commit

Permalink
refactor [squash]: remove CreateCustomStudySessionListener.kt (#17510)
Browse files Browse the repository at this point in the history
* refactor: remove hide/showProgressBar

We now have all of these calls in `launchCatchingTask` /
`showProgress`

so an additional progress bar is not necessary

Adds `withProgress { }` for Fragments with
a default 'Processing' string

* refactor: inline CreateCustomStudySessionListener
It's just a callback, so use the interface

* refactor: remove CreateCustomStudySessionListener.kt
Just call the method after it's executed
We're now using coroutines, so a continuation is much simpler

* refactor: remove use of 'decks' outside `withCol`

* refactor: 'cram' to 'dynamicDeck'
We no longer use 'cram'

* docs: dismissAllDialogFragments is required
and can't be this.dismiss() inside the block for now
  • Loading branch information
david-allison authored Nov 29, 2024
1 parent 34b36c1 commit 12f9953
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ open class SingleFragmentActivity : AnkiActivity(), CustomStudyDialog.CustomStud
}

override fun onExtendStudyLimits() {
Timber.v("CustomStudyListener::hideProgressBar() - not handled")
Timber.v("CustomStudyListener::onExtendStudyLimits()")
openStudyOptionsAndFinish()
}

Expand All @@ -142,10 +142,6 @@ open class SingleFragmentActivity : AnkiActivity(), CustomStudyDialog.CustomStud
openStudyOptionsAndFinish()
}

override fun hideProgressBar() {
Timber.v("CustomStudyListener::hideProgressBar() - not handled")
}

// END CustomStudyListener temporary implementation - should refactor out
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import androidx.annotation.VisibleForTesting
import androidx.appcompat.app.AlertDialog
import androidx.core.content.edit
import androidx.fragment.app.DialogFragment
import com.ichi2.anki.CollectionManager.withCol
import com.ichi2.anki.CrashReportService
import com.ichi2.anki.R
import com.ichi2.anki.Reviewer
Expand All @@ -48,6 +49,7 @@ import com.ichi2.anki.launchCatchingTask
import com.ichi2.anki.model.CardStateFilter
import com.ichi2.anki.preferences.sharedPrefs
import com.ichi2.anki.showThemedToast
import com.ichi2.anki.withProgress
import com.ichi2.annotations.NeedsTest
import com.ichi2.libanki.Collection
import com.ichi2.libanki.Consts
Expand Down Expand Up @@ -83,7 +85,8 @@ private const val DID = "did"
private const val JUMP_TO_REVIEWER = "jumpToReviewer"
class CustomStudyDialog(private val collection: Collection, private val customStudyListener: CustomStudyListener?) : AnalyticsDialogFragment(), TagsDialogListener {

interface CustomStudyListener : CreateCustomStudySessionListener.Callback {
interface CustomStudyListener {
fun onCreateCustomStudySession()
fun onExtendStudyLimits()
fun showDialogFragment(newFragment: DialogFragment)
fun dismissAllDialogFragments()
Expand Down Expand Up @@ -440,11 +443,20 @@ class CustomStudyDialog(private val collection: Collection, private val customSt
Timber.i("Rebuilding Custom Study Deck")
// PERF: Should be in background
collection.decks.save(dyn)
requireActivity().launchCatchingTask { rebuildCram(CreateCustomStudySessionListener(customStudyListener!!)) }
// Hide the dialogs
// launch this in the activity scope, rather than the fragment scope
requireActivity().launchCatchingTask { rebuildDynamicDeck() }
// Hide the dialogs (required due to a DeckPicker issue)
customStudyListener?.dismissAllDialogFragments()
}

private suspend fun rebuildDynamicDeck() {
Timber.d("rebuildDynamicDeck()")
withProgress {
withCol { sched.rebuildDyn(decks.selected()) }
customStudyListener?.onCreateCustomStudySession()
}
}

private fun onLimitsExtended(jumpToReviewer: Boolean) {
if (jumpToReviewer) {
customStudyListener?.startActivity(Intent(requireContext(), Reviewer::class.java))
Expand Down
8 changes: 0 additions & 8 deletions AnkiDroid/src/main/java/com/ichi2/anki/pages/CongratsPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -165,18 +165,10 @@ class CongratsPage :
openStudyOptionsAndFinish()
}

override fun showProgressBar() {
Timber.v("CustomStudyListener::showProgressBar() - not handled")
}

override fun dismissAllDialogFragments() {
Timber.v("CustomStudyListener::dismissAllDialogFragments() - not handled")
}

override fun hideProgressBar() {
Timber.v("CustomStudyListener::hideProgressBar() - not handled")
}

companion object {
fun getIntent(context: Context): Intent {
return getIntent(context, path = "congrats", clazz = CongratsPage::class)
Expand Down

0 comments on commit 12f9953

Please sign in to comment.