Skip to content

Commit 60df0bc

Browse files
Add hint to download LLM on settings screen
1 parent 0a1a449 commit 60df0bc

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

app/src/main/java/org/vonderheidt/hips/ui/screens/SettingsScreen.kt

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,25 @@ import androidx.compose.foundation.layout.fillMaxWidth
1111
import androidx.compose.foundation.layout.height
1212
import androidx.compose.foundation.layout.width
1313
import androidx.compose.foundation.rememberScrollState
14+
import androidx.compose.foundation.shape.RoundedCornerShape
1415
import androidx.compose.foundation.verticalScroll
1516
import androidx.compose.material.icons.Icons
1617
import androidx.compose.material.icons.automirrored.outlined.ArrowBack
18+
import androidx.compose.material.icons.outlined.CheckCircle
1719
import androidx.compose.material.icons.outlined.Person
1820
import androidx.compose.material.icons.outlined.Star
21+
import androidx.compose.material.icons.outlined.Warning
22+
import androidx.compose.material3.Button
23+
import androidx.compose.material3.HorizontalDivider
1924
import androidx.compose.material3.Icon
2025
import androidx.compose.material3.IconButton
2126
import androidx.compose.material3.Text
2227
import androidx.compose.runtime.Composable
28+
import androidx.compose.runtime.getValue
29+
import androidx.compose.runtime.mutableStateOf
30+
import androidx.compose.runtime.rememberCoroutineScope
31+
import androidx.compose.runtime.saveable.rememberSaveable
32+
import androidx.compose.runtime.setValue
2333
import androidx.compose.ui.Alignment
2434
import androidx.compose.ui.Modifier
2535
import androidx.compose.ui.platform.LocalContext
@@ -30,20 +40,29 @@ import androidx.compose.ui.unit.sp
3040
import androidx.navigation.NavController
3141
import androidx.navigation.NavHostController
3242
import androidx.navigation.compose.rememberNavController
43+
import kotlinx.coroutines.launch
3344
import org.vonderheidt.hips.navigation.Screen
3445
import org.vonderheidt.hips.ui.theme.HiPSTheme
46+
import org.vonderheidt.hips.utils.downloadLLM
47+
import org.vonderheidt.hips.utils.llmDownloaded
3548

3649
/**
3750
* Function that defines the settings screen.
3851
*/
3952
@Composable
4053
fun SettingsScreen(navController: NavController, modifier: Modifier) {
4154
// State variables
55+
var llmDownloaded by rememberSaveable { mutableStateOf(llmDownloaded()) }
56+
4257
// Scrolling
4358
val scrollState = rememberScrollState()
59+
4460
// Links
4561
val currentLocalContext = LocalContext.current
4662

63+
// Coroutines
64+
val coroutineScope = rememberCoroutineScope()
65+
4766
// UI components
4867
Column(
4968
modifier = modifier
@@ -75,6 +94,67 @@ fun SettingsScreen(navController: NavController, modifier: Modifier) {
7594
}
7695
}
7796

97+
// LLM download hint
98+
Row(
99+
modifier = modifier.fillMaxWidth(0.9f)
100+
) {
101+
if (llmDownloaded) {
102+
Icon(
103+
imageVector = Icons.Outlined.CheckCircle,
104+
contentDescription = "Check mark"
105+
)
106+
}
107+
else {
108+
Icon(
109+
imageVector = Icons.Outlined.Warning,
110+
contentDescription = "Warning"
111+
)
112+
}
113+
114+
Spacer(modifier = modifier.width(16.dp))
115+
116+
Column {
117+
Text(
118+
text = "Large Language Model",
119+
fontSize = 18.sp,
120+
fontWeight = FontWeight.Bold
121+
)
122+
123+
if (llmDownloaded) {
124+
Text(text = "The LLM has been downloaded. You can now start using this app.")
125+
}
126+
else {
127+
Text(text = "Before using this app, you need to download the LLM.")
128+
}
129+
}
130+
}
131+
132+
Spacer(modifier = modifier.height(16.dp))
133+
134+
// Download button
135+
Row {
136+
Button(
137+
onClick = {
138+
if(!llmDownloaded) {
139+
coroutineScope.launch {
140+
downloadLLM()
141+
llmDownloaded = true
142+
}
143+
}
144+
},
145+
enabled = !llmDownloaded,
146+
shape = RoundedCornerShape(4.dp)
147+
) {
148+
Text(text = "Download")
149+
}
150+
}
151+
152+
Spacer(modifier = modifier.height(16.dp))
153+
154+
HorizontalDivider()
155+
156+
Spacer(modifier = modifier.height(16.dp))
157+
78158
// Author credits
79159
// Make the whole row clickable instead of just the text for better accessibility
80160
Row(
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.vonderheidt.hips.utils
2+
3+
import kotlinx.coroutines.delay
4+
5+
/**
6+
* Function to check if the LLM has already been downloaded.
7+
*/
8+
fun llmDownloaded(): Boolean {
9+
// Initially, LLM hasn't been downloaded yet
10+
return false
11+
}
12+
13+
/**
14+
* Function to download the LLM.
15+
*/
16+
suspend fun downloadLLM() {
17+
// Wait 5 seconds
18+
delay(5000)
19+
}

0 commit comments

Comments
 (0)