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 55c54df15..ded221a6d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt @@ -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() { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/RepeatRuleDailyDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/RepeatRuleDailyDialog.kt new file mode 100644 index 000000000..3983910c6 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/RepeatRuleDailyDialog.kt @@ -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(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 + } +} diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt index 2610130c7..0d3814104 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt @@ -472,7 +472,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont private val allColumns: Array 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 { val events = ArrayList() diff --git a/app/src/main/res/layout/dialog_vertical_linear_layout.xml b/app/src/main/res/layout/dialog_vertical_linear_layout.xml new file mode 100644 index 000000000..7fc649528 --- /dev/null +++ b/app/src/main/res/layout/dialog_vertical_linear_layout.xml @@ -0,0 +1,10 @@ + + diff --git a/app/src/main/res/layout/my_checkbox.xml b/app/src/main/res/layout/my_checkbox.xml new file mode 100644 index 000000000..365519af5 --- /dev/null +++ b/app/src/main/res/layout/my_checkbox.xml @@ -0,0 +1,9 @@ + +