Merge pull request #780 from NWuensche/696-default-time

Add default start time and default duration for events in settings
This commit is contained in:
Tibor Kaputa 2019-02-13 13:37:37 +01:00 committed by GitHub
commit e7fe4e325c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 163 additions and 6 deletions

View file

@ -286,8 +286,12 @@ class EventActivity : SimpleActivity() {
val dateTime = Formatter.getDateTimeFromTS(startTS)
mEventStartDateTime = dateTime
val addHours = if (intent.getBooleanExtra(NEW_EVENT_SET_HOUR_DURATION, false)) 1 else 0
mEventEndDateTime = mEventStartDateTime.plusHours(addHours)
val addMinutes = if (intent.getBooleanExtra(NEW_EVENT_SET_HOUR_DURATION, false)) {
60
} else {
config.defaultDuration
}
mEventEndDateTime = mEventStartDateTime.plusMinutes(addMinutes)
}
}

View file

@ -71,6 +71,8 @@ class SettingsActivity : SimpleActivity() {
updateTextColors(settings_holder)
checkPrimaryColor()
setupSectionColors()
setupDefaultStartTime()
setupDefaultDuration()
}
override fun onPause() {
@ -101,7 +103,7 @@ class SettingsActivity : SimpleActivity() {
private fun setupSectionColors() {
val adjustedPrimaryColor = getAdjustedPrimaryColor()
arrayListOf(reminders_label, caldav_label, weekly_view_label, monthly_view_label, simple_event_list_label, widgets_label, events_label).forEach {
arrayListOf(reminders_label, caldav_label, weekly_view_label, monthly_view_label, simple_event_list_label, widgets_label, events_label, new_events_label).forEach {
it.setTextColor(adjustedPrimaryColor)
}
}
@ -298,6 +300,7 @@ class SettingsActivity : SimpleActivity() {
}
}
private fun setupWeekNumbers() {
settings_week_numbers.isChecked = config.showWeekNumbers
settings_week_numbers_holder.setOnClickListener {
@ -548,4 +551,49 @@ class SettingsActivity : SimpleActivity() {
updateReminderSound(newAlarmSound)
}
}
private fun setupDefaultStartTime() {
settings_set_default_start_time.text = getHoursString(config.defaultStartTime)
if (config.defaultStartTime == -1) {
settings_set_default_start_time.text = "/"
}
settings_set_default_start_time_holder.setOnClickListener {
val items = ArrayList<RadioItem>()
items.add(RadioItem(-1, "/"))
(0..24).mapTo(items) { RadioItem(it, getHoursString(it)) }
RadioGroupDialog(this@SettingsActivity, items, config.defaultStartTime) {
config.defaultStartTime = it as Int
settings_set_default_start_time.text = getHoursString(it)
if (it == -1) {
settings_set_default_start_time.text = "/"
}
}
}
}
private fun setupDefaultDuration() {
var defaultDuration = config.defaultDuration
updateDefaultDurationText(defaultDuration)
settings_set_default_duration_time_holder.setOnClickListener {
CustomIntervalPickerDialog(this, defaultDuration * 60) {
val result = it / 60
defaultDuration = result
config.defaultDuration = result
updateDefaultDurationText(result)
}
}
}
private fun updateDefaultDurationText(defaultDuration: Int) {
settings_set_default_duration_time.text = getDefaultDurationText(defaultDuration)
}
private fun getDefaultDurationText(defaultDuration: Int): String {
return if (defaultDuration == 0) {
"0 " + getString(R.string.minutes_raw)
} else {
getFormattedMinutes(defaultDuration, false)
}
}
}

View file

@ -313,9 +313,17 @@ fun Context.launchNewEventIntent(dayCode: String = Formatter.getTodayCode()) {
}
fun Context.getNewEventTimestampFromCode(dayCode: String): Long {
val currHour = DateTime(System.currentTimeMillis(), DateTimeZone.getDefault()).hourOfDay
val dateTime = Formatter.getLocalDateTimeFromCode(dayCode).withHourOfDay(currHour)
val newDateTime = dateTime.plusHours(1).withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0)
val defaultStartTime = config.defaultStartTime
var currHour = DateTime(System.currentTimeMillis(), DateTimeZone.getDefault()).hourOfDay
var dateTime = Formatter.getLocalDateTimeFromCode(dayCode).withHourOfDay(currHour)
var newDateTime = dateTime.plusHours(1).withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0)
if (defaultStartTime != -1) {
currHour = defaultStartTime
dateTime = Formatter.getLocalDateTimeFromCode(dayCode).withHourOfDay(currHour)
newDateTime = dateTime
}
// make sure the date doesn't change
return newDateTime.withDate(dateTime.year, dateTime.monthOfYear, dateTime.dayOfMonth).seconds()
}

View file

@ -173,4 +173,12 @@ class Config(context: Context) : BaseConfig(context) {
var lastVibrateOnReminder: Boolean
get() = prefs.getBoolean(LAST_VIBRATE_ON_REMINDER, context.config.vibrateOnReminder)
set(lastVibrateOnReminder) = prefs.edit().putBoolean(LAST_VIBRATE_ON_REMINDER, lastVibrateOnReminder).apply()
var defaultStartTime: Int
get() = prefs.getInt(DEFAULT_START_TIME, -1)
set(defaultStartTime) = prefs.edit().putInt(DEFAULT_START_TIME, defaultStartTime).apply()
var defaultDuration: Int
get() = prefs.getInt(DEFAULT_DURATION, 0)
set(defaultDuration) = prefs.edit().putInt(DEFAULT_DURATION, defaultDuration).apply()
}

View file

@ -68,6 +68,8 @@ const val DEFAULT_REMINDER_2 = "default_reminder_2"
const val DEFAULT_REMINDER_3 = "default_reminder_3"
const val PULL_TO_REFRESH = "pull_to_refresh"
const val LAST_VIBRATE_ON_REMINDER = "last_vibrate_on_reminder"
const val DEFAULT_START_TIME = "default_start_time"
const val DEFAULT_DURATION = "default_duration"
// repeat_rule for monthly and yearly repetition
const val REPEAT_SAME_DAY = 1 // i.e. 25th every month, or 3rd june (if yearly repetition)

View file

@ -922,5 +922,92 @@
android:text="@string/delete_all_events"/>
</RelativeLayout>
<View
android:id="@+id/new_events_divider"
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/divider_grey"
android:importantForAccessibility="no"/>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/new_events_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/bigger_margin"
android:layout_marginLeft="@dimen/bigger_margin"
android:layout_marginTop="@dimen/activity_margin"
android:text="@string/new_event"
android:textAllCaps="true"
android:textSize="@dimen/smaller_text_size"/>
<RelativeLayout
android:id="@+id/settings_set_default_start_time_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:paddingLeft="@dimen/normal_margin"
android:paddingTop="@dimen/bigger_margin"
android:paddingRight="@dimen/normal_margin"
android:paddingBottom="@dimen/bigger_margin">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_set_default_start_time_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toStartOf="@+id/settings_set_default_start_time"
android:layout_toLeftOf="@+id/settings_set_default_start_time"
android:paddingLeft="@dimen/medium_margin"
android:paddingRight="@dimen/medium_margin"
android:text="@string/new_event_default_start"/>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_set_default_start_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="@dimen/small_margin"
android:layout_marginRight="@dimen/small_margin"
android:background="@null"
android:clickable="false"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_set_default_duration_time_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:paddingLeft="@dimen/normal_margin"
android:paddingTop="@dimen/bigger_margin"
android:paddingRight="@dimen/normal_margin"
android:paddingBottom="@dimen/bigger_margin">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_set_default_duration_time_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toStartOf="@+id/settings_set_default_duration_time"
android:layout_toLeftOf="@+id/settings_set_default_duration_time"
android:paddingLeft="@dimen/medium_margin"
android:paddingRight="@dimen/medium_margin"
android:text="@string/new_event_default_duration"/>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_set_default_duration_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="@dimen/small_margin"
android:layout_marginRight="@dimen/small_margin"
android:background="@null"
android:clickable="false"/>
</RelativeLayout>
</LinearLayout>
</ScrollView>