From a41c0f8b69159f2cee7dc7190a8c5f2ee446dbfe Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Fri, 16 Jul 2021 17:03:43 +0200 Subject: [PATCH] add confirm dialog before clearing chat history Signed-off-by: Marcel Hibbe --- .../controllers/ConversationInfoController.kt | 25 ++++++++++++++++++- app/src/main/res/values/strings.xml | 1 + 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ConversationInfoController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ConversationInfoController.kt index d698ae887..d0af8ca91 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ConversationInfoController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ConversationInfoController.kt @@ -166,7 +166,7 @@ class ConversationInfoController(args: Bundle) : binding.deleteConversationAction.setOnClickListener { showDeleteConversationDialog(null) } binding.leaveConversationAction.setOnClickListener { leaveConversation() } - binding.clearConversationHistory.setOnClickListener { clearHistory() } + binding.clearConversationHistory.setOnClickListener { showClearHistoryDialog(null) } binding.addParticipantsAction.setOnClickListener { addParticipants() } fetchRoomInfo() @@ -301,6 +301,7 @@ class ConversationInfoController(args: Bundle) : private fun showLovelyDialog(dialogId: Int, savedInstanceState: Bundle) { when (dialogId) { ID_DELETE_CONVERSATION_DIALOG -> showDeleteConversationDialog(savedInstanceState) + ID_CLEAR_CHAT_DIALOG -> showClearHistoryDialog(savedInstanceState) else -> { } } @@ -490,6 +491,27 @@ class ConversationInfoController(args: Bundle) : } } + private fun showClearHistoryDialog(savedInstanceState: Bundle?) { + if (activity != null) { + LovelyStandardDialog(activity, LovelyStandardDialog.ButtonLayout.HORIZONTAL) + .setTopColorRes(R.color.nc_darkRed) + .setIcon( + DisplayUtils.getTintedDrawable( + context!!.resources, + R.drawable.ic_delete_black_24dp, R.color.bg_default + ) + ) + .setPositiveButtonColor(context!!.resources.getColor(R.color.nc_darkRed)) + .setTitle(R.string.nc_clear_history) + .setMessage(R.string.nc_clear_history_warning) + .setPositiveButton(R.string.nc_delete) { clearHistory() } + .setNegativeButton(R.string.nc_cancel, null) + .setInstanceStateHandler(ID_CLEAR_CHAT_DIALOG, saveStateHandler!!) + .setSavedInstanceState(savedInstanceState) + .show() + } + } + private fun clearHistory() { val apiVersion = ApiUtils.getChatApiVersion(conversationUser, intArrayOf(1)) @@ -1039,6 +1061,7 @@ class ConversationInfoController(args: Bundle) : companion object { private const val TAG = "ConversationInfControll" private const val ID_DELETE_CONVERSATION_DIALOG = 0 + private const val ID_CLEAR_CHAT_DIALOG = 1 private val LOW_EMPHASIS_OPACITY: Float = 0.38f } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1950309e2..58a8cd267 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -168,6 +168,7 @@ Configure conversation Leave conversation Clear history + The chat history will be deleted. Chat history was cleared Rename conversation Set a password