Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Commit

Permalink
Bug 1812181 - Firefox for Android crashes submitting form
Browse files Browse the repository at this point in the history
Add a check for fragment attached and current context nullability before using requireContext.
  • Loading branch information
AdrianaMaries committed Mar 20, 2024
1 parent e5a9344 commit 642f9f6
Showing 1 changed file with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package mozilla.components.feature.prompts.creditcard

import android.app.Dialog
import android.content.Context
import android.content.DialogInterface
import android.os.Bundle
import android.view.LayoutInflater
Expand Down Expand Up @@ -137,23 +138,31 @@ internal class CreditCardSaveDialogFragment : PromptDialogFragment() {
confirmResult = validationDelegate.shouldCreateOrUpdate(creditCard)

withContext(Main) {
when (confirmResult) {
is Result.CanBeCreated -> setViewText(
view = view,
header = requireContext().getString(R.string.mozac_feature_prompts_save_credit_card_prompt_title),
cancelButtonText = requireContext().getString(R.string.mozac_feature_prompt_not_now),
confirmButtonText = requireContext().getString(R.string.mozac_feature_prompt_save_confirmation),
)
is Result.CanBeUpdated -> setViewText(
view = view,
header = requireContext().getString(R.string.mozac_feature_prompts_update_credit_card_prompt_title),
cancelButtonText = requireContext().getString(R.string.mozac_feature_prompts_cancel),
confirmButtonText = requireContext().getString(R.string.mozac_feature_prompt_update_confirmation),
showMessageBody = false,
)
checkIfFragmentAttached {
when (confirmResult) {
is Result.CanBeCreated -> setViewText(
view = view,
header = requireContext().getString(R.string.mozac_feature_prompts_save_credit_card_prompt_title),
cancelButtonText = requireContext().getString(R.string.mozac_feature_prompt_not_now),
confirmButtonText = requireContext().getString(R.string.mozac_feature_prompt_save_confirmation),
)

is Result.CanBeUpdated -> setViewText(
view = view,
header = requireContext().getString(R.string.mozac_feature_prompts_update_credit_card_prompt_title),
cancelButtonText = requireContext().getString(R.string.mozac_feature_prompts_cancel),
confirmButtonText = requireContext().getString(R.string.mozac_feature_prompt_update_confirmation),
showMessageBody = false,
)
}
}
}
}
private fun checkIfFragmentAttached(operation: Context.() -> Unit) {
if (isAdded && context != null) {
operation(requireContext())
}
}

/**
* Updates the header and button text in the dialog.
Expand Down

0 comments on commit 642f9f6

Please sign in to comment.