some more work on the default event reminder setting

This commit is contained in:
tibbi
2016-11-01 23:12:44 +01:00
parent 2bd5a6dce4
commit 3a3fac2a48
7 changed files with 106 additions and 52 deletions

View File

@@ -64,4 +64,22 @@ public class Config {
public void setStoredView(int view) { public void setStoredView(int view) {
mPrefs.edit().putInt(Constants.VIEW, view).apply(); mPrefs.edit().putInt(Constants.VIEW, view).apply();
} }
public int getDefaultReminderType() {
return mPrefs.getInt(Constants.REMINDER_TYPE, Constants.REMINDER_AT_START);
}
public void setDefaultReminderType(int type) {
mPrefs.edit().putInt(Constants.REMINDER_TYPE, type).apply();
}
public int getDefaultReminderMinutes() {
return mPrefs.getInt(Constants.REMINDER_MINUTES, 0);
}
public void setDefaultReminderMinutes(int mins) {
if (mins == 0)
setDefaultReminderType(Constants.REMINDER_AT_START);
mPrefs.edit().putInt(Constants.REMINDER_MINUTES, mins).apply();
}
} }

View File

@@ -13,12 +13,19 @@ public class Constants {
public static final int YEARLY_VIEW = 2; public static final int YEARLY_VIEW = 2;
public static final int EVENTS_LIST_VIEW = 3; public static final int EVENTS_LIST_VIEW = 3;
public static final int REMINDER_OFF = -1;
public static final int REMINDER_AT_START = 0;
public static final int REMINDER_CUSTOM = 1;
public static final int DAY = 86400; public static final int DAY = 86400;
public static final int WEEK = 604800; public static final int WEEK = 604800;
public static final int BIWEEK = 1209600; public static final int BIWEEK = 1209600;
public static final int MONTH = 2592000; // exact value not taken into account, Joda is used for adding months and years public static final int MONTH = 2592000; // exact value not taken into account, Joda is used for adding months and years
public static final int YEAR = 31536000; public static final int YEAR = 31536000;
public static final int HOUR_MINS = 60;
public static final int DAY_MINS = 1440;
// Shared Preferences // Shared Preferences
public static final String PREFS_KEY = "Calendar"; public static final String PREFS_KEY = "Calendar";
public static final String IS_FIRST_RUN = "is_first_run"; public static final String IS_FIRST_RUN = "is_first_run";
@@ -26,6 +33,8 @@ public class Constants {
public static final String SUNDAY_FIRST = "sunday_first"; public static final String SUNDAY_FIRST = "sunday_first";
public static final String WEEK_NUMBERS = "week_numbers"; public static final String WEEK_NUMBERS = "week_numbers";
public static final String VIEW = "view"; public static final String VIEW = "view";
public static final String REMINDER_TYPE = "reminder_type";
public static final String REMINDER_MINUTES = "reminder_minutes";
public static final String WIDGET_BG_COLOR = "widget_bg_color"; public static final String WIDGET_BG_COLOR = "widget_bg_color";
public static final String WIDGET_TEXT_COLOR = "widget_text_color"; public static final String WIDGET_TEXT_COLOR = "widget_text_color";
public static final String LAST_OTHER_REMINDER_MINS = "last_other_reminder_mins"; public static final String LAST_OTHER_REMINDER_MINS = "last_other_reminder_mins";

View File

@@ -18,9 +18,6 @@ import org.joda.time.DateTime
import org.joda.time.DateTimeZone import org.joda.time.DateTimeZone
class EventActivity : SimpleActivity(), DBHelper.EventsListener { class EventActivity : SimpleActivity(), DBHelper.EventsListener {
val HOUR_MINS = 60
val DAY_MINS = 1440
private var mWasReminderInit: Boolean = false private var mWasReminderInit: Boolean = false
private var mWasEndDateSet: Boolean = false private var mWasEndDateSet: Boolean = false
private var mWasEndTimeSet: Boolean = false private var mWasEndTimeSet: Boolean = false
@@ -93,13 +90,13 @@ class EventActivity : SimpleActivity(), DBHelper.EventsListener {
title = resources.getString(R.string.new_event) title = resources.getString(R.string.new_event)
mEventStartDateTime = Formatter.getDateTimeFromCode(dayCode).withZoneRetainFields(DateTimeZone.getDefault()).withHourOfDay(13) mEventStartDateTime = Formatter.getDateTimeFromCode(dayCode).withZoneRetainFields(DateTimeZone.getDefault()).withHourOfDay(13)
mEventEndDateTime = mEventStartDateTime mEventEndDateTime = mEventStartDateTime
event_reminder_other.setText(mConfig.lastOtherReminderMins.toString()) custom_reminder_value.setText(mConfig.lastOtherReminderMins.toString())
} }
private fun setupReminder() { private fun setupReminder() {
when (mEvent.reminderMinutes) { when (mEvent.reminderMinutes) {
-1 -> event_reminder.setSelection(0) Constants.REMINDER_OFF -> event_reminder.setSelection(0)
0 -> event_reminder.setSelection(1) Constants.REMINDER_AT_START -> event_reminder.setSelection(1)
else -> { else -> {
event_reminder.setSelection(2) event_reminder.setSelection(2)
toggleCustomReminderVisibility(true) toggleCustomReminderVisibility(true)
@@ -136,8 +133,8 @@ class EventActivity : SimpleActivity(), DBHelper.EventsListener {
if (event_reminder.selectedItemPosition == event_reminder.count - 1) { if (event_reminder.selectedItemPosition == event_reminder.count - 1) {
toggleCustomReminderVisibility(true) toggleCustomReminderVisibility(true)
event_reminder_other.requestFocus() custom_reminder_value.requestFocus()
showKeyboard(event_reminder_other) showKeyboard(custom_reminder_value)
} else { } else {
hideKeyboard() hideKeyboard()
toggleCustomReminderVisibility(false) toggleCustomReminderVisibility(false)
@@ -147,22 +144,22 @@ class EventActivity : SimpleActivity(), DBHelper.EventsListener {
private fun setupReminderPeriod() { private fun setupReminderPeriod() {
val mins = mEvent.reminderMinutes val mins = mEvent.reminderMinutes
var value = mins var value = mins
if (mins % DAY_MINS == 0) { if (mins % Constants.DAY_MINS == 0) {
value = mins / DAY_MINS value = mins / Constants.DAY_MINS
settings_custom_reminder_other_period.setSelection(2) custom_reminder_other_period.setSelection(2)
} else if (mins % HOUR_MINS == 0) { } else if (mins % Constants.HOUR_MINS == 0) {
value = mins / HOUR_MINS value = mins / Constants.HOUR_MINS
settings_custom_reminder_other_period.setSelection(1) custom_reminder_other_period.setSelection(1)
} else { } else {
settings_custom_reminder_other_period.setSelection(0) custom_reminder_other_period.setSelection(0)
} }
event_reminder_other.setText(value.toString()) custom_reminder_value.setText(value.toString())
} }
fun toggleCustomReminderVisibility(show: Boolean) { fun toggleCustomReminderVisibility(show: Boolean) {
settings_custom_reminder_other_period.beVisibleIf(show) custom_reminder_other_period.beVisibleIf(show)
settings_custom_reminder_other_val.beVisibleIf(show) custom_reminder_other_val.beVisibleIf(show)
event_reminder_other.beVisibleIf(show) custom_reminder_value.beVisibleIf(show)
} }
override fun onCreateOptionsMenu(menu: Menu): Boolean { override fun onCreateOptionsMenu(menu: Menu): Boolean {
@@ -242,13 +239,13 @@ class EventActivity : SimpleActivity(), DBHelper.EventsListener {
0 -> -1 0 -> -1
1 -> 0 1 -> 0
else -> { else -> {
val value = event_reminder_other.value val value = custom_reminder_value.value
if (value.isEmpty()) if (value.isEmpty())
0 0
val multiplier = when (settings_custom_reminder_other_period.selectedItemPosition) { val multiplier = when (custom_reminder_other_period.selectedItemPosition) {
1 -> HOUR_MINS 1 -> Constants.HOUR_MINS
2 -> DAY_MINS 2 -> Constants.DAY_MINS
else -> 1 else -> 1
} }
Integer.valueOf(value) * multiplier Integer.valueOf(value) * multiplier

View File

@@ -93,7 +93,7 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener, ChangeV
private fun updateView(view: Int) { private fun updateView(view: Int) {
mIsMonthSelected = view == Constants.MONTHLY_VIEW mIsMonthSelected = view == Constants.MONTHLY_VIEW
mConfig.view = view mConfig.storedView = view
updateViewPager() updateViewPager()
} }

View File

@@ -4,6 +4,7 @@ import android.os.Bundle
import android.support.v4.app.TaskStackBuilder import android.support.v4.app.TaskStackBuilder
import android.view.View import android.view.View
import android.widget.AdapterView import android.widget.AdapterView
import com.simplemobiletools.calendar.Constants
import com.simplemobiletools.calendar.R import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.extensions.beVisibleIf import com.simplemobiletools.calendar.extensions.beVisibleIf
import com.simplemobiletools.calendar.extensions.hideKeyboard import com.simplemobiletools.calendar.extensions.hideKeyboard
@@ -39,7 +40,7 @@ class SettingsActivity : SimpleActivity() {
} }
private fun setupWeekNumbers() { private fun setupWeekNumbers() {
settings_week_numbers!!.isChecked = mConfig.displayWeekNumbers settings_week_numbers.isChecked = mConfig.displayWeekNumbers
settings_week_numbers_holder.setOnClickListener { settings_week_numbers_holder.setOnClickListener {
settings_week_numbers.toggle() settings_week_numbers.toggle()
mConfig.displayWeekNumbers = settings_week_numbers.isChecked mConfig.displayWeekNumbers = settings_week_numbers.isChecked
@@ -47,6 +48,16 @@ class SettingsActivity : SimpleActivity() {
} }
private fun setupEventReminder() { private fun setupEventReminder() {
val reminderType = mConfig.defaultReminderType
val reminderMinutes = mConfig.defaultReminderMinutes
settings_default_reminder.setSelection(when (reminderType) {
Constants.REMINDER_OFF -> 0
Constants.REMINDER_AT_START -> 1
else -> 2
})
setupReminderPeriod(reminderMinutes)
settings_custom_reminder_holder.beVisibleIf(reminderType == 2)
settings_default_reminder.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { settings_default_reminder.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onNothingSelected(p0: AdapterView<*>?) { override fun onNothingSelected(p0: AdapterView<*>?) {
} }
@@ -54,12 +65,34 @@ class SettingsActivity : SimpleActivity() {
override fun onItemSelected(p0: AdapterView<*>?, p1: View?, itemIndex: Int, p3: Long) { override fun onItemSelected(p0: AdapterView<*>?, p1: View?, itemIndex: Int, p3: Long) {
settings_custom_reminder_holder.beVisibleIf(itemIndex == 2) settings_custom_reminder_holder.beVisibleIf(itemIndex == 2)
if (itemIndex == 2) if (itemIndex == 2)
showKeyboard(settings_custom_reminder_other) showKeyboard(custom_reminder_value)
else else
hideKeyboard() hideKeyboard()
mConfig.defaultReminderType = when (itemIndex) {
0 -> Constants.REMINDER_OFF
1 -> Constants.REMINDER_AT_START
else -> Constants.REMINDER_CUSTOM
} }
} }
} }
}
private fun setupReminderPeriod(mins: Int) {
var value = mins
if (mins == 0) {
custom_reminder_other_period.setSelection(0)
} else if (mins % Constants.DAY_MINS == 0) {
value = mins / Constants.DAY_MINS
custom_reminder_other_period.setSelection(2)
} else if (mins % Constants.HOUR_MINS == 0) {
value = mins / Constants.HOUR_MINS
custom_reminder_other_period.setSelection(1)
} else {
custom_reminder_other_period.setSelection(0)
}
custom_reminder_value.setText(value.toString())
}
private fun restartActivity() { private fun restartActivity() {
TaskStackBuilder.create(applicationContext).addNextIntentWithParentStack(intent).startActivities() TaskStackBuilder.create(applicationContext).addNextIntentWithParentStack(intent).startActivities()

View File

@@ -128,7 +128,7 @@
android:padding="@dimen/activity_margin"/> android:padding="@dimen/activity_margin"/>
<EditText <EditText
android:id="@+id/event_reminder_other" android:id="@+id/custom_reminder_value"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/event_reminder" android:layout_below="@+id/event_reminder"
@@ -140,24 +140,24 @@
android:visibility="gone"/> android:visibility="gone"/>
<android.support.v7.widget.AppCompatSpinner <android.support.v7.widget.AppCompatSpinner
android:id="@+id/settings_custom_reminder_other_period" android:id="@+id/custom_reminder_other_period"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignBottom="@+id/event_reminder_other" android:layout_alignBottom="@+id/custom_reminder_value"
android:layout_alignTop="@+id/event_reminder_other" android:layout_alignTop="@+id/custom_reminder_value"
android:layout_toRightOf="@+id/event_reminder_other" android:layout_toRightOf="@+id/custom_reminder_value"
android:entries="@array/custom_reminders" android:entries="@array/custom_reminders"
android:gravity="center_vertical" android:gravity="center_vertical"
android:paddingLeft="@dimen/activity_margin" android:paddingLeft="@dimen/activity_margin"
android:visibility="gone"/> android:visibility="gone"/>
<TextView <TextView
android:id="@+id/settings_custom_reminder_other_val" android:id="@+id/custom_reminder_other_val"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignBottom="@+id/event_reminder_other" android:layout_alignBottom="@+id/custom_reminder_value"
android:layout_alignTop="@+id/event_reminder_other" android:layout_alignTop="@+id/custom_reminder_value"
android:layout_toRightOf="@+id/settings_custom_reminder_other_period" android:layout_toRightOf="@+id/custom_reminder_other_period"
android:gravity="center_vertical" android:gravity="center_vertical"
android:text="@string/before" android:text="@string/before"
android:visibility="gone"/> android:visibility="gone"/>
@@ -166,7 +166,7 @@
android:id="@+id/event_repetition_label" android:id="@+id/event_repetition_label"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/event_reminder_other" android:layout_below="@+id/custom_reminder_value"
android:layout_marginTop="@dimen/activity_margin" android:layout_marginTop="@dimen/activity_margin"
android:text="@string/repetition" android:text="@string/repetition"
android:textSize="@dimen/day_text_size"/> android:textSize="@dimen/day_text_size"/>

View File

@@ -118,43 +118,40 @@
android:id="@+id/settings_custom_reminder_holder" android:id="@+id/settings_custom_reminder_holder"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/settings_padding"
android:layout_marginTop="@dimen/settings_padding" android:layout_marginTop="@dimen/settings_padding"
android:paddingLeft="@dimen/activity_margin"
android:visibility="gone"> android:visibility="gone">
<EditText <EditText
android:id="@+id/settings_custom_reminder_other" android:id="@+id/custom_reminder_value"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_margin" android:layout_marginLeft="@dimen/activity_margin"
android:digits="0123456789" android:digits="0123456789"
android:inputType="number" android:inputType="number"
android:minEms="5" android:minEms="5"
android:textSize="@dimen/day_text_size" android:textSize="@dimen/day_text_size"/>
android:visibility="visible"/>
<android.support.v7.widget.AppCompatSpinner <android.support.v7.widget.AppCompatSpinner
android:id="@+id/settings_custom_reminder_other_period" android:id="@+id/custom_reminder_other_period"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignBottom="@+id/settings_custom_reminder_other" android:layout_alignBottom="@+id/custom_reminder_value"
android:layout_alignTop="@+id/settings_custom_reminder_other" android:layout_alignTop="@+id/custom_reminder_value"
android:layout_toRightOf="@+id/settings_custom_reminder_other" android:layout_toRightOf="@+id/custom_reminder_value"
android:entries="@array/custom_reminders" android:entries="@array/custom_reminders"
android:gravity="center_vertical" android:gravity="center_vertical"
android:paddingLeft="@dimen/activity_margin" android:paddingLeft="@dimen/activity_margin"/>
android:visibility="visible"/>
<TextView <TextView
android:id="@+id/settings_custom_reminder_other_val" android:id="@+id/custom_reminder_other_val"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignBottom="@+id/settings_custom_reminder_other" android:layout_alignBottom="@+id/custom_reminder_value"
android:layout_alignTop="@+id/settings_custom_reminder_other" android:layout_alignTop="@+id/custom_reminder_value"
android:layout_toRightOf="@+id/settings_custom_reminder_other_period" android:layout_toRightOf="@+id/custom_reminder_other_period"
android:gravity="center_vertical" android:gravity="center_vertical"
android:text="@string/before" android:text="@string/before"/>
android:visibility="visible"/>
</RelativeLayout> </RelativeLayout>
</LinearLayout> </LinearLayout>