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 { defaultConfig {
applicationId "com.simplemobiletools.clock" applicationId "com.simplemobiletools.clock"
minSdkVersion 29 minSdkVersion 23
targetSdkVersion 31 targetSdkVersion 31
versionCode 29 versionCode 29
versionName "5.8.1" versionName "5.8.1"
@ -64,7 +64,7 @@ android {
} }
dependencies { dependencies {
implementation 'com.github.SimpleMobileTools:Simple-Commons:638d77dd39' implementation 'com.github.SimpleMobileTools:Simple-Commons:dc5ab26794'
implementation 'com.facebook.stetho:stetho:1.5.1' implementation 'com.facebook.stetho:stetho:1.5.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.shawnlin:number-picker:2.4.6' 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.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() {
@ -132,7 +133,9 @@ 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()
@ -140,10 +143,12 @@ class ReminderActivity : SimpleActivity() {
snoozeAlarm() snoozeAlarm()
} }
if (isOreoPlus()) {
notificationManager.cancelAll() notificationManager.cancelAll()
} }
} }
} }
}
true true
} }
} }

View File

@ -290,6 +290,7 @@ 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) {
@ -316,6 +317,7 @@ fun Context.getTimerNotification(timer: Timer, pendingIntent: PendingIntent, add
enableVibration(timer.vibrate) enableVibration(timer.vibrate)
notificationManager.createNotificationChannel(this) notificationManager.createNotificationChannel(this)
} }
}
val title = if (timer.label.isEmpty()) { val title = if (timer.label.isEmpty()) {
getString(R.string.timer) getString(R.string.timer)
@ -386,6 +388,7 @@ fun Context.getAlarmNotification(pendingIntent: PendingIntent, alarm: Alarm): No
getString(R.string.alarm) 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)
@ -403,6 +406,7 @@ fun Context.getAlarmNotification(pendingIntent: PendingIntent, alarm: Alarm): No
setSound(Uri.parse(soundUri), audioAttributes) setSound(Uri.parse(soundUri), audioAttributes)
notificationManager.createNotificationChannel(this) notificationManager.createNotificationChannel(this)
} }
}
val dismissIntent = getHideAlarmPendingIntent(alarm) val dismissIntent = getHideAlarmPendingIntent(alarm)
val builder = NotificationCompat.Builder(this) val builder = NotificationCompat.Builder(this)

View File

@ -9,7 +9,6 @@ import android.content.Intent
import android.media.AudioAttributes import android.media.AudioAttributes
import android.net.Uri import android.net.Uri
import android.os.Handler import android.os.Handler
import android.os.PowerManager
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import com.simplemobiletools.clock.R import com.simplemobiletools.clock.R
import com.simplemobiletools.clock.activities.ReminderActivity 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_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,6 +30,7 @@ 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)
@ -44,12 +45,11 @@ class AlarmReceiver : BroadcastReceiver() {
} }
} }
val reminderActivityIntent = 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)
val pendingIntent = PendingIntent.getActivity(context, 0, reminderActivityIntent, 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))
@ -60,13 +60,16 @@ class AlarmReceiver : BroadcastReceiver() {
try { try {
notificationManager.notify(ALARM_NOTIF_ID, builder.build()) 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) { } 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

@ -6,9 +6,7 @@ import android.app.NotificationManager
import android.app.Service import android.app.Service
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Handler
import android.os.IBinder import android.os.IBinder
import android.os.Looper
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import com.simplemobiletools.clock.R 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.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
@ -52,10 +51,7 @@ class TimerService : Service() {
firstTimer.label.isNotEmpty() -> getString(R.string.timer_single_notification_label_msg, firstTimer.label) 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) 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 { } else {
stopService() stopService()
} }
@ -76,7 +72,11 @@ class TimerService : Service() {
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,11 +88,13 @@ 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)
.setContentTitle(title) .setContentTitle(title)
@ -114,9 +116,7 @@ class TimerService : Service() {
} }
fun startTimerService(context: Context) { 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 object TimerStopService

View File

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

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists 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