add confirm dialog before clearing chat history

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2021-07-16 17:03:43 +02:00 committed by Andy Scherzinger
parent 1558c8ed33
commit a41c0f8b69
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
2 changed files with 25 additions and 1 deletions

View file

@ -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
}

View file

@ -168,6 +168,7 @@
<string name="nc_configure_room">Configure conversation</string>
<string name="nc_leave">Leave conversation</string>
<string name="nc_clear_history">Clear history</string>
<string name="nc_clear_history_warning">The chat history will be deleted.</string>
<string name="nc_clear_history_success">Chat history was cleared</string>
<string name="nc_rename">Rename conversation</string>
<string name="nc_set_password">Set a password</string>