improving some code readability
This commit is contained in:
parent
3768a4195c
commit
f240f4f695
|
@ -15,7 +15,11 @@ import kotlinx.android.synthetic.main.schedule_message_dialog.view.*
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class ScheduleSendDialog(private val activity: BaseSimpleActivity, private var dateTime: DateTime? = null, private val callback: (dt: DateTime?) -> Unit) {
|
class ScheduleSendDialog(
|
||||||
|
private val activity: BaseSimpleActivity,
|
||||||
|
private var dateTime: DateTime? = null,
|
||||||
|
private val callback: (dateTime: DateTime?) -> Unit
|
||||||
|
) {
|
||||||
private val view = activity.layoutInflater.inflate(R.layout.schedule_message_dialog, null)
|
private val view = activity.layoutInflater.inflate(R.layout.schedule_message_dialog, null)
|
||||||
private val textColor = activity.getProperTextColor()
|
private val textColor = activity.getProperTextColor()
|
||||||
|
|
||||||
|
@ -26,11 +30,19 @@ class ScheduleSendDialog(private val activity: BaseSimpleActivity, private var d
|
||||||
private val calendar = Calendar.getInstance()
|
private val calendar = Calendar.getInstance()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
arrayOf(view.subtitle, view.edit_time, view.edit_date).forEach { it.setTextColor(textColor) }
|
arrayOf(view.subtitle, view.edit_time, view.edit_date).forEach {
|
||||||
arrayOf(view.date_image, view.time_image).forEach { it.applyColorFilter(textColor) }
|
it.setTextColor(textColor)
|
||||||
|
}
|
||||||
|
|
||||||
|
arrayOf(view.date_image, view.time_image).forEach {
|
||||||
|
it.applyColorFilter(textColor)
|
||||||
|
}
|
||||||
|
|
||||||
view.edit_date.setOnClickListener { showDatePicker() }
|
view.edit_date.setOnClickListener { showDatePicker() }
|
||||||
view.edit_time.setOnClickListener { showTimePicker() }
|
view.edit_time.setOnClickListener { showTimePicker() }
|
||||||
updateTexts(dateTime ?: DateTime.now().plusHours(1))
|
|
||||||
|
val targetDateTime = dateTime ?: DateTime.now().plusHours(1)
|
||||||
|
updateTexts(targetDateTime)
|
||||||
|
|
||||||
if (isNewMessage) {
|
if (isNewMessage) {
|
||||||
showDatePicker()
|
showDatePicker()
|
||||||
|
@ -39,15 +51,18 @@ class ScheduleSendDialog(private val activity: BaseSimpleActivity, private var d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateTexts(dt: DateTime) {
|
private fun updateTexts(dateTime: DateTime) {
|
||||||
val dateFormat = activity.config.dateFormat
|
val dateFormat = activity.config.dateFormat
|
||||||
val timeFormat = activity.getTimeFormat()
|
val timeFormat = activity.getTimeFormat()
|
||||||
view.edit_date.text = dt.toString(dateFormat)
|
view.edit_date.text = dateTime.toString(dateFormat)
|
||||||
view.edit_time.text = dt.toString(timeFormat)
|
view.edit_time.text = dateTime.toString(timeFormat)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showPreview() {
|
private fun showPreview() {
|
||||||
if (previewShown) return
|
if (previewShown) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
activity.getAlertDialogBuilder()
|
activity.getAlertDialogBuilder()
|
||||||
.setPositiveButton(R.string.ok, null)
|
.setPositiveButton(R.string.ok, null)
|
||||||
.setNegativeButton(R.string.cancel, null)
|
.setNegativeButton(R.string.cancel, null)
|
||||||
|
@ -61,6 +76,7 @@ class ScheduleSendDialog(private val activity: BaseSimpleActivity, private var d
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dialog.setOnDismissListener {
|
dialog.setOnDismissListener {
|
||||||
previewShown = false
|
previewShown = false
|
||||||
previewDialog = null
|
previewDialog = null
|
||||||
|
@ -94,7 +110,7 @@ class ScheduleSendDialog(private val activity: BaseSimpleActivity, private var d
|
||||||
val hourOfDay = dateTime?.hourOfDay ?: getNextHour()
|
val hourOfDay = dateTime?.hourOfDay ?: getNextHour()
|
||||||
val minute = dateTime?.minuteOfHour ?: getNextMinute()
|
val minute = dateTime?.minuteOfHour ?: getNextMinute()
|
||||||
|
|
||||||
val timeSetListener = OnTimeSetListener { _, h, m -> timeSet(h, m) }
|
val timeSetListener = OnTimeSetListener { _, hours, minutes -> timeSet(hours, minutes) }
|
||||||
TimePickerDialog(
|
TimePickerDialog(
|
||||||
activity, activity.getDatePickerDialogTheme(), timeSetListener, hourOfDay, minute, DateFormat.is24HourFormat(activity)
|
activity, activity.getDatePickerDialogTheme(), timeSetListener, hourOfDay, minute, DateFormat.is24HourFormat(activity)
|
||||||
).apply {
|
).apply {
|
||||||
|
@ -123,9 +139,11 @@ class ScheduleSendDialog(private val activity: BaseSimpleActivity, private var d
|
||||||
withTime(getNextHour(), getNextMinute(), 0, 0)
|
withTime(getNextHour(), getNextMinute(), 0, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isNewMessage) {
|
if (!isNewMessage) {
|
||||||
validateDateTime()
|
validateDateTime()
|
||||||
}
|
}
|
||||||
|
|
||||||
isNewMessage = false
|
isNewMessage = false
|
||||||
updateTexts(dateTime!!)
|
updateTexts(dateTime!!)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue