add reminder calculation at importing events

This commit is contained in:
tibbi 2017-01-26 18:58:30 +01:00
parent a6c54e0b7a
commit 7e8bc89eeb
4 changed files with 31 additions and 11 deletions

View File

@ -162,13 +162,13 @@ class SettingsActivity : SimpleActivity() {
}
private fun saveReminder() {
val value = custom_reminder_value.value
val multiplier = when (custom_reminder_other_period.selectedItemPosition) {
1 -> HOUR_MINS
2 -> DAY_MINS
else -> 1
}
val value = custom_reminder_value.value
config.defaultReminderMinutes = Integer.valueOf(if (value.isEmpty()) "0" else value) * multiplier
config.defaultReminderType = REMINDER_CUSTOM
toast(R.string.reminder_saved)

View File

@ -8,10 +8,14 @@ import android.widget.AdapterView
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.extensions.getDefaultReminderTypeIndex
import com.simplemobiletools.calendar.extensions.setupReminderPeriod
import com.simplemobiletools.commons.extensions.hideKeyboard
import com.simplemobiletools.calendar.helpers.DAY_MINS
import com.simplemobiletools.calendar.helpers.HOUR_MINS
import com.simplemobiletools.calendar.helpers.REMINDER_AT_START
import com.simplemobiletools.calendar.helpers.REMINDER_OFF
import com.simplemobiletools.commons.extensions.humanizePath
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.extensions.showKeyboard
import com.simplemobiletools.commons.extensions.value
import kotlinx.android.synthetic.main.dialog_import_events.view.*
class ImportEventsDialog(val activity: Activity, val path: String, val callback: () -> Unit) : AlertDialog.Builder(activity) {
@ -27,12 +31,12 @@ class ImportEventsDialog(val activity: Activity, val path: String, val callback:
import_events_custom_reminder_holder.visibility = View.VISIBLE
activity.showKeyboard(import_events_custom_reminder_value)
} else {
activity.hideKeyboard()
import_events_custom_reminder_holder.visibility = View.GONE
}
}
override fun onNothingSelected(p0: AdapterView<*>?) {
}
}
}
@ -42,9 +46,24 @@ class ImportEventsDialog(val activity: Activity, val path: String, val callback:
.setNegativeButton(R.string.cancel, null)
.create().apply {
activity.setupDialogStuff(view, this, R.string.import_events)
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(View.OnClickListener {
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({
val minutes = when (view.import_events_reminder.selectedItemPosition) {
0 -> REMINDER_OFF
1 -> REMINDER_AT_START
else -> getReminderMinutes(view)
}
})
}
}
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

@ -230,11 +230,11 @@
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_margin"
android:layout_marginLeft="@dimen/activity_margin"
android:layout_marginStart="@dimen/activity_margin"
android:layout_marginRight="@dimen/activity_margin"
android:digits="0123456789"
android:ems="3"
android:inputType="number"
android:maxLength="10"
android:minEms="3"
android:maxLength="4"
android:textCursorDrawable="@null"
android:textSize="@dimen/day_text_size"/>

View File

@ -37,6 +37,7 @@
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"/>
@ -54,11 +55,11 @@
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_margin"
android:layout_marginLeft="@dimen/activity_margin"
android:layout_marginStart="@dimen/activity_margin"
android:layout_marginRight="@dimen/activity_margin"
android:digits="0123456789"
android:ems="3"
android:inputType="number"
android:maxLength="10"
android:minEms="3"
android:maxLength="4"
android:textCursorDrawable="@null"
android:textSize="@dimen/day_text_size"/>