ExportMessagesDialog code refactoring
This commit is contained in:
parent
ec6bf55025
commit
c72dc199aa
|
@ -2,12 +2,7 @@ package com.simplemobiletools.smsmessenger.dialogs
|
||||||
|
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
|
import com.simplemobiletools.commons.extensions.*
|
||||||
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.smsmessenger.R
|
import com.simplemobiletools.smsmessenger.R
|
||||||
import com.simplemobiletools.smsmessenger.activities.SimpleActivity
|
import com.simplemobiletools.smsmessenger.activities.SimpleActivity
|
||||||
import com.simplemobiletools.smsmessenger.extensions.config
|
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 {
|
val view = (activity.layoutInflater.inflate(R.layout.dialog_export_messages, null) as ViewGroup).apply {
|
||||||
export_sms_checkbox.isChecked = config.exportSms
|
export_sms_checkbox.isChecked = config.exportSms
|
||||||
export_mms_checkbox.isChecked = config.exportMms
|
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.getAlertDialogBuilder()
|
||||||
activity.setupDialogStuff(view, this, R.string.export_messages) { alertDialog ->
|
.setPositiveButton(R.string.ok, null)
|
||||||
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
|
.setNegativeButton(R.string.cancel, null)
|
||||||
config.exportSms = view.export_sms_checkbox.isChecked
|
.apply {
|
||||||
config.exportMms = view.export_mms_checkbox.isChecked
|
activity.setupDialogStuff(view, this, R.string.export_messages) { alertDialog ->
|
||||||
val filename = view.export_messages_filename.value
|
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
|
||||||
when {
|
config.exportSms = view.export_sms_checkbox.isChecked
|
||||||
filename.isEmpty() -> activity.toast(R.string.empty_name)
|
config.exportMms = view.export_mms_checkbox.isChecked
|
||||||
filename.isAValidFilename() -> {
|
val filename = view.export_messages_filename.value
|
||||||
callback(filename)
|
when {
|
||||||
alertDialog.dismiss()
|
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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue