android, desktop: withLongRunningApi when needed (#3710)

This commit is contained in:
Stanislav Dmitrenko
2024-01-19 17:01:33 +00:00
committed by GitHub
parent ab9a6dcab5
commit 5d8bb24d1c
21 changed files with 40 additions and 46 deletions
@@ -8,9 +8,7 @@ import androidx.core.content.ContextCompat
import chat.simplex.common.R
import chat.simplex.common.platform.SoundPlayerInterface
import chat.simplex.common.platform.androidAppContext
import chat.simplex.common.views.helpers.withScope
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.*
object SoundPlayer: SoundPlayerInterface {
private var player: MediaPlayer? = null
@@ -31,7 +29,7 @@ object SoundPlayer: SoundPlayerInterface {
val vibrator = ContextCompat.getSystemService(androidAppContext, Vibrator::class.java)
val effect = VibrationEffect.createOneShot(250, VibrationEffect.DEFAULT_AMPLITUDE)
playing = true
withScope(scope) {
scope.launch {
while (playing) {
if (sound) player?.start()
vibrator?.vibrate(effect)
@@ -383,7 +383,7 @@ private fun DisabledBackgroundCallsButton() {
Modifier
.padding(bottom = 24.dp)
.clickable {
withBGApi {
withLongRunningApi {
show = !platform.androidAskToAllowBackgroundCalls()
}
}
@@ -133,7 +133,7 @@ actual fun QRCodeScanner(
}
}
!cameraPermissionState.hasPermission -> {
Button({ withBGApi { cameraPermissionState.launchPermissionRequest() } }, modifier = modifier, colors = buttonColors) {
Button({ cameraPermissionState.launchPermissionRequest() }, modifier = modifier, colors = buttonColors) {
Icon(painterResource(MR.images.ic_camera_enhance), null)
Spacer(Modifier.width(DEFAULT_PADDING_HALF))
Text(stringResource(MR.strings.enable_camera_access))
@@ -102,7 +102,7 @@ fun AppearanceScope.AppearanceLayout(
val state = rememberSaveable { mutableStateOf(languagePref.get() ?: "system") }
LangSelector(state) {
state.value = it
withBGApi {
withApi {
delay(200)
val activity = context as? Activity
if (activity != null) {