From 0f8d61c0d0835bca85c0654030e50f8ffb60cb23 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 5 Mar 2018 22:43:55 +0100 Subject: [PATCH] properly update the alarm in the database after changing --- .../com/simplemobiletools/clock/dialogs/EditAlarmDialog.kt | 4 ++++ .../com/simplemobiletools/clock/fragments/AlarmFragment.kt | 2 +- .../kotlin/com/simplemobiletools/clock/helpers/DBHelper.kt | 7 +++++++ app/src/main/res/layout/item_alarm.xml | 1 + 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/dialogs/EditAlarmDialog.kt b/app/src/main/kotlin/com/simplemobiletools/clock/dialogs/EditAlarmDialog.kt index 405519d..79ccff9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/dialogs/EditAlarmDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/dialogs/EditAlarmDialog.kt @@ -7,6 +7,7 @@ import android.widget.TextView import com.simplemobiletools.clock.R import com.simplemobiletools.clock.activities.SimpleActivity import com.simplemobiletools.clock.extensions.config +import com.simplemobiletools.clock.extensions.dbHelper import com.simplemobiletools.clock.extensions.formatAlarmTime import com.simplemobiletools.clock.models.Alarm import com.simplemobiletools.commons.extensions.* @@ -91,6 +92,9 @@ class EditAlarmDialog(val activity: SimpleActivity, val alarm: Alarm, val callba private fun dialogConfirmed() { alarm.label = view.edit_alarm_label.value + if (!activity.dbHelper.updateAlarm(alarm)) { + activity.toast(R.string.unknown_error_occurred) + } callback() } diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/fragments/AlarmFragment.kt b/app/src/main/kotlin/com/simplemobiletools/clock/fragments/AlarmFragment.kt index 51e47a4..29555b5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/fragments/AlarmFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/fragments/AlarmFragment.kt @@ -57,7 +57,7 @@ class AlarmFragment : Fragment() { private fun openEditAlarm(alarm: Alarm) { EditAlarmDialog(activity as SimpleActivity, alarm) { - + setupAlarms() } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/clock/helpers/DBHelper.kt index 4c194fe..5fc37b1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/helpers/DBHelper.kt @@ -60,6 +60,13 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont db.insert(ALARMS_TABLE_NAME, null, values) } + fun updateAlarm(alarm: Alarm): Boolean { + val selectionArgs = arrayOf(alarm.id.toString()) + val values = fillAlarmContentValues(alarm) + val selection = "$COL_ID = ?" + return mDb.update(ALARMS_TABLE_NAME, values, selection, selectionArgs) == 1 + } + private fun fillAlarmContentValues(alarm: Alarm): ContentValues { return ContentValues().apply { put(COL_TIME_IN_MINUTES, alarm.timeInMinutes) diff --git a/app/src/main/res/layout/item_alarm.xml b/app/src/main/res/layout/item_alarm.xml index 0535440..8b27859 100644 --- a/app/src/main/res/layout/item_alarm.xml +++ b/app/src/main/res/layout/item_alarm.xml @@ -32,6 +32,7 @@ android:layout_height="wrap_content" android:layout_below="@+id/alarm_time" android:paddingBottom="@dimen/normal_margin" + android:paddingLeft="@dimen/tiny_margin" android:textSize="@dimen/big_text_size" tools:text="Mon, Tue, Wed, Thu, Fri"/>