1
0
Fork 0

For #2025 - Create and theme Dialog for deleting all history

master
Emily Kager 2019-05-20 15:33:59 -07:00 committed by Jeff Boek
parent fd4de3509d
commit 028c6cad70
4 changed files with 40 additions and 4 deletions

View File

@ -4,6 +4,7 @@
package org.mozilla.fenix.library.history
import android.content.DialogInterface
import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter
import android.os.Bundle
@ -14,7 +15,9 @@ import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.view.ContextThemeWrapper
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.navigation.Navigation
@ -136,9 +139,28 @@ class HistoryFragment : Fragment(), CoroutineScope, BackHandler {
.onNext(HistoryChange.RemoveItemForRemoval(it.item))
is HistoryAction.BackPressed -> getManagedEmitter<HistoryChange>()
.onNext(HistoryChange.ExitEditMode)
is HistoryAction.Delete.All -> launch(Dispatchers.IO) {
requireComponents.core.historyStorage.deleteEverything()
reloadData()
is HistoryAction.Delete.All -> {
activity?.let {
AlertDialog.Builder(
ContextThemeWrapper(
it,
R.style.DialogStyle
)
).apply {
setMessage(R.string.history_delete_all_dialog)
setNegativeButton(android.R.string.cancel) { dialog: DialogInterface, _ ->
dialog.cancel()
}
setPositiveButton(android.R.string.ok) { dialog: DialogInterface, _ ->
launch(Dispatchers.IO) {
requireComponents.core.historyStorage.deleteEverything()
reloadData()
}
dialog.dismiss()
}
create()
}.show()
}
}
is HistoryAction.Delete.One -> launch(Dispatchers.IO) {
requireComponents.core.historyStorage.deleteVisit(it.item.url, it.item.visitedAt)

View File

@ -11,6 +11,7 @@ import android.graphics.Typeface.BOLD
import android.graphics.Typeface.ITALIC
import android.os.Bundle
import android.text.style.StyleSpan
import android.view.ContextThemeWrapper
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -112,7 +113,12 @@ class SearchFragment : Fragment(), BackHandler {
onScanResult = { result ->
search_scan_button.isChecked = false
activity?.let {
AlertDialog.Builder(it).apply {
AlertDialog.Builder(
ContextThemeWrapper(
it,
R.style.DialogStyle
)
).apply {
val spannable = resources.getSpannable(
R.string.qr_scanner_confirmation_dialog_message,
listOf(

View File

@ -299,6 +299,8 @@
<!-- History -->
<!-- Text for the button to clear all history -->
<string name="history_delete_all">Delete history</string>
<!-- Text for the dialog to confirm clearing all history -->
<string name="history_delete_all_dialog">Are you sure you want to clear your history?</string>
<!-- Text for the button to delete a single history item -->
<string name="history_delete_item">Delete</string>
<!-- History multi select title in app bar

View File

@ -47,6 +47,12 @@
<style name="NormalTheme" parent="NormalThemeBase" />
<style name="DialogStyle" parent="Theme.MaterialComponents.Dialog.Alert">
<item name="android:background">?above</item>
<item name="colorAccent">?accent</item>
<item name="android:textColorPrimary">?primaryText</item>
</style>
<style name="PrivateThemeBase" parent="Theme.AppCompat.NoActionBar">
<!-- Android system styling -->
<item name="android:windowAnimationStyle">@style/WindowAnimationTransition</item>