Skip to content

Commit

Permalink
Added BackHandler{} for each screen
Browse files Browse the repository at this point in the history
HarshPanchal18 committed Jan 18, 2024
1 parent 9e4c9e8 commit d273baf
Showing 4 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ package com.harsh.askgemini.feature.chat

import android.Manifest
import android.widget.Toast
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
@@ -86,6 +87,7 @@ internal fun ChatRoute(
val chatUiState by chatViewModel.uiState.collectAsState()
val listState = rememberLazyListState()
val coroutineScope = rememberCoroutineScope()
BackHandler { navController.popBackStack() }

Scaffold(
containerColor = MaterialTheme.colorScheme.primary.copy(0.40F),
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import android.graphics.drawable.BitmapDrawable
import android.net.Uri
import android.os.Build
import android.widget.Toast
import androidx.activity.compose.BackHandler
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.PickVisualMediaRequest
import androidx.activity.result.contract.ActivityResultContracts
@@ -80,6 +81,8 @@ internal fun PhotoReasoningRoute(
val imageRequestBuilder = ImageRequest.Builder(context)
val imageLoader = ImageLoader.Builder(context).build()

BackHandler { navController.popBackStack() }

PhotoReasoningScreen(
uiState = photoReasoningUiState,
navController = navController
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.harsh.askgemini.feature.text

import androidx.activity.compose.BackHandler
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
@@ -64,6 +65,7 @@ internal fun SummarizeRoute(
val summarizeUiState by summarizeViewModel.uiState.collectAsState()
val coroutineScope = rememberCoroutineScope()

BackHandler { navController.popBackStack() }
SummarizedScreen(uiState = summarizeUiState, navController = navController) { inputText ->
coroutineScope.launch {
summarizeViewModel.summarizeStreaming(inputText = inputText)
Original file line number Diff line number Diff line change
@@ -37,8 +37,8 @@ fun WindowNavigation() {
}

sealed class WindowNavigationItem(val route: String) {
data object Menu: WindowNavigationItem("menu")
data object Summarize: WindowNavigationItem("summarize")
data object Chat: WindowNavigationItem("chat")
data object PhotoReasoning: WindowNavigationItem("reasoning")
data object Menu : WindowNavigationItem("menu")
data object Summarize : WindowNavigationItem("summarize")
data object Chat : WindowNavigationItem("chat")
data object PhotoReasoning : WindowNavigationItem("reasoning")
}

0 comments on commit d273baf

Please sign in to comment.