lets set the minimal required OS version to Android 10

This commit is contained in:
tibbi 2022-04-20 20:15:22 +02:00
parent 6daddd310a
commit 77556c2481
7 changed files with 94 additions and 123 deletions

View File

@ -14,7 +14,7 @@ android {
defaultConfig { defaultConfig {
applicationId "com.simplemobiletools.clock" applicationId "com.simplemobiletools.clock"
minSdkVersion 21 minSdkVersion 29
targetSdkVersion 31 targetSdkVersion 31
versionCode 25 versionCode 25
versionName "5.6.1" versionName "5.6.1"

View File

@ -14,10 +14,7 @@ import com.simplemobiletools.clock.extensions.getNextAlarm
import com.simplemobiletools.clock.extensions.rescheduleEnabledAlarms import com.simplemobiletools.clock.extensions.rescheduleEnabledAlarms
import com.simplemobiletools.clock.helpers.* import com.simplemobiletools.clock.helpers.*
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.LICENSE_NUMBER_PICKER import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.helpers.LICENSE_RTL
import com.simplemobiletools.commons.helpers.LICENSE_STETHO
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.models.FAQItem import com.simplemobiletools.commons.models.FAQItem
import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.activity_main.*

View File

@ -18,7 +18,6 @@ import com.simplemobiletools.clock.models.Alarm
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.MINUTE_SECONDS import com.simplemobiletools.commons.helpers.MINUTE_SECONDS
import com.simplemobiletools.commons.helpers.SILENT import com.simplemobiletools.commons.helpers.SILENT
import com.simplemobiletools.commons.helpers.isOreoPlus
import kotlinx.android.synthetic.main.activity_reminder.* import kotlinx.android.synthetic.main.activity_reminder.*
class ReminderActivity : SimpleActivity() { class ReminderActivity : SimpleActivity() {
@ -127,9 +126,7 @@ class ReminderActivity : SimpleActivity() {
finishActivity() finishActivity()
} }
if (isOreoPlus()) { notificationManager.cancelAll()
notificationManager.cancelAll()
}
} else if (reminder_draggable.x <= minDragX + 50f) { } else if (reminder_draggable.x <= minDragX + 50f) {
if (!didVibrate) { if (!didVibrate) {
reminder_draggable.performHapticFeedback() reminder_draggable.performHapticFeedback()
@ -137,9 +134,7 @@ class ReminderActivity : SimpleActivity() {
snoozeAlarm() snoozeAlarm()
} }
if (isOreoPlus()) { notificationManager.cancelAll()
notificationManager.cancelAll()
}
} }
} }
} }

View File

@ -33,8 +33,6 @@ import com.simplemobiletools.clock.services.SnoozeService
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.DAY_MINUTES import com.simplemobiletools.commons.helpers.DAY_MINUTES
import com.simplemobiletools.commons.helpers.SILENT import com.simplemobiletools.commons.helpers.SILENT
import com.simplemobiletools.commons.helpers.isMarshmallowPlus
import com.simplemobiletools.commons.helpers.isOreoPlus
import java.util.* import java.util.*
import kotlin.math.pow import kotlin.math.pow
@ -85,7 +83,17 @@ fun Context.createNewAlarm(timeInMinutes: Int, weekDays: Int): Alarm {
} }
fun Context.createNewTimer(): Timer { 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) { fun Context.scheduleNextAlarm(alarm: Alarm, showToast: Boolean) {
@ -193,11 +201,7 @@ fun Context.scheduleNextWidgetUpdate() {
val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager
val triggerAtMillis = System.currentTimeMillis() + getMSTillNextMinute() val triggerAtMillis = System.currentTimeMillis() + getMSTillNextMinute()
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC, triggerAtMillis, pendingIntent)
when {
isMarshmallowPlus() -> alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC, triggerAtMillis, pendingIntent)
else -> alarmManager.setExact(AlarmManager.RTC, triggerAtMillis, pendingIntent) //MAYBE RTC_WAKEUP
}
} }
fun Context.getFormattedTime(passedSeconds: Int, showSeconds: Boolean, makeAmPmSmaller: Boolean): SpannableString { 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()}" val channelId = timer.channelId ?: "simple_timer_channel_${soundUri}_${System.currentTimeMillis()}"
timerHelper.insertOrUpdateTimer(timer.copy(channelId = channelId)) timerHelper.insertOrUpdateTimer(timer.copy(channelId = channelId))
if (isOreoPlus()) { try {
try { notificationManager.deleteNotificationChannel(channelId)
notificationManager.deleteNotificationChannel(channelId) } catch (e: Exception) {
} 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() enableVibration(true)
.setUsage(AudioAttributes.USAGE_ALARM) notificationManager.createNotificationChannel(this)
.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)
}
} }
val reminderActivityIntent = getReminderActivityIntent() val reminderActivityIntent = getReminderActivityIntent()
val builder = NotificationCompat.Builder(this) 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)) .setContentText(getString(R.string.time_expired))
.setSmallIcon(R.drawable.ic_hourglass_vector) .setSmallIcon(R.drawable.ic_hourglass_vector)
.setContentIntent(pendingIntent) .setContentIntent(pendingIntent)
@ -318,7 +320,11 @@ fun Context.getTimerNotification(timer: Timer, pendingIntent: PendingIntent, add
.setAutoCancel(true) .setAutoCancel(true)
.setSound(Uri.parse(soundUri), STREAM_ALARM) .setSound(Uri.parse(soundUri), STREAM_ALARM)
.setChannelId(channelId) .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) { if (addDeleteIntent) {
builder.setDeleteIntent(reminderActivityIntent) builder.setDeleteIntent(reminderActivityIntent)
@ -356,24 +362,22 @@ fun Context.getAlarmNotification(pendingIntent: PendingIntent, alarm: Alarm): No
val channelId = "simple_alarm_channel_$soundUri" val channelId = "simple_alarm_channel_$soundUri"
val label = if (alarm.label.isNotEmpty()) alarm.label else getString(R.string.alarm) val label = if (alarm.label.isNotEmpty()) alarm.label else getString(R.string.alarm)
if (isOreoPlus()) { val audioAttributes = AudioAttributes.Builder()
val audioAttributes = AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_ALARM)
.setUsage(AudioAttributes.USAGE_ALARM) .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) .setLegacyStreamType(STREAM_ALARM)
.setLegacyStreamType(STREAM_ALARM) .setFlags(AudioAttributes.FLAG_AUDIBILITY_ENFORCED)
.setFlags(AudioAttributes.FLAG_AUDIBILITY_ENFORCED) .build()
.build()
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val importance = NotificationManager.IMPORTANCE_HIGH val importance = NotificationManager.IMPORTANCE_HIGH
NotificationChannel(channelId, label, importance).apply { NotificationChannel(channelId, label, importance).apply {
setBypassDnd(true) setBypassDnd(true)
enableLights(true) enableLights(true)
lightColor = getProperPrimaryColor() lightColor = getProperPrimaryColor()
enableVibration(alarm.vibrate) enableVibration(alarm.vibrate)
setSound(Uri.parse(soundUri), audioAttributes) setSound(Uri.parse(soundUri), audioAttributes)
notificationManager.createNotificationChannel(this) notificationManager.createNotificationChannel(this)
}
} }
val dismissIntent = getHideAlarmPendingIntent(alarm) val dismissIntent = getHideAlarmPendingIntent(alarm)

View File

@ -13,7 +13,6 @@ import com.simplemobiletools.clock.R
import com.simplemobiletools.clock.activities.SplashActivity import com.simplemobiletools.clock.activities.SplashActivity
import com.simplemobiletools.clock.extensions.* import com.simplemobiletools.clock.extensions.*
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.isOreoPlus
import java.util.* import java.util.*
class MyWidgetDateTimeProvider : AppWidgetProvider() { class MyWidgetDateTimeProvider : AppWidgetProvider() {
@ -42,17 +41,9 @@ class MyWidgetDateTimeProvider : AppWidgetProvider() {
} }
private fun getProperLayout(context: Context) = if (context.config.useTextShadow) { private fun getProperLayout(context: Context) = if (context.config.useTextShadow) {
if (isOreoPlus()) { R.layout.widget_date_time_with_shadow
R.layout.widget_date_time_with_shadow
} else {
R.layout.widget_date_time_with_shadow_pre_oreo
}
} else { } else {
if (isOreoPlus()) { R.layout.widget_date_time
R.layout.widget_date_time
} else {
R.layout.widget_date_time_pre_oreo
}
} }
private fun updateTexts(context: Context, views: RemoteViews) { private fun updateTexts(context: Context, views: RemoteViews) {

View File

@ -16,7 +16,6 @@ import com.simplemobiletools.clock.extensions.*
import com.simplemobiletools.clock.helpers.ALARM_ID import com.simplemobiletools.clock.helpers.ALARM_ID
import com.simplemobiletools.clock.helpers.ALARM_NOTIF_ID import com.simplemobiletools.clock.helpers.ALARM_NOTIF_ID
import com.simplemobiletools.commons.extensions.showErrorToast import com.simplemobiletools.commons.extensions.showErrorToast
import com.simplemobiletools.commons.helpers.isOreoPlus
class AlarmReceiver : BroadcastReceiver() { class AlarmReceiver : BroadcastReceiver() {
@ -30,45 +29,37 @@ class AlarmReceiver : BroadcastReceiver() {
context.hideNotification(id) context.hideNotification(id)
}, context.config.alarmMaxReminderSecs * 1000L) }, context.config.alarmMaxReminderSecs * 1000L)
} else { } else {
if (isOreoPlus()) { val audioAttributes = AudioAttributes.Builder()
val audioAttributes = AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_ALARM)
.setUsage(AudioAttributes.USAGE_ALARM) .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) .build()
.build()
val notificationManager = context.getSystemService(NotificationManager::class.java) val notificationManager = context.getSystemService(NotificationManager::class.java)
if (notificationManager.getNotificationChannel("Alarm") == null) { if (notificationManager.getNotificationChannel("Alarm") == null) {
NotificationChannel("Alarm", "Alarm", NotificationManager.IMPORTANCE_HIGH).apply { NotificationChannel("Alarm", "Alarm", NotificationManager.IMPORTANCE_HIGH).apply {
setBypassDnd(true) setBypassDnd(true)
setSound(Uri.parse(alarm.soundUri), audioAttributes) setSound(Uri.parse(alarm.soundUri), audioAttributes)
notificationManager.createNotificationChannel(this) notificationManager.createNotificationChannel(this)
}
} }
}
val pendingIntent = PendingIntent.getActivity(context, 0, Intent(context, ReminderActivity::class.java).apply { val pendingIntent = PendingIntent.getActivity(context, 0, Intent(context, ReminderActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
putExtra(ALARM_ID, id) putExtra(ALARM_ID, id)
}, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) }, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
val builder = NotificationCompat.Builder(context, "Alarm") val builder = NotificationCompat.Builder(context, "Alarm")
.setSmallIcon(R.drawable.ic_alarm_vector) .setSmallIcon(R.drawable.ic_alarm_vector)
.setContentTitle(context.getString(R.string.alarm)) .setContentTitle(context.getString(R.string.alarm))
.setAutoCancel(true) .setAutoCancel(true)
.setPriority(NotificationCompat.PRIORITY_HIGH) .setPriority(NotificationCompat.PRIORITY_HIGH)
.setCategory(NotificationCompat.CATEGORY_ALARM) .setCategory(NotificationCompat.CATEGORY_ALARM)
.setFullScreenIntent(pendingIntent, true) .setFullScreenIntent(pendingIntent, true)
try { try {
notificationManager.notify(ALARM_NOTIF_ID, builder.build()) notificationManager.notify(ALARM_NOTIF_ID, builder.build())
} catch (e: Exception) { } catch (e: Exception) {
context.showErrorToast(e) context.showErrorToast(e)
}
} else {
Intent(context, ReminderActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
putExtra(ALARM_ID, id)
context.startActivity(this)
}
} }
} }
} }

View File

@ -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.helpers.TIMER_RUNNING_NOTIF_ID
import com.simplemobiletools.clock.models.TimerEvent import com.simplemobiletools.clock.models.TimerEvent
import com.simplemobiletools.clock.models.TimerState import com.simplemobiletools.clock.models.TimerState
import com.simplemobiletools.commons.helpers.isOreoPlus
import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode import org.greenrobot.eventbus.ThreadMode
@ -65,18 +64,14 @@ class TimerService : Service() {
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
fun onMessageEvent(event: TimerEvent.Refresh) { fun onMessageEvent(event: TimerEvent.Refresh) {
if(!isStopping){ if (!isStopping) {
updateNotification() updateNotification()
} }
} }
private fun stopService() { private fun stopService() {
isStopping = true isStopping = true
if (isOreoPlus()) { stopForeground(true)
stopForeground(true)
} else {
stopSelf()
}
} }
override fun onDestroy() { override fun onDestroy() {
@ -88,12 +83,10 @@ class TimerService : Service() {
val channelId = "simple_alarm_timer" val channelId = "simple_alarm_timer"
val label = getString(R.string.timer) val label = getString(R.string.timer)
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
if (isOreoPlus()) { val importance = NotificationManager.IMPORTANCE_DEFAULT
val importance = NotificationManager.IMPORTANCE_DEFAULT NotificationChannel(channelId, label, importance).apply {
NotificationChannel(channelId, label, importance).apply { setSound(null, null)
setSound(null, null) notificationManager.createNotificationChannel(this)
notificationManager.createNotificationChannel(this)
}
} }
val builder = NotificationCompat.Builder(this) val builder = NotificationCompat.Builder(this)