update the event reminder picker at importing ICS files

This commit is contained in:
tibbi
2017-02-05 16:29:35 +01:00
parent 494bfec835
commit 8c8c886b91
6 changed files with 23 additions and 126 deletions

View File

@@ -3,33 +3,29 @@ package com.simplemobiletools.calendar.dialogs
import android.app.Activity import android.app.Activity
import android.support.v7.app.AlertDialog import android.support.v7.app.AlertDialog
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View
import android.widget.AdapterView
import com.simplemobiletools.calendar.R import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.extensions.getDefaultReminderTypeIndex import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.extensions.setupReminderPeriod import com.simplemobiletools.calendar.extensions.getReminderText
import com.simplemobiletools.calendar.helpers.* import com.simplemobiletools.calendar.helpers.IcsParser
import com.simplemobiletools.calendar.helpers.IcsParser.ImportResult.* import com.simplemobiletools.calendar.helpers.IcsParser.ImportResult.*
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.humanizePath
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.extensions.toast
import kotlinx.android.synthetic.main.dialog_import_events.view.* import kotlinx.android.synthetic.main.dialog_import_events.view.*
class ImportEventsDialog(val activity: Activity, val path: String, val callback: (refreshView: Boolean) -> Unit) : AlertDialog.Builder(activity) { class ImportEventsDialog(val activity: Activity, val path: String, val callback: (refreshView: Boolean) -> Unit) : AlertDialog.Builder(activity) {
var reminderMinutes = 0
init { init {
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_import_events, null).apply { val view = LayoutInflater.from(activity).inflate(R.layout.dialog_import_events, null).apply {
reminderMinutes = activity.config.defaultReminderMinutes
import_events_filename.text = activity.humanizePath(path) import_events_filename.text = activity.humanizePath(path)
import_events_reminder.setSelection(context.getDefaultReminderTypeIndex()) import_events_reminder.text = activity.getReminderText(reminderMinutes)
context.setupReminderPeriod(import_events_custom_reminder_other_period, import_events_custom_reminder_value)
import_events_reminder.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(p0: AdapterView<*>?, p1: View?, itemIndex: Int, p3: Long) {
import_events_custom_reminder_holder.beVisibleIf(itemIndex == 2)
if (itemIndex == 2) {
activity.showKeyboard(import_events_custom_reminder_value)
}
}
override fun onNothingSelected(p0: AdapterView<*>?) {
import_events_reminder.setOnClickListener {
EventReminderDialog(activity, reminderMinutes) {
reminderMinutes = it
import_events_reminder.text = activity.getReminderText(it)
} }
} }
} }
@@ -40,14 +36,8 @@ class ImportEventsDialog(val activity: Activity, val path: String, val callback:
.create().apply { .create().apply {
activity.setupDialogStuff(view, this, R.string.import_events) activity.setupDialogStuff(view, this, R.string.import_events)
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({ getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({
val minutes = when (view.import_events_reminder.selectedItemPosition) {
0 -> REMINDER_OFF
1 -> REMINDER_AT_START
else -> getReminderMinutes(view)
}
Thread({ Thread({
val result = IcsParser().parseIcs(context, minutes, path) val result = IcsParser().parseIcs(context, reminderMinutes, path)
handleParseResult(result) handleParseResult(result)
dismiss() dismiss()
}).start() }).start()
@@ -65,15 +55,4 @@ class ImportEventsDialog(val activity: Activity, val path: String, val callback:
callback.invoke(result != IMPORT_FAIL) callback.invoke(result != IMPORT_FAIL)
} }
} }
private fun getReminderMinutes(view: View): Int {
val multiplier = when (view.import_events_custom_reminder_other_period.selectedItemPosition) {
1 -> HOUR_MINS
2 -> DAY_MINS
else -> 1
}
val value = view.import_events_custom_reminder_value.value
return Integer.valueOf(if (value.isEmpty()) "0" else value) * multiplier
}
} }

View File

@@ -9,8 +9,6 @@ import android.content.Intent
import android.graphics.Color import android.graphics.Color
import android.os.Build import android.os.Build
import android.os.SystemClock import android.os.SystemClock
import android.support.v7.widget.AppCompatSpinner
import android.widget.EditText
import com.simplemobiletools.calendar.R import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.helpers.* import com.simplemobiletools.calendar.helpers.*
import com.simplemobiletools.calendar.models.Event import com.simplemobiletools.calendar.models.Event
@@ -100,32 +98,6 @@ fun Context.getAppropriateTheme(): Int {
return if (config.backgroundColor.getContrastColor() == Color.WHITE) R.style.MyDialogTheme_Dark else R.style.MyDialogTheme return if (config.backgroundColor.getContrastColor() == Color.WHITE) R.style.MyDialogTheme_Dark else R.style.MyDialogTheme
} }
fun Context.getDefaultReminderTypeIndex(): Int {
val reminderType = config.defaultReminderType
return when (reminderType) {
REMINDER_OFF -> 0
REMINDER_AT_START -> 1
else -> 2
}
}
fun Context.setupReminderPeriod(otherPeriod: AppCompatSpinner, otherValue: EditText) {
val mins = config.defaultReminderMinutes
var value = mins
if (mins == 0) {
otherPeriod.setSelection(0)
} else if (mins % DAY_MINS == 0) {
value = mins / DAY_MINS
otherPeriod.setSelection(2)
} else if (mins % HOUR_MINS == 0) {
value = mins / HOUR_MINS
otherPeriod.setSelection(1)
} else {
otherPeriod.setSelection(0)
}
otherValue.setText(value.toString())
}
fun Context.getReminderText(minutes: Int) = when (minutes) { fun Context.getReminderText(minutes: Int) = when (minutes) {
-1 -> getString(R.string.no_reminder) -1 -> getString(R.string.no_reminder)
0 -> getString(R.string.at_start) 0 -> getString(R.string.at_start)

View File

@@ -291,6 +291,9 @@ class WeekFragment : Fragment(), WeeklyCalendar {
mView.week_top_holder.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener { mView.week_top_holder.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() { override fun onGlobalLayout() {
if (activity == null)
return
mView.week_top_holder.viewTreeObserver.removeOnGlobalLayoutListener(this) mView.week_top_holder.viewTreeObserver.removeOnGlobalLayoutListener(this)
if (isFragmentVisible) { if (isFragmentVisible) {
(activity as MainActivity).updateHoursTopMargin(mView.week_top_holder.height) (activity as MainActivity).updateHoursTopMargin(mView.week_top_holder.height)

View File

@@ -41,23 +41,9 @@ class Config(context: Context) : BaseConfig(context) {
get() = prefs.getInt(VIEW, MONTHLY_VIEW) get() = prefs.getInt(VIEW, MONTHLY_VIEW)
set(view) = prefs.edit().putInt(VIEW, view).apply() set(view) = prefs.edit().putInt(VIEW, view).apply()
var defaultReminderType: Int
get() = prefs.getInt(REMINDER_TYPE, REMINDER_AT_START)
set(type) {
var newType = type
if (newType == REMINDER_CUSTOM && defaultReminderMinutes == 0)
newType = REMINDER_AT_START
prefs.edit().putInt(REMINDER_TYPE, newType).apply()
}
var defaultReminderMinutes: Int var defaultReminderMinutes: Int
get() = prefs.getInt(REMINDER_MINUTES, 10) get() = prefs.getInt(REMINDER_MINUTES, 10)
set(mins) { set(mins) = prefs.edit().putInt(REMINDER_MINUTES, mins).apply()
if (mins == 0)
defaultReminderType = REMINDER_AT_START
prefs.edit().putInt(REMINDER_MINUTES, mins).apply()
}
var googleSync: Boolean var googleSync: Boolean
get() = prefs.getBoolean(GOOGLE_SYNC, false) get() = prefs.getBoolean(GOOGLE_SYNC, false)

View File

@@ -17,8 +17,6 @@ val EVENTS_LIST_VIEW = 3
val WEEKLY_VIEW = 4 val WEEKLY_VIEW = 4
val REMINDER_OFF = -1 val REMINDER_OFF = -1
val REMINDER_AT_START = 0
val REMINDER_CUSTOM = 1
val DAY = 86400 val DAY = 86400
val WEEK = 604800 val WEEK = 604800
@@ -26,9 +24,6 @@ val BIWEEK = 1209600
val MONTH = 2592000 // exact value not taken into account, Joda is used for adding months and years val MONTH = 2592000 // exact value not taken into account, Joda is used for adding months and years
val YEAR = 31536000 val YEAR = 31536000
val HOUR_MINS = 60
val DAY_MINS = 1440
// Shared Preferences // Shared Preferences
val SUNDAY_FIRST = "sunday_first" val SUNDAY_FIRST = "sunday_first"
val WEEK_NUMBERS = "week_numbers" val WEEK_NUMBERS = "week_numbers"
@@ -37,7 +32,6 @@ val END_WEEKLY_AT = "end_weekly_at"
val VIBRATE = "vibrate" val VIBRATE = "vibrate"
val REMINDER_SOUND = "reminder_sound" val REMINDER_SOUND = "reminder_sound"
val VIEW = "view" val VIEW = "view"
val REMINDER_TYPE = "reminder_type"
val REMINDER_MINUTES = "reminder_minutes" val REMINDER_MINUTES = "reminder_minutes"
val GOOGLE_SYNC = "google_sync" val GOOGLE_SYNC = "google_sync"
val SYNC_ACCOUNT_NAME = "sync_account_name" val SYNC_ACCOUNT_NAME = "sync_account_name"

View File

@@ -33,49 +33,12 @@
android:text="@string/event_reminder" android:text="@string/event_reminder"
android:textSize="@dimen/smaller_text_size"/> android:textSize="@dimen/smaller_text_size"/>
<com.simplemobiletools.commons.views.MyAppCompatSpinner <com.simplemobiletools.commons.views.MyTextView
android:id="@+id/import_events_reminder" android:id="@+id/import_events_reminder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_margin"
android:layout_marginTop="@dimen/medium_margin"
android:entries="@array/reminders"/>
<LinearLayout
android:id="@+id/import_events_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_marginRight="@dimen/activity_margin" android:layout_marginEnd="@dimen/small_margin"
android:orientation="horizontal" android:layout_marginRight="@dimen/small_margin"
android:visibility="gone"> android:padding="@dimen/normal_margin"/>
<com.simplemobiletools.commons.views.MyEditText
android:id="@+id/import_events_custom_reminder_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_margin"
android:layout_marginLeft="@dimen/activity_margin"
android:layout_marginRight="@dimen/activity_margin"
android:digits="0123456789"
android:ems="3"
android:inputType="number"
android:maxLength="4"
android:textCursorDrawable="@null"
android:textSize="@dimen/day_text_size"/>
<com.simplemobiletools.commons.views.MyAppCompatSpinner
android:id="@+id/import_events_custom_reminder_other_period"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:entries="@array/custom_reminders"
android:gravity="center"/>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/import_events_custom_reminder_other_val"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/before"/>
</LinearLayout>
</LinearLayout> </LinearLayout>