properly update the alarm in the database after changing

This commit is contained in:
tibbi 2018-03-05 22:43:55 +01:00
parent 2c0ad467a1
commit 0f8d61c0d0
4 changed files with 13 additions and 1 deletions

View file

@ -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()
}

View file

@ -57,7 +57,7 @@ class AlarmFragment : Fragment() {
private fun openEditAlarm(alarm: Alarm) {
EditAlarmDialog(activity as SimpleActivity, alarm) {
setupAlarms()
}
}
}

View file

@ -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)

View file

@ -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"/>