diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/clock/extensions/Activity.kt index 5badadd..1300fbd 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/extensions/Activity.kt @@ -1,7 +1,11 @@ package com.simplemobiletools.clock.extensions import android.app.Activity +import android.media.RingtoneManager import android.view.WindowManager +import com.simplemobiletools.clock.models.AlarmSound +import com.simplemobiletools.commons.extensions.showErrorToast +import java.util.* fun Activity.showOverLockscreen() { window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON or @@ -9,3 +13,30 @@ fun Activity.showOverLockscreen() { WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) } + +fun Activity.getAlarms(): ArrayList { + val alarms = ArrayList() + val manager = RingtoneManager(this) + manager.setType(RingtoneManager.TYPE_ALARM) + + try { + val cursor = manager.cursor + val defaultAlarm = AlarmSound(getDefaultAlarmTitle(), getDefaultAlarmUri().toString()) + alarms.add(defaultAlarm) + + while (cursor.moveToNext()) { + val title = cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX) + var uri = cursor.getString(RingtoneManager.URI_COLUMN_INDEX) + val id = cursor.getString(RingtoneManager.ID_COLUMN_INDEX) + if (!uri.endsWith(id)) { + uri += "/$id" + } + val alarmSound = AlarmSound(title, uri) + alarms.add(alarmSound) + } + } catch (e: Exception) { + showErrorToast(e) + } + + return alarms +} diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/clock/extensions/Context.kt index 54b5b0a..550c7f8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/extensions/Context.kt @@ -22,7 +22,6 @@ import com.simplemobiletools.clock.activities.SnoozeReminderActivity import com.simplemobiletools.clock.activities.SplashActivity import com.simplemobiletools.clock.helpers.* import com.simplemobiletools.clock.models.Alarm -import com.simplemobiletools.clock.models.AlarmSound import com.simplemobiletools.clock.models.MyTimeZone import com.simplemobiletools.clock.receivers.AlarmReceiver import com.simplemobiletools.clock.receivers.DateTimeWidgetUpdateReceiver @@ -78,29 +77,6 @@ fun Context.getAllTimeZonesModified(): ArrayList { fun Context.getModifiedTimeZoneTitle(id: Int) = getAllTimeZonesModified().firstOrNull { it.id == id }?.title ?: getDefaultTimeZoneTitle(id) -fun Context.getAlarms(): ArrayList { - val manager = RingtoneManager(this) - manager.setType(RingtoneManager.TYPE_ALARM) - val cursor = manager.cursor - - val alarms = ArrayList() - val defaultAlarm = AlarmSound(getDefaultAlarmTitle(), getDefaultAlarmUri().toString()) - alarms.add(defaultAlarm) - - while (cursor.moveToNext()) { - val title = cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX) - var uri = cursor.getString(RingtoneManager.URI_COLUMN_INDEX) - val id = cursor.getString(RingtoneManager.ID_COLUMN_INDEX) - if (!uri.endsWith(id)) { - uri += "/$id" - } - val alarmSound = AlarmSound(title, uri) - alarms.add(alarmSound) - } - - return alarms -} - fun Context.getDefaultAlarmUri() = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM) fun Context.getDefaultAlarmTitle() = RingtoneManager.getRingtone(this, getDefaultAlarmUri()).getTitle(this)