11package com.paulcoding.hviewer.ui.page.settings
22
33import androidx.activity.ComponentActivity
4+ import androidx.compose.foundation.background
45import androidx.compose.foundation.clickable
56import androidx.compose.foundation.interaction.MutableInteractionSource
67import androidx.compose.foundation.layout.Arrangement
8+ import androidx.compose.foundation.layout.Box
79import androidx.compose.foundation.layout.Column
810import androidx.compose.foundation.layout.Row
911import androidx.compose.foundation.layout.RowScope
@@ -16,10 +18,12 @@ import androidx.compose.material.icons.Icons
1618import androidx.compose.material.icons.outlined.BugReport
1719import androidx.compose.material.icons.outlined.Description
1820import androidx.compose.material.icons.outlined.Edit
21+ import androidx.compose.material.icons.outlined.Update
1922import androidx.compose.material3.ExperimentalMaterial3Api
2023import androidx.compose.material3.HorizontalDivider
2124import androidx.compose.material3.Icon
2225import androidx.compose.material3.LocalMinimumInteractiveComponentSize
26+ import androidx.compose.material3.MaterialTheme
2327import androidx.compose.material3.Scaffold
2428import androidx.compose.material3.Switch
2529import androidx.compose.material3.SwitchColors
@@ -35,17 +39,22 @@ import androidx.compose.runtime.remember
3539import androidx.compose.runtime.setValue
3640import androidx.compose.ui.Alignment
3741import androidx.compose.ui.Modifier
42+ import androidx.compose.ui.graphics.Color
3843import androidx.compose.ui.platform.LocalContext
3944import androidx.compose.ui.res.stringResource
4045import androidx.compose.ui.text.font.FontWeight
4146import androidx.compose.ui.unit.dp
4247import androidx.compose.ui.unit.sp
48+ import com.paulcoding.hviewer.BuildConfig
4349import com.paulcoding.hviewer.R
4450import com.paulcoding.hviewer.extensions.setSecureScreen
4551import com.paulcoding.hviewer.helper.makeToast
4652import com.paulcoding.hviewer.preference.Preferences
53+ import com.paulcoding.hviewer.ui.component.ConfirmDialog
4754import com.paulcoding.hviewer.ui.component.H7Tap
4855import com.paulcoding.hviewer.ui.component.HBackIcon
56+ import com.paulcoding.hviewer.ui.component.HIcon
57+ import com.paulcoding.hviewer.ui.component.HLoading
4958import com.paulcoding.hviewer.ui.page.AppViewModel
5059
5160@OptIn(ExperimentalMaterial3Api ::class )
@@ -63,6 +72,8 @@ fun SettingsPage(
6372 val window = (context as ComponentActivity ).window
6473 var lockModalVisible by remember { mutableStateOf(false ) }
6574 var appLockEnabled by remember { mutableStateOf(Preferences .pin.isNotEmpty()) }
75+ var newVersion by remember { mutableStateOf(" " ) }
76+ var downloadUrl by remember { mutableStateOf(" " ) }
6677 val scrollState = rememberScrollState()
6778
6879 fun onAppLockEnabled (pin : String ) {
@@ -147,8 +158,19 @@ fun SettingsPage(
147158 }
148159 }
149160
150- H7Tap (modifier = Modifier .align(Alignment .CenterHorizontally )) {
151- appViewModel.setDevMode(it)
161+ Row (
162+ modifier = Modifier .align(Alignment .CenterHorizontally ),
163+ verticalAlignment = Alignment .CenterVertically
164+ ) {
165+ H7Tap () {
166+ appViewModel.setDevMode(it)
167+ }
168+ HIcon (Icons .Outlined .Update , tint = MaterialTheme .colorScheme.primary) {
169+ appViewModel.checkForUpdate(BuildConfig .VERSION_NAME ) { version, url ->
170+ newVersion = version
171+ downloadUrl = url
172+ }
173+ }
152174 }
153175 }
154176 }
@@ -169,6 +191,33 @@ fun SettingsPage(
169191 if (lockModalVisible) LockModal (onDismiss = { lockModalVisible = false }) {
170192 onAppLockEnabled(it)
171193 }
194+
195+ ConfirmDialog (
196+ showDialog = newVersion.isNotEmpty(),
197+ title = " Update Available" ,
198+ text = newVersion,
199+ confirmColor = MaterialTheme .colorScheme.primary,
200+ dismissColor = MaterialTheme .colorScheme.onBackground,
201+ onDismiss = {
202+ newVersion = " "
203+ },
204+ onConfirm = {
205+ appViewModel.downloadAndInstallApk(context, downloadUrl)
206+ newVersion = " "
207+ }
208+ )
209+
210+ if (appState.updatingApk) {
211+ Box (
212+ modifier = Modifier
213+ .fillMaxSize()
214+ .background(Color .Black .copy(alpha = 0.5f ))
215+ ) {
216+ Box (modifier = Modifier .align(Alignment .Center )) {
217+ HLoading ()
218+ }
219+ }
220+ }
172221}
173222
174223@Composable
0 commit comments