mirror of
				https://github.com/SimpleMobileTools/Simple-Clock.git
				synced 2025-06-05 22:19:17 +02:00 
			
		
		
		
	Add handling for fullScreenIntentPermission
This commit is contained in:
		@@ -10,12 +10,12 @@ if (keystorePropertiesFile.exists()) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
android {
 | 
			
		||||
    compileSdkVersion 33
 | 
			
		||||
    compileSdkVersion 34
 | 
			
		||||
 | 
			
		||||
    defaultConfig {
 | 
			
		||||
        applicationId "com.simplemobiletools.clock"
 | 
			
		||||
        minSdkVersion 23
 | 
			
		||||
        targetSdkVersion 33
 | 
			
		||||
        targetSdkVersion 34
 | 
			
		||||
        versionCode 39
 | 
			
		||||
        versionName "5.10.3"
 | 
			
		||||
        setProperty("archivesBaseName", "clock")
 | 
			
		||||
@@ -64,7 +64,7 @@ android {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
dependencies {
 | 
			
		||||
    implementation 'com.github.SimpleMobileTools:Simple-Commons:42733f39a4'
 | 
			
		||||
    implementation 'com.github.esensar:Simple-Commons:2d54383217'
 | 
			
		||||
    implementation 'com.facebook.stetho:stetho:1.5.1'
 | 
			
		||||
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
 | 
			
		||||
    implementation 'io.github.ShawnLin013:number-picker:2.4.13'
 | 
			
		||||
 
 | 
			
		||||
@@ -154,7 +154,7 @@ class EditAlarmDialog(val activity: SimpleActivity, val alarm: Alarm, val callba
 | 
			
		||||
                        alarm.isEnabled = true
 | 
			
		||||
 | 
			
		||||
                        var alarmId = alarm.id
 | 
			
		||||
                        activity.handleNotificationPermission { granted ->
 | 
			
		||||
                        activity.handleFullScreenNotificationsPermission { granted ->
 | 
			
		||||
                            if (granted) {
 | 
			
		||||
                                if (alarm.id == 0) {
 | 
			
		||||
                                    alarmId = activity.dbHelper.insertAlarm(alarm)
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,30 @@
 | 
			
		||||
package com.simplemobiletools.clock.extensions
 | 
			
		||||
 | 
			
		||||
import com.simplemobiletools.clock.R
 | 
			
		||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
 | 
			
		||||
import com.simplemobiletools.commons.dialogs.PermissionRequiredDialog
 | 
			
		||||
import com.simplemobiletools.commons.extensions.canUseFullScreenIntent
 | 
			
		||||
 | 
			
		||||
fun BaseSimpleActivity.handleFullScreenNotificationsPermission(callback: (granted: Boolean) -> Unit) {
 | 
			
		||||
    handleNotificationPermission { granted ->
 | 
			
		||||
        if (granted) {
 | 
			
		||||
            if (canUseFullScreenIntent()) {
 | 
			
		||||
                callback(true)
 | 
			
		||||
            } else {
 | 
			
		||||
                PermissionRequiredDialog(
 | 
			
		||||
                    activity = this,
 | 
			
		||||
                    textId = R.string.allow_full_screen_notifications_reminders,
 | 
			
		||||
                    positiveActionCallback = {
 | 
			
		||||
                        callback(true)
 | 
			
		||||
                    },
 | 
			
		||||
                    negativeActionCallback = {
 | 
			
		||||
                        // It is not critical to have full screen intents, so we should allow users to continue using the app
 | 
			
		||||
                        callback(true)
 | 
			
		||||
                    }
 | 
			
		||||
                )
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            callback(false)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -127,10 +127,10 @@ class AlarmFragment : Fragment(), ToggleAlarmInterface {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    override fun alarmToggled(id: Int, isEnabled: Boolean) {
 | 
			
		||||
        (activity as SimpleActivity).handleNotificationPermission { granted ->
 | 
			
		||||
        (activity as SimpleActivity).handleFullScreenNotificationsPermission { granted ->
 | 
			
		||||
            if (granted) {
 | 
			
		||||
                if (requireContext().dbHelper.updateAlarmEnabledState(id, isEnabled)) {
 | 
			
		||||
                    val alarm = alarms.firstOrNull { it.id == id } ?: return@handleNotificationPermission
 | 
			
		||||
                    val alarm = alarms.firstOrNull { it.id == id } ?: return@handleFullScreenNotificationsPermission
 | 
			
		||||
                    alarm.isEnabled = isEnabled
 | 
			
		||||
                    checkAlarmState(alarm)
 | 
			
		||||
                } else {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user