Add dialog protection and remote deletion to disabling stories and deleting lists.

This commit is contained in:
Alex Hart
2022-10-05 15:04:54 -03:00
committed by GitHub
parent ad1801108d
commit 4b94509a7a
15 changed files with 212 additions and 19 deletions

View File

@@ -0,0 +1,35 @@
package org.thoughtcrime.securesms.components
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
/**
* Manages the lifecycle of displaying a dialog fragment. Will automatically close and nullify the reference
* if the bound lifecycle is destroyed, and handles repeat calls to show such that no more than one dialog is
* displayed.
*/
class DialogFragmentDisplayManager(private val builder: () -> DialogFragment) : DefaultLifecycleObserver {
private var dialogFragment: DialogFragment? = null
fun show(lifecycleOwner: LifecycleOwner, fragmentManager: FragmentManager, tag: String? = null) {
val fragment = dialogFragment ?: builder()
if (fragment.dialog?.isShowing != true) {
fragment.show(fragmentManager, tag)
dialogFragment = fragment
lifecycleOwner.lifecycle.addObserver(this)
}
}
fun hide() {
dialogFragment?.dismissNow()
dialogFragment = null
}
override fun onDestroy(owner: LifecycleOwner) {
owner.lifecycle.removeObserver(this)
hide()
}
}

View File

@@ -0,0 +1,20 @@
package org.thoughtcrime.securesms.components
import android.app.Dialog
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import androidx.fragment.app.DialogFragment
import org.thoughtcrime.securesms.R
/**
* Displays a small progress spinner in a card view, as a non-cancellable dialog fragment.
*/
class ProgressCardDialogFragment : DialogFragment(R.layout.progress_card_dialog) {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
isCancelable = false
return super.onCreateDialog(savedInstanceState).apply {
this.window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
}
}
}

View File

@@ -44,6 +44,33 @@ class StoryDialogLauncherFragment : DSLSettingsFragment(titleId = R.string.prefe
}
}
)
clickPref(
title = DSLSettingsText.from(R.string.preferences__internal_turn_off_stories),
onClick = {
StoryDialogs.disableStories(requireContext(), false) {
Toast.makeText(requireContext(), R.string.preferences__internal_turn_off_stories, Toast.LENGTH_SHORT).show()
}
}
)
clickPref(
title = DSLSettingsText.from(R.string.preferences__internal_turn_off_stories_with_stories_on_disk),
onClick = {
StoryDialogs.disableStories(requireContext(), true) {
Toast.makeText(requireContext(), R.string.preferences__internal_turn_off_stories_with_stories_on_disk, Toast.LENGTH_SHORT).show()
}
}
)
clickPref(
title = DSLSettingsText.from(R.string.preferences__internal_delete_private_story),
onClick = {
StoryDialogs.deleteDistributionList(requireContext(), "Family") {
Toast.makeText(requireContext(), R.string.preferences__internal_delete_private_story, Toast.LENGTH_SHORT).show()
}
}
)
}
}
}