Skip to content

Commit 689cbdf

Browse files
Updated model version to the latest, more UI and naviagtion fixes
1 parent b7fddf0 commit 689cbdf

File tree

6 files changed

+80
-83
lines changed

6 files changed

+80
-83
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<category android:name="android.intent.category.LAUNCHER" />
3131
</intent-filter>
3232
</activity>
33-
<receiver android:name=".notification.AlarmReceiver" />
33+
<!--<receiver android:name=".notification.AlarmReceiver" />-->
3434
</application>
3535

3636
</manifest>

app/src/main/java/com/harsh/askgemini/feature/chat/ChatScreen.kt

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import android.widget.Toast
55
import androidx.activity.compose.BackHandler
66
import androidx.compose.animation.animateContentSize
77
import androidx.compose.foundation.background
8+
import androidx.compose.foundation.layout.Arrangement
89
import androidx.compose.foundation.layout.BoxWithConstraints
910
import androidx.compose.foundation.layout.Column
1011
import androidx.compose.foundation.layout.IntrinsicSize
1112
import androidx.compose.foundation.layout.Row
12-
import androidx.compose.foundation.layout.Spacer
1313
import androidx.compose.foundation.layout.fillMaxSize
1414
import androidx.compose.foundation.layout.fillMaxWidth
1515
import androidx.compose.foundation.layout.height
@@ -37,7 +37,6 @@ import androidx.compose.material3.Icon
3737
import androidx.compose.material3.IconButton
3838
import androidx.compose.material3.MaterialTheme
3939
import androidx.compose.material3.Scaffold
40-
import androidx.compose.material3.SmallFloatingActionButton
4140
import androidx.compose.material3.Text
4241
import androidx.compose.material3.TextField
4342
import androidx.compose.material3.TextFieldDefaults
@@ -73,7 +72,6 @@ import com.google.accompanist.permissions.ExperimentalPermissionsApi
7372
import com.google.accompanist.permissions.isGranted
7473
import com.google.accompanist.permissions.rememberPermissionState
7574
import com.harsh.askgemini.R
76-
import com.harsh.askgemini.navigation.WindowNavigationItem
7775
import com.harsh.askgemini.ui.DotLoadingAnimation
7876
import com.harsh.askgemini.util.Cupboard.cleanedString
7977
import com.harsh.askgemini.util.Cupboard.startSpeechToText
@@ -88,7 +86,7 @@ internal fun ChatRoute(
8886
navController: NavHostController,
8987
) {
9088

91-
BackHandler { navController.popBackStack() }
89+
BackHandler { navController.navigateUp() }
9290
val chatUiState by chatViewModel.uiState.collectAsState()
9391
val coroutineScope = rememberCoroutineScope()
9492
val listState = rememberLazyListState()
@@ -364,17 +362,15 @@ fun TopAppBarOfChat(
364362

365363
Row(
366364
modifier = Modifier
367-
//.padding(bottom = 4.dp)
368365
.fillMaxWidth()
369366
.background(color = Color.White.copy(0.8F))
370367
//.padding(all = 4.dp) // Adjust padding as needed
371368
.height(IntrinsicSize.Min),
372369
verticalAlignment = Alignment.CenterVertically,
370+
horizontalArrangement = Arrangement.SpaceBetween
373371
) {
374372
IconButton(onClick = {
375-
navController.navigate(WindowNavigationItem.Menu.route) {
376-
popUpTo(WindowNavigationItem.Menu.route) { inclusive = true }
377-
}
373+
navController.navigateUp()
378374
}) {
379375
Icon(
380376
imageVector = Icons.AutoMirrored.Filled.KeyboardArrowLeft,
@@ -383,36 +379,33 @@ fun TopAppBarOfChat(
383379
)
384380
}
385381

386-
Spacer(modifier = Modifier.weight(1F))
387-
388-
Text(
389-
text = "Chat with AI ",
390-
fontFamily = FontFamily(Font(R.font.mavitya, FontWeight.SemiBold)),
391-
style = MaterialTheme.typography.titleLarge,
392-
color = Color.DarkGray,
393-
textAlign = TextAlign.Center
394-
)
395-
396-
Icon(
397-
imageVector = Icons.Outlined.BubbleChart,
398-
contentDescription = "Prompt icon",
399-
tint = Color.DarkGray,
400-
modifier = Modifier.requiredSize(24.dp)
401-
)
402-
403-
Spacer(modifier = Modifier.weight(1F))
382+
Row {
383+
Text(
384+
text = "Chat with AI ",
385+
fontFamily = FontFamily(Font(R.font.mavitya, FontWeight.SemiBold)),
386+
style = MaterialTheme.typography.titleLarge,
387+
color = Color.DarkGray,
388+
textAlign = TextAlign.Center
389+
)
390+
Icon(
391+
imageVector = Icons.Outlined.BubbleChart,
392+
contentDescription = "Prompt icon",
393+
tint = Color.DarkGray,
394+
modifier = Modifier.requiredSize(24.dp)
395+
)
396+
}
404397

405-
SmallFloatingActionButton(
398+
IconButton(
406399
onClick = {
407400
coroutineScope.launch {
408401
listState.scrollToItem(0)
409402
}
410403
},
411-
containerColor = Color.LightGray,
412404
) {
413405
Icon(
414406
imageVector = Icons.Default.KeyboardDoubleArrowDown,
415-
contentDescription = ""
407+
contentDescription = "",
408+
tint = Color.Black
416409
)
417410
}
418411
}

app/src/main/java/com/harsh/askgemini/feature/multimodal/PhotoReasoningScreen.kt

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import androidx.compose.foundation.layout.fillMaxSize
1717
import androidx.compose.foundation.layout.fillMaxWidth
1818
import androidx.compose.foundation.layout.padding
1919
import androidx.compose.foundation.layout.requiredSize
20+
import androidx.compose.foundation.layout.wrapContentSize
2021
import androidx.compose.foundation.lazy.LazyRow
2122
import androidx.compose.foundation.lazy.items
2223
import androidx.compose.foundation.rememberScrollState
@@ -43,11 +44,11 @@ import androidx.compose.runtime.rememberCoroutineScope
4344
import androidx.compose.runtime.saveable.rememberSaveable
4445
import androidx.compose.runtime.setValue
4546
import androidx.compose.ui.Alignment
46-
import androidx.compose.ui.ExperimentalComposeUiApi
4747
import androidx.compose.ui.Modifier
4848
import androidx.compose.ui.draw.clip
4949
import androidx.compose.ui.graphics.Color
5050
import androidx.compose.ui.platform.LocalContext
51+
import androidx.compose.ui.platform.LocalFocusManager
5152
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
5253
import androidx.compose.ui.res.stringResource
5354
import androidx.compose.ui.text.font.Font
@@ -85,7 +86,7 @@ internal fun PhotoReasoningRoute(
8586
val imageRequestBuilder = ImageRequest.Builder(context)
8687
val imageLoader = ImageLoader.Builder(context).build()
8788

88-
BackHandler { navController.popBackStack() }
89+
BackHandler { navController.navigateUp() }
8990

9091
PhotoReasoningScreen(
9192
uiState = photoReasoningUiState,
@@ -114,7 +115,7 @@ internal fun PhotoReasoningRoute(
114115
}
115116
}
116117

117-
@OptIn(ExperimentalComposeUiApi::class, ExperimentalPermissionsApi::class)
118+
@OptIn(ExperimentalPermissionsApi::class)
118119
@Composable
119120
fun PhotoReasoningScreen(
120121
uiState: PhotoReasoningUiState = PhotoReasoningUiState.Loading,
@@ -123,7 +124,8 @@ fun PhotoReasoningScreen(
123124
) {
124125
val context = LocalContext.current
125126
var userQuestion by rememberSaveable { mutableStateOf("") }
126-
val localKeyboardManager = LocalSoftwareKeyboardController.current
127+
val keyboardManager = LocalSoftwareKeyboardController.current
128+
val focusManager = LocalFocusManager.current
127129
val imageUris = rememberSaveable(saver = UriSaver()) { mutableStateListOf() }
128130
val pickMedia = rememberLauncherForActivityResult(
129131
contract = ActivityResultContracts.PickVisualMedia(),
@@ -141,15 +143,14 @@ fun PhotoReasoningScreen(
141143
Column(modifier = Modifier.verticalScroll(rememberScrollState())) {
142144
Card(
143145
modifier = Modifier
144-
.padding(10.dp)
146+
.padding(6.dp)
145147
.fillMaxWidth()
146148
.clip(RoundedCornerShape(25.dp))
147149
) {
148150
Column {
149151
Row(
150152
modifier = Modifier
151-
.padding(top = 10.dp)
152-
.padding(horizontal = 4.dp)
153+
.padding(top = 4.dp)
153154
) {
154155

155156
TextField(
@@ -174,14 +175,11 @@ fun PhotoReasoningScreen(
174175
focusedIndicatorColor = Color.Transparent,
175176
unfocusedIndicatorColor = Color.Transparent,
176177
),
178+
maxLines = 3,
177179
leadingIcon = {
178180
IconButton(
179181
onClick = {
180-
navController.navigate(WindowNavigationItem.Menu.route) {
181-
popUpTo(WindowNavigationItem.Menu.route) {
182-
inclusive = true
183-
}
184-
}
182+
navController.navigateUp()
185183
},
186184
modifier = Modifier.padding(all = 4.dp)
187185
) {
@@ -196,7 +194,7 @@ fun PhotoReasoningScreen(
196194
if (userQuestion.isNotEmpty()) {
197195
IconButton(onClick = {
198196
userQuestion = ""
199-
localKeyboardManager?.show()
197+
keyboardManager?.show()
200198
}) {
201199
Icon(
202200
imageVector = Icons.Default.Close,
@@ -215,7 +213,7 @@ fun PhotoReasoningScreen(
215213
} // TextField Row
216214

217215
// Button Row
218-
Row(modifier = Modifier.padding(horizontal = 8.dp)) {
216+
Row(modifier = Modifier.padding(horizontal = 4.dp)) {
219217
TextButton(
220218
onClick = {
221219
if (storagePermission.status.isGranted) {
@@ -264,7 +262,8 @@ fun PhotoReasoningScreen(
264262
onClick = {
265263
if (userQuestion.isNotBlank())
266264
onReasonClicked(userQuestion, imageUris.toList())
267-
localKeyboardManager?.hide()
265+
keyboardManager?.hide()
266+
focusManager.clearFocus(force = true)
268267
},
269268
modifier = Modifier
270269
.padding(4.dp)
@@ -283,14 +282,20 @@ fun PhotoReasoningScreen(
283282
} // Input Box
284283

285284
// Image Row
286-
LazyRow(modifier = Modifier.padding(8.dp)) {
285+
LazyRow(
286+
modifier = Modifier
287+
.padding(4.dp)
288+
.fillMaxWidth()
289+
) {
287290
items(imageUris) { imageUri ->
288291
AsyncImage(
289292
model = imageUri,
290293
contentDescription = null,
291294
modifier = Modifier
292-
.padding(4.dp)
293295
.requiredSize(125.dp)
296+
.wrapContentSize()
297+
.padding(4.dp)
298+
.clip(RoundedCornerShape(20.dp))
294299
)
295300
}
296301
}

app/src/main/java/com/harsh/askgemini/feature/text/SummarizeScreen.kt

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ import androidx.compose.runtime.rememberCoroutineScope
3636
import androidx.compose.runtime.saveable.rememberSaveable
3737
import androidx.compose.runtime.setValue
3838
import androidx.compose.ui.Alignment
39-
import androidx.compose.ui.ExperimentalComposeUiApi
4039
import androidx.compose.ui.Modifier
4140
import androidx.compose.ui.draw.clip
4241
import androidx.compose.ui.graphics.Color
42+
import androidx.compose.ui.platform.LocalFocusManager
4343
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
4444
import androidx.compose.ui.res.stringResource
4545
import androidx.compose.ui.text.TextStyle
@@ -52,7 +52,6 @@ import androidx.compose.ui.unit.dp
5252
import androidx.lifecycle.viewmodel.compose.viewModel
5353
import androidx.navigation.NavHostController
5454
import com.harsh.askgemini.R
55-
import com.harsh.askgemini.navigation.WindowNavigationItem
5655
import com.harsh.askgemini.ui.DotLoadingAnimation
5756
import com.harsh.askgemini.ui.ErrorLayout
5857
import com.harsh.askgemini.ui.SuccessLayout
@@ -68,7 +67,7 @@ internal fun SummarizeRoute(
6867
val summarizeUiState by summarizeViewModel.uiState.collectAsState()
6968
val coroutineScope = rememberCoroutineScope()
7069

71-
BackHandler { navController.popBackStack() }
70+
BackHandler { navController.navigateUp() }
7271
SummarizedScreen(uiState = summarizeUiState, navController = navController) { inputText ->
7372
coroutineScope.launch {
7473
summarizeViewModel.summarizeStreaming(inputText = inputText)
@@ -78,7 +77,6 @@ internal fun SummarizeRoute(
7877

7978
var textCopyHolder: String = "" // Holding generated content to make copy to clipboard
8079

81-
@OptIn(ExperimentalComposeUiApi::class)
8280
@Composable
8381
fun SummarizedScreen(
8482
uiState: SummarizeUiState = SummarizeUiState.Loading,
@@ -87,16 +85,17 @@ fun SummarizedScreen(
8785
) {
8886
var textToSummarize by rememberSaveable { mutableStateOf("") }
8987
var suggestion = rememberSaveable { randomSuggestion() }
90-
val localKeyboardManager = LocalSoftwareKeyboardController.current
88+
val keyboardManager = LocalSoftwareKeyboardController.current
89+
val focusManager = LocalFocusManager.current
9190

9291
Column(
9392
modifier = Modifier.verticalScroll(rememberScrollState())
9493
) {
9594
ElevatedCard(
9695
modifier = Modifier
97-
.padding(10.dp)
96+
.padding(all = 8.dp)
9897
.fillMaxWidth()
99-
.clip(RoundedCornerShape(25.dp)),
98+
.clip(RoundedCornerShape(24.dp)),
10099
shape = MaterialTheme.shapes.large,
101100
) {
102101
TextField(
@@ -110,6 +109,7 @@ fun SummarizedScreen(
110109
color = Color.Black
111110
)
112111
},
112+
maxLines = 4,
113113
modifier = Modifier
114114
.padding(12.dp)
115115
.fillMaxWidth()
@@ -125,11 +125,7 @@ fun SummarizedScreen(
125125
leadingIcon = {
126126
IconButton(
127127
onClick = {
128-
navController.navigate(WindowNavigationItem.Menu.route) {
129-
popUpTo(WindowNavigationItem.Menu.route) {
130-
inclusive = true
131-
}
132-
}
128+
navController.navigateUp()
133129
}
134130
) {
135131
Icon(
@@ -143,7 +139,7 @@ fun SummarizedScreen(
143139
if (textToSummarize.isNotEmpty()) {
144140
IconButton(onClick = {
145141
textToSummarize = ""
146-
localKeyboardManager?.show()
142+
keyboardManager?.show()
147143
}) {
148144
Icon(
149145
imageVector = Icons.Default.Close, contentDescription = null,
@@ -175,7 +171,8 @@ fun SummarizedScreen(
175171
Text(
176172
text = suggestion,
177173
fontFamily = FontFamily(Font(R.font.mavitya)),
178-
style = MaterialTheme.typography.bodyLarge
174+
style = MaterialTheme.typography.bodyLarge,
175+
modifier = Modifier.padding(vertical = 3.dp)
179176
)
180177
},
181178
colors = SuggestionChipDefaults.suggestionChipColors(
@@ -186,9 +183,9 @@ fun SummarizedScreen(
186183
Icon(
187184
imageVector = Icons.Default.AutoAwesome,
188185
contentDescription = "Chip Icon",
189-
tint = MaterialTheme.colorScheme.onSecondaryContainer
186+
tint = Color.Black
190187
)
191-
}
188+
},
192189
)
193190
}
194191

@@ -198,7 +195,8 @@ fun SummarizedScreen(
198195
onSummarizeClicked(textToSummarize)
199196

200197
suggestion = randomSuggestion()
201-
localKeyboardManager?.hide()
198+
keyboardManager?.hide()
199+
focusManager.clearFocus(force = true)
202200
},
203201
modifier = Modifier.padding(horizontal = 5.dp)
204202
) {

0 commit comments

Comments
 (0)