This repository has been archived by the owner on Nov 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #9471: Fix Confirm and Alert js dialogs don't show buttons whe…
…n the message is too long.
- Loading branch information
1 parent
72a4f34
commit d63d0c5
Showing
12 changed files
with
161 additions
and
153 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
...c/main/java/mozilla/components/feature/prompts/dialog/AbstractPromptTextDialogFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package mozilla.components.feature.prompts.dialog | ||
|
||
import android.annotation.SuppressLint | ||
import android.text.method.ScrollingMovementMethod | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.widget.CheckBox | ||
import android.widget.TextView | ||
import androidx.annotation.IdRes | ||
import androidx.appcompat.app.AlertDialog | ||
import androidx.core.view.isVisible | ||
import mozilla.components.feature.prompts.R | ||
|
||
internal const val KEY_MANY_ALERTS = "KEY_MANY_ALERTS" | ||
internal const val KEY_USER_CHECK_BOX = "KEY_USER_CHECK_BOX" | ||
/** | ||
* An abstract alert for showing a text message plus a checkbox for handling [hasShownManyDialogs]. | ||
*/ | ||
internal abstract class AbstractPromptTextDialogFragment : PromptDialogFragment() { | ||
|
||
/** | ||
* Tells if a checkbox should be shown for preventing this [sessionId] from showing more dialogs. | ||
*/ | ||
internal val hasShownManyDialogs: Boolean by lazy { safeArguments.getBoolean(KEY_MANY_ALERTS) } | ||
|
||
/** | ||
* Stores the user's decision from the checkbox | ||
* for preventing this [sessionId] from showing more dialogs. | ||
*/ | ||
internal var userSelectionNoMoreDialogs: Boolean | ||
get() = safeArguments.getBoolean(KEY_USER_CHECK_BOX) | ||
set(value) { | ||
safeArguments.putBoolean(KEY_USER_CHECK_BOX, value) | ||
} | ||
|
||
/** | ||
* Creates custom view that adds a [TextView] + [CheckBox] and attach the corresponding | ||
* events for handling [hasShownManyDialogs]. | ||
*/ | ||
@SuppressLint("InflateParams") | ||
internal fun setCustomMessageView(builder: AlertDialog.Builder): AlertDialog.Builder { | ||
val inflater = LayoutInflater.from(requireContext()) | ||
val view = inflater.inflate(R.layout.mozac_feature_prompt_with_check_box, null) | ||
val textView = view.findViewById<TextView>(R.id.message) | ||
textView.text = message | ||
textView.movementMethod = ScrollingMovementMethod() | ||
|
||
addCheckBoxIfNeeded(view) | ||
|
||
builder.setView(view) | ||
|
||
return builder | ||
} | ||
|
||
internal fun addCheckBoxIfNeeded( | ||
view: View, | ||
@IdRes id: Int = R.id.mozac_feature_prompts_no_more_dialogs_check_box | ||
) { | ||
if ((hasShownManyDialogs)) { | ||
val checkBox = view.findViewById<CheckBox>(id) | ||
checkBox.isVisible = true | ||
checkBox.setOnCheckedChangeListener { _, isChecked -> | ||
userSelectionNoMoreDialogs = isChecked | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 0 additions & 20 deletions
20
...nents/feature/prompts/src/main/res/layout/mozac_feature_many_dialogs_checkbox_dialogs.xml
This file was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
components/feature/prompts/src/main/res/layout/mozac_feature_prompt_with_check_box.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- This Source Code Form is subject to the terms of the Mozilla Public | ||
- License, v. 2.0. If a copy of the MPL was not distributed with this | ||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. --> | ||
|
||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:paddingTop="?android:attr/listPreferredItemPaddingLeft" | ||
android:paddingStart="?android:attr/listPreferredItemPaddingLeft" | ||
android:paddingEnd="?android:attr/listPreferredItemPaddingLeft"> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:paddingStart="?android:attr/listPreferredItemPaddingLeft" | ||
android:paddingEnd="?android:attr/listPreferredItemPaddingLeft"> | ||
|
||
<TextView | ||
android:id="@+id/message" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:maxLines="30" | ||
android:scrollbars="vertical" | ||
android:textColor="?android:attr/textColorPrimary" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
tools:text="Message" /> | ||
|
||
<CheckBox | ||
android:id="@id/mozac_feature_prompts_no_more_dialogs_check_box" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:text="@string/mozac_feature_prompts_no_more_dialogs" | ||
android:textColor="?android:attr/textColorPrimary" | ||
android:visibility="gone" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@id/message" | ||
tools:visibility="visible" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
</ScrollView> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- This Source Code Form is subject to the terms of the Mozilla Public | ||
- License, v. 2.0. If a copy of the MPL was not distributed with this | ||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. --> | ||
<resources> | ||
<item name="mozac_feature_prompts_no_more_dialogs_check_box" type="id"/> | ||
</resources> |
Oops, something went wrong.