Use compose `PermissionRequiredAlertDialog` for sleep timer permission
This commit is contained in:
parent
c37ced08a7
commit
eae63898e3
|
@ -20,6 +20,7 @@ import androidx.activity.result.contract.ActivityResultContracts
|
|||
import androidx.activity.viewModels
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.Lifecycle
|
||||
|
@ -31,7 +32,7 @@ import com.simplemobiletools.commons.compose.alert_dialog.rememberAlertDialogSta
|
|||
import com.simplemobiletools.commons.compose.extensions.onEventValue
|
||||
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
|
||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||
import com.simplemobiletools.commons.dialogs.PermissionRequiredDialog
|
||||
import com.simplemobiletools.commons.dialogs.PermissionRequiredAlertDialog
|
||||
import com.simplemobiletools.commons.dialogs.RadioGroupAlertDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.*
|
||||
|
@ -109,6 +110,21 @@ class MainActivity : ComponentActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
val sleepTimerPermissionDialogState = rememberAlertDialogState().apply {
|
||||
DialogMember {
|
||||
PermissionRequiredAlertDialog(
|
||||
alertDialogState = this,
|
||||
text = stringResource(id = R.string.allow_alarm_sleep_timer),
|
||||
positiveActionCallback = {
|
||||
openRequestExactAlarmSettings(baseConfig.appId)
|
||||
},
|
||||
negativeActionCallback = {
|
||||
sleepTimerDialogState.show()
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
MainScreen(
|
||||
flashlightButton = {
|
||||
val flashlightActive by viewModel.flashlightOn.collectAsStateWithLifecycle()
|
||||
|
@ -193,7 +209,7 @@ class MainActivity : ComponentActivity() {
|
|||
openSettings = ::launchSettings,
|
||||
openAbout = ::launchAbout,
|
||||
openSleepTimer = {
|
||||
showSleepTimerPermission {
|
||||
showSleepTimerPermission(sleepTimerPermissionDialogState) {
|
||||
sleepTimerDialogState.show()
|
||||
}
|
||||
},
|
||||
|
@ -302,15 +318,13 @@ class MainActivity : ComponentActivity() {
|
|||
)
|
||||
}
|
||||
|
||||
private fun showSleepTimerPermission(callback: () -> Unit) {
|
||||
private fun showSleepTimerPermission(
|
||||
showSleepTimerDialogState: AlertDialogState,
|
||||
callback: () -> Unit
|
||||
) {
|
||||
val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||
if (isSPlus() && !alarmManager.canScheduleExactAlarms()) {
|
||||
PermissionRequiredDialog(
|
||||
this,
|
||||
com.simplemobiletools.commons.R.string.allow_alarm_sleep_timer,
|
||||
positiveActionCallback = { openRequestExactAlarmSettings(baseConfig.appId) },
|
||||
negativeActionCallback = { callback() }
|
||||
)
|
||||
showSleepTimerDialogState.show()
|
||||
return
|
||||
}
|
||||
callback()
|
||||
|
|
|
@ -6,7 +6,7 @@ androidx-customView = "1.2.0-alpha02"
|
|||
androidx-customViewPooling = "1.0.0"
|
||||
androidx-lifecycle = "2.7.0-alpha02"
|
||||
#Simple tools
|
||||
simple-commons = "dfe8acfbf9"
|
||||
simple-commons = "ffe7d33846"
|
||||
#Compose
|
||||
composeActivity = "1.8.0-rc01"
|
||||
compose = "1.6.0-alpha06"
|
||||
|
|
Loading…
Reference in New Issue