mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-23 12:38:33 +00:00
Add warning dialog for chat color deletion with no uses.
This commit is contained in:
committed by
Cody Henthorne
parent
416e62112f
commit
172cc302fc
@@ -46,7 +46,11 @@ class ChatColorSelectionFragment : Fragment(R.layout.chat_color_selection_fragme
|
|||||||
|
|
||||||
viewModel.events.observe(viewLifecycleOwner) { event ->
|
viewModel.events.observe(viewLifecycleOwner) { event ->
|
||||||
if (event is ChatColorSelectionViewModel.Event.ConfirmDeletion) {
|
if (event is ChatColorSelectionViewModel.Event.ConfirmDeletion) {
|
||||||
showWarningDialog(event)
|
if (event.usageCount > 0) {
|
||||||
|
showWarningDialogForMultipleUses(event)
|
||||||
|
} else {
|
||||||
|
showWarningDialogForNoUses(event)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -56,7 +60,20 @@ class ChatColorSelectionFragment : Fragment(R.layout.chat_color_selection_fragme
|
|||||||
viewModel.refresh()
|
viewModel.refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showWarningDialog(confirmDeletion: ChatColorSelectionViewModel.Event.ConfirmDeletion) {
|
private fun showWarningDialogForNoUses(confirmDeletion: ChatColorSelectionViewModel.Event.ConfirmDeletion) {
|
||||||
|
MaterialAlertDialogBuilder(requireContext())
|
||||||
|
.setMessage(R.string.ChatColorSelectionFragment__delete_chat_color)
|
||||||
|
.setPositiveButton(R.string.ChatColorSelectionFragment__delete) { dialog, _ ->
|
||||||
|
viewModel.deleteNow(confirmDeletion.chatColors)
|
||||||
|
dialog.dismiss()
|
||||||
|
}
|
||||||
|
.setNegativeButton(android.R.string.cancel) { dialog, _ ->
|
||||||
|
dialog.dismiss()
|
||||||
|
}
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showWarningDialogForMultipleUses(confirmDeletion: ChatColorSelectionViewModel.Event.ConfirmDeletion) {
|
||||||
MaterialAlertDialogBuilder(requireContext())
|
MaterialAlertDialogBuilder(requireContext())
|
||||||
.setTitle(R.string.ChatColorSelectionFragment__delete_color)
|
.setTitle(R.string.ChatColorSelectionFragment__delete_color)
|
||||||
.setMessage(resources.getQuantityString(R.plurals.ChatColorSelectionFragment__this_custom_color_is_used, confirmDeletion.usageCount, confirmDeletion.usageCount))
|
.setMessage(resources.getQuantityString(R.plurals.ChatColorSelectionFragment__this_custom_color_is_used, confirmDeletion.usageCount, confirmDeletion.usageCount))
|
||||||
|
|||||||
@@ -43,11 +43,7 @@ class ChatColorSelectionViewModel(private val repository: ChatColorSelectionRepo
|
|||||||
|
|
||||||
fun startDeletion(chatColors: ChatColors) {
|
fun startDeletion(chatColors: ChatColors) {
|
||||||
repository.getUsageCount(chatColors.id) {
|
repository.getUsageCount(chatColors.id) {
|
||||||
if (it > 0) {
|
|
||||||
internalEvents.postValue(Event.ConfirmDeletion(it, chatColors))
|
internalEvents.postValue(Event.ConfirmDeletion(it, chatColors))
|
||||||
} else {
|
|
||||||
deleteNow(chatColors)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3498,6 +3498,7 @@
|
|||||||
<item quantity="one">This custom color is used in %1$d chat. Do you want to delete it for all chats?</item>
|
<item quantity="one">This custom color is used in %1$d chat. Do you want to delete it for all chats?</item>
|
||||||
<item quantity="other">This custom color is used in %1$d chats. Do you want to delete it for all chats?</item>
|
<item quantity="other">This custom color is used in %1$d chats. Do you want to delete it for all chats?</item>
|
||||||
</plurals>
|
</plurals>
|
||||||
|
<string name="ChatColorSelectionFragment__delete_chat_color">Delete chat color?</string>
|
||||||
|
|
||||||
<!-- CustomChatColorCreatorFragment -->
|
<!-- CustomChatColorCreatorFragment -->
|
||||||
<string name="CustomChatColorCreatorFragment__solid">Solid</string>
|
<string name="CustomChatColorCreatorFragment__solid">Solid</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user