move event reminder from spinner into a dialog

This commit is contained in:
tibbi 2017-02-02 23:34:46 +01:00
parent cddd52ffa9
commit fa214a5896
18 changed files with 185 additions and 123 deletions

View File

@ -33,7 +33,7 @@ android {
}
dependencies {
compile 'com.simplemobiletools:commons:2.5.5'
compile 'com.simplemobiletools:commons:2.5.7'
compile 'joda-time:joda-time:2.9.1'
compile 'com.facebook.stetho:stetho:1.4.1'
compile 'com.bignerdranch.android:recyclerview-multiselect:0.2'

View File

@ -6,10 +6,9 @@ import android.graphics.PorterDuff
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.WindowManager
import android.widget.AdapterView
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.dialogs.EventReminderDialog
import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.extensions.getAppropriateTheme
import com.simplemobiletools.calendar.extensions.scheduleNotification
@ -22,9 +21,9 @@ import kotlinx.android.synthetic.main.activity_event.*
import org.joda.time.DateTime
class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
private var mWasReminderInit = false
private var mWasEndDateSet = false
private var mWasEndTimeSet = false
private var mReminderMinutes = 0
private var mDialogTheme = 0
lateinit var mEventStartDateTime: DateTime
@ -38,23 +37,22 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
val intent = intent ?: return
mDialogTheme = getAppropriateTheme()
mWasReminderInit = false
val eventId = intent.getIntExtra(EVENT_ID, 0)
val event = DBHelper(applicationContext).getEvent(eventId)
if (event != null) {
mEvent = event
setupEditEvent()
setupReminder()
} else {
mEvent = Event()
mReminderMinutes = config.defaultReminderMinutes
val startTS = intent.getIntExtra(NEW_EVENT_START_TS, 0)
if (startTS == 0)
return
setupNewEvent(Formatter.getDateTimeFromTS(startTS))
setupDefaultReminderType()
}
updateReminderText()
updateStartDate()
updateStartTime()
updateEndDate()
@ -70,15 +68,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
event_end_time.setOnClickListener { setupEndTime() }
event_all_day.setOnCheckedChangeListener { compoundButton, isChecked -> toggleAllDay(isChecked) }
event_reminder.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onNothingSelected(p0: AdapterView<*>?) {
}
override fun onItemSelected(p0: AdapterView<*>?, p1: View?, p2: Int, p3: Long) {
reminderItemSelected()
}
}
event_reminder.setOnClickListener { showReminderDialog() }
updateTextColors(event_scrollview)
updateIconColors()
@ -91,56 +81,40 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
mEventEndDateTime = Formatter.getDateTimeFromTS(mEvent.endTS)
event_title.setText(mEvent.title)
event_description.setText(mEvent.description)
mReminderMinutes = mEvent.reminderMinutes
}
private fun setupNewEvent(dateTime: DateTime) {
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
title = resources.getString(R.string.new_event)
mEventStartDateTime = dateTime
mEventEndDateTime = mEventStartDateTime
setupDefaultReminderType()
mEventEndDateTime = mEventStartDateTime.plusHours(1)
}
private fun setupDefaultReminderType() {
val type = config.defaultReminderType
toggleCustomReminderVisibility(type == REMINDER_CUSTOM)
if (type == REMINDER_OFF) {
event_reminder.setSelection(0)
} else if (type == REMINDER_AT_START) {
event_reminder.setSelection(1)
} else {
event_reminder.setSelection(2)
setupDefaultReminderValue()
private fun showReminderDialog() {
EventReminderDialog(this, mReminderMinutes) {
mReminderMinutes = it
updateReminderText()
}
}
private fun setupDefaultReminderValue() {
val mins = config.defaultReminderMinutes
var value = mins
if (mins == 0) {
custom_reminder_other_period.setSelection(0)
} else if (mins % DAY_MINS == 0) {
value = mins / DAY_MINS
custom_reminder_other_period.setSelection(2)
} else if (mins % HOUR_MINS == 0) {
value = mins / HOUR_MINS
custom_reminder_other_period.setSelection(1)
} else {
custom_reminder_other_period.setSelection(0)
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)
"${minutes / 1440} ${getString(R.string.days)}"
else if (minutes % 60 == 0)
"${minutes / 60} ${getString(R.string.hours)}"
else
"$minutes ${getString(R.string.minutes)}"
}
custom_reminder_value.setText(value.toString())
}
private fun setupReminder() {
when (mEvent.reminderMinutes) {
REMINDER_OFF -> event_reminder.setSelection(0)
REMINDER_AT_START -> event_reminder.setSelection(1)
else -> {
event_reminder.setSelection(2)
toggleCustomReminderVisibility(true)
setupReminderPeriod()
}
}
private fun updateReminderText() {
event_reminder.text = getReminderMinutesToString(mReminderMinutes)
}
private fun setupRepetition() {
@ -161,41 +135,6 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
event_end_time.beGoneIf(isChecked)
}
fun reminderItemSelected() {
if (!mWasReminderInit) {
mWasReminderInit = true
return
}
if (event_reminder.selectedItemPosition == event_reminder.count - 1) {
toggleCustomReminderVisibility(true)
custom_reminder_value.requestFocus()
showKeyboard(custom_reminder_value)
} else {
hideKeyboard()
toggleCustomReminderVisibility(false)
}
}
private fun setupReminderPeriod() {
val mins = mEvent.reminderMinutes
var value = mins
if (mins % DAY_MINS == 0) {
value = mins / DAY_MINS
custom_reminder_other_period.setSelection(2)
} else if (mins % HOUR_MINS == 0) {
value = mins / HOUR_MINS
custom_reminder_other_period.setSelection(1)
} else {
custom_reminder_other_period.setSelection(0)
}
custom_reminder_value.setText(value.toString())
}
fun toggleCustomReminderVisibility(show: Boolean) {
custom_reminder_holder.beVisibleIf(show)
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_event, menu)
val item = menu.findItem(R.id.cab_delete)
@ -244,7 +183,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
endTS = newEndTS
title = newTitle
description = newDescription
reminderMinutes = getReminderMinutes()
reminderMinutes = mReminderMinutes
repeatInterval = getRepeatInterval()
}
@ -255,22 +194,6 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
}
}
private fun getReminderMinutes(): Int {
return when (event_reminder.selectedItemPosition) {
0 -> REMINDER_OFF
1 -> REMINDER_AT_START
else -> {
val value = custom_reminder_value.value
val multiplier = when (custom_reminder_other_period.selectedItemPosition) {
1 -> HOUR_MINS
2 -> DAY_MINS
else -> 1
}
Integer.valueOf(if (value.isEmpty()) "0" else value) * multiplier
}
}
}
private fun getRepeatInterval(): Int {
return when (event_repetition.selectedItemPosition) {
1 -> DAY

View File

@ -0,0 +1,46 @@
package com.simplemobiletools.calendar.dialogs
import android.app.Activity
import android.support.v7.app.AlertDialog
import android.view.LayoutInflater
import android.widget.RadioGroup
import com.simplemobiletools.calendar.R
import com.simplemobiletools.commons.extensions.setupDialogStuff
import kotlinx.android.synthetic.main.dialog_change_views.view.*
class EventReminderDialog(val activity: Activity, val defaultMinutes: Int, val callback: (mins: Int) -> Unit) : AlertDialog.Builder(activity), RadioGroup.OnCheckedChangeListener {
val dialog: AlertDialog?
init {
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_event_reminder, null).dialog_radio_view.apply {
check(getCheckedItem())
setOnCheckedChangeListener(this@EventReminderDialog)
}
dialog = AlertDialog.Builder(activity)
.create().apply {
activity.setupDialogStuff(view, this, R.string.select_event_reminder)
}
}
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
}
override fun onCheckedChanged(group: RadioGroup?, checkedId: Int) {
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
}
}

View File

@ -48,7 +48,7 @@
android:layout_below="@+id/event_description"
android:layout_marginBottom="@dimen/normal_margin"
android:layout_marginTop="@dimen/activity_margin"
android:background="#66808080"/>
android:background="@color/darker_divider"/>
<ImageView
android:id="@+id/event_time_image"
@ -91,6 +91,7 @@
android:layout_below="@+id/event_time_image"
android:background="?attr/selectableItemBackground"
android:paddingBottom="@dimen/activity_margin"
android:paddingEnd="@dimen/activity_margin"
android:paddingRight="@dimen/activity_margin"
android:paddingTop="@dimen/activity_margin"
android:text="January 1 1970"
@ -117,6 +118,7 @@
android:layout_below="@+id/event_start_date"
android:background="?attr/selectableItemBackground"
android:paddingBottom="@dimen/activity_margin"
android:paddingEnd="@dimen/activity_margin"
android:paddingRight="@dimen/activity_margin"
android:paddingTop="@dimen/activity_margin"
android:text="January 1 1970"
@ -141,7 +143,7 @@
android:layout_below="@+id/event_end_date"
android:layout_marginBottom="@dimen/medium_margin"
android:layout_marginTop="@dimen/medium_margin"
android:background="#66808080"/>
android:background="@color/darker_divider"/>
<ImageView
android:id="@+id/event_reminder_image"
@ -156,14 +158,19 @@
android:padding="@dimen/medium_margin"
android:src="@drawable/ic_bell"/>
<com.simplemobiletools.commons.views.MyAppCompatSpinner
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/event_reminder"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/event_date_time_divider"
android:layout_marginLeft="@dimen/small_margin"
android:layout_marginStart="@dimen/small_margin"
android:layout_toEndOf="@+id/event_reminder_image"
android:layout_toRightOf="@+id/event_reminder_image"
android:entries="@array/reminders"
android:padding="@dimen/normal_margin"/>
android:background="?attr/selectableItemBackground"
android:paddingBottom="@dimen/normal_margin"
android:paddingTop="@dimen/normal_margin"
android:textSize="@dimen/day_text_size"/>
<ImageView
android:id="@+id/event_reminder_divider"
@ -172,7 +179,7 @@
android:layout_below="@+id/event_reminder"
android:layout_marginBottom="@dimen/medium_margin"
android:layout_marginTop="@dimen/medium_margin"
android:background="#66808080"/>
android:background="@color/darker_divider"/>
<LinearLayout
android:id="@+id/custom_reminder_holder"

View File

@ -0,0 +1,49 @@
<?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

@ -37,7 +37,10 @@
<string name="monthly">Monatlich</string>
<string name="yearly">Jährlich</string>
<!-- Custom reminder -->
<!-- Event Reminders -->
<string name="select_event_reminder">Select an event reminder</string>
<string name="mins_before_10">10 minutes before</string>
<string name="mins_before_30">30 minutes before</string>
<string name="before">vorher</string>
<string name="minutes">Minuten</string>
<string name="hours">Stunden</string>

View File

@ -37,7 +37,10 @@
<string name="monthly">Mensual</string>
<string name="yearly">Anual</string>
<!-- Custom reminder -->
<!-- Event Reminders -->
<string name="select_event_reminder">Select an event reminder</string>
<string name="mins_before_10">10 minutes before</string>
<string name="mins_before_30">30 minutes before</string>
<string name="before">antes de</string>
<string name="minutes">minutos</string>
<string name="hours">horas</string>

View File

@ -37,7 +37,10 @@
<string name="monthly">Mensuelle</string>
<string name="yearly">Annuelle</string>
<!-- Custom reminder -->
<!-- Event Reminders -->
<string name="select_event_reminder">Select an event reminder</string>
<string name="mins_before_10">10 minutes before</string>
<string name="mins_before_30">30 minutes before</string>
<string name="before">avant</string>
<string name="minutes">minutes</string>
<string name="hours">heures</string>

View File

@ -37,7 +37,10 @@
<string name="monthly">मासिक</string>
<string name="yearly">वार्षिक</string>
<!-- Custom reminder -->
<!-- Event Reminders -->
<string name="select_event_reminder">Select an event reminder</string>
<string name="mins_before_10">10 minutes before</string>
<string name="mins_before_30">30 minutes before</string>
<string name="before">before</string>
<string name="minutes">minutes</string>
<string name="hours">hours</string>

View File

@ -37,7 +37,10 @@
<string name="monthly">Havonta</string>
<string name="yearly">Évente</string>
<!-- Custom reminder -->
<!-- Event Reminders -->
<string name="select_event_reminder">Select an event reminder</string>
<string name="mins_before_10">10 minutes before</string>
<string name="mins_before_30">30 minutes before</string>
<string name="before">korábban</string>
<string name="minutes">perccel</string>
<string name="hours">órával</string>

View File

@ -37,7 +37,10 @@
<string name="monthly">Monthly</string>
<string name="yearly">Yearly</string>
<!-- Custom reminder -->
<!-- Event Reminders -->
<string name="select_event_reminder">Select an event reminder</string>
<string name="mins_before_10">10 minutes before</string>
<string name="mins_before_30">30 minutes before</string>
<string name="before">before</string>
<string name="minutes">minutes</string>
<string name="hours">hours</string>

View File

@ -37,7 +37,10 @@
<string name="monthly">חודשית</string>
<string name="yearly">שנתית</string>
<!-- Custom reminder -->
<!-- Event Reminders -->
<string name="select_event_reminder">Select an event reminder</string>
<string name="mins_before_10">10 minutes before</string>
<string name="mins_before_30">30 minutes before</string>
<string name="before">לפני</string>
<string name="minutes">דקות</string>
<string name="hours">שעות</string>

View File

@ -37,7 +37,10 @@
<string name="monthly">毎月</string>
<string name="yearly">毎年</string>
<!-- Custom reminder -->
<!-- Event Reminders -->
<string name="select_event_reminder">Select an event reminder</string>
<string name="mins_before_10">10 minutes before</string>
<string name="mins_before_30">30 minutes before</string>
<string name="before"></string>
<string name="minutes"></string>
<string name="hours">時間</string>

View File

@ -37,7 +37,10 @@
<string name="monthly">Mensal</string>
<string name="yearly">Anual</string>
<!-- Custom reminder -->
<!-- Event Reminders -->
<string name="select_event_reminder">Select an event reminder</string>
<string name="mins_before_10">10 minutes before</string>
<string name="mins_before_30">30 minutes before</string>
<string name="before">antes</string>
<string name="minutes">minutos</string>
<string name="hours">horas</string>

View File

@ -37,7 +37,10 @@
<string name="monthly">Ежемесячно</string>
<string name="yearly">Ежегодно</string>
<!-- Custom reminder -->
<!-- Event Reminders -->
<string name="select_event_reminder">Select an event reminder</string>
<string name="mins_before_10">10 minutes before</string>
<string name="mins_before_30">30 minutes before</string>
<string name="before">до события</string>
<string name="minutes">минут</string>
<string name="hours">часов</string>

View File

@ -37,7 +37,10 @@
<string name="monthly">Månadsvis</string>
<string name="yearly">Årligen</string>
<!-- Custom reminder -->
<!-- Event Reminders -->
<string name="select_event_reminder">Select an event reminder</string>
<string name="mins_before_10">10 minutes before</string>
<string name="mins_before_30">30 minutes before</string>
<string name="before">före</string>
<string name="minutes">minuter</string>
<string name="hours">timmar</string>

View File

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="dark_theme_dialog_background">#ff444444</color>
<color name="darker_divider">#66808080</color>
</resources>

View File

@ -37,7 +37,10 @@
<string name="monthly">Monthly</string>
<string name="yearly">Yearly</string>
<!-- Custom reminder -->
<!-- Event Reminders -->
<string name="select_event_reminder">Select an event reminder</string>
<string name="mins_before_10">10 minutes before</string>
<string name="mins_before_30">30 minutes before</string>
<string name="before">before</string>
<string name="minutes">minutes</string>
<string name="hours">hours</string>