From f026c5230becc3caf06f344f21c753d1f93b7d6d Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 1 Nov 2016 23:49:14 +0100 Subject: [PATCH] add a Save button and save the custom reminder value --- .../calendar/activities/EventActivity.kt | 3 --- .../calendar/activities/SettingsActivity.kt | 25 ++++++++++++++----- .../calendar/extensions/Context.kt | 5 ++++ app/src/main/res/layout/activity_settings.xml | 16 ++++++++++-- app/src/main/res/values-de/strings.xml | 1 + app/src/main/res/values-it/strings.xml | 1 + app/src/main/res/values-ja/strings.xml | 1 + app/src/main/res/values-pt-rPT/strings.xml | 1 + app/src/main/res/values-sv/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 10 files changed, 44 insertions(+), 11 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt index cbdb39c6a..3ae4ee7a8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt @@ -240,9 +240,6 @@ class EventActivity : SimpleActivity(), DBHelper.EventsListener { 1 -> 0 else -> { val value = custom_reminder_value.value - if (value.isEmpty()) - 0 - val multiplier = when (custom_reminder_other_period.selectedItemPosition) { 1 -> Constants.HOUR_MINS 2 -> Constants.DAY_MINS diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt index 60fc7faf2..9ac17a06f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt @@ -6,9 +6,7 @@ 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 -import com.simplemobiletools.calendar.extensions.showKeyboard +import com.simplemobiletools.calendar.extensions.* import kotlinx.android.synthetic.main.activity_settings.* class SettingsActivity : SimpleActivity() { @@ -55,19 +53,23 @@ class SettingsActivity : SimpleActivity() { Constants.REMINDER_AT_START -> 1 else -> 2 }) + custom_reminder_save.setTextColor(custom_reminder_other_val.currentTextColor) setupReminderPeriod(reminderMinutes) settings_custom_reminder_holder.beVisibleIf(reminderType == 2) + custom_reminder_save.setOnClickListener { saveReminder() } settings_default_reminder.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { override fun onNothingSelected(p0: AdapterView<*>?) { } override fun onItemSelected(p0: AdapterView<*>?, p1: View?, itemIndex: Int, p3: Long) { - settings_custom_reminder_holder.beVisibleIf(itemIndex == 2) - if (itemIndex == 2) + if (itemIndex == 2) { + settings_custom_reminder_holder.visibility = View.VISIBLE showKeyboard(custom_reminder_value) - else + } else { hideKeyboard() + settings_custom_reminder_holder.visibility = View.GONE + } mConfig.defaultReminderType = when (itemIndex) { 0 -> Constants.REMINDER_OFF @@ -78,6 +80,17 @@ class SettingsActivity : SimpleActivity() { } } + private fun saveReminder() { + val value = custom_reminder_value.value + val multiplier = when (custom_reminder_other_period.selectedItemPosition) { + 1 -> Constants.HOUR_MINS + 2 -> Constants.DAY_MINS + else -> 1 + } + mConfig.defaultReminderMinutes = Integer.valueOf(value) * multiplier + toast(R.string.reminder_saved) + } + private fun setupReminderPeriod(mins: Int) { var value = mins if (mins == 0) { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt index 665790f81..2f3236a98 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt @@ -4,6 +4,7 @@ import android.appwidget.AppWidgetManager import android.content.ComponentName import android.content.Context import android.content.Intent +import android.widget.Toast import com.simplemobiletools.calendar.MyWidgetProvider import com.simplemobiletools.calendar.R @@ -18,3 +19,7 @@ fun Context.updateWidget() { intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids) sendBroadcast(intent) } + +fun Context.toast(id: Int) = Toast.makeText(this, resources.getString(id), Toast.LENGTH_SHORT).show() + +fun Context.toast(message: String) = Toast.makeText(this, message, Toast.LENGTH_SHORT).show() diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 089ef7a4f..a90df1123 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -119,6 +119,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="@dimen/settings_padding" + android:layout_marginRight="@dimen/activity_margin" android:layout_marginTop="@dimen/settings_padding" android:visibility="gone"> @@ -129,7 +130,7 @@ android:layout_marginLeft="@dimen/activity_margin" android:digits="0123456789" android:inputType="number" - android:minEms="5" + android:minEms="3" android:textSize="@dimen/day_text_size"/> + android:paddingLeft="@dimen/settings_padding"/> +