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 androidx.activity.ComponentActivity
|
||||
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.State
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import com.google.accompanist.permissions.ExperimentalPermissionsApi
|
||||
import com.google.accompanist.permissions.rememberPermissionState
|
||||
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.MainState
|
||||
import ua.acclorite.book_story.presentation.screens.settings.components.SwitchWithTitle
|
||||
|
|
@ -33,6 +38,28 @@ fun LazyItemScope.CheckForUpdatesSetting(
|
|||
val notificationsPermissionState = rememberPermissionState(
|
||||
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(
|
||||
selected = state.value.checkForUpdates!!,
|
||||
|
|
@ -46,11 +73,10 @@ fun LazyItemScope.CheckForUpdatesSetting(
|
|||
activity = activity,
|
||||
notificationsPermissionState = notificationsPermissionState,
|
||||
onChangeCheckForUpdates = {
|
||||
onMainEvent(
|
||||
MainEvent.OnChangeCheckForUpdates(
|
||||
it
|
||||
)
|
||||
)
|
||||
when (it) {
|
||||
true -> showConfirmation.value = true
|
||||
false -> onMainEvent(MainEvent.OnChangeCheckForUpdates(false))
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -45,11 +45,7 @@ fun StartScreenRoot() {
|
|||
LaunchedEffect(Unit) {
|
||||
startViewModel.checkPermissions(
|
||||
storagePermissionState = storagePermissionState,
|
||||
notificationPermissionState = notificationsPermissionState,
|
||||
isCheckForUpdatesEnabled = mainState.value.checkForUpdates!!,
|
||||
onEnableCheckForUpdates = {
|
||||
mainViewModel.onEvent(MainEvent.OnChangeCheckForUpdates(true))
|
||||
}
|
||||
notificationPermissionState = notificationsPermissionState
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -160,10 +160,7 @@ fun StartSettings(
|
|||
onEvent(
|
||||
StartEvent.OnNotificationsPermissionRequest(
|
||||
activity,
|
||||
notificationsPermissionState,
|
||||
onEnableUpdates = {
|
||||
onMainEvent(MainEvent.OnChangeCheckForUpdates(true))
|
||||
}
|
||||
notificationsPermissionState
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,7 +74,10 @@ fun StartPermissionItem(
|
|||
onClick = onGrantClick,
|
||||
contentPadding = ButtonDefaults.TextButtonContentPadding
|
||||
) {
|
||||
Text(text = stringResource(id = R.string.grant))
|
||||
Text(
|
||||
text = stringResource(id = R.string.grant),
|
||||
style = MaterialTheme.typography.labelLarge
|
||||
)
|
||||
}
|
||||
} else {
|
||||
TextButton(onClick = onGrantClick) {
|
||||
|
|
|
|||
|
|
@ -19,8 +19,7 @@ sealed class StartEvent {
|
|||
|
||||
data class OnNotificationsPermissionRequest(
|
||||
val activity: ComponentActivity,
|
||||
val notificationsPermissionState: PermissionState,
|
||||
val onEnableUpdates: () -> Unit
|
||||
val notificationsPermissionState: PermissionState
|
||||
) : StartEvent()
|
||||
|
||||
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.launch
|
||||
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.launchActivity
|
||||
import javax.inject.Inject
|
||||
|
||||
@OptIn(ExperimentalPermissionsApi::class)
|
||||
@HiltViewModel
|
||||
class StartViewModel @Inject constructor(
|
||||
private val checkForUpdates: CheckForUpdates,
|
||||
) : ViewModel() {
|
||||
class StartViewModel @Inject constructor() : ViewModel() {
|
||||
|
||||
private val _state = MutableStateFlow(StartState())
|
||||
val state = _state.asStateFlow()
|
||||
|
|
@ -198,7 +195,6 @@ class StartViewModel @Inject constructor(
|
|||
notificationsPermissionGranted = true
|
||||
)
|
||||
}
|
||||
event.onEnableUpdates()
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -234,11 +230,6 @@ class StartViewModel @Inject constructor(
|
|||
)
|
||||
}
|
||||
|
||||
event.onEnableUpdates()
|
||||
checkForUpdates.execute(
|
||||
postNotification = true
|
||||
)
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
@ -267,9 +258,7 @@ class StartViewModel @Inject constructor(
|
|||
|
||||
fun checkPermissions(
|
||||
storagePermissionState: PermissionState,
|
||||
notificationPermissionState: PermissionState,
|
||||
isCheckForUpdatesEnabled: Boolean,
|
||||
onEnableCheckForUpdates: () -> Unit
|
||||
notificationPermissionState: PermissionState
|
||||
) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
val legacyStoragePermission = Build.VERSION.SDK_INT < Build.VERSION_CODES.R
|
||||
|
|
@ -286,13 +275,6 @@ class StartViewModel @Inject constructor(
|
|||
true
|
||||
}
|
||||
|
||||
if (notificationPermissionGranted && !isCheckForUpdatesEnabled) {
|
||||
onEnableCheckForUpdates()
|
||||
checkForUpdates.execute(
|
||||
postNotification = true
|
||||
)
|
||||
}
|
||||
|
||||
_state.update {
|
||||
it.copy(
|
||||
storagePermissionGranted = storagePermissionGranted,
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@
|
|||
<string name="move_book">Перемістити книгу?</string>
|
||||
<string name="delete_history">Видалити історію читання?</string>
|
||||
<string name="confirm_update">Підтвердити оновлення?</string>
|
||||
<string name="enable_check_for_updates">Увімнкути перевірку на оновлення?</string>
|
||||
|
||||
<!-- Dialog Descriptions -->
|
||||
<string name="storage_permission_description">
|
||||
|
|
@ -77,6 +78,11 @@
|
|||
Натиснувши на кнопку «Завантажити», ви перейдете в ваш браузер
|
||||
та завантажете останнє оновлення автоматично.
|
||||
</string>
|
||||
<string name="enable_check_for_updates_description">
|
||||
Увімкнувши «Перевіряти на оновлення» застосунок буде отримувати інформацію про останній реліз
|
||||
з «api.github.com» кожен раз, коли застосунок запускається.
|
||||
Хочете продовжити та увімкнути «Перевіряти на оновлення»?
|
||||
</string>
|
||||
|
||||
<!-- Errors -->
|
||||
<string name="error_permission">
|
||||
|
|
@ -153,6 +159,7 @@
|
|||
<string name="no">Ні</string>
|
||||
<string name="download">Завантажити</string>
|
||||
<string name="done">Готово</string>
|
||||
<string name="enable">Увімкнути</string>
|
||||
|
||||
<!-- Items -->
|
||||
<string name="files">файли</string>
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@
|
|||
<string name="move_book">Move book?</string>
|
||||
<string name="delete_history">Delete reading history?</string>
|
||||
<string name="confirm_update">Confirm update?</string>
|
||||
<string name="enable_check_for_updates">Enable check for updates?</string>
|
||||
|
||||
<!-- Dialog Descriptions -->
|
||||
<string name="storage_permission_description">
|
||||
|
|
@ -93,6 +94,12 @@
|
|||
By clicking the «Download» button you will be transferred
|
||||
to your browser and download the latest update automatically.
|
||||
</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 -->
|
||||
<string name="error_permission">
|
||||
|
|
@ -168,6 +175,7 @@
|
|||
<string name="no">No</string>
|
||||
<string name="download">Download</string>
|
||||
<string name="done">Done</string>
|
||||
<string name="enable">Enable</string>
|
||||
|
||||
<!-- Items -->
|
||||
<string name="files">files</string>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue