add some views in Settings related to setting custom event reminder

This commit is contained in:
tibbi 2016-11-01 22:44:47 +01:00
parent d3afa4b343
commit 9a1d9d6b3b
11 changed files with 123 additions and 25 deletions

View File

@ -3,19 +3,14 @@ package com.simplemobiletools.calendar.activities
import android.app.Activity
import android.app.DatePickerDialog
import android.app.TimePickerDialog
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.inputmethod.InputMethodManager
import android.widget.AdapterView
import android.widget.EditText
import com.simplemobiletools.calendar.*
import com.simplemobiletools.calendar.extensions.beVisibleIf
import com.simplemobiletools.calendar.extensions.updateWidget
import com.simplemobiletools.calendar.extensions.value
import com.simplemobiletools.calendar.extensions.*
import com.simplemobiletools.calendar.fragments.DayFragment
import com.simplemobiletools.calendar.models.Event
import kotlinx.android.synthetic.main.activity_event.*
@ -101,16 +96,6 @@ class EventActivity : SimpleActivity(), DBHelper.EventsListener {
event_reminder_other.setText(mConfig.lastOtherReminderMins.toString())
}
private fun hideKeyboard() {
val inputMethodManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.hideSoftInputFromWindow((currentFocus ?: View(this)).windowToken, 0)
}
private fun showKeyboard(et: EditText) {
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.showSoftInput(et, InputMethodManager.SHOW_IMPLICIT)
}
private fun setupReminder() {
when (mEvent.reminderMinutes) {
-1 -> event_reminder.setSelection(0)
@ -164,19 +149,19 @@ class EventActivity : SimpleActivity(), DBHelper.EventsListener {
var value = mins
if (mins % DAY_MINS == 0) {
value = mins / DAY_MINS
event_reminder_other_period.setSelection(2)
settings_custom_reminder_other_period.setSelection(2)
} else if (mins % HOUR_MINS == 0) {
value = mins / HOUR_MINS
event_reminder_other_period.setSelection(1)
settings_custom_reminder_other_period.setSelection(1)
} else {
event_reminder_other_period.setSelection(0)
settings_custom_reminder_other_period.setSelection(0)
}
event_reminder_other.setText(value.toString())
}
fun toggleCustomReminderVisibility(show: Boolean) {
event_reminder_other_period.beVisibleIf(show)
event_reminder_other_val.beVisibleIf(show)
settings_custom_reminder_other_period.beVisibleIf(show)
settings_custom_reminder_other_val.beVisibleIf(show)
event_reminder_other.beVisibleIf(show)
}
@ -261,7 +246,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventsListener {
if (value.isEmpty())
0
val multiplier = when (event_reminder_other_period.selectedItemPosition) {
val multiplier = when (settings_custom_reminder_other_period.selectedItemPosition) {
1 -> HOUR_MINS
2 -> DAY_MINS
else -> 1

View File

@ -2,7 +2,12 @@ package com.simplemobiletools.calendar.activities
import android.os.Bundle
import android.support.v4.app.TaskStackBuilder
import android.view.View
import android.widget.AdapterView
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.extensions.beVisibleIf
import com.simplemobiletools.calendar.extensions.hideKeyboard
import com.simplemobiletools.calendar.extensions.showKeyboard
import kotlinx.android.synthetic.main.activity_settings.*
class SettingsActivity : SimpleActivity() {
@ -13,6 +18,7 @@ class SettingsActivity : SimpleActivity() {
setupDarkTheme()
setupSundayFirst()
setupWeekNumbers()
setupEventReminder()
}
private fun setupDarkTheme() {
@ -40,6 +46,21 @@ class SettingsActivity : SimpleActivity() {
}
}
private fun setupEventReminder() {
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)
showKeyboard(settings_custom_reminder_other)
else
hideKeyboard()
}
}
}
private fun restartActivity() {
TaskStackBuilder.create(applicationContext).addNextIntentWithParentStack(intent).startActivities()
}

View File

@ -0,0 +1,17 @@
package com.simplemobiletools.calendar.extensions
import android.app.Activity
import android.content.Context
import android.view.View
import android.view.inputmethod.InputMethodManager
import android.widget.EditText
fun Activity.hideKeyboard() {
val inputMethodManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.hideSoftInputFromWindow((currentFocus ?: View(this)).windowToken, 0)
}
fun Activity.showKeyboard(et: EditText) {
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.showSoftInput(et, InputMethodManager.SHOW_IMPLICIT)
}

View File

@ -140,7 +140,7 @@
android:visibility="gone"/>
<android.support.v7.widget.AppCompatSpinner
android:id="@+id/event_reminder_other_period"
android:id="@+id/settings_custom_reminder_other_period"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/event_reminder_other"
@ -152,12 +152,12 @@
android:visibility="gone"/>
<TextView
android:id="@+id/event_reminder_other_val"
android:id="@+id/settings_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/event_reminder_other_period"
android:layout_toRightOf="@+id/settings_custom_reminder_other_period"
android:gravity="center_vertical"
android:text="@string/before"
android:visibility="gone"/>

View File

@ -88,5 +88,74 @@
android:clickable="false"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_default_reminder_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/settings_padding"
android:background="?attr/selectableItemBackground"
android:padding="@dimen/activity_margin">
<TextView
android:id="@+id/settings_default_reminder_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:paddingLeft="@dimen/settings_padding"
android:text="@string/default_event_reminder"/>
<android.support.v7.widget.AppCompatSpinner
android:id="@+id/settings_default_reminder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:entries="@array/reminders"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_custom_reminder_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/settings_padding"
android:paddingLeft="@dimen/activity_margin"
android:visibility="gone">
<EditText
android:id="@+id/settings_custom_reminder_other"
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.support.v7.widget.AppCompatSpinner
android:id="@+id/settings_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:entries="@array/custom_reminders"
android:gravity="center_vertical"
android:paddingLeft="@dimen/activity_margin"
android:visibility="visible"/>
<TextView
android:id="@+id/settings_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:gravity="center_vertical"
android:text="@string/before"
android:visibility="visible"/>
</RelativeLayout>
</LinearLayout>
</ScrollView>

View File

@ -64,6 +64,7 @@
<string name="dark_theme">Dunkles Design</string>
<string name="sunday_first">Sonntag als erster Wochentag</string>
<string name="week_numbers">Zeige Kalenderwoche an</string>
<string name="default_event_reminder">Default event reminder</string>
<!-- License -->
<string name="notice">Diese App nutzt die folgenden Drittanbieterbibliotheken, die mein Leben einfacher machen. Danke.</string>

View File

@ -64,6 +64,7 @@
<string name="dark_theme">Tema scuro</string>
<string name="sunday_first">Sunday as first day</string>
<string name="week_numbers">Display week numbers</string>
<string name="default_event_reminder">Default event reminder</string>
<!-- License -->
<string name="notice">Questa app usa le seguenti librerie di terze parti per semplificarmi la vita. Grazie.</string>

View File

@ -64,6 +64,7 @@
<string name="dark_theme">ダークテーマ</string>
<string name="sunday_first">Sunday as first day</string>
<string name="week_numbers">Display week numbers</string>
<string name="default_event_reminder">Default event reminder</string>
<!-- License -->
<string name="notice">このアプリは、私の人生を容易にするために、次のサードパーティのライブラリーを使用しています。 ありがとうございます。</string>

View File

@ -64,6 +64,7 @@
<string name="dark_theme">Tema escuro</string>
<string name="sunday_first">Domingo como primeiro dia</string>
<string name="week_numbers">Display week numbers</string>
<string name="default_event_reminder">Default event reminder</string>
<!-- License -->
<string name="notice">Esta aplicação usa as seguintes bibliotecas de terceiros para facilitar a minha vida. Obrigado.</string>

View File

@ -64,6 +64,7 @@
<string name="dark_theme">Mörkt tema</string>
<string name="sunday_first">Sunday as first day</string>
<string name="week_numbers">Display week numbers</string>
<string name="default_event_reminder">Default event reminder</string>
<!-- License -->
<string name="notice">Denna app använder följande tredjepartsbibliotek för att göra mitt liv enklare. Tack.</string>

View File

@ -65,6 +65,7 @@
<string name="dark_theme">Dark theme</string>
<string name="sunday_first">Sunday as first day</string>
<string name="week_numbers">Display week numbers</string>
<string name="default_event_reminder">Default event reminder</string>
<!-- License -->
<string name="notice">This app uses the following third party libraries to make my life easier. Thank you.</string>