Add warning dialog for chat color deletion with no uses.

fork-5.53.8
Alex Hart 2021-07-09 10:39:38 -03:00 zatwierdzone przez Cody Henthorne
rodzic 416e62112f
commit 172cc302fc
3 zmienionych plików z 21 dodań i 7 usunięć

Wyświetl plik

@ -46,7 +46,11 @@ class ChatColorSelectionFragment : Fragment(R.layout.chat_color_selection_fragme
viewModel.events.observe(viewLifecycleOwner) { event ->
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()
}
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())
.setTitle(R.string.ChatColorSelectionFragment__delete_color)
.setMessage(resources.getQuantityString(R.plurals.ChatColorSelectionFragment__this_custom_color_is_used, confirmDeletion.usageCount, confirmDeletion.usageCount))

Wyświetl plik

@ -43,11 +43,7 @@ class ChatColorSelectionViewModel(private val repository: ChatColorSelectionRepo
fun startDeletion(chatColors: ChatColors) {
repository.getUsageCount(chatColors.id) {
if (it > 0) {
internalEvents.postValue(Event.ConfirmDeletion(it, chatColors))
} else {
deleteNow(chatColors)
}
internalEvents.postValue(Event.ConfirmDeletion(it, chatColors))
}
}

Wyświetl plik

@ -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="other">This custom color is used in %1$d chats. Do you want to delete it for all chats?</item>
</plurals>
<string name="ChatColorSelectionFragment__delete_chat_color">Delete chat color?</string>
<!-- CustomChatColorCreatorFragment -->
<string name="CustomChatColorCreatorFragment__solid">Solid</string>