implement the custom event reminder dialog
This commit is contained in:
parent
83594dd47e
commit
6e91b0abbe
|
@ -89,7 +89,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
|
|||
}
|
||||
|
||||
private fun setupNewEvent(dateTime: DateTime) {
|
||||
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
|
||||
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE)
|
||||
title = resources.getString(R.string.new_event)
|
||||
mEventStartDateTime = dateTime
|
||||
mEventEndDateTime = mEventStartDateTime.plusHours(1)
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
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.view.WindowManager
|
||||
import com.simplemobiletools.calendar.R
|
||||
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) {
|
||||
var dialog: AlertDialog
|
||||
var view: ViewGroup = LayoutInflater.from(activity).inflate(R.layout.dialog_custom_event_reminder, null) as ViewGroup
|
||||
|
||||
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)
|
||||
.create().apply {
|
||||
window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
|
||||
activity.setupDialogStuff(view, this, R.string.select_event_reminder)
|
||||
}
|
||||
}
|
||||
|
||||
private fun confirmReminder() {
|
||||
val value = view.dialog_custom_reminder_value.value
|
||||
val multiplier = getMultiplier(view.dialog_radio_view.checkedRadioButtonId)
|
||||
val minutes = Integer.valueOf(if (value.isEmpty()) "0" else value)
|
||||
callback.invoke(minutes * multiplier)
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
||||
private fun getMultiplier(id: Int) = when (id) {
|
||||
R.id.dialog_radio_hours -> 60
|
||||
R.id.dialog_radio_days -> 1440
|
||||
else -> 1
|
||||
}
|
||||
}
|
|
@ -32,15 +32,21 @@ class EventReminderDialog(val activity: Activity, val defaultMinutes: Int, val c
|
|||
}
|
||||
|
||||
override fun onCheckedChanged(group: RadioGroup?, checkedId: Int) {
|
||||
callback.invoke(getSelectionValue(checkedId))
|
||||
dialog?.dismiss()
|
||||
if (checkedId == R.id.dialog_radio_custom) {
|
||||
CustomEventReminderDialog(activity) {
|
||||
callback.invoke(it)
|
||||
dialog?.dismiss()
|
||||
}
|
||||
} else {
|
||||
callback.invoke(getSelectionValue(checkedId))
|
||||
dialog?.dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
private fun getSelectionValue(id: Int) = when (id) {
|
||||
R.id.dialog_radio_no_reminder -> -1
|
||||
R.id.dialog_radio_at_start -> 0
|
||||
R.id.dialog_radio_mins_before_10 -> 10
|
||||
R.id.dialog_radio_mins_before_30 -> 30
|
||||
else -> 2
|
||||
else -> -1
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/dialog_custom_reminder_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="@dimen/activity_margin"
|
||||
android:paddingRight="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/activity_margin">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyEditText
|
||||
android:id="@+id/dialog_custom_reminder_value"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:digits="0123456789"
|
||||
android:ems="3"
|
||||
android:inputType="number"
|
||||
android:maxLength="4"
|
||||
android:textCursorDrawable="@null"/>
|
||||
|
||||
<RadioGroup
|
||||
android:id="@+id/dialog_radio_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="@dimen/activity_margin">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||
android:id="@+id/dialog_radio_minutes"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/activity_margin"
|
||||
android:text="@string/minutes"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||
android:id="@+id/dialog_radio_hours"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/activity_margin"
|
||||
android:text="@string/hours"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||
android:id="@+id/dialog_radio_days"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/activity_margin"
|
||||
android:text="@string/days"/>
|
||||
|
||||
</RadioGroup>
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue