Disabled "Check for updates" by default + Confirmation dialog to enable "Check for updates".
This commit is contained in:
parent
5b8ddb4dfb
commit
96d0d1e3f6
8 changed files with 55 additions and 37 deletions
|
|
@ -4,14 +4,19 @@ import android.Manifest
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
import androidx.compose.foundation.lazy.LazyItemScope
|
import androidx.compose.foundation.lazy.LazyItemScope
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.filled.Security
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.State
|
import androidx.compose.runtime.State
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import com.google.accompanist.permissions.ExperimentalPermissionsApi
|
import com.google.accompanist.permissions.ExperimentalPermissionsApi
|
||||||
import com.google.accompanist.permissions.rememberPermissionState
|
import com.google.accompanist.permissions.rememberPermissionState
|
||||||
import ua.acclorite.book_story.R
|
import ua.acclorite.book_story.R
|
||||||
|
import ua.acclorite.book_story.presentation.components.custom_dialog.CustomDialogWithContent
|
||||||
import ua.acclorite.book_story.presentation.data.MainEvent
|
import ua.acclorite.book_story.presentation.data.MainEvent
|
||||||
import ua.acclorite.book_story.presentation.data.MainState
|
import ua.acclorite.book_story.presentation.data.MainState
|
||||||
import ua.acclorite.book_story.presentation.screens.settings.components.SwitchWithTitle
|
import ua.acclorite.book_story.presentation.screens.settings.components.SwitchWithTitle
|
||||||
|
|
@ -33,6 +38,28 @@ fun LazyItemScope.CheckForUpdatesSetting(
|
||||||
val notificationsPermissionState = rememberPermissionState(
|
val notificationsPermissionState = rememberPermissionState(
|
||||||
permission = Manifest.permission.POST_NOTIFICATIONS
|
permission = Manifest.permission.POST_NOTIFICATIONS
|
||||||
)
|
)
|
||||||
|
val showConfirmation = remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
if (showConfirmation.value) {
|
||||||
|
println(showConfirmation.value)
|
||||||
|
CustomDialogWithContent(
|
||||||
|
title = stringResource(id = R.string.enable_check_for_updates),
|
||||||
|
description = stringResource(id = R.string.enable_check_for_updates_description),
|
||||||
|
actionText = stringResource(id = R.string.enable),
|
||||||
|
imageVectorIcon = Icons.Default.Security,
|
||||||
|
isActionEnabled = true,
|
||||||
|
onDismiss = { showConfirmation.value = false },
|
||||||
|
onAction = {
|
||||||
|
onMainEvent(
|
||||||
|
MainEvent.OnChangeCheckForUpdates(
|
||||||
|
true
|
||||||
|
)
|
||||||
|
)
|
||||||
|
showConfirmation.value = false
|
||||||
|
},
|
||||||
|
withDivider = false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
SwitchWithTitle(
|
SwitchWithTitle(
|
||||||
selected = state.value.checkForUpdates!!,
|
selected = state.value.checkForUpdates!!,
|
||||||
|
|
@ -46,11 +73,10 @@ fun LazyItemScope.CheckForUpdatesSetting(
|
||||||
activity = activity,
|
activity = activity,
|
||||||
notificationsPermissionState = notificationsPermissionState,
|
notificationsPermissionState = notificationsPermissionState,
|
||||||
onChangeCheckForUpdates = {
|
onChangeCheckForUpdates = {
|
||||||
onMainEvent(
|
when (it) {
|
||||||
MainEvent.OnChangeCheckForUpdates(
|
true -> showConfirmation.value = true
|
||||||
it
|
false -> onMainEvent(MainEvent.OnChangeCheckForUpdates(false))
|
||||||
)
|
}
|
||||||
)
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -45,11 +45,7 @@ fun StartScreenRoot() {
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
startViewModel.checkPermissions(
|
startViewModel.checkPermissions(
|
||||||
storagePermissionState = storagePermissionState,
|
storagePermissionState = storagePermissionState,
|
||||||
notificationPermissionState = notificationsPermissionState,
|
notificationPermissionState = notificationsPermissionState
|
||||||
isCheckForUpdatesEnabled = mainState.value.checkForUpdates!!,
|
|
||||||
onEnableCheckForUpdates = {
|
|
||||||
mainViewModel.onEvent(MainEvent.OnChangeCheckForUpdates(true))
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -160,10 +160,7 @@ fun StartSettings(
|
||||||
onEvent(
|
onEvent(
|
||||||
StartEvent.OnNotificationsPermissionRequest(
|
StartEvent.OnNotificationsPermissionRequest(
|
||||||
activity,
|
activity,
|
||||||
notificationsPermissionState,
|
notificationsPermissionState
|
||||||
onEnableUpdates = {
|
|
||||||
onMainEvent(MainEvent.OnChangeCheckForUpdates(true))
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,10 @@ fun StartPermissionItem(
|
||||||
onClick = onGrantClick,
|
onClick = onGrantClick,
|
||||||
contentPadding = ButtonDefaults.TextButtonContentPadding
|
contentPadding = ButtonDefaults.TextButtonContentPadding
|
||||||
) {
|
) {
|
||||||
Text(text = stringResource(id = R.string.grant))
|
Text(
|
||||||
|
text = stringResource(id = R.string.grant),
|
||||||
|
style = MaterialTheme.typography.labelLarge
|
||||||
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
TextButton(onClick = onGrantClick) {
|
TextButton(onClick = onGrantClick) {
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,7 @@ sealed class StartEvent {
|
||||||
|
|
||||||
data class OnNotificationsPermissionRequest(
|
data class OnNotificationsPermissionRequest(
|
||||||
val activity: ComponentActivity,
|
val activity: ComponentActivity,
|
||||||
val notificationsPermissionState: PermissionState,
|
val notificationsPermissionState: PermissionState
|
||||||
val onEnableUpdates: () -> Unit
|
|
||||||
) : StartEvent()
|
) : StartEvent()
|
||||||
|
|
||||||
data class OnGoToBrowse(val onNavigate: OnNavigate, val onCompletedStartGuide: () -> Unit) :
|
data class OnGoToBrowse(val onNavigate: OnNavigate, val onCompletedStartGuide: () -> Unit) :
|
||||||
|
|
|
||||||
|
|
@ -20,16 +20,13 @@ import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.flow.update
|
import kotlinx.coroutines.flow.update
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.yield
|
import kotlinx.coroutines.yield
|
||||||
import ua.acclorite.book_story.domain.use_case.CheckForUpdates
|
|
||||||
import ua.acclorite.book_story.presentation.data.Screen
|
import ua.acclorite.book_story.presentation.data.Screen
|
||||||
import ua.acclorite.book_story.presentation.data.launchActivity
|
import ua.acclorite.book_story.presentation.data.launchActivity
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@OptIn(ExperimentalPermissionsApi::class)
|
@OptIn(ExperimentalPermissionsApi::class)
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class StartViewModel @Inject constructor(
|
class StartViewModel @Inject constructor() : ViewModel() {
|
||||||
private val checkForUpdates: CheckForUpdates,
|
|
||||||
) : ViewModel() {
|
|
||||||
|
|
||||||
private val _state = MutableStateFlow(StartState())
|
private val _state = MutableStateFlow(StartState())
|
||||||
val state = _state.asStateFlow()
|
val state = _state.asStateFlow()
|
||||||
|
|
@ -198,7 +195,6 @@ class StartViewModel @Inject constructor(
|
||||||
notificationsPermissionGranted = true
|
notificationsPermissionGranted = true
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
event.onEnableUpdates()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -234,11 +230,6 @@ class StartViewModel @Inject constructor(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
event.onEnableUpdates()
|
|
||||||
checkForUpdates.execute(
|
|
||||||
postNotification = true
|
|
||||||
)
|
|
||||||
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -267,9 +258,7 @@ class StartViewModel @Inject constructor(
|
||||||
|
|
||||||
fun checkPermissions(
|
fun checkPermissions(
|
||||||
storagePermissionState: PermissionState,
|
storagePermissionState: PermissionState,
|
||||||
notificationPermissionState: PermissionState,
|
notificationPermissionState: PermissionState
|
||||||
isCheckForUpdatesEnabled: Boolean,
|
|
||||||
onEnableCheckForUpdates: () -> Unit
|
|
||||||
) {
|
) {
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
val legacyStoragePermission = Build.VERSION.SDK_INT < Build.VERSION_CODES.R
|
val legacyStoragePermission = Build.VERSION.SDK_INT < Build.VERSION_CODES.R
|
||||||
|
|
@ -286,13 +275,6 @@ class StartViewModel @Inject constructor(
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notificationPermissionGranted && !isCheckForUpdatesEnabled) {
|
|
||||||
onEnableCheckForUpdates()
|
|
||||||
checkForUpdates.execute(
|
|
||||||
postNotification = true
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
_state.update {
|
_state.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
storagePermissionGranted = storagePermissionGranted,
|
storagePermissionGranted = storagePermissionGranted,
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@
|
||||||
<string name="move_book">Перемістити книгу?</string>
|
<string name="move_book">Перемістити книгу?</string>
|
||||||
<string name="delete_history">Видалити історію читання?</string>
|
<string name="delete_history">Видалити історію читання?</string>
|
||||||
<string name="confirm_update">Підтвердити оновлення?</string>
|
<string name="confirm_update">Підтвердити оновлення?</string>
|
||||||
|
<string name="enable_check_for_updates">Увімнкути перевірку на оновлення?</string>
|
||||||
|
|
||||||
<!-- Dialog Descriptions -->
|
<!-- Dialog Descriptions -->
|
||||||
<string name="storage_permission_description">
|
<string name="storage_permission_description">
|
||||||
|
|
@ -77,6 +78,11 @@
|
||||||
Натиснувши на кнопку «Завантажити», ви перейдете в ваш браузер
|
Натиснувши на кнопку «Завантажити», ви перейдете в ваш браузер
|
||||||
та завантажете останнє оновлення автоматично.
|
та завантажете останнє оновлення автоматично.
|
||||||
</string>
|
</string>
|
||||||
|
<string name="enable_check_for_updates_description">
|
||||||
|
Увімкнувши «Перевіряти на оновлення» застосунок буде отримувати інформацію про останній реліз
|
||||||
|
з «api.github.com» кожен раз, коли застосунок запускається.
|
||||||
|
Хочете продовжити та увімкнути «Перевіряти на оновлення»?
|
||||||
|
</string>
|
||||||
|
|
||||||
<!-- Errors -->
|
<!-- Errors -->
|
||||||
<string name="error_permission">
|
<string name="error_permission">
|
||||||
|
|
@ -153,6 +159,7 @@
|
||||||
<string name="no">Ні</string>
|
<string name="no">Ні</string>
|
||||||
<string name="download">Завантажити</string>
|
<string name="download">Завантажити</string>
|
||||||
<string name="done">Готово</string>
|
<string name="done">Готово</string>
|
||||||
|
<string name="enable">Увімкнути</string>
|
||||||
|
|
||||||
<!-- Items -->
|
<!-- Items -->
|
||||||
<string name="files">файли</string>
|
<string name="files">файли</string>
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@
|
||||||
<string name="move_book">Move book?</string>
|
<string name="move_book">Move book?</string>
|
||||||
<string name="delete_history">Delete reading history?</string>
|
<string name="delete_history">Delete reading history?</string>
|
||||||
<string name="confirm_update">Confirm update?</string>
|
<string name="confirm_update">Confirm update?</string>
|
||||||
|
<string name="enable_check_for_updates">Enable check for updates?</string>
|
||||||
|
|
||||||
<!-- Dialog Descriptions -->
|
<!-- Dialog Descriptions -->
|
||||||
<string name="storage_permission_description">
|
<string name="storage_permission_description">
|
||||||
|
|
@ -93,6 +94,12 @@
|
||||||
By clicking the «Download» button you will be transferred
|
By clicking the «Download» button you will be transferred
|
||||||
to your browser and download the latest update automatically.
|
to your browser and download the latest update automatically.
|
||||||
</string>
|
</string>
|
||||||
|
<string name="enable_check_for_updates_description">
|
||||||
|
By enabling «Check for updates»
|
||||||
|
the app will retrieve latest release information from «api.github.com» each time
|
||||||
|
when app starts.
|
||||||
|
Do you want to proceed and enable «Check for updates»?
|
||||||
|
</string>
|
||||||
|
|
||||||
<!-- Errors -->
|
<!-- Errors -->
|
||||||
<string name="error_permission">
|
<string name="error_permission">
|
||||||
|
|
@ -168,6 +175,7 @@
|
||||||
<string name="no">No</string>
|
<string name="no">No</string>
|
||||||
<string name="download">Download</string>
|
<string name="download">Download</string>
|
||||||
<string name="done">Done</string>
|
<string name="done">Done</string>
|
||||||
|
<string name="enable">Enable</string>
|
||||||
|
|
||||||
<!-- Items -->
|
<!-- Items -->
|
||||||
<string name="files">files</string>
|
<string name="files">files</string>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue