1
1
package com.olup.notable
2
2
3
+ import android.content.Intent
4
+ import android.net.Uri
3
5
import androidx.compose.foundation.background
4
6
import androidx.compose.foundation.border
5
7
import androidx.compose.foundation.layout.*
@@ -16,39 +18,51 @@ import androidx.compose.ui.text.font.FontStyle
16
18
import androidx.compose.ui.text.style.TextDecoration
17
19
import androidx.compose.ui.unit.dp
18
20
import androidx.compose.ui.window.Dialog
21
+ import androidx.compose.ui.window.DialogProperties
19
22
import com.olup.notable.components.SelectMenu
20
23
import com.olup.notable.db.Kv
21
24
import com.olup.notable.db.KvProxy
22
25
import kotlinx.coroutines.launch
23
26
import kotlinx.serialization.decodeFromString
24
27
import kotlinx.serialization.encodeToString
25
28
import kotlinx.serialization.json.Json
29
+ import kotlin.concurrent.thread
26
30
27
31
@kotlinx.serialization.Serializable
28
- data class AppSettings (
32
+ data class AppSettings (
29
33
val version : Int ,
30
- val defaultNativeTemplate : String = " blank" ,
31
- val quickNavPages : List <String > = listOf()
34
+ val defaultNativeTemplate : String = " blank" ,
35
+ val quickNavPages : List <String > = listOf()
32
36
)
33
37
34
38
35
39
@Composable
36
40
fun AppSettingsModal (onClose : () -> Unit ) {
37
41
val context = LocalContext .current
38
42
val kv = KvProxy (context)
39
- val isLatestVersion = remember {
40
- isLatestVersion(context)
43
+
44
+ var isLatestVersion by remember {
45
+ mutableStateOf(true )
41
46
}
42
- val settings by kv.observeKv(" APP_SETTINGS" , AppSettings .serializer(), AppSettings (version = 1 )).observeAsState()
43
- val uriHandler = LocalUriHandler .current
47
+ LaunchedEffect (key1 = Unit , block = {
48
+ thread {
49
+ isLatestVersion = isLatestVersion(context)
50
+ }
51
+ })
52
+
53
+ val settings by kv.observeKv(" APP_SETTINGS" , AppSettings .serializer(), AppSettings (version = 1 ))
54
+ .observeAsState()
44
55
56
+ if (settings == null ) return
45
57
46
- if (settings == null ) return
47
58
Dialog (
48
- onDismissRequest = { onClose() }
49
- ) {
59
+ onDismissRequest = { onClose() },
60
+ properties = DialogProperties (usePlatformDefaultWidth = false ),
61
+
62
+ ) {
50
63
Column (
51
64
modifier = Modifier
65
+ .padding(40 .dp)
52
66
.background(Color .White )
53
67
.fillMaxWidth()
54
68
.border(2 .dp, Color .Black , RectangleShape )
@@ -81,7 +95,11 @@ fun AppSettingsModal(onClose: () -> Unit) {
81
95
" squared" to " Small squares grid"
82
96
),
83
97
onChange = {
84
- kv.setKv(" APP_SETTINGS" , settings!! .copy(defaultNativeTemplate = it), AppSettings .serializer())
98
+ kv.setKv(
99
+ " APP_SETTINGS" ,
100
+ settings!! .copy(defaultNativeTemplate = it),
101
+ AppSettings .serializer()
102
+ )
85
103
},
86
104
value = settings?.defaultNativeTemplate ? : " blank"
87
105
)
@@ -92,9 +110,16 @@ fun AppSettingsModal(onClose: () -> Unit) {
92
110
// if(!isLatestVersion){
93
111
Text (text = " It seems a new version of ypu app is available on github." , fontStyle = FontStyle .Italic )
94
112
Spacer (Modifier .height(10 .dp))
95
- Text (text = " See release in browser" , textDecoration = TextDecoration .Underline , modifier= Modifier .noRippleClickable {
96
- uriHandler.openUri(" https://github.com/olup/notable-public/releases" )
97
- })
113
+ Text (
114
+ text = " See release in browser" ,
115
+ textDecoration = TextDecoration .Underline ,
116
+ modifier = Modifier .noRippleClickable {
117
+ val urlIntent = Intent (
118
+ Intent .ACTION_VIEW ,
119
+ Uri .parse(" https://github.com/olup/notable-public/releases" )
120
+ )
121
+ context.startActivity(urlIntent)
122
+ })
98
123
Spacer (Modifier .height(10 .dp))
99
124
// }
100
125
}
0 commit comments