couple improvements to repeat type dialog

This commit is contained in:
tibbi 2017-04-23 12:44:48 +02:00
parent 3ff2d52b43
commit 3fc9469dbb
3 changed files with 34 additions and 20 deletions

View File

@ -66,10 +66,10 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
checkReminderTexts() checkReminderTexts()
updateRepetitionText() updateRepetitionText()
updateStartDate() updateStartDateText()
updateStartTime() updateStartTimeText()
updateEndDate() updateEndDateText()
updateEndTime() updateEndTimeText()
updateEventType() updateEventType()
mWasEndDateSet = event != null mWasEndDateSet = event != null
@ -172,11 +172,15 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
private fun showRepetitionTypePicker() { private fun showRepetitionTypePicker() {
hideKeyboard() hideKeyboard()
RepeatTypePickerDialog(this, mRepeatLimit, mEventStartDateTime.seconds()) { RepeatTypePickerDialog(this, mRepeatLimit, mEventStartDateTime.seconds()) {
mRepeatLimit = it setRepeatLimit(it)
checkRepetitionLimitText()
} }
} }
private fun setRepeatLimit(limit: Int) {
mRepeatLimit = limit
checkRepetitionLimitText()
}
private fun checkRepetitionLimitText() { private fun checkRepetitionLimitText() {
event_repetition_limit.text = if (mRepeatLimit == 0) { event_repetition_limit.text = if (mRepeatLimit == 0) {
resources.getString(R.string.forever) resources.getString(R.string.forever)
@ -371,19 +375,19 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
} }
} }
private fun updateStartDate() { private fun updateStartDateText() {
event_start_date.text = Formatter.getDate(applicationContext, mEventStartDateTime) event_start_date.text = Formatter.getDate(applicationContext, mEventStartDateTime)
} }
private fun updateStartTime() { private fun updateStartTimeText() {
event_start_time.text = Formatter.getTime(this, mEventStartDateTime) event_start_time.text = Formatter.getTime(this, mEventStartDateTime)
} }
private fun updateEndDate() { private fun updateEndDateText() {
event_end_date.text = Formatter.getDate(applicationContext, mEventEndDateTime) event_end_date.text = Formatter.getDate(applicationContext, mEventEndDateTime)
} }
private fun updateEndTime() { private fun updateEndTimeText() {
event_end_time.text = Formatter.getTime(this, mEventEndDateTime) event_end_time.text = Formatter.getTime(this, mEventEndDateTime)
} }
@ -445,15 +449,15 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
private fun dateSet(year: Int, month: Int, day: Int, isStart: Boolean) { private fun dateSet(year: Int, month: Int, day: Int, isStart: Boolean) {
if (isStart) { if (isStart) {
mEventStartDateTime = mEventStartDateTime.withDate(year, month + 1, day) mEventStartDateTime = mEventStartDateTime.withDate(year, month + 1, day)
updateStartDate() updateStartDateText()
if (mEventStartDateTime.isAfter(mEventEndDateTime)) { if (mEventStartDateTime.isAfter(mEventEndDateTime)) {
mEventEndDateTime = mEventStartDateTime mEventEndDateTime = mEventStartDateTime
updateEndDate() updateEndDateText()
updateEndTime() updateEndTimeText()
} }
} else { } else {
mEventEndDateTime = mEventEndDateTime.withDate(year, month + 1, day) mEventEndDateTime = mEventEndDateTime.withDate(year, month + 1, day)
updateEndDate() updateEndDateText()
mWasEndDateSet = true mWasEndDateSet = true
} }
} }
@ -461,14 +465,14 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
private fun timeSet(hours: Int, minutes: Int, isStart: Boolean) { private fun timeSet(hours: Int, minutes: Int, isStart: Boolean) {
if (isStart) { if (isStart) {
mEventStartDateTime = mEventStartDateTime.withHourOfDay(hours).withMinuteOfHour(minutes) mEventStartDateTime = mEventStartDateTime.withHourOfDay(hours).withMinuteOfHour(minutes)
updateStartTime() updateStartTimeText()
if (mEventStartDateTime.isAfter(mEventEndDateTime)) { if (mEventStartDateTime.isAfter(mEventEndDateTime)) {
mEventEndDateTime = mEventStartDateTime mEventEndDateTime = mEventStartDateTime
updateEndTime() updateEndTimeText()
} }
} else { } else {
mEventEndDateTime = mEventEndDateTime.withHourOfDay(hours).withMinuteOfHour(minutes) mEventEndDateTime = mEventEndDateTime.withHourOfDay(hours).withMinuteOfHour(minutes)
updateEndTime() updateEndTimeText()
mWasEndTimeSet = true mWasEndTimeSet = true
} }
} }

View File

@ -23,6 +23,9 @@ class RepeatTypePickerDialog(val activity: Activity, var repeatLimit: Int, val s
init { init {
view.repeat_type_date.setOnClickListener { showRepetitionLimitDialog() } view.repeat_type_date.setOnClickListener { showRepetitionLimitDialog() }
view.repeat_type_forever.setOnClickListener { callback(0); dialog.dismiss() } view.repeat_type_forever.setOnClickListener { callback(0); dialog.dismiss() }
if (repeatLimit < startTS)
repeatLimit = startTS
updateRepeatLimitText() updateRepeatLimitText()
dialog = AlertDialog.Builder(activity) dialog = AlertDialog.Builder(activity)
@ -30,6 +33,7 @@ class RepeatTypePickerDialog(val activity: Activity, var repeatLimit: Int, val s
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.create().apply { .create().apply {
activity.setupDialogStuff(view, this) activity.setupDialogStuff(view, this)
activity.currentFocus?.clearFocus()
} }
} }
@ -42,7 +46,11 @@ class RepeatTypePickerDialog(val activity: Activity, var repeatLimit: Int, val s
} }
private fun confirmRepetition() { private fun confirmRepetition() {
when (view.dialog_radio_view.checkedRadioButtonId) {
R.id.repeat_type_till_date -> callback(repeatLimit)
else -> { }
}
dialog.dismiss()
} }
@SuppressLint("NewApi") @SuppressLint("NewApi")
@ -59,13 +67,15 @@ class RepeatTypePickerDialog(val activity: Activity, var repeatLimit: Int, val s
datepicker.show() datepicker.show()
} }
private val repetitionLimitDateSetListener = DatePickerDialog.OnDateSetListener { view, year, monthOfYear, dayOfMonth -> private val repetitionLimitDateSetListener = DatePickerDialog.OnDateSetListener { v, year, monthOfYear, dayOfMonth ->
val repeatLimitDateTime = DateTime().withDate(year, monthOfYear + 1, dayOfMonth).withTime(23, 59, 59, 0) val repeatLimitDateTime = DateTime().withDate(year, monthOfYear + 1, dayOfMonth).withTime(23, 59, 59, 0)
if (repeatLimitDateTime.seconds() < startTS) { if (repeatLimitDateTime.seconds() < startTS) {
repeatLimit = 0 repeatLimit = 0
} else { } else {
repeatLimit = repeatLimitDateTime.seconds() repeatLimit = repeatLimitDateTime.seconds()
} }
view.dialog_radio_view.check(R.id.repeat_type_till_date)
updateRepeatLimitText() updateRepeatLimitText()
} }
} }

View File

@ -25,7 +25,7 @@
android:layout_marginStart="@dimen/repeat_type_margin_start" android:layout_marginStart="@dimen/repeat_type_margin_start"
android:paddingBottom="@dimen/normal_margin" android:paddingBottom="@dimen/normal_margin"
android:paddingTop="@dimen/medium_margin" android:paddingTop="@dimen/medium_margin"
android:text="asd"/> android:text="January 1 1970"/>
<com.simplemobiletools.commons.views.MyCompatRadioButton <com.simplemobiletools.commons.views.MyCompatRadioButton
android:id="@+id/repeat_type_x_times" android:id="@+id/repeat_type_x_times"