show the repeatability related things only if an event is repeatable

This commit is contained in:
tibbi 2017-03-05 17:23:37 +01:00
parent f8dedf89a6
commit c91390f3a1
2 changed files with 17 additions and 2 deletions

View File

@ -4,13 +4,22 @@ 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 com.simplemobiletools.calendar.R import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.helpers.DBHelper
import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.extensions.setupDialogStuff
import kotlinx.android.synthetic.main.dialog_delete_event.view.*
class DeleteEventDialog(val activity: Activity, val eventIds: List<Int>, val callback: (allOccurrences: Boolean) -> Unit) : AlertDialog.Builder(activity) { class DeleteEventDialog(val activity: Activity, eventIds: List<Int>, val callback: (allOccurrences: Boolean) -> Unit) : AlertDialog.Builder(activity) {
val dialog: AlertDialog? val dialog: AlertDialog?
init { init {
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_delete_event, null) val events = DBHelper.newInstance(activity).getEventsWithIds(eventIds)
val hasRepeatableEvent = events.any { it.repeatInterval > 0 }
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_delete_event, null).apply {
delete_event_repeat_description.beVisibleIf(hasRepeatableEvent)
delete_event_radio_view.beVisibleIf(hasRepeatableEvent)
}
dialog = AlertDialog.Builder(activity) dialog = AlertDialog.Builder(activity)
.setPositiveButton(R.string.yes, { dialog, which -> dialogConfirmed() }) .setPositiveButton(R.string.yes, { dialog, which -> dialogConfirmed() })

View File

@ -385,6 +385,12 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
return events return events
} }
fun getEventsWithIds(ids: List<Int>): List<Event> {
val args = TextUtils.join(", ", ids)
val selection = "$MAIN_TABLE_NAME.$COL_ID IN ($args)"
return getEvents(selection)
}
fun getEventsAtReboot(): List<Event> { fun getEventsAtReboot(): List<Event> {
val selection = "$COL_REMINDER_MINUTES != -1 AND ($COL_START_TS > ? OR $COL_REPEAT_INTERVAL != 0)" val selection = "$COL_REMINDER_MINUTES != -1 AND ($COL_START_TS > ? OR $COL_REPEAT_INTERVAL != 0)"
val selectionArgs = arrayOf(DateTime.now().seconds().toString()) val selectionArgs = arrayOf(DateTime.now().seconds().toString())