From c91390f3a17ef21c3987be8c7579c2598428a599 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 5 Mar 2017 17:23:37 +0100 Subject: [PATCH] show the repeatability related things only if an event is repeatable --- .../calendar/dialogs/DeleteEventDialog.kt | 13 +++++++++++-- .../simplemobiletools/calendar/helpers/DBHelper.kt | 6 ++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/DeleteEventDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/DeleteEventDialog.kt index 9869d00a9..b0ba34bba 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/DeleteEventDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/DeleteEventDialog.kt @@ -4,13 +4,22 @@ import android.app.Activity import android.support.v7.app.AlertDialog import android.view.LayoutInflater import com.simplemobiletools.calendar.R +import com.simplemobiletools.calendar.helpers.DBHelper +import com.simplemobiletools.commons.extensions.beVisibleIf import com.simplemobiletools.commons.extensions.setupDialogStuff +import kotlinx.android.synthetic.main.dialog_delete_event.view.* -class DeleteEventDialog(val activity: Activity, val eventIds: List, val callback: (allOccurrences: Boolean) -> Unit) : AlertDialog.Builder(activity) { +class DeleteEventDialog(val activity: Activity, eventIds: List, val callback: (allOccurrences: Boolean) -> Unit) : AlertDialog.Builder(activity) { val dialog: AlertDialog? 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) .setPositiveButton(R.string.yes, { dialog, which -> dialogConfirmed() }) 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 a8c8a2779..cdd02bb02 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt @@ -385,6 +385,12 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont return events } + fun getEventsWithIds(ids: List): List { + val args = TextUtils.join(", ", ids) + val selection = "$MAIN_TABLE_NAME.$COL_ID IN ($args)" + return getEvents(selection) + } + fun getEventsAtReboot(): List { val selection = "$COL_REMINDER_MINUTES != -1 AND ($COL_START_TS > ? OR $COL_REPEAT_INTERVAL != 0)" val selectionArgs = arrayOf(DateTime.now().seconds().toString())