parent
b1e17bb939
commit
832fd71afc
|
@ -4,12 +4,15 @@
|
||||||
|
|
||||||
package org.mozilla.fenix.home
|
package org.mozilla.fenix.home
|
||||||
|
|
||||||
|
import android.content.DialogInterface
|
||||||
import android.content.res.Resources
|
import android.content.res.Resources
|
||||||
import android.graphics.drawable.BitmapDrawable
|
import android.graphics.drawable.BitmapDrawable
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.view.ContextThemeWrapper
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.constraintlayout.widget.ConstraintLayout.LayoutParams.PARENT_ID
|
import androidx.constraintlayout.widget.ConstraintLayout.LayoutParams.PARENT_ID
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
|
@ -85,7 +88,6 @@ class HomeFragment : Fragment(), CoroutineScope, AccountObserver {
|
||||||
|
|
||||||
var deleteAllSessionsJob: (suspend () -> Unit)? = null
|
var deleteAllSessionsJob: (suspend () -> Unit)? = null
|
||||||
var deleteSessionJob: (suspend () -> Unit)? = null
|
var deleteSessionJob: (suspend () -> Unit)? = null
|
||||||
var deleteCollectionJob: (suspend () -> Unit)? = null
|
|
||||||
|
|
||||||
private val onboarding by lazy { FenixOnboarding(requireContext()) }
|
private val onboarding by lazy { FenixOnboarding(requireContext()) }
|
||||||
private lateinit var sessionControlComponent: SessionControlComponent
|
private lateinit var sessionControlComponent: SessionControlComponent
|
||||||
|
@ -346,14 +348,29 @@ class HomeFragment : Fragment(), CoroutineScope, AccountObserver {
|
||||||
deleteAllSessionsJob = null
|
deleteAllSessionsJob = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
deleteCollectionJob?.let {
|
private fun createDeleteCollectionPrompt(tabCollection: TabCollection) {
|
||||||
launch {
|
AlertDialog.Builder(
|
||||||
it.invoke()
|
ContextThemeWrapper(
|
||||||
|
activity,
|
||||||
|
R.style.DialogStyle
|
||||||
|
)
|
||||||
|
).apply {
|
||||||
|
val message = context.getString(R.string.tab_collection_dialog_message, tabCollection.title)
|
||||||
|
setMessage(message)
|
||||||
|
setNegativeButton(R.string.tab_collection_dialog_negative) { dialog: DialogInterface, _ ->
|
||||||
|
dialog.cancel()
|
||||||
|
}
|
||||||
|
setPositiveButton(R.string.tab_collection_dialog_positive) { dialog: DialogInterface, _ ->
|
||||||
|
launch(Dispatchers.IO) {
|
||||||
|
requireComponents.core.tabCollectionStorage.removeCollection(tabCollection)
|
||||||
}.invokeOnCompletion {
|
}.invokeOnCompletion {
|
||||||
deleteCollectionJob = null
|
dialog.dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
create()
|
||||||
|
}.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("ComplexMethod")
|
@Suppress("ComplexMethod")
|
||||||
|
@ -368,7 +385,7 @@ class HomeFragment : Fragment(), CoroutineScope, AccountObserver {
|
||||||
.onNext(SessionControlChange.ExpansionChange(action.collection, false))
|
.onNext(SessionControlChange.ExpansionChange(action.collection, false))
|
||||||
}
|
}
|
||||||
is CollectionAction.Delete -> {
|
is CollectionAction.Delete -> {
|
||||||
removeCollectionWithUndo(action.collection)
|
createDeleteCollectionPrompt(action.collection)
|
||||||
}
|
}
|
||||||
is CollectionAction.AddTab -> {
|
is CollectionAction.AddTab -> {
|
||||||
ItsNotBrokenSnack(context!!).showSnackbar(issueNumber = "1575")
|
ItsNotBrokenSnack(context!!).showSnackbar(issueNumber = "1575")
|
||||||
|
@ -569,32 +586,6 @@ class HomeFragment : Fragment(), CoroutineScope, AccountObserver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun removeCollectionWithUndo(tabCollection: TabCollection) {
|
|
||||||
// Update the UI with the tab collection removed, but don't remove it from storage yet
|
|
||||||
val updatedCollectionList = requireComponents.core.tabCollectionStorage.cachedTabCollections.toMutableList()
|
|
||||||
updatedCollectionList.remove(tabCollection)
|
|
||||||
getManagedEmitter<SessionControlChange>().onNext(SessionControlChange.CollectionsChange(updatedCollectionList))
|
|
||||||
|
|
||||||
deleteCollectionJob = {
|
|
||||||
launch(Dispatchers.IO) {
|
|
||||||
requireComponents.core.tabCollectionStorage.removeCollection(tabCollection)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CoroutineScope(Dispatchers.Main).allowUndo(
|
|
||||||
view!!, getString(R.string.snackbar_collection_deleted),
|
|
||||||
getString(R.string.snackbar_deleted_undo), {
|
|
||||||
deleteCollectionJob = null
|
|
||||||
getManagedEmitter<SessionControlChange>().onNext(SessionControlChange
|
|
||||||
.CollectionsChange(requireComponents.core.tabCollectionStorage.cachedTabCollections))
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
launch(Dispatchers.IO) {
|
|
||||||
requireComponents.core.tabCollectionStorage.removeCollection(tabCollection)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun emitSessionChanges() {
|
private fun emitSessionChanges() {
|
||||||
val sessionManager = requireComponents.core.sessionManager
|
val sessionManager = requireComponents.core.sessionManager
|
||||||
|
|
||||||
|
|
|
@ -513,6 +513,12 @@
|
||||||
<string name="qr_scanner_dialog_positive">ALLOW</string>
|
<string name="qr_scanner_dialog_positive">ALLOW</string>
|
||||||
<!-- QR code scanner prompt dialog positive option to deny navigation to scanned link -->
|
<!-- QR code scanner prompt dialog positive option to deny navigation to scanned link -->
|
||||||
<string name="qr_scanner_dialog_negative">DENY</string>
|
<string name="qr_scanner_dialog_negative">DENY</string>
|
||||||
|
<!-- Tab collection deletion prompt dialog message. Placeholder will be replaced with the collection name -->
|
||||||
|
<string name="tab_collection_dialog_message">Are you sure you want to delete %1$s?</string>
|
||||||
|
<!-- Tab collection deletion prompt dialog option to delete the collection -->
|
||||||
|
<string name="tab_collection_dialog_positive">Delete</string>
|
||||||
|
<!-- Tab collection deletion prompt dialog option to cancel deleting the collection -->
|
||||||
|
<string name="tab_collection_dialog_negative">Cancel</string>
|
||||||
<!-- Text displayed in a notification when the user enters full screen mode -->
|
<!-- Text displayed in a notification when the user enters full screen mode -->
|
||||||
<string name="full_screen_notification">Entering full screen mode</string>
|
<string name="full_screen_notification">Entering full screen mode</string>
|
||||||
<!-- Message for copying the URL via long press on the toolbar -->
|
<!-- Message for copying the URL via long press on the toolbar -->
|
||||||
|
|
Loading…
Reference in New Issue