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

fix: ignore shared deck download and dialog dismissal at inappropriate lifecycle states #17483

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
11 changes: 7 additions & 4 deletions AnkiDroid/src/main/java/com/ichi2/anki/AnkiActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -580,10 +580,13 @@ open class AnkiActivity : AppCompatActivity, SimpleMessageDialogListener, Shortc

// Dismiss whatever dialog is showing
fun dismissAllDialogFragments() {
supportFragmentManager.popBackStack(
DIALOG_FRAGMENT_TAG,
FragmentManager.POP_BACK_STACK_INCLUSIVE
)
// trying to pop fragment manager back state crashes if state already saved
if (!supportFragmentManager.isStateSaved) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally, the callers shouldn't be trying to manually dismiss a dialog when an activity is being destroyed.

Given our need to fix an issue and the current disorder in AnkiActivity, this is reasonable. But, the whole area needs some work in the future.

supportFragmentManager.popBackStack(
DIALOG_FRAGMENT_TAG,
FragmentManager.POP_BACK_STACK_INCLUSIVE
)
}
}

/**
Expand Down
13 changes: 8 additions & 5 deletions AnkiDroid/src/main/java/com/ichi2/anki/SharedDecksActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,14 @@ class SharedDecksActivity : AnkiActivity() {
webView.loadUrl(resources.getString(R.string.shared_decks_url))
webView.webViewClient = WebViewClient()
webView.setDownloadListener { url, userAgent, contentDisposition, mimetype, _ ->
val sharedDecksDownloadFragment = SharedDecksDownloadFragment()
sharedDecksDownloadFragment.arguments = bundleOf(DOWNLOAD_FILE to DownloadFile(url, userAgent, contentDisposition, mimetype))

supportFragmentManager.commit {
add(R.id.shared_decks_fragment_container, sharedDecksDownloadFragment, SHARED_DECKS_DOWNLOAD_FRAGMENT).addToBackStack(null)
// If the activity/fragment lifecycle has already begun teardown process,
// avoid handling the download, as FragmentManager.commit will throw
if (!supportFragmentManager.isStateSaved) {
val sharedDecksDownloadFragment = SharedDecksDownloadFragment()
sharedDecksDownloadFragment.arguments = bundleOf(DOWNLOAD_FILE to DownloadFile(url, userAgent, contentDisposition, mimetype))
supportFragmentManager.commit {
add(R.id.shared_decks_fragment_container, sharedDecksDownloadFragment, SHARED_DECKS_DOWNLOAD_FRAGMENT).addToBackStack(null)
}
}
}

Expand Down