Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
TeamPrinterV2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Aleksandr
TeamPrinterV2
Commits
c39a2157
Commit
c39a2157
authored
Jul 25, 2024
by
Aleksandr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix back navigation on preview screen in different cases
parent
70de6755
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
69 additions
and
9 deletions
+69
-9
app/src/main/java/com/isidroid/c23/MainActivity.kt
+2
-1
app/src/main/java/com/isidroid/c23/ui/_component/BackCloseComponent.kt
+44
-0
app/src/main/java/com/isidroid/c23/ui/navigation/destinations/ContentScreenDestination.kt
+4
-2
app/src/main/java/com/isidroid/c23/ui/navigation/destinations/RenderScreenDestination.kt
+9
-1
app/src/main/java/com/isidroid/c23/ui/screen/content/ContentScreen.kt
+0
-4
core/core/src/main/java/com/isidroid/core/ext/ExtNavigation.kt
+10
-1
No files found.
app/src/main/java/com/isidroid/c23/MainActivity.kt
View file @
c39a2157
...
...
@@ -29,6 +29,7 @@ import com.isidroid.c23.ui.navigation.routeHome
import
com.isidroid.c23.ui.theme.AppTheme
import
com.isidroid.core.ext.navigateSingleTopTo
import
com.isidroid.core.ext.printCurrentDestination
import
com.isidroid.core.ext.printNavigationStack
import
com.isidroid.utils.extractUris
import
dagger.hilt.android.AndroidEntryPoint
...
...
@@ -64,7 +65,7 @@ fun ComposeApp() {
navController
.
navigateSingleTopTo
(
routeHome
(
uris
=
uris
.
joinToString
()))
}
LaunchedEffect
(
Unit
)
{
navController
.
print
CurrentDestination
()
}
LaunchedEffect
(
Unit
)
{
navController
.
print
NavigationStack
()
}
val
surfaceModifier
=
with
(
Modifier
)
{
if
(!
isEdgeToEdge
)
...
...
app/src/main/java/com/isidroid/c23/ui/_component/BackCloseComponent.kt
0 → 100644
View file @
c39a2157
package
com.isidroid.c23.ui._component
import
android.widget.Toast
import
androidx.activity.ComponentActivity
import
androidx.activity.compose.BackHandler
import
androidx.compose.runtime.Composable
import
androidx.compose.runtime.LaunchedEffect
import
androidx.compose.runtime.getValue
import
androidx.compose.runtime.mutableStateOf
import
androidx.compose.runtime.remember
import
androidx.compose.runtime.rememberCoroutineScope
import
androidx.compose.runtime.setValue
import
androidx.compose.ui.platform.LocalContext
import
androidx.navigation.NavController
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.delay
import
kotlinx.coroutines.launch
@Composable
internal
fun
BackCloseComponent
(
navController
:
NavController
)
{
var
showExitApp
by
remember
{
mutableStateOf
(
false
)
}
val
activity
=
LocalContext
.
current
as
?
ComponentActivity
val
scope
=
rememberCoroutineScope
()
LaunchedEffect
(
showExitApp
)
{
if
(
showExitApp
)
scope
.
launch
(
Dispatchers
.
Default
)
{
delay
(
2000
)
showExitApp
=
false
}
}
BackHandler
{
when
{
navController
.
previousBackStackEntry
!=
null
->
navController
.
popBackStack
()
showExitApp
->
activity
?.
finish
()
else
->
{
showExitApp
=
true
Toast
.
makeText
(
activity
,
"Tap back again to close the app"
,
Toast
.
LENGTH_LONG
).
show
()
}
}
}
}
\ No newline at end of file
app/src/main/java/com/isidroid/c23/ui/navigation/destinations/ContentScreenDestination.kt
View file @
c39a2157
...
...
@@ -3,18 +3,20 @@ package com.isidroid.c23.ui.navigation.destinations
import
androidx.compose.runtime.Composable
import
androidx.hilt.navigation.compose.hiltViewModel
import
androidx.navigation.NavHostController
import
com.isidroid.c23.ui._component.BackCloseComponent
import
com.isidroid.c23.ui.navigation.routeMap
import
com.isidroid.c23.ui.navigation.routePrintJobs
import
com.isidroid.c23.ui.navigation.routeRenderPreview
import
com.isidroid.c23.ui.screen.content.ContentContract
import
com.isidroid.c23.ui.screen.content.ContentScreen
import
com.isidroid.c23.ui.screen.content.ContentViewModel
import
com.isidroid.core.ext.navigateSingleTopTo
@Composable
fun
ContentScreenDestination
(
navController
:
NavHostController
)
{
val
viewModel
:
ContentViewModel
=
hiltViewModel
()
BackCloseComponent
(
navController
)
ContentScreen
(
state
=
viewModel
.
viewState
,
effectFlow
=
viewModel
.
effect
,
...
...
@@ -22,7 +24,7 @@ fun ContentScreenDestination(navController: NavHostController) {
onNavigationRequested
=
{
effect
->
when
(
effect
)
{
is
ContentContract
.
Effect
.
Navigation
.
ToRenderPreview
->
navController
.
navigate
(
routeRenderPreview
(
uris
=
effect
.
uris
))
is
ContentContract
.
Effect
.
Navigation
.
ToMap
->
navController
.
navigate
SingleTopTo
(
routeMap
(
effect
.
lat
?.
toString
(),
effect
.
lng
?.
toString
(),
effect
.
spotId
))
is
ContentContract
.
Effect
.
Navigation
.
ToMap
->
navController
.
navigate
(
routeMap
(
effect
.
lat
?.
toString
(),
effect
.
lng
?.
toString
(),
effect
.
spotId
))
ContentContract
.
Effect
.
Navigation
.
ToBack
->
navController
.
popBackStack
()
ContentContract
.
Effect
.
Navigation
.
ToPrintJobList
->
navController
.
navigate
(
routePrintJobs
())
}
...
...
app/src/main/java/com/isidroid/c23/ui/navigation/destinations/RenderScreenDestination.kt
View file @
c39a2157
...
...
@@ -3,12 +3,14 @@ package com.isidroid.c23.ui.navigation.destinations
import
androidx.compose.runtime.Composable
import
androidx.hilt.navigation.compose.hiltViewModel
import
androidx.navigation.NavController
import
com.isidroid.c23.ui._component.BackCloseComponent
import
com.isidroid.c23.ui.navigation.routeMap
import
com.isidroid.c23.ui.navigation.routeSelectContent
import
com.isidroid.c23.ui.screen.render_preview.RenderContract
import
com.isidroid.c23.ui.screen.render_preview.RenderPreviewScreen
import
com.isidroid.c23.ui.screen.render_preview.RenderViewModel
import
com.isidroid.core.ext.navigateSingleTopTo
import
timber.log.Timber
@Composable
fun
RenderScreenDestination
(
navController
:
NavController
)
{
...
...
@@ -21,7 +23,13 @@ fun RenderScreenDestination(navController: NavController) {
onEventSent
=
{
event
->
viewModel
.
setEvent
(
event
)
},
onNavigationRequested
=
{
effect
->
when
(
effect
)
{
RenderContract
.
Effect
.
Navigation
.
ToBack
->
navController
.
popBackStack
()
RenderContract
.
Effect
.
Navigation
.
ToBack
->
{
if
(
navController
.
previousBackStackEntry
!=
null
)
navController
.
popBackStack
()
else
navController
.
navigateSingleTopTo
(
routeSelectContent
())
}
RenderContract
.
Effect
.
Navigation
.
ToMap
->
navController
.
navigate
(
routeMap
())
RenderContract
.
Effect
.
Navigation
.
ToSelectContent
->
navController
.
navigateSingleTopTo
(
routeSelectContent
())
}
...
...
app/src/main/java/com/isidroid/c23/ui/screen/content/ContentScreen.kt
View file @
c39a2157
...
...
@@ -71,10 +71,6 @@ fun ContentScreen(
onEventSent
(
ContentContract
.
Event
.
CopyRenderedFilesToPublicFolder
(
it
))
}
BackHandler
{
onEventSent
(
ContentContract
.
Event
.
GoBack
)
}
LaunchedEffect
(
state
.
value
.
galleryHash
)
{
if
(
state
.
value
.
galleryHash
!=
null
)
launcher
.
launch
(
"image/*"
)
}
LaunchedEffect
(
state
.
value
.
documentHash
)
{
if
(
state
.
value
.
documentHash
!=
null
)
launcher
.
launch
(
"application/pdf"
)
}
LaunchedEffect
(
state
.
value
.
wordHash
)
{
if
(
state
.
value
.
wordHash
!=
null
)
launcher
.
launch
(
"application/msword"
)
}
...
...
core/core/src/main/java/com/isidroid/core/ext/ExtNavigation.kt
View file @
c39a2157
package
com.isidroid.core.ext
import
android.annotation.SuppressLint
import
androidx.core.net.toUri
import
androidx.navigation.NavController
import
androidx.navigation.NavGraph.Companion.findStartDestination
import
androidx.navigation.NavHostController
...
...
@@ -71,4 +73,10 @@ suspend fun NavHostController?.printCurrentDestination(
}.
collect
()
}
@SuppressLint
(
"RestrictedApi"
)
suspend
fun
NavHostController
.
printNavigationStack
(
tag
:
String
=
"navigation_graph"
)
{
currentBackStack
.
collect
{
list
->
val
backstack
=
list
.
mapNotNull
{
navBackStackEntry
->
navBackStackEntry
.
destination
.
route
?.
toUri
()
?.
path
}.
joinToString
()
Timber
.
tag
(
tag
).
i
(
backstack
)
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment