diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt index 702ca3a78..ff92aa812 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt @@ -223,17 +223,19 @@ class SettingsActivity : SimpleActivity() { } private fun setupDisplayPastEvents() { - updatePastEventsText() + var displayPastEvents = config.displayPastEvents + updatePastEventsText(displayPastEvents) settings_display_past_events_holder.setOnClickListener { - CustomEventReminderDialog(this) { + CustomEventReminderDialog(this, displayPastEvents) { + displayPastEvents = it config.displayPastEvents = it - updatePastEventsText() + updatePastEventsText(it) } } } - private fun updatePastEventsText() { - settings_display_past_events.text = getDisplayPastEventsText(config.displayPastEvents) + private fun updatePastEventsText(displayPastEvents: Int) { + settings_display_past_events.text = getDisplayPastEventsText(displayPastEvents) } private fun getDisplayPastEventsText(displayPastEvents: Int): String { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/CustomEventReminderDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/CustomEventReminderDialog.kt index b18669437..f4913afe6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/CustomEventReminderDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/CustomEventReminderDialog.kt @@ -2,6 +2,7 @@ package com.simplemobiletools.calendar.dialogs import android.app.Activity import android.support.v7.app.AlertDialog +import android.view.View import android.view.ViewGroup import android.view.WindowManager import com.simplemobiletools.calendar.R @@ -10,13 +11,24 @@ import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.extensions.value import kotlinx.android.synthetic.main.dialog_custom_event_reminder.view.* -class CustomEventReminderDialog(val activity: Activity, val callback: (minutes: Int) -> Unit) : AlertDialog.Builder(activity) { +class CustomEventReminderDialog(val activity: Activity, val selectedMinutes: Int = 0, val callback: (minutes: Int) -> Unit) : AlertDialog.Builder(activity) { var dialog: AlertDialog - var view = activity.layoutInflater.inflate(R.layout.dialog_custom_event_reminder, null) as ViewGroup + var view: View = (activity.layoutInflater.inflate(R.layout.dialog_custom_event_reminder, null) as ViewGroup).apply { + if (selectedMinutes == 0) { + dialog_radio_view.check(R.id.dialog_radio_minutes) + } else if (selectedMinutes % 1440 == 0) { + dialog_radio_view.check(R.id.dialog_radio_days) + dialog_custom_reminder_value.setText((selectedMinutes / 1440).toString()) + } else if (selectedMinutes % 60 == 0) { + dialog_radio_view.check(R.id.dialog_radio_hours) + dialog_custom_reminder_value.setText((selectedMinutes / 60).toString()) + } else { + dialog_radio_view.check(R.id.dialog_radio_minutes) + dialog_custom_reminder_value.setText(selectedMinutes.toString()) + } + } init { - view.dialog_radio_view.check(R.id.dialog_radio_minutes) - dialog = AlertDialog.Builder(activity) .setPositiveButton(R.string.ok, { dialogInterface, i -> confirmReminder() }) .setNegativeButton(R.string.cancel, null) diff --git a/app/src/main/res/layout/dialog_custom_event_reminder.xml b/app/src/main/res/layout/dialog_custom_event_reminder.xml index bb1b944c0..98eefa397 100644 --- a/app/src/main/res/layout/dialog_custom_event_reminder.xml +++ b/app/src/main/res/layout/dialog_custom_event_reminder.xml @@ -16,12 +16,12 @@