add the repeat rule picker for daily repetition
This commit is contained in:
parent
7a17bce90f
commit
0e8e89dbd4
|
@ -9,6 +9,7 @@ import android.view.MenuItem
|
|||
import android.view.WindowManager
|
||||
import com.simplemobiletools.calendar.R
|
||||
import com.simplemobiletools.calendar.dialogs.DeleteEventDialog
|
||||
import com.simplemobiletools.calendar.dialogs.RepeatRuleDailyDialog
|
||||
import com.simplemobiletools.calendar.dialogs.SelectEventTypeDialog
|
||||
import com.simplemobiletools.calendar.extensions.*
|
||||
import com.simplemobiletools.calendar.helpers.*
|
||||
|
@ -107,7 +108,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
|
|||
mRepeatLimit = mEvent.repeatLimit
|
||||
mRepeatRule = mEvent.repeatRule
|
||||
mEventTypeId = mEvent.eventType
|
||||
checkRepeatLimit(mRepeatInterval)
|
||||
checkRepeatTexts(mRepeatInterval)
|
||||
}
|
||||
|
||||
private fun setupNewEvent(dateTime: DateTime) {
|
||||
|
@ -144,11 +145,11 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
|
|||
showEventRepeatIntervalDialog(mRepeatInterval) {
|
||||
mRepeatInterval = it
|
||||
updateRepetitionText()
|
||||
checkRepeatLimit(it)
|
||||
checkRepeatTexts(it)
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkRepeatLimit(limit: Int) {
|
||||
private fun checkRepeatTexts(limit: Int) {
|
||||
event_repetition_limit_holder.beGoneIf(limit == 0)
|
||||
checkRepetitionLimitText()
|
||||
|
||||
|
@ -183,7 +184,11 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
|
|||
}
|
||||
|
||||
private fun showRepetitionRuleDialog() {
|
||||
|
||||
if (mRepeatInterval == DAY) {
|
||||
RepeatRuleDailyDialog(this, mRepeatRule) {
|
||||
mRepeatRule = it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkRepetitionRuleText() {
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
package com.simplemobiletools.calendar.dialogs
|
||||
|
||||
import android.app.Activity
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.view.View
|
||||
import com.simplemobiletools.calendar.R
|
||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
import com.simplemobiletools.commons.views.MyAppCompatCheckbox
|
||||
import kotlinx.android.synthetic.main.dialog_vertical_linear_layout.view.*
|
||||
|
||||
class RepeatRuleDailyDialog(val activity: Activity, val curRepeatRule: Int, val callback: (repeatRule: Int) -> Unit) :
|
||||
AlertDialog.Builder(activity) {
|
||||
val dialog: AlertDialog
|
||||
val view: View = activity.layoutInflater.inflate(R.layout.dialog_vertical_linear_layout, null)
|
||||
|
||||
init {
|
||||
val days = arrayOf(R.string.monday, R.string.tuesday, R.string.wednesday, R.string.thursday, R.string.friday, R.string.saturday, R.string.sunday)
|
||||
val res = activity.resources
|
||||
val checkboxes = ArrayList<MyAppCompatCheckbox>(7)
|
||||
for (i in 0..6) {
|
||||
val pow = Math.pow(2.0, i.toDouble()).toInt()
|
||||
(activity.layoutInflater.inflate(R.layout.my_checkbox, null) as MyAppCompatCheckbox).apply {
|
||||
isChecked = curRepeatRule and pow != 0
|
||||
text = res.getString(days[i])
|
||||
id = pow
|
||||
checkboxes.add(this)
|
||||
}
|
||||
}
|
||||
|
||||
checkboxes.forEach {
|
||||
view.dialog_vertical_linear_layout.addView(it)
|
||||
}
|
||||
|
||||
dialog = AlertDialog.Builder(activity)
|
||||
.setPositiveButton(R.string.ok, { dialog, which -> callback(getRepeatRuleSum()) })
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.create().apply {
|
||||
activity.setupDialogStuff(view, this)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getRepeatRuleSum(): Int {
|
||||
var sum = 0
|
||||
val cnt = view.dialog_vertical_linear_layout.childCount
|
||||
for (i in 0..cnt - 1) {
|
||||
val child = view.dialog_vertical_linear_layout.getChildAt(i)
|
||||
if (child is MyAppCompatCheckbox) {
|
||||
if (child.isChecked)
|
||||
sum += child.id
|
||||
}
|
||||
}
|
||||
return sum
|
||||
}
|
||||
}
|
|
@ -472,7 +472,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
|
||||
private val allColumns: Array<String>
|
||||
get() = arrayOf("$MAIN_TABLE_NAME.$COL_ID", COL_START_TS, COL_END_TS, COL_TITLE, COL_DESCRIPTION, COL_REMINDER_MINUTES, COL_REMINDER_MINUTES_2,
|
||||
COL_REMINDER_MINUTES_3, COL_REPEAT_INTERVAL, COL_IMPORT_ID, COL_FLAGS, COL_REPEAT_LIMIT, COL_EVENT_TYPE)
|
||||
COL_REMINDER_MINUTES_3, COL_REPEAT_INTERVAL, COL_REPEAT_RULE, COL_IMPORT_ID, COL_FLAGS, COL_REPEAT_LIMIT, COL_EVENT_TYPE)
|
||||
|
||||
private fun fillEvents(cursor: Cursor?): List<Event> {
|
||||
val events = ArrayList<Event>()
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/dialog_vertical_linear_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="@dimen/activity_margin"
|
||||
android:paddingRight="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/activity_margin"/>
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/my_checkbox"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:paddingBottom="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/activity_margin"/>
|
Loading…
Reference in New Issue