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 85b439b
Showing 1 changed file with 24 additions and 13 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 @@ -138,22 +139,32 @@ internal class CreditCardSaveDialogFragment : PromptDialogFragment() {

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,
)
is Result.CanBeCreated -> checkIfFragmentAttached {
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 -> checkIfFragmentAttached {
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 85b439b

Please sign in to comment.