diff --git a/app/build.gradle b/app/build.gradle index c525601..72601e7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -14,7 +14,7 @@ android { defaultConfig { applicationId "com.simplemobiletools.clock" - minSdkVersion 21 + minSdkVersion 29 targetSdkVersion 31 versionCode 25 versionName "5.6.1" diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/clock/activities/MainActivity.kt index 4962d07..286aad0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/activities/MainActivity.kt @@ -14,10 +14,7 @@ import com.simplemobiletools.clock.extensions.getNextAlarm import com.simplemobiletools.clock.extensions.rescheduleEnabledAlarms import com.simplemobiletools.clock.helpers.* import com.simplemobiletools.commons.extensions.* -import com.simplemobiletools.commons.helpers.LICENSE_NUMBER_PICKER -import com.simplemobiletools.commons.helpers.LICENSE_RTL -import com.simplemobiletools.commons.helpers.LICENSE_STETHO -import com.simplemobiletools.commons.helpers.ensureBackgroundThread +import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.models.FAQItem import kotlinx.android.synthetic.main.activity_main.* diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/activities/ReminderActivity.kt b/app/src/main/kotlin/com/simplemobiletools/clock/activities/ReminderActivity.kt index efd69c6..4aea843 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/activities/ReminderActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/activities/ReminderActivity.kt @@ -18,7 +18,6 @@ import com.simplemobiletools.clock.models.Alarm import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.MINUTE_SECONDS import com.simplemobiletools.commons.helpers.SILENT -import com.simplemobiletools.commons.helpers.isOreoPlus import kotlinx.android.synthetic.main.activity_reminder.* class ReminderActivity : SimpleActivity() { @@ -127,9 +126,7 @@ class ReminderActivity : SimpleActivity() { finishActivity() } - if (isOreoPlus()) { - notificationManager.cancelAll() - } + notificationManager.cancelAll() } else if (reminder_draggable.x <= minDragX + 50f) { if (!didVibrate) { reminder_draggable.performHapticFeedback() @@ -137,9 +134,7 @@ class ReminderActivity : SimpleActivity() { snoozeAlarm() } - if (isOreoPlus()) { - notificationManager.cancelAll() - } + notificationManager.cancelAll() } } } 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 ed7bcb0..d3ab177 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/extensions/Context.kt @@ -33,8 +33,6 @@ import com.simplemobiletools.clock.services.SnoozeService import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.DAY_MINUTES import com.simplemobiletools.commons.helpers.SILENT -import com.simplemobiletools.commons.helpers.isMarshmallowPlus -import com.simplemobiletools.commons.helpers.isOreoPlus import java.util.* import kotlin.math.pow @@ -85,7 +83,17 @@ fun Context.createNewAlarm(timeInMinutes: Int, weekDays: Int): Alarm { } fun Context.createNewTimer(): Timer { - return Timer(null, config.timerSeconds, config.timerState, config.timerVibrate, config.timerSoundUri, config.timerSoundTitle, config.timerLabel ?: "", System.currentTimeMillis(), config.timerChannelId, ) + return Timer( + null, + config.timerSeconds, + config.timerState, + config.timerVibrate, + config.timerSoundUri, + config.timerSoundTitle, + config.timerLabel ?: "", + System.currentTimeMillis(), + config.timerChannelId, + ) } fun Context.scheduleNextAlarm(alarm: Alarm, showToast: Boolean) { @@ -193,11 +201,7 @@ fun Context.scheduleNextWidgetUpdate() { val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager val triggerAtMillis = System.currentTimeMillis() + getMSTillNextMinute() - - when { - isMarshmallowPlus() -> alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC, triggerAtMillis, pendingIntent) - else -> alarmManager.setExact(AlarmManager.RTC, triggerAtMillis, pendingIntent) //MAYBE RTC_WAKEUP - } + alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC, triggerAtMillis, pendingIntent) } fun Context.getFormattedTime(passedSeconds: Int, showSeconds: Boolean, makeAmPmSmaller: Boolean): SpannableString { @@ -277,38 +281,36 @@ fun Context.getTimerNotification(timer: Timer, pendingIntent: PendingIntent, add val channelId = timer.channelId ?: "simple_timer_channel_${soundUri}_${System.currentTimeMillis()}" timerHelper.insertOrUpdateTimer(timer.copy(channelId = channelId)) - if (isOreoPlus()) { - try { - notificationManager.deleteNotificationChannel(channelId) - } catch (e: Exception) { + try { + notificationManager.deleteNotificationChannel(channelId) + } catch (e: Exception) { + } + + val audioAttributes = AudioAttributes.Builder() + .setUsage(AudioAttributes.USAGE_ALARM) + .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) + .setLegacyStreamType(STREAM_ALARM) + .build() + + val name = getString(R.string.timer) + val importance = NotificationManager.IMPORTANCE_HIGH + NotificationChannel(channelId, name, importance).apply { + setBypassDnd(true) + enableLights(true) + lightColor = getProperPrimaryColor() + setSound(Uri.parse(soundUri), audioAttributes) + + if (!timer.vibrate) { + vibrationPattern = longArrayOf(0L) } - val audioAttributes = AudioAttributes.Builder() - .setUsage(AudioAttributes.USAGE_ALARM) - .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) - .setLegacyStreamType(STREAM_ALARM) - .build() - - val name = getString(R.string.timer) - val importance = NotificationManager.IMPORTANCE_HIGH - NotificationChannel(channelId, name, importance).apply { - setBypassDnd(true) - enableLights(true) - lightColor = getProperPrimaryColor() - setSound(Uri.parse(soundUri), audioAttributes) - - if (!timer.vibrate) { - vibrationPattern = longArrayOf(0L) - } - - enableVibration(true) - notificationManager.createNotificationChannel(this) - } + enableVibration(true) + notificationManager.createNotificationChannel(this) } val reminderActivityIntent = getReminderActivityIntent() val builder = NotificationCompat.Builder(this) - .setContentTitle(if(timer.label.isEmpty()) getString(R.string.timer) else timer.label) + .setContentTitle(if (timer.label.isEmpty()) getString(R.string.timer) else timer.label) .setContentText(getString(R.string.time_expired)) .setSmallIcon(R.drawable.ic_hourglass_vector) .setContentIntent(pendingIntent) @@ -318,7 +320,11 @@ fun Context.getTimerNotification(timer: Timer, pendingIntent: PendingIntent, add .setAutoCancel(true) .setSound(Uri.parse(soundUri), STREAM_ALARM) .setChannelId(channelId) - .addAction(R.drawable.ic_cross_vector, getString(R.string.dismiss), if (addDeleteIntent) reminderActivityIntent else getHideTimerPendingIntent(timer.id!!)) + .addAction( + R.drawable.ic_cross_vector, + getString(R.string.dismiss), + if (addDeleteIntent) reminderActivityIntent else getHideTimerPendingIntent(timer.id!!) + ) if (addDeleteIntent) { builder.setDeleteIntent(reminderActivityIntent) @@ -356,24 +362,22 @@ fun Context.getAlarmNotification(pendingIntent: PendingIntent, alarm: Alarm): No val channelId = "simple_alarm_channel_$soundUri" val label = if (alarm.label.isNotEmpty()) alarm.label else getString(R.string.alarm) - if (isOreoPlus()) { - val audioAttributes = AudioAttributes.Builder() - .setUsage(AudioAttributes.USAGE_ALARM) - .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) - .setLegacyStreamType(STREAM_ALARM) - .setFlags(AudioAttributes.FLAG_AUDIBILITY_ENFORCED) - .build() + val audioAttributes = AudioAttributes.Builder() + .setUsage(AudioAttributes.USAGE_ALARM) + .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) + .setLegacyStreamType(STREAM_ALARM) + .setFlags(AudioAttributes.FLAG_AUDIBILITY_ENFORCED) + .build() - val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager - val importance = NotificationManager.IMPORTANCE_HIGH - NotificationChannel(channelId, label, importance).apply { - setBypassDnd(true) - enableLights(true) - lightColor = getProperPrimaryColor() - enableVibration(alarm.vibrate) - setSound(Uri.parse(soundUri), audioAttributes) - notificationManager.createNotificationChannel(this) - } + val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager + val importance = NotificationManager.IMPORTANCE_HIGH + NotificationChannel(channelId, label, importance).apply { + setBypassDnd(true) + enableLights(true) + lightColor = getProperPrimaryColor() + enableVibration(alarm.vibrate) + setSound(Uri.parse(soundUri), audioAttributes) + notificationManager.createNotificationChannel(this) } val dismissIntent = getHideAlarmPendingIntent(alarm) diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/helpers/MyWidgetDateTimeProvider.kt b/app/src/main/kotlin/com/simplemobiletools/clock/helpers/MyWidgetDateTimeProvider.kt index fa5fa20..36a321f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/helpers/MyWidgetDateTimeProvider.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/helpers/MyWidgetDateTimeProvider.kt @@ -13,7 +13,6 @@ import com.simplemobiletools.clock.R import com.simplemobiletools.clock.activities.SplashActivity import com.simplemobiletools.clock.extensions.* import com.simplemobiletools.commons.extensions.* -import com.simplemobiletools.commons.helpers.isOreoPlus import java.util.* class MyWidgetDateTimeProvider : AppWidgetProvider() { @@ -42,17 +41,9 @@ class MyWidgetDateTimeProvider : AppWidgetProvider() { } private fun getProperLayout(context: Context) = if (context.config.useTextShadow) { - if (isOreoPlus()) { - R.layout.widget_date_time_with_shadow - } else { - R.layout.widget_date_time_with_shadow_pre_oreo - } + R.layout.widget_date_time_with_shadow } else { - if (isOreoPlus()) { - R.layout.widget_date_time - } else { - R.layout.widget_date_time_pre_oreo - } + R.layout.widget_date_time } private fun updateTexts(context: Context, views: RemoteViews) { diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/receivers/AlarmReceiver.kt b/app/src/main/kotlin/com/simplemobiletools/clock/receivers/AlarmReceiver.kt index f757271..d74ea31 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/receivers/AlarmReceiver.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/receivers/AlarmReceiver.kt @@ -16,7 +16,6 @@ import com.simplemobiletools.clock.extensions.* import com.simplemobiletools.clock.helpers.ALARM_ID import com.simplemobiletools.clock.helpers.ALARM_NOTIF_ID import com.simplemobiletools.commons.extensions.showErrorToast -import com.simplemobiletools.commons.helpers.isOreoPlus class AlarmReceiver : BroadcastReceiver() { @@ -30,45 +29,37 @@ class AlarmReceiver : BroadcastReceiver() { context.hideNotification(id) }, context.config.alarmMaxReminderSecs * 1000L) } else { - if (isOreoPlus()) { - val audioAttributes = AudioAttributes.Builder() - .setUsage(AudioAttributes.USAGE_ALARM) - .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) - .build() + val audioAttributes = AudioAttributes.Builder() + .setUsage(AudioAttributes.USAGE_ALARM) + .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) + .build() - val notificationManager = context.getSystemService(NotificationManager::class.java) - if (notificationManager.getNotificationChannel("Alarm") == null) { - NotificationChannel("Alarm", "Alarm", NotificationManager.IMPORTANCE_HIGH).apply { - setBypassDnd(true) - setSound(Uri.parse(alarm.soundUri), audioAttributes) - notificationManager.createNotificationChannel(this) - } + val notificationManager = context.getSystemService(NotificationManager::class.java) + if (notificationManager.getNotificationChannel("Alarm") == null) { + NotificationChannel("Alarm", "Alarm", NotificationManager.IMPORTANCE_HIGH).apply { + setBypassDnd(true) + setSound(Uri.parse(alarm.soundUri), audioAttributes) + notificationManager.createNotificationChannel(this) } + } - val pendingIntent = PendingIntent.getActivity(context, 0, Intent(context, ReminderActivity::class.java).apply { - addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - putExtra(ALARM_ID, id) - }, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) + val pendingIntent = PendingIntent.getActivity(context, 0, Intent(context, ReminderActivity::class.java).apply { + addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + putExtra(ALARM_ID, id) + }, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) - val builder = NotificationCompat.Builder(context, "Alarm") - .setSmallIcon(R.drawable.ic_alarm_vector) - .setContentTitle(context.getString(R.string.alarm)) - .setAutoCancel(true) - .setPriority(NotificationCompat.PRIORITY_HIGH) - .setCategory(NotificationCompat.CATEGORY_ALARM) - .setFullScreenIntent(pendingIntent, true) + val builder = NotificationCompat.Builder(context, "Alarm") + .setSmallIcon(R.drawable.ic_alarm_vector) + .setContentTitle(context.getString(R.string.alarm)) + .setAutoCancel(true) + .setPriority(NotificationCompat.PRIORITY_HIGH) + .setCategory(NotificationCompat.CATEGORY_ALARM) + .setFullScreenIntent(pendingIntent, true) - try { - notificationManager.notify(ALARM_NOTIF_ID, builder.build()) - } catch (e: Exception) { - context.showErrorToast(e) - } - } else { - Intent(context, ReminderActivity::class.java).apply { - addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - putExtra(ALARM_ID, id) - context.startActivity(this) - } + try { + notificationManager.notify(ALARM_NOTIF_ID, builder.build()) + } catch (e: Exception) { + context.showErrorToast(e) } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/services/TimerService.kt b/app/src/main/kotlin/com/simplemobiletools/clock/services/TimerService.kt index c18db6c..83889d4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/services/TimerService.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/services/TimerService.kt @@ -17,7 +17,6 @@ import com.simplemobiletools.clock.helpers.INVALID_TIMER_ID import com.simplemobiletools.clock.helpers.TIMER_RUNNING_NOTIF_ID import com.simplemobiletools.clock.models.TimerEvent import com.simplemobiletools.clock.models.TimerState -import com.simplemobiletools.commons.helpers.isOreoPlus import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.ThreadMode @@ -65,18 +64,14 @@ class TimerService : Service() { @Subscribe(threadMode = ThreadMode.MAIN) fun onMessageEvent(event: TimerEvent.Refresh) { - if(!isStopping){ + if (!isStopping) { updateNotification() } } private fun stopService() { isStopping = true - if (isOreoPlus()) { - stopForeground(true) - } else { - stopSelf() - } + stopForeground(true) } override fun onDestroy() { @@ -88,12 +83,10 @@ class TimerService : Service() { val channelId = "simple_alarm_timer" val label = getString(R.string.timer) val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager - if (isOreoPlus()) { - val importance = NotificationManager.IMPORTANCE_DEFAULT - NotificationChannel(channelId, label, importance).apply { - setSound(null, null) - notificationManager.createNotificationChannel(this) - } + val importance = NotificationManager.IMPORTANCE_DEFAULT + NotificationChannel(channelId, label, importance).apply { + setSound(null, null) + notificationManager.createNotificationChannel(this) } val builder = NotificationCompat.Builder(this)