fill the event reminder dialog values dynamically, so we can add the custom values

This commit is contained in:
tibbi 2017-02-03 18:14:16 +01:00
parent 521bcdc528
commit dd65a0f10b
17 changed files with 138 additions and 162 deletions

View File

@ -10,10 +10,7 @@ import android.view.WindowManager
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.dialogs.EventReminderDialog
import com.simplemobiletools.calendar.dialogs.EventRepeatIntervalDialog
import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.extensions.getAppropriateTheme
import com.simplemobiletools.calendar.extensions.scheduleNotification
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
@ -110,22 +107,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
}
private fun updateReminderText() {
event_reminder.text = getReminderMinutesToString(mReminderMinutes)
}
private fun getReminderMinutesToString(minutes: Int) = when (minutes) {
-1 -> getString(R.string.no_reminder)
0 -> getString(R.string.at_start)
10 -> getString(R.string.mins_before_10)
30 -> getString(R.string.mins_before_30)
else -> {
if (minutes % 1440 == 0)
resources.getQuantityString(R.plurals.days, minutes / 1440, minutes / 1440)
else if (minutes % 60 == 0)
resources.getQuantityString(R.plurals.hours, minutes / 60, minutes / 60)
else
resources.getQuantityString(R.plurals.minutes, minutes, minutes)
}
event_reminder.text = getReminderText(mReminderMinutes)
}
private fun updateRepetitionText() {

View File

@ -2,51 +2,68 @@ 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.getReminderText
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 EventReminderDialog(val activity: Activity, val defaultMinutes: Int, val callback: (mins: Int) -> Unit) : AlertDialog.Builder(activity), RadioGroup.OnCheckedChangeListener {
class EventReminderDialog(val activity: Activity, val defaultMinutes: Int, val callback: (minutes: Int) -> Unit) : AlertDialog.Builder(activity), RadioGroup.OnCheckedChangeListener {
val dialog: AlertDialog?
var wasInit = false
var minutes = TreeSet<Int>()
var radioGroup: RadioGroup
init {
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_event_reminder, null).dialog_radio_view.apply {
check(getCheckedItem())
setOnCheckedChangeListener(this@EventReminderDialog)
val view = activity.layoutInflater.inflate(R.layout.dialog_radio_group, null)
radioGroup = view.dialog_radio_group
radioGroup.setOnCheckedChangeListener(this)
minutes.apply {
add(-1)
add(0)
add(10)
add(30)
add(defaultMinutes)
}
minutes.forEachIndexed { index, value ->
addRadioButton(activity.getReminderText(value), value, index)
}
addRadioButton(activity.getString(R.string.custom), -2, minutes.size)
dialog = AlertDialog.Builder(activity)
.create().apply {
activity.setupDialogStuff(view, this, R.string.select_event_reminder)
}
wasInit = true
}
private fun getCheckedItem() = when (defaultMinutes) {
-1 -> R.id.dialog_radio_no_reminder
0 -> R.id.dialog_radio_at_start
10 -> R.id.dialog_radio_mins_before_10
30 -> R.id.dialog_radio_mins_before_30
else -> R.id.dialog_radio_custom
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
id = index
}
radioGroup.addView(radioButton, RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
}
override fun onCheckedChanged(group: RadioGroup?, checkedId: Int) {
if (checkedId == R.id.dialog_radio_custom) {
if (!wasInit)
return
if (checkedId == minutes.size) {
CustomEventReminderDialog(activity) {
callback.invoke(it)
dialog?.dismiss()
}
} else {
callback.invoke(getSelectionValue(checkedId))
callback.invoke(minutes.elementAt(checkedId))
dialog?.dismiss()
}
}
private fun getSelectionValue(id: Int) = when (id) {
R.id.dialog_radio_at_start -> 0
R.id.dialog_radio_mins_before_10 -> 10
R.id.dialog_radio_mins_before_30 -> 30
else -> -1
}
}

View File

@ -134,6 +134,19 @@ fun Context.setupReminderPeriod(otherPeriod: AppCompatSpinner, otherValue: EditT
otherValue.setText(value.toString())
}
fun Context.getReminderText(minutes: Int) = when (minutes) {
-1 -> getString(R.string.no_reminder)
0 -> getString(R.string.at_start)
else -> {
if (minutes % 1440 == 0)
resources.getQuantityString(R.plurals.days, minutes / 1440, minutes / 1440)
else if (minutes % 60 == 0)
resources.getQuantityString(R.plurals.hours, minutes / 60, minutes / 60)
else
resources.getQuantityString(R.plurals.minutes, minutes, minutes)
}
}
fun Context.getNewEventTimestampFromCode(dayCode: String) = Formatter.getLocalDateTimeFromCode(dayCode).withTime(13, 0, 0, 0).seconds()
val Context.config: Config get() = Config.newInstance(this)

View File

@ -1,49 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RadioGroup
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dialog_radio_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/activity_margin">
<com.simplemobiletools.commons.views.MyCompatRadioButton
android:id="@+id/dialog_radio_no_reminder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_margin"
android:paddingTop="@dimen/activity_margin"
android:text="@string/no_reminder"/>
<com.simplemobiletools.commons.views.MyCompatRadioButton
android:id="@+id/dialog_radio_at_start"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_margin"
android:paddingTop="@dimen/activity_margin"
android:text="@string/at_start"/>
<com.simplemobiletools.commons.views.MyCompatRadioButton
android:id="@+id/dialog_radio_mins_before_10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_margin"
android:paddingTop="@dimen/activity_margin"
android:text="@string/mins_before_10"/>
<com.simplemobiletools.commons.views.MyCompatRadioButton
android:id="@+id/dialog_radio_mins_before_30"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_margin"
android:paddingTop="@dimen/activity_margin"
android:text="@string/mins_before_30"/>
<com.simplemobiletools.commons.views.MyCompatRadioButton
android:id="@+id/dialog_radio_custom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_margin"
android:paddingTop="@dimen/activity_margin"
android:text="@string/custom"/>
</RadioGroup>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dialog_radio_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioGroup
android:id="@+id/dialog_radio_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/activity_margin"/>
</ScrollView>

View File

@ -50,18 +50,18 @@
<string name="days_raw">Tage</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>
<item quantity="other">%1$d Minuten</item>
<item quantity="one">%1$d minute before</item>
<item quantity="other">%1$d Minuten vorher</item>
</plurals>
<plurals name="hours">
<item quantity="one">%1$d hour</item>
<item quantity="other">%1$d Stunden</item>
<item quantity="one">%1$d hour before</item>
<item quantity="other">%1$d Stunden vorher</item>
</plurals>
<plurals name="days">
<item quantity="one">%1$d day</item>
<item quantity="other">%1$d Tage</item>
<item quantity="one">%1$d day before</item>
<item quantity="other">%1$d Tage vorher</item>
</plurals>
<!-- Importing -->

View File

@ -50,18 +50,18 @@
<string name="days_raw">días</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>
<item quantity="other">%1$d minutos</item>
<item quantity="one">%1$d minute before</item>
<item quantity="other">%1$d minutos antes de</item>
</plurals>
<plurals name="hours">
<item quantity="one">%1$d hour</item>
<item quantity="other">%1$d horas</item>
<item quantity="one">%1$d hour before</item>
<item quantity="other">%1$d horas antes de</item>
</plurals>
<plurals name="days">
<item quantity="one">%1$d day</item>
<item quantity="other">%1$d días</item>
<item quantity="one">%1$d day before</item>
<item quantity="other">%1$d días antes de</item>
</plurals>
<!-- Importing -->

View File

@ -50,18 +50,18 @@
<string name="days_raw">jours</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>
<item quantity="other">%1$d minutes</item>
<item quantity="one">%1$d minute before</item>
<item quantity="other">%1$d minutes avant</item>
</plurals>
<plurals name="hours">
<item quantity="one">%1$d hour</item>
<item quantity="other">%1$d heures</item>
<item quantity="one">%1$d hour before</item>
<item quantity="other">%1$d heures avant</item>
</plurals>
<plurals name="days">
<item quantity="one">%1$d day</item>
<item quantity="other">%1$d jours</item>
<item quantity="one">%1$d day before</item>
<item quantity="other">%1$d jours avant</item>
</plurals>
<!-- Importing -->

View File

@ -50,18 +50,18 @@
<string name="days_raw">days</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>
<item quantity="other">%1$d minutes</item>
<item quantity="one">%1$d minute before</item>
<item quantity="other">%1$d minutes before</item>
</plurals>
<plurals name="hours">
<item quantity="one">%1$d hour</item>
<item quantity="other">%1$d hours</item>
<item quantity="one">%1$d hour before</item>
<item quantity="other">%1$d hours before</item>
</plurals>
<plurals name="days">
<item quantity="one">%1$d day</item>
<item quantity="other">%1$d days</item>
<item quantity="one">%1$d day before</item>
<item quantity="other">%1$d days before</item>
</plurals>
<!-- Importing -->

View File

@ -50,18 +50,18 @@
<string name="days_raw">nap</string>
<plurals name="minutes">
<item quantity="one">%1$d percel</item>
<item quantity="other">%1$d percel</item>
<item quantity="one">%1$d percel korábban</item>
<item quantity="other">%1$d percel korábban</item>
</plurals>
<plurals name="hours">
<item quantity="one">%1$d órával</item>
<item quantity="other">%1$d órával</item>
<item quantity="one">%1$d órával korábban</item>
<item quantity="other">%1$d órával korábban</item>
</plurals>
<plurals name="days">
<item quantity="one">%1$d nappal</item>
<item quantity="other">%1$d nappal</item>
<item quantity="one">%1$d nappal korábban</item>
<item quantity="other">%1$d nappal korábban</item>
</plurals>
<!-- Importing -->

View File

@ -50,18 +50,18 @@
<string name="days_raw">days</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>
<item quantity="other">%1$d minutes</item>
<item quantity="one">%1$d minute before</item>
<item quantity="other">%1$d minutes before</item>
</plurals>
<plurals name="hours">
<item quantity="one">%1$d hour</item>
<item quantity="other">%1$d hours</item>
<item quantity="one">%1$d hour before</item>
<item quantity="other">%1$d hours before</item>
</plurals>
<plurals name="days">
<item quantity="one">%1$d day</item>
<item quantity="other">%1$d days</item>
<item quantity="one">%1$d day before</item>
<item quantity="other">%1$d days before</item>
</plurals>
<!-- Importing -->

View File

@ -50,18 +50,18 @@
<string name="days_raw">days</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>
<item quantity="other">%1$d minutes</item>
<item quantity="one">%1$d minute before</item>
<item quantity="other">%1$d minutes before</item>
</plurals>
<plurals name="hours">
<item quantity="one">%1$d hour</item>
<item quantity="other">%1$d hours</item>
<item quantity="one">%1$d hour before</item>
<item quantity="other">%1$d hours before</item>
</plurals>
<plurals name="days">
<item quantity="one">%1$d day</item>
<item quantity="other">%1$d days</item>
<item quantity="one">%1$d day before</item>
<item quantity="other">%1$d days before</item>
</plurals>
<!-- Importing -->

View File

@ -50,18 +50,18 @@
<string name="days_raw"></string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>
<item quantity="other">%1$d 分</item>
<item quantity="one">%1$d minute before</item>
<item quantity="other">%1$d 分</item>
</plurals>
<plurals name="hours">
<item quantity="one">%1$d hour</item>
<item quantity="other">%1$d 時間</item>
<item quantity="one">%1$d hour before</item>
<item quantity="other">%1$d 時間</item>
</plurals>
<plurals name="days">
<item quantity="one">%1$d day</item>
<item quantity="other">%1$d 日</item>
<item quantity="one">%1$d day before</item>
<item quantity="other">%1$d 日</item>
</plurals>
<!-- Importing -->

View File

@ -50,18 +50,18 @@
<string name="days_raw">dias</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>
<item quantity="other">%1$d minutos</item>
<item quantity="one">%1$d minute before</item>
<item quantity="other">%1$d minutos antes</item>
</plurals>
<plurals name="hours">
<item quantity="one">%1$d hour</item>
<item quantity="other">%1$d horas</item>
<item quantity="one">%1$d hour before</item>
<item quantity="other">%1$d horas antes</item>
</plurals>
<plurals name="days">
<item quantity="one">%1$d day</item>
<item quantity="other">%1$d dias</item>
<item quantity="one">%1$d day before</item>
<item quantity="other">%1$d dias antes</item>
</plurals>
<!-- Importing -->

View File

@ -50,18 +50,18 @@
<string name="days_raw">дней</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>
<item quantity="other">%1$d минут</item>
<item quantity="one">%1$d minute before</item>
<item quantity="other">%1$d минут до события</item>
</plurals>
<plurals name="hours">
<item quantity="one">%1$d hour</item>
<item quantity="other">%1$d часов</item>
<item quantity="one">%1$d hour before</item>
<item quantity="other">%1$d часов до события</item>
</plurals>
<plurals name="days">
<item quantity="one">%1$d day</item>
<item quantity="other">%1$d дней</item>
<item quantity="one">%1$d day before</item>
<item quantity="other">%1$d дней до события</item>
</plurals>
<!-- Importing -->

View File

@ -50,18 +50,18 @@
<string name="days_raw">dagar</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>
<item quantity="other">%1$d minuter</item>
<item quantity="one">%1$d minute before</item>
<item quantity="other">%1$d minuter före</item>
</plurals>
<plurals name="hours">
<item quantity="one">%1$d hour</item>
<item quantity="other">%1$d timmar</item>
<item quantity="one">%1$d hour before</item>
<item quantity="other">%1$d timmar före</item>
</plurals>
<plurals name="days">
<item quantity="one">%1$d day</item>
<item quantity="other">%1$d dagar</item>
<item quantity="one">%1$d day before</item>
<item quantity="other">%1$d dagar före</item>
</plurals>
<!-- Importing -->

View File

@ -50,18 +50,18 @@
<string name="days_raw">days</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>
<item quantity="other">%1$d minutes</item>
<item quantity="one">%1$d minute before</item>
<item quantity="other">%1$d minutes before</item>
</plurals>
<plurals name="hours">
<item quantity="one">%1$d hour</item>
<item quantity="other">%1$d hours</item>
<item quantity="one">%1$d hour before</item>
<item quantity="other">%1$d hours before</item>
</plurals>
<plurals name="days">
<item quantity="one">%1$d day</item>
<item quantity="other">%1$d days</item>
<item quantity="one">%1$d day before</item>
<item quantity="other">%1$d days before</item>
</plurals>
<!-- Importing -->