mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-17 04:10:45 +01:00
some more work on the default event reminder setting
This commit is contained in:
parent
2bd5a6dce4
commit
3a3fac2a48
@ -64,4 +64,22 @@ public class Config {
|
||||
public void setStoredView(int view) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -13,12 +13,19 @@ public class Constants {
|
||||
public static final int YEARLY_VIEW = 2;
|
||||
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 WEEK = 604800;
|
||||
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 YEAR = 31536000;
|
||||
|
||||
public static final int HOUR_MINS = 60;
|
||||
public static final int DAY_MINS = 1440;
|
||||
|
||||
// Shared Preferences
|
||||
public static final String PREFS_KEY = "Calendar";
|
||||
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 WEEK_NUMBERS = "week_numbers";
|
||||
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_TEXT_COLOR = "widget_text_color";
|
||||
public static final String LAST_OTHER_REMINDER_MINS = "last_other_reminder_mins";
|
||||
|
@ -18,9 +18,6 @@ import org.joda.time.DateTime
|
||||
import org.joda.time.DateTimeZone
|
||||
|
||||
class EventActivity : SimpleActivity(), DBHelper.EventsListener {
|
||||
val HOUR_MINS = 60
|
||||
val DAY_MINS = 1440
|
||||
|
||||
private var mWasReminderInit: Boolean = false
|
||||
private var mWasEndDateSet: Boolean = false
|
||||
private var mWasEndTimeSet: Boolean = false
|
||||
@ -93,13 +90,13 @@ class EventActivity : SimpleActivity(), DBHelper.EventsListener {
|
||||
title = resources.getString(R.string.new_event)
|
||||
mEventStartDateTime = Formatter.getDateTimeFromCode(dayCode).withZoneRetainFields(DateTimeZone.getDefault()).withHourOfDay(13)
|
||||
mEventEndDateTime = mEventStartDateTime
|
||||
event_reminder_other.setText(mConfig.lastOtherReminderMins.toString())
|
||||
custom_reminder_value.setText(mConfig.lastOtherReminderMins.toString())
|
||||
}
|
||||
|
||||
private fun setupReminder() {
|
||||
when (mEvent.reminderMinutes) {
|
||||
-1 -> event_reminder.setSelection(0)
|
||||
0 -> event_reminder.setSelection(1)
|
||||
Constants.REMINDER_OFF -> event_reminder.setSelection(0)
|
||||
Constants.REMINDER_AT_START -> event_reminder.setSelection(1)
|
||||
else -> {
|
||||
event_reminder.setSelection(2)
|
||||
toggleCustomReminderVisibility(true)
|
||||
@ -136,8 +133,8 @@ class EventActivity : SimpleActivity(), DBHelper.EventsListener {
|
||||
|
||||
if (event_reminder.selectedItemPosition == event_reminder.count - 1) {
|
||||
toggleCustomReminderVisibility(true)
|
||||
event_reminder_other.requestFocus()
|
||||
showKeyboard(event_reminder_other)
|
||||
custom_reminder_value.requestFocus()
|
||||
showKeyboard(custom_reminder_value)
|
||||
} else {
|
||||
hideKeyboard()
|
||||
toggleCustomReminderVisibility(false)
|
||||
@ -147,22 +144,22 @@ class EventActivity : SimpleActivity(), DBHelper.EventsListener {
|
||||
private fun setupReminderPeriod() {
|
||||
val mins = mEvent.reminderMinutes
|
||||
var value = mins
|
||||
if (mins % DAY_MINS == 0) {
|
||||
value = mins / DAY_MINS
|
||||
settings_custom_reminder_other_period.setSelection(2)
|
||||
} else if (mins % HOUR_MINS == 0) {
|
||||
value = mins / HOUR_MINS
|
||||
settings_custom_reminder_other_period.setSelection(1)
|
||||
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 {
|
||||
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) {
|
||||
settings_custom_reminder_other_period.beVisibleIf(show)
|
||||
settings_custom_reminder_other_val.beVisibleIf(show)
|
||||
event_reminder_other.beVisibleIf(show)
|
||||
custom_reminder_other_period.beVisibleIf(show)
|
||||
custom_reminder_other_val.beVisibleIf(show)
|
||||
custom_reminder_value.beVisibleIf(show)
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
@ -242,13 +239,13 @@ class EventActivity : SimpleActivity(), DBHelper.EventsListener {
|
||||
0 -> -1
|
||||
1 -> 0
|
||||
else -> {
|
||||
val value = event_reminder_other.value
|
||||
val value = custom_reminder_value.value
|
||||
if (value.isEmpty())
|
||||
0
|
||||
|
||||
val multiplier = when (settings_custom_reminder_other_period.selectedItemPosition) {
|
||||
1 -> HOUR_MINS
|
||||
2 -> DAY_MINS
|
||||
val multiplier = when (custom_reminder_other_period.selectedItemPosition) {
|
||||
1 -> Constants.HOUR_MINS
|
||||
2 -> Constants.DAY_MINS
|
||||
else -> 1
|
||||
}
|
||||
Integer.valueOf(value) * multiplier
|
||||
|
@ -93,7 +93,7 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener, ChangeV
|
||||
|
||||
private fun updateView(view: Int) {
|
||||
mIsMonthSelected = view == Constants.MONTHLY_VIEW
|
||||
mConfig.view = view
|
||||
mConfig.storedView = view
|
||||
updateViewPager()
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import android.os.Bundle
|
||||
import android.support.v4.app.TaskStackBuilder
|
||||
import android.view.View
|
||||
import android.widget.AdapterView
|
||||
import com.simplemobiletools.calendar.Constants
|
||||
import com.simplemobiletools.calendar.R
|
||||
import com.simplemobiletools.calendar.extensions.beVisibleIf
|
||||
import com.simplemobiletools.calendar.extensions.hideKeyboard
|
||||
@ -39,7 +40,7 @@ class SettingsActivity : SimpleActivity() {
|
||||
}
|
||||
|
||||
private fun setupWeekNumbers() {
|
||||
settings_week_numbers!!.isChecked = mConfig.displayWeekNumbers
|
||||
settings_week_numbers.isChecked = mConfig.displayWeekNumbers
|
||||
settings_week_numbers_holder.setOnClickListener {
|
||||
settings_week_numbers.toggle()
|
||||
mConfig.displayWeekNumbers = settings_week_numbers.isChecked
|
||||
@ -47,6 +48,16 @@ class SettingsActivity : SimpleActivity() {
|
||||
}
|
||||
|
||||
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 {
|
||||
override fun onNothingSelected(p0: AdapterView<*>?) {
|
||||
}
|
||||
@ -54,13 +65,35 @@ class SettingsActivity : SimpleActivity() {
|
||||
override fun onItemSelected(p0: AdapterView<*>?, p1: View?, itemIndex: Int, p3: Long) {
|
||||
settings_custom_reminder_holder.beVisibleIf(itemIndex == 2)
|
||||
if (itemIndex == 2)
|
||||
showKeyboard(settings_custom_reminder_other)
|
||||
showKeyboard(custom_reminder_value)
|
||||
else
|
||||
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() {
|
||||
TaskStackBuilder.create(applicationContext).addNextIntentWithParentStack(intent).startActivities()
|
||||
}
|
||||
|
@ -128,7 +128,7 @@
|
||||
android:padding="@dimen/activity_margin"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/event_reminder_other"
|
||||
android:id="@+id/custom_reminder_value"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/event_reminder"
|
||||
@ -140,24 +140,24 @@
|
||||
android:visibility="gone"/>
|
||||
|
||||
<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_height="wrap_content"
|
||||
android:layout_alignBottom="@+id/event_reminder_other"
|
||||
android:layout_alignTop="@+id/event_reminder_other"
|
||||
android:layout_toRightOf="@+id/event_reminder_other"
|
||||
android:layout_alignBottom="@+id/custom_reminder_value"
|
||||
android:layout_alignTop="@+id/custom_reminder_value"
|
||||
android:layout_toRightOf="@+id/custom_reminder_value"
|
||||
android:entries="@array/custom_reminders"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingLeft="@dimen/activity_margin"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/settings_custom_reminder_other_val"
|
||||
android:id="@+id/custom_reminder_other_val"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignBottom="@+id/event_reminder_other"
|
||||
android:layout_alignTop="@+id/event_reminder_other"
|
||||
android:layout_toRightOf="@+id/settings_custom_reminder_other_period"
|
||||
android:layout_alignBottom="@+id/custom_reminder_value"
|
||||
android:layout_alignTop="@+id/custom_reminder_value"
|
||||
android:layout_toRightOf="@+id/custom_reminder_other_period"
|
||||
android:gravity="center_vertical"
|
||||
android:text="@string/before"
|
||||
android:visibility="gone"/>
|
||||
@ -166,7 +166,7 @@
|
||||
android:id="@+id/event_repetition_label"
|
||||
android:layout_width="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:text="@string/repetition"
|
||||
android:textSize="@dimen/day_text_size"/>
|
||||
|
@ -118,43 +118,40 @@
|
||||
android:id="@+id/settings_custom_reminder_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/settings_padding"
|
||||
android:layout_marginTop="@dimen/settings_padding"
|
||||
android:paddingLeft="@dimen/activity_margin"
|
||||
android:visibility="gone">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/settings_custom_reminder_other"
|
||||
android:id="@+id/custom_reminder_value"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/activity_margin"
|
||||
android:digits="0123456789"
|
||||
android:inputType="number"
|
||||
android:minEms="5"
|
||||
android:textSize="@dimen/day_text_size"
|
||||
android:visibility="visible"/>
|
||||
android:textSize="@dimen/day_text_size"/>
|
||||
|
||||
<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_height="wrap_content"
|
||||
android:layout_alignBottom="@+id/settings_custom_reminder_other"
|
||||
android:layout_alignTop="@+id/settings_custom_reminder_other"
|
||||
android:layout_toRightOf="@+id/settings_custom_reminder_other"
|
||||
android:layout_alignBottom="@+id/custom_reminder_value"
|
||||
android:layout_alignTop="@+id/custom_reminder_value"
|
||||
android:layout_toRightOf="@+id/custom_reminder_value"
|
||||
android:entries="@array/custom_reminders"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingLeft="@dimen/activity_margin"
|
||||
android:visibility="visible"/>
|
||||
android:paddingLeft="@dimen/activity_margin"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/settings_custom_reminder_other_val"
|
||||
android:id="@+id/custom_reminder_other_val"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignBottom="@+id/settings_custom_reminder_other"
|
||||
android:layout_alignTop="@+id/settings_custom_reminder_other"
|
||||
android:layout_toRightOf="@+id/settings_custom_reminder_other_period"
|
||||
android:layout_alignBottom="@+id/custom_reminder_value"
|
||||
android:layout_alignTop="@+id/custom_reminder_value"
|
||||
android:layout_toRightOf="@+id/custom_reminder_other_period"
|
||||
android:gravity="center_vertical"
|
||||
android:text="@string/before"
|
||||
android:visibility="visible"/>
|
||||
android:text="@string/before"/>
|
||||
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
|
Loading…
x
Reference in New Issue
Block a user