diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt index 97c096376..dc1c61d0d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt @@ -11,10 +11,7 @@ import com.simplemobiletools.calendar.R import com.simplemobiletools.calendar.dialogs.EventReminderDialog import com.simplemobiletools.calendar.dialogs.EventRepeatIntervalDialog import com.simplemobiletools.calendar.dialogs.SelectEventTypeDialog -import com.simplemobiletools.calendar.extensions.config -import com.simplemobiletools.calendar.extensions.getAppropriateTheme -import com.simplemobiletools.calendar.extensions.getReminderText -import com.simplemobiletools.calendar.extensions.seconds +import com.simplemobiletools.calendar.extensions.* import com.simplemobiletools.calendar.helpers.* import com.simplemobiletools.calendar.models.Event import com.simplemobiletools.commons.dialogs.ConfirmationDialog @@ -228,7 +225,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { } private fun updateRepetitionText() { - event_repetition.text = getRepetitionToString(mRepeatInterval) + event_repetition.text = getRepetitionText(mRepeatInterval) } private fun updateEventType() { @@ -239,15 +236,6 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { } } - private fun getRepetitionToString(seconds: Int) = getString(when (seconds) { - DAY -> R.string.daily - WEEK -> R.string.weekly - BIWEEK -> R.string.biweekly - MONTH -> R.string.monthly - YEAR -> R.string.yearly - else -> R.string.no_repetition - }) - fun toggleAllDay(isChecked: Boolean) { event_start_time.beGoneIf(isChecked) event_end_time.beGoneIf(isChecked) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/EventReminderDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/EventReminderDialog.kt index f586ed540..42b074620 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/EventReminderDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/EventReminderDialog.kt @@ -11,7 +11,8 @@ import com.simplemobiletools.commons.extensions.setupDialogStuff import kotlinx.android.synthetic.main.dialog_radio_group.view.* import java.util.* -class EventReminderDialog(val activity: Activity, val defaultMinutes: Int, val callback: (minutes: Int) -> Unit) : AlertDialog.Builder(activity), RadioGroup.OnCheckedChangeListener { +class EventReminderDialog(val activity: Activity, val reminderMinutes: Int, val callback: (minutes: Int) -> Unit) : AlertDialog.Builder(activity), + RadioGroup.OnCheckedChangeListener { val dialog: AlertDialog? var wasInit = false var minutes = TreeSet() @@ -27,7 +28,7 @@ class EventReminderDialog(val activity: Activity, val defaultMinutes: Int, val c add(0) add(10) add(30) - add(defaultMinutes) + add(reminderMinutes) } minutes.forEachIndexed { index, value -> @@ -46,7 +47,7 @@ class EventReminderDialog(val activity: Activity, val defaultMinutes: Int, val c private fun addRadioButton(textValue: String, value: Int, index: Int) { val radioButton = (activity.layoutInflater.inflate(R.layout.radio_button, null) as RadioButton).apply { text = textValue - isChecked = value == defaultMinutes + isChecked = value == reminderMinutes id = index } radioGroup.addView(radioButton, RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/EventRepeatIntervalDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/EventRepeatIntervalDialog.kt index ea5ab3c9a..b0078514f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/EventRepeatIntervalDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/EventRepeatIntervalDialog.kt @@ -2,49 +2,69 @@ package com.simplemobiletools.calendar.dialogs import android.app.Activity import android.support.v7.app.AlertDialog -import android.view.LayoutInflater +import android.view.ViewGroup +import android.widget.RadioButton import android.widget.RadioGroup import com.simplemobiletools.calendar.R +import com.simplemobiletools.calendar.extensions.getRepetitionText import com.simplemobiletools.calendar.helpers.* import com.simplemobiletools.commons.extensions.setupDialogStuff -import kotlinx.android.synthetic.main.dialog_change_views.view.* +import kotlinx.android.synthetic.main.dialog_radio_group.view.* +import java.util.* -class EventRepeatIntervalDialog(val activity: Activity, val repeatInterval: Int, val callback: (mins: Int) -> Unit) : AlertDialog.Builder(activity), +class EventRepeatIntervalDialog(val activity: Activity, val repeatSeconds: Int, val callback: (mins: Int) -> Unit) : AlertDialog.Builder(activity), RadioGroup.OnCheckedChangeListener { val dialog: AlertDialog? + var wasInit = false + var seconds = TreeSet() + var radioGroup: RadioGroup init { - val view = LayoutInflater.from(activity).inflate(R.layout.dialog_event_repeat_interval, null).dialog_radio_view.apply { - check(getCheckedItem()) - setOnCheckedChangeListener(this@EventRepeatIntervalDialog) + val view = activity.layoutInflater.inflate(R.layout.dialog_radio_group, null) + radioGroup = view.dialog_radio_group + radioGroup.setOnCheckedChangeListener(this) + + seconds.apply { + add(0) + add(DAY) + add(WEEK) + add(BIWEEK) + add(MONTH) + add(YEAR) + add(repeatSeconds) } + seconds.forEachIndexed { index, value -> + addRadioButton(activity.getRepetitionText(value), value, index) + } + addRadioButton(activity.getString(R.string.custom), -1, seconds.size) + dialog = AlertDialog.Builder(activity) .create().apply { activity.setupDialogStuff(view, this, R.string.select_repeat_interval) } + + wasInit = true } - private fun getCheckedItem() = when (repeatInterval) { - DAY -> R.id.dialog_radio_daily - WEEK -> R.id.dialog_radio_weekly - BIWEEK -> R.id.dialog_radio_biweekly - MONTH -> R.id.dialog_radio_monthly - YEAR -> R.id.dialog_radio_yearly - else -> R.id.dialog_radio_no_repetition + private fun addRadioButton(textValue: String, value: Int, index: Int) { + val radioButton = (activity.layoutInflater.inflate(R.layout.radio_button, null) as RadioButton).apply { + text = textValue + isChecked = value == repeatSeconds + id = index + } + radioGroup.addView(radioButton, RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)) } override fun onCheckedChanged(group: RadioGroup?, checkedId: Int) { - callback.invoke(getSelectionValue(checkedId)) - dialog?.dismiss() - } + if (!wasInit) + return - private fun getSelectionValue(id: Int) = when (id) { - R.id.dialog_radio_daily -> DAY - R.id.dialog_radio_weekly -> WEEK - R.id.dialog_radio_biweekly -> BIWEEK - R.id.dialog_radio_monthly -> MONTH - R.id.dialog_radio_yearly -> YEAR - else -> 0 + if (checkedId == seconds.size) { + + } else { + callback.invoke(seconds.elementAt(checkedId)) + dialog?.dismiss() + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt index 57842a54e..58a65c68c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt @@ -122,6 +122,28 @@ fun Context.getReminderText(minutes: Int) = when (minutes) { } } +fun Context.getRepetitionText(seconds: Int): String { + val days = seconds / 60 / 60 / 24 + return when (days) { + 0 -> getString(R.string.no_repetition) + 1 -> getString(R.string.daily) + 7 -> getString(R.string.weekly) + 14 -> getString(R.string.biweekly) + 30 -> getString(R.string.monthly) + 365 -> getString(R.string.yearly) + else -> { + if (days % 365 == 0) + resources.getQuantityString(R.plurals.years, days / 365, days / 365) + else if (days % 30 == 0) + resources.getQuantityString(R.plurals.months, days / 30, days / 30) + else if (days % 7 == 0) + resources.getQuantityString(R.plurals.weeks, days / 7, days / 7) + else + resources.getQuantityString(R.plurals.days, days, days) + } + } +} + fun Context.getFilteredEvents(events: List): List { val displayEventTypes = config.displayEventTypes val filtered = events.filter { displayEventTypes.contains(it.eventType.toString()) } diff --git a/app/src/main/res/layout/dialog_event_repeat_interval.xml b/app/src/main/res/layout/dialog_event_repeat_interval.xml deleted file mode 100644 index ceae80674..000000000 --- a/app/src/main/res/layout/dialog_event_repeat_interval.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/app/src/main/res/values-ca-rES/strings.xml b/app/src/main/res/values-ca-rES/strings.xml index 5108162eb..acc2e1803 100644 --- a/app/src/main/res/values-ca-rES/strings.xml +++ b/app/src/main/res/values-ca-rES/strings.xml @@ -38,6 +38,26 @@ Repeat till: Forever + + %1$d day + %1$d days + + + + %1$d week + %1$d weeks + + + + %1$d month + %1$d months + + + + %1$d year + %1$d years + + Select an event reminder Recordatorio @@ -60,7 +80,7 @@ %1$d horas antes de - + %1$d day before %1$d días antes de diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index bfbc8efc7..b2e716b3b 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -38,6 +38,26 @@ Wiederholen bis: unendlich + + %1$d day + %1$d days + + + + %1$d week + %1$d weeks + + + + %1$d month + %1$d months + + + + %1$d year + %1$d years + + Wähle eine Termin Erinnerung Erinnerung @@ -60,7 +80,7 @@ %1$d Stunden vorher - + %1$d Tag vorher %1$d Tage vorher diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index 5108162eb..acc2e1803 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -38,6 +38,26 @@ Repeat till: Forever + + %1$d day + %1$d days + + + + %1$d week + %1$d weeks + + + + %1$d month + %1$d months + + + + %1$d year + %1$d years + + Select an event reminder Recordatorio @@ -60,7 +80,7 @@ %1$d horas antes de - + %1$d day before %1$d días antes de diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 51da2c81a..5f4c486d2 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -38,6 +38,26 @@ Repeat till: Forever + + %1$d day + %1$d days + + + + %1$d week + %1$d weeks + + + + %1$d month + %1$d months + + + + %1$d year + %1$d years + + Select an event reminder Rappel @@ -60,7 +80,7 @@ %1$d heures avant - + %1$d day before %1$d jours avant diff --git a/app/src/main/res/values-gl-rES/strings.xml b/app/src/main/res/values-gl-rES/strings.xml index 5108162eb..acc2e1803 100644 --- a/app/src/main/res/values-gl-rES/strings.xml +++ b/app/src/main/res/values-gl-rES/strings.xml @@ -38,6 +38,26 @@ Repeat till: Forever + + %1$d day + %1$d days + + + + %1$d week + %1$d weeks + + + + %1$d month + %1$d months + + + + %1$d year + %1$d years + + Select an event reminder Recordatorio @@ -60,7 +80,7 @@ %1$d horas antes de - + %1$d day before %1$d días antes de diff --git a/app/src/main/res/values-hi-rIN/strings.xml b/app/src/main/res/values-hi-rIN/strings.xml index bb687cc96..d69c7f8be 100644 --- a/app/src/main/res/values-hi-rIN/strings.xml +++ b/app/src/main/res/values-hi-rIN/strings.xml @@ -38,6 +38,26 @@ Repeat till: Forever + + %1$d day + %1$d days + + + + %1$d week + %1$d weeks + + + + %1$d month + %1$d months + + + + %1$d year + %1$d years + + Select an event reminder रिमाइंडर @@ -60,7 +80,7 @@ %1$d hours before - + %1$d day before %1$d days before diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index 1a2ede199..b3b3fafb6 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -38,6 +38,26 @@ Repeat till: Forever + + %1$d day + %1$d days + + + + %1$d week + %1$d weeks + + + + %1$d month + %1$d months + + + + %1$d year + %1$d years + + Select an event reminder Emlékeztető @@ -60,7 +80,7 @@ %1$d órával korábban - + %1$d nappal korábban %1$d nappal korábban diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 3bf7eacfd..c99ad934e 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -38,6 +38,26 @@ Repeat till: Forever + + %1$d day + %1$d days + + + + %1$d week + %1$d weeks + + + + %1$d month + %1$d months + + + + %1$d year + %1$d years + + Select an event reminder Promemoria @@ -60,7 +80,7 @@ %1$d hours before - + %1$d day before %1$d days before diff --git a/app/src/main/res/values-iw/strings.xml b/app/src/main/res/values-iw/strings.xml index 9a788b279..11e85118e 100644 --- a/app/src/main/res/values-iw/strings.xml +++ b/app/src/main/res/values-iw/strings.xml @@ -38,6 +38,26 @@ Repeat till: Forever + + %1$d day + %1$d days + + + + %1$d week + %1$d weeks + + + + %1$d month + %1$d months + + + + %1$d year + %1$d years + + Select an event reminder תזכורת @@ -60,7 +80,7 @@ %1$d hours before - + %1$d day before %1$d days before diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index cce547164..991a76766 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -38,6 +38,26 @@ Repeat till: Forever + + %1$d day + %1$d days + + + + %1$d week + %1$d weeks + + + + %1$d month + %1$d months + + + + %1$d year + %1$d years + + Select an event reminder リマインダー @@ -60,7 +80,7 @@ %1$d 時間 前 - + %1$d day before %1$d 日 前 diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index 17489cd53..e8d5f0f24 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -38,6 +38,26 @@ Repetir até: Eternamente + + %1$d day + %1$d days + + + + %1$d week + %1$d weeks + + + + %1$d month + %1$d months + + + + %1$d year + %1$d years + + Selecione um lembrete Lembrete @@ -60,7 +80,7 @@ %1$d horas antes - + %1$d dia antes %1$d dias antes diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index d8ee5e2bf..0bcc2de6f 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -38,6 +38,26 @@ Повторять до: Бесконечно + + %1$d day + %1$d days + + + + %1$d week + %1$d weeks + + + + %1$d month + %1$d months + + + + %1$d year + %1$d years + + Выбрать напоминание для события Напоминание @@ -60,7 +80,7 @@ %1$d часа(-ов) до события - + %1$d день до события %1$d дня(-ей) до события diff --git a/app/src/main/res/values-sk/strings.xml b/app/src/main/res/values-sk/strings.xml index 79a651f48..aea6ef6bd 100644 --- a/app/src/main/res/values-sk/strings.xml +++ b/app/src/main/res/values-sk/strings.xml @@ -38,6 +38,30 @@ Opakovať do: Navždy + + %1$d deň + %1$d dni + %1$d dní + + + + %1$d týždeň + %1$d týždne + %1$d týždňov + + + + %1$d mesiac + %1$d mesiace + %1$d mesiacov + + + + %1$d rok + %1$d roky + %1$d rokov + + Zvoľte pripomienku Pripomenka @@ -52,16 +76,19 @@ %1$d minútu vopred + %1$d minúty vopred %1$d minút vopred %1$d hodinu vopred + %1$d hodiny vopred %1$d hodín vopred - + %1$d deň vopred + %1$d dni vopred %1$d dní vopred diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index 12ebb8a35..65e636e01 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -38,6 +38,26 @@ Repeat till: Forever + + %1$d day + %1$d days + + + + %1$d week + %1$d weeks + + + + %1$d month + %1$d months + + + + %1$d year + %1$d years + + Select an event reminder Påminnelse @@ -60,7 +80,7 @@ %1$d timmar före - + %1$d day before %1$d dagar före diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 52cac957c..a875a6300 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -38,6 +38,26 @@ Repeat till: Forever + + %1$d day + %1$d days + + + + %1$d week + %1$d weeks + + + + %1$d month + %1$d months + + + + %1$d year + %1$d years + + Select an event reminder Reminder @@ -60,7 +80,7 @@ %1$d hours before - + %1$d day before %1$d days before