Skip to content

Commit

Permalink
Updated model version to the latest, more UI and naviagtion fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
HarshPanchal18 committed Jun 22, 2024
1 parent b7fddf0 commit 689cbdf
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 83 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".notification.AlarmReceiver" />
<!--<receiver android:name=".notification.AlarmReceiver" />-->
</application>

</manifest>
51 changes: 22 additions & 29 deletions app/src/main/java/com/harsh/askgemini/feature/chat/ChatScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import android.widget.Toast
import androidx.activity.compose.BackHandler
import androidx.compose.animation.animateContentSize
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
Expand Down Expand Up @@ -37,7 +37,6 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SmallFloatingActionButton
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.material3.TextFieldDefaults
Expand Down Expand Up @@ -73,7 +72,6 @@ import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.google.accompanist.permissions.isGranted
import com.google.accompanist.permissions.rememberPermissionState
import com.harsh.askgemini.R
import com.harsh.askgemini.navigation.WindowNavigationItem
import com.harsh.askgemini.ui.DotLoadingAnimation
import com.harsh.askgemini.util.Cupboard.cleanedString
import com.harsh.askgemini.util.Cupboard.startSpeechToText
Expand All @@ -88,7 +86,7 @@ internal fun ChatRoute(
navController: NavHostController,
) {

BackHandler { navController.popBackStack() }
BackHandler { navController.navigateUp() }
val chatUiState by chatViewModel.uiState.collectAsState()
val coroutineScope = rememberCoroutineScope()
val listState = rememberLazyListState()
Expand Down Expand Up @@ -364,17 +362,15 @@ fun TopAppBarOfChat(

Row(
modifier = Modifier
//.padding(bottom = 4.dp)
.fillMaxWidth()
.background(color = Color.White.copy(0.8F))
//.padding(all = 4.dp) // Adjust padding as needed
.height(IntrinsicSize.Min),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
IconButton(onClick = {
navController.navigate(WindowNavigationItem.Menu.route) {
popUpTo(WindowNavigationItem.Menu.route) { inclusive = true }
}
navController.navigateUp()
}) {
Icon(
imageVector = Icons.AutoMirrored.Filled.KeyboardArrowLeft,
Expand All @@ -383,36 +379,33 @@ fun TopAppBarOfChat(
)
}

Spacer(modifier = Modifier.weight(1F))

Text(
text = "Chat with AI ",
fontFamily = FontFamily(Font(R.font.mavitya, FontWeight.SemiBold)),
style = MaterialTheme.typography.titleLarge,
color = Color.DarkGray,
textAlign = TextAlign.Center
)

Icon(
imageVector = Icons.Outlined.BubbleChart,
contentDescription = "Prompt icon",
tint = Color.DarkGray,
modifier = Modifier.requiredSize(24.dp)
)

Spacer(modifier = Modifier.weight(1F))
Row {
Text(
text = "Chat with AI ",
fontFamily = FontFamily(Font(R.font.mavitya, FontWeight.SemiBold)),
style = MaterialTheme.typography.titleLarge,
color = Color.DarkGray,
textAlign = TextAlign.Center
)
Icon(
imageVector = Icons.Outlined.BubbleChart,
contentDescription = "Prompt icon",
tint = Color.DarkGray,
modifier = Modifier.requiredSize(24.dp)
)
}

SmallFloatingActionButton(
IconButton(
onClick = {
coroutineScope.launch {
listState.scrollToItem(0)
}
},
containerColor = Color.LightGray,
) {
Icon(
imageVector = Icons.Default.KeyboardDoubleArrowDown,
contentDescription = ""
contentDescription = "",
tint = Color.Black
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.requiredSize
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.rememberScrollState
Expand All @@ -43,11 +44,11 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.Font
Expand Down Expand Up @@ -85,7 +86,7 @@ internal fun PhotoReasoningRoute(
val imageRequestBuilder = ImageRequest.Builder(context)
val imageLoader = ImageLoader.Builder(context).build()

BackHandler { navController.popBackStack() }
BackHandler { navController.navigateUp() }

PhotoReasoningScreen(
uiState = photoReasoningUiState,
Expand Down Expand Up @@ -114,7 +115,7 @@ internal fun PhotoReasoningRoute(
}
}

@OptIn(ExperimentalComposeUiApi::class, ExperimentalPermissionsApi::class)
@OptIn(ExperimentalPermissionsApi::class)
@Composable
fun PhotoReasoningScreen(
uiState: PhotoReasoningUiState = PhotoReasoningUiState.Loading,
Expand All @@ -123,7 +124,8 @@ fun PhotoReasoningScreen(
) {
val context = LocalContext.current
var userQuestion by rememberSaveable { mutableStateOf("") }
val localKeyboardManager = LocalSoftwareKeyboardController.current
val keyboardManager = LocalSoftwareKeyboardController.current
val focusManager = LocalFocusManager.current
val imageUris = rememberSaveable(saver = UriSaver()) { mutableStateListOf() }
val pickMedia = rememberLauncherForActivityResult(
contract = ActivityResultContracts.PickVisualMedia(),
Expand All @@ -141,15 +143,14 @@ fun PhotoReasoningScreen(
Column(modifier = Modifier.verticalScroll(rememberScrollState())) {
Card(
modifier = Modifier
.padding(10.dp)
.padding(6.dp)
.fillMaxWidth()
.clip(RoundedCornerShape(25.dp))
) {
Column {
Row(
modifier = Modifier
.padding(top = 10.dp)
.padding(horizontal = 4.dp)
.padding(top = 4.dp)
) {

TextField(
Expand All @@ -174,14 +175,11 @@ fun PhotoReasoningScreen(
focusedIndicatorColor = Color.Transparent,
unfocusedIndicatorColor = Color.Transparent,
),
maxLines = 3,
leadingIcon = {
IconButton(
onClick = {
navController.navigate(WindowNavigationItem.Menu.route) {
popUpTo(WindowNavigationItem.Menu.route) {
inclusive = true
}
}
navController.navigateUp()
},
modifier = Modifier.padding(all = 4.dp)
) {
Expand All @@ -196,7 +194,7 @@ fun PhotoReasoningScreen(
if (userQuestion.isNotEmpty()) {
IconButton(onClick = {
userQuestion = ""
localKeyboardManager?.show()
keyboardManager?.show()
}) {
Icon(
imageVector = Icons.Default.Close,
Expand All @@ -215,7 +213,7 @@ fun PhotoReasoningScreen(
} // TextField Row

// Button Row
Row(modifier = Modifier.padding(horizontal = 8.dp)) {
Row(modifier = Modifier.padding(horizontal = 4.dp)) {
TextButton(
onClick = {
if (storagePermission.status.isGranted) {
Expand Down Expand Up @@ -264,7 +262,8 @@ fun PhotoReasoningScreen(
onClick = {
if (userQuestion.isNotBlank())
onReasonClicked(userQuestion, imageUris.toList())
localKeyboardManager?.hide()
keyboardManager?.hide()
focusManager.clearFocus(force = true)
},
modifier = Modifier
.padding(4.dp)
Expand All @@ -283,14 +282,20 @@ fun PhotoReasoningScreen(
} // Input Box

// Image Row
LazyRow(modifier = Modifier.padding(8.dp)) {
LazyRow(
modifier = Modifier
.padding(4.dp)
.fillMaxWidth()
) {
items(imageUris) { imageUri ->
AsyncImage(
model = imageUri,
contentDescription = null,
modifier = Modifier
.padding(4.dp)
.requiredSize(125.dp)
.wrapContentSize()
.padding(4.dp)
.clip(RoundedCornerShape(20.dp))
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
Expand All @@ -52,7 +52,6 @@ import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController
import com.harsh.askgemini.R
import com.harsh.askgemini.navigation.WindowNavigationItem
import com.harsh.askgemini.ui.DotLoadingAnimation
import com.harsh.askgemini.ui.ErrorLayout
import com.harsh.askgemini.ui.SuccessLayout
Expand All @@ -68,7 +67,7 @@ internal fun SummarizeRoute(
val summarizeUiState by summarizeViewModel.uiState.collectAsState()
val coroutineScope = rememberCoroutineScope()

BackHandler { navController.popBackStack() }
BackHandler { navController.navigateUp() }
SummarizedScreen(uiState = summarizeUiState, navController = navController) { inputText ->
coroutineScope.launch {
summarizeViewModel.summarizeStreaming(inputText = inputText)
Expand All @@ -78,7 +77,6 @@ internal fun SummarizeRoute(

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

@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun SummarizedScreen(
uiState: SummarizeUiState = SummarizeUiState.Loading,
Expand All @@ -87,16 +85,17 @@ fun SummarizedScreen(
) {
var textToSummarize by rememberSaveable { mutableStateOf("") }
var suggestion = rememberSaveable { randomSuggestion() }
val localKeyboardManager = LocalSoftwareKeyboardController.current
val keyboardManager = LocalSoftwareKeyboardController.current
val focusManager = LocalFocusManager.current

Column(
modifier = Modifier.verticalScroll(rememberScrollState())
) {
ElevatedCard(
modifier = Modifier
.padding(10.dp)
.padding(all = 8.dp)
.fillMaxWidth()
.clip(RoundedCornerShape(25.dp)),
.clip(RoundedCornerShape(24.dp)),
shape = MaterialTheme.shapes.large,
) {
TextField(
Expand All @@ -110,6 +109,7 @@ fun SummarizedScreen(
color = Color.Black
)
},
maxLines = 4,
modifier = Modifier
.padding(12.dp)
.fillMaxWidth()
Expand All @@ -125,11 +125,7 @@ fun SummarizedScreen(
leadingIcon = {
IconButton(
onClick = {
navController.navigate(WindowNavigationItem.Menu.route) {
popUpTo(WindowNavigationItem.Menu.route) {
inclusive = true
}
}
navController.navigateUp()
}
) {
Icon(
Expand All @@ -143,7 +139,7 @@ fun SummarizedScreen(
if (textToSummarize.isNotEmpty()) {
IconButton(onClick = {
textToSummarize = ""
localKeyboardManager?.show()
keyboardManager?.show()
}) {
Icon(
imageVector = Icons.Default.Close, contentDescription = null,
Expand Down Expand Up @@ -175,7 +171,8 @@ fun SummarizedScreen(
Text(
text = suggestion,
fontFamily = FontFamily(Font(R.font.mavitya)),
style = MaterialTheme.typography.bodyLarge
style = MaterialTheme.typography.bodyLarge,
modifier = Modifier.padding(vertical = 3.dp)
)
},
colors = SuggestionChipDefaults.suggestionChipColors(
Expand All @@ -186,9 +183,9 @@ fun SummarizedScreen(
Icon(
imageVector = Icons.Default.AutoAwesome,
contentDescription = "Chip Icon",
tint = MaterialTheme.colorScheme.onSecondaryContainer
tint = Color.Black
)
}
},
)
}

Expand All @@ -198,7 +195,8 @@ fun SummarizedScreen(
onSummarizeClicked(textToSummarize)

suggestion = randomSuggestion()
localKeyboardManager?.hide()
keyboardManager?.hide()
focusManager.clearFocus(force = true)
},
modifier = Modifier.padding(horizontal = 5.dp)
) {
Expand Down
Loading

0 comments on commit 689cbdf

Please sign in to comment.