lowering the required OS version back to Android 6

This commit is contained in:
tibbi 2022-08-31 18:55:54 +02:00
parent a64086ab5a
commit e204ff15bc
7 changed files with 103 additions and 91 deletions

View File

@ -14,7 +14,7 @@ android {
defaultConfig {
applicationId "com.simplemobiletools.clock"
minSdkVersion 29
minSdkVersion 23
targetSdkVersion 31
versionCode 29
versionName "5.8.1"
@ -64,7 +64,7 @@ android {
}
dependencies {
implementation 'com.github.SimpleMobileTools:Simple-Commons:638d77dd39'
implementation 'com.github.SimpleMobileTools:Simple-Commons:dc5ab26794'
implementation 'com.facebook.stetho:stetho:1.5.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.shawnlin:number-picker:2.4.6'

View File

@ -23,6 +23,7 @@ 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() {
@ -132,7 +133,9 @@ class ReminderActivity : SimpleActivity() {
finishActivity()
}
notificationManager.cancelAll()
if (isOreoPlus()) {
notificationManager.cancelAll()
}
} else if (reminder_draggable.x <= minDragX + 50f) {
if (!didVibrate) {
reminder_draggable.performHapticFeedback()
@ -140,7 +143,9 @@ class ReminderActivity : SimpleActivity() {
snoozeAlarm()
}
notificationManager.cancelAll()
if (isOreoPlus()) {
notificationManager.cancelAll()
}
}
}
}

View File

@ -290,31 +290,33 @@ fun Context.getTimerNotification(timer: Timer, pendingIntent: PendingIntent, add
val channelId = timer.channelId ?: "simple_timer_channel_${soundUri}_${System.currentTimeMillis()}"
timerHelper.insertOrUpdateTimer(timer.copy(channelId = channelId))
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)
if (isOreoPlus()) {
try {
notificationManager.deleteNotificationChannel(channelId)
} catch (e: Exception) {
}
enableVibration(timer.vibrate)
notificationManager.createNotificationChannel(this)
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(timer.vibrate)
notificationManager.createNotificationChannel(this)
}
}
val title = if (timer.label.isEmpty()) {
@ -386,22 +388,24 @@ fun Context.getAlarmNotification(pendingIntent: PendingIntent, alarm: Alarm): No
getString(R.string.alarm)
}
val audioAttributes = AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_ALARM)
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setLegacyStreamType(STREAM_ALARM)
.setFlags(AudioAttributes.FLAG_AUDIBILITY_ENFORCED)
.build()
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 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

@ -9,7 +9,6 @@ import android.content.Intent
import android.media.AudioAttributes
import android.net.Uri
import android.os.Handler
import android.os.PowerManager
import androidx.core.app.NotificationCompat
import com.simplemobiletools.clock.R
import com.simplemobiletools.clock.activities.ReminderActivity
@ -17,6 +16,7 @@ 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,42 +30,45 @@ class AlarmReceiver : BroadcastReceiver() {
context.hideNotification(id)
}, context.config.alarmMaxReminderSecs * 1000L)
} else {
val audioAttributes = AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_ALARM)
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.build()
if (isOreoPlus()) {
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 reminderActivityIntent = Intent(context, ReminderActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
putExtra(ALARM_ID, id)
}
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, reminderActivityIntent, 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())
val powerManager = context.getSystemService(Context.POWER_SERVICE) as PowerManager
val wakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK or PowerManager.ACQUIRE_CAUSES_WAKEUP, "simpleClock:showAlarmLock")
wakeLock.acquire(10000)
} catch (e: Exception) {
context.showErrorToast(e)
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)
}
}
}
}

View File

@ -6,9 +6,7 @@ import android.app.NotificationManager
import android.app.Service
import android.content.Context
import android.content.Intent
import android.os.Handler
import android.os.IBinder
import android.os.Looper
import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat
import com.simplemobiletools.clock.R
@ -19,6 +17,7 @@ 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
@ -52,10 +51,7 @@ class TimerService : Service() {
firstTimer.label.isNotEmpty() -> getString(R.string.timer_single_notification_label_msg, firstTimer.label)
else -> resources.getQuantityString(R.plurals.timer_notification_msg, runningTimers.size, runningTimers.size)
}
Handler(Looper.getMainLooper()).post {
startForeground(TIMER_RUNNING_NOTIF_ID, notification(formattedDuration, contextText, firstTimer.id!!))
}
startForeground(TIMER_RUNNING_NOTIF_ID, notification(formattedDuration, contextText, firstTimer.id!!))
} else {
stopService()
}
@ -76,7 +72,11 @@ class TimerService : Service() {
private fun stopService() {
isStopping = true
stopForeground(true)
if (isOreoPlus()) {
stopForeground(true)
} else {
stopSelf()
}
}
override fun onDestroy() {
@ -88,10 +88,12 @@ class TimerService : Service() {
val channelId = "simple_alarm_timer"
val label = getString(R.string.timer)
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val importance = NotificationManager.IMPORTANCE_DEFAULT
NotificationChannel(channelId, label, importance).apply {
setSound(null, null)
notificationManager.createNotificationChannel(this)
if (isOreoPlus()) {
val importance = NotificationManager.IMPORTANCE_DEFAULT
NotificationChannel(channelId, label, importance).apply {
setSound(null, null)
notificationManager.createNotificationChannel(this)
}
}
val builder = NotificationCompat.Builder(this)
@ -114,9 +116,7 @@ class TimerService : Service() {
}
fun startTimerService(context: Context) {
Handler(Looper.getMainLooper()).post {
ContextCompat.startForegroundService(context, Intent(context, TimerService::class.java))
}
ContextCompat.startForegroundService(context, Intent(context, TimerService::class.java))
}
object TimerStopService

View File

@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.6.21'
ext.kotlin_version = '1.7.10'
repositories {
google()
@ -9,7 +9,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.3'
classpath 'com.android.tools.build:gradle:7.2.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip