From c72dc199aac17a5326328b112721c800475f4223 Mon Sep 17 00:00:00 2001 From: merkost Date: Sat, 22 Jul 2023 00:10:17 +1000 Subject: [PATCH] ExportMessagesDialog code refactoring --- .../dialogs/ExportMessagesDialog.kt | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/dialogs/ExportMessagesDialog.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/dialogs/ExportMessagesDialog.kt index c3f5818f..d694b313 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/dialogs/ExportMessagesDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/dialogs/ExportMessagesDialog.kt @@ -2,12 +2,7 @@ package com.simplemobiletools.smsmessenger.dialogs import android.view.ViewGroup import androidx.appcompat.app.AlertDialog -import com.simplemobiletools.commons.extensions.getAlertDialogBuilder -import com.simplemobiletools.commons.extensions.getCurrentFormattedDateTime -import com.simplemobiletools.commons.extensions.isAValidFilename -import com.simplemobiletools.commons.extensions.setupDialogStuff -import com.simplemobiletools.commons.extensions.toast -import com.simplemobiletools.commons.extensions.value +import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.smsmessenger.R import com.simplemobiletools.smsmessenger.activities.SimpleActivity import com.simplemobiletools.smsmessenger.extensions.config @@ -26,27 +21,32 @@ class ExportMessagesDialog( val view = (activity.layoutInflater.inflate(R.layout.dialog_export_messages, null) as ViewGroup).apply { export_sms_checkbox.isChecked = config.exportSms export_mms_checkbox.isChecked = config.exportMms - export_messages_filename.setText("${activity.getString(R.string.messages)}_${activity.getCurrentFormattedDateTime()}") + export_messages_filename.setText( + activity.getString(R.string.messages) + "_" + activity.getCurrentFormattedDateTime() + ) } - activity.getAlertDialogBuilder().setPositiveButton(R.string.ok, null).setNegativeButton(R.string.cancel, null).apply { - activity.setupDialogStuff(view, this, R.string.export_messages) { alertDialog -> - alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { - config.exportSms = view.export_sms_checkbox.isChecked - config.exportMms = view.export_mms_checkbox.isChecked - val filename = view.export_messages_filename.value - when { - filename.isEmpty() -> activity.toast(R.string.empty_name) - filename.isAValidFilename() -> { - callback(filename) - alertDialog.dismiss() + activity.getAlertDialogBuilder() + .setPositiveButton(R.string.ok, null) + .setNegativeButton(R.string.cancel, null) + .apply { + activity.setupDialogStuff(view, this, R.string.export_messages) { alertDialog -> + alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { + config.exportSms = view.export_sms_checkbox.isChecked + config.exportMms = view.export_mms_checkbox.isChecked + val filename = view.export_messages_filename.value + when { + filename.isEmpty() -> activity.toast(R.string.empty_name) + filename.isAValidFilename() -> { + callback(filename) + alertDialog.dismiss() + } + + else -> activity.toast(R.string.invalid_name) } - - else -> activity.toast(R.string.invalid_name) } } } - } } }