Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove legacy collection loading code from AnkiFragment #17457

Merged
Merged
Show file tree
Hide file tree
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
44 changes: 0 additions & 44 deletions AnkiDroid/src/main/java/com/ichi2/anki/AnkiFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.Fragment
import com.ichi2.anki.android.input.ShortcutGroup
import com.ichi2.async.CollectionLoader
import com.ichi2.libanki.Collection
import com.ichi2.themes.Themes
import com.ichi2.utils.increaseHorizontalPaddingOfOverflowMenuIcons
Expand Down Expand Up @@ -61,13 +60,6 @@ open class AnkiFragment(@LayoutRes layout: Int) : Fragment(layout), AnkiActivity

// Open function: These can be overridden to react to specific parts of the lifecycle

/**
* Callback for [startLoadingCollection], executed once the collection is available.
*/
protected open fun onCollectionLoaded(col: Collection) {
hideProgressBar()
}

@Suppress("deprecation", "API35 properly handle edge-to-edge")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
requireActivity().window.statusBarColor = Themes.getColorFromAttr(requireContext(), R.attr.appBarColor)
Expand Down Expand Up @@ -111,16 +103,6 @@ open class AnkiFragment(@LayoutRes layout: Int) : Fragment(layout), AnkiActivity
return requireView().findViewById(id)
}

/**
* Hides progress bar.
*/
private fun hideProgressBar() = ankiActivity.hideProgressBar()

/**
* Shows progress bar.
*/
private fun showProgressBar() = ankiActivity.showProgressBar()

/**
* Unregisters a previously registered broadcast receiver.
*
Expand Down Expand Up @@ -163,32 +145,6 @@ open class AnkiFragment(@LayoutRes layout: Int) : Fragment(layout), AnkiActivity
mainToolbar.setTitle(title)
}

/**
* Starts loading the Anki collection asynchronously if it hasn't been opened yet.
* If the collection is already open, calls `onCollectionLoaded` synchronously.
* Shows a progress bar during loading.
*/
protected fun startLoadingCollection() {
Timber.d("AnkiFragment.startLoadingCollection()")
if (CollectionManager.isOpenUnsafe()) {
Timber.d("Synchronously calling onCollectionLoaded")
onCollectionLoaded(getColUnsafe)
return
}
// Open collection asynchronously if it hasn't already been opened
showProgressBar()
CollectionLoader.load(
this
) { col: Collection? ->
if (col != null) {
Timber.d("Asynchronously calling onCollectionLoaded")
onCollectionLoaded(col)
} else {
ankiActivity.onCollectionLoadError()
}
}
}

/**
* Method to show dialog fragment including adding it to back stack
*
Expand Down
10 changes: 7 additions & 3 deletions AnkiDroid/src/main/java/com/ichi2/anki/NoteEditor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,12 @@ class NoteEditor : AnkiFragment(R.layout.note_editor), DeckSelectionListener, Su
)
setIconColor(MaterialColors.getColor(requireContext(), R.attr.toolbarIconColor, 0))
}
startLoadingCollection()
try {
setupEditor(getColUnsafe)
} catch (ex: RuntimeException) {
ankiActivity.onCollectionLoadError()
return
}
// TODO this callback doesn't handle predictive back navigation!
// see #14678, added to temporarily fix for a bug
requireActivity().onBackPressedDispatcher.addCallback(this) {
Expand Down Expand Up @@ -574,8 +579,7 @@ class NoteEditor : AnkiFragment(R.layout.note_editor), DeckSelectionListener, Su
get() = NoteService.getFieldsAsBundleForPreview(editFields, shouldReplaceNewlines())

// Finish initializing the fragment after the collection has been correctly loaded
override fun onCollectionLoaded(col: Collection) {
super.onCollectionLoaded(col)
private fun setupEditor(col: Collection) {
val intent = requireActivity().intent
Timber.d("NoteEditor() onCollectionLoaded: caller: %d", caller)
ankiActivity.registerReceiver()
Expand Down
2 changes: 0 additions & 2 deletions AnkiDroid/src/main/res/layout/note_editor.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,4 @@
android:id="@+id/editor_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

<include layout="@layout/anki_progress"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>