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()
updateRepetitionText()
updateStartDate()
updateStartTime()
updateEndDate()
updateEndTime()
updateStartDateText()
updateStartTimeText()
updateEndDateText()
updateEndTimeText()
updateEventType()
mWasEndDateSet = event != null
@ -172,11 +172,15 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
private fun showRepetitionTypePicker() {
hideKeyboard()
RepeatTypePickerDialog(this, mRepeatLimit, mEventStartDateTime.seconds()) {
mRepeatLimit = it
checkRepetitionLimitText()
setRepeatLimit(it)
}
}
private fun setRepeatLimit(limit: Int) {
mRepeatLimit = limit
checkRepetitionLimitText()
}
private fun checkRepetitionLimitText() {
event_repetition_limit.text = if (mRepeatLimit == 0) {
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)
}
private fun updateStartTime() {
private fun updateStartTimeText() {
event_start_time.text = Formatter.getTime(this, mEventStartDateTime)
}
private fun updateEndDate() {
private fun updateEndDateText() {
event_end_date.text = Formatter.getDate(applicationContext, mEventEndDateTime)
}
private fun updateEndTime() {
private fun updateEndTimeText() {
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) {
if (isStart) {
mEventStartDateTime = mEventStartDateTime.withDate(year, month + 1, day)
updateStartDate()
updateStartDateText()
if (mEventStartDateTime.isAfter(mEventEndDateTime)) {
mEventEndDateTime = mEventStartDateTime
updateEndDate()
updateEndTime()
updateEndDateText()
updateEndTimeText()
}
} else {
mEventEndDateTime = mEventEndDateTime.withDate(year, month + 1, day)
updateEndDate()
updateEndDateText()
mWasEndDateSet = true
}
}
@ -461,14 +465,14 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
private fun timeSet(hours: Int, minutes: Int, isStart: Boolean) {
if (isStart) {
mEventStartDateTime = mEventStartDateTime.withHourOfDay(hours).withMinuteOfHour(minutes)
updateStartTime()
updateStartTimeText()
if (mEventStartDateTime.isAfter(mEventEndDateTime)) {
mEventEndDateTime = mEventStartDateTime
updateEndTime()
updateEndTimeText()
}
} else {
mEventEndDateTime = mEventEndDateTime.withHourOfDay(hours).withMinuteOfHour(minutes)
updateEndTime()
updateEndTimeText()
mWasEndTimeSet = true
}
}

View File

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

View File

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