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 {
applicationId "com.simplemobiletools.clock"
minSdkVersion 21
minSdkVersion 29
targetSdkVersion 31
versionCode 25
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.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.*

View File

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

View File

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

View File

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

View File

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

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