|
@@ -23,12 +23,16 @@ import androidx.compose.foundation.background
|
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
|
import androidx.compose.foundation.layout.Column
|
|
import androidx.compose.foundation.layout.Column
|
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
|
|
|
+import androidx.compose.foundation.shape.RoundedCornerShape
|
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.runtime.Composable
|
|
|
import androidx.compose.ui.Alignment
|
|
import androidx.compose.ui.Alignment
|
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.Modifier
|
|
|
import androidx.compose.ui.graphics.Color
|
|
import androidx.compose.ui.graphics.Color
|
|
|
-import androidx.compose.ui.graphics.RectangleShape
|
|
|
|
|
|
|
+import androidx.compose.ui.graphics.Shape
|
|
|
import androidx.compose.ui.graphics.vector.ImageVector
|
|
import androidx.compose.ui.graphics.vector.ImageVector
|
|
|
|
|
+import androidx.compose.ui.text.font.FontWeight
|
|
|
|
|
+import androidx.compose.ui.unit.Dp
|
|
|
|
|
+import androidx.compose.ui.unit.dp
|
|
|
import androidx.compose.ui.unit.sp
|
|
import androidx.compose.ui.unit.sp
|
|
|
import androidx.navigation.NamedNavArgument
|
|
import androidx.navigation.NamedNavArgument
|
|
|
import androidx.navigation.NavBackStackEntry
|
|
import androidx.navigation.NavBackStackEntry
|
|
@@ -50,19 +54,13 @@ import kotlin.reflect.full.createInstance
|
|
|
*
|
|
*
|
|
|
* @constructor Create empty constructor for screen
|
|
* @constructor Create empty constructor for screen
|
|
|
*/
|
|
*/
|
|
|
-@Suppress("unused")
|
|
|
|
|
|
|
+@Suppress("unused", "LeakingThis")
|
|
|
open class Screen : NavController.OnDestinationChangedListener {
|
|
open class Screen : NavController.OnDestinationChangedListener {
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * Autogenerated path / route
|
|
|
|
|
- */
|
|
|
|
|
private val routeBase: String
|
|
private val routeBase: String
|
|
|
get() = (this::class.simpleName ?: "-") + "?"
|
|
get() = (this::class.simpleName ?: "-") + "?"
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * Complete autogenerated path / route with parameters
|
|
|
|
|
- */
|
|
|
|
|
- val completeRoute: String
|
|
|
|
|
|
|
+ open val completeRoute: String
|
|
|
get() = routeBase.let { rb ->
|
|
get() = routeBase.let { rb ->
|
|
|
var routeImpl = rb
|
|
var routeImpl = rb
|
|
|
args.forEach { arg ->
|
|
args.forEach { arg ->
|
|
@@ -71,47 +69,26 @@ open class Screen : NavController.OnDestinationChangedListener {
|
|
|
routeImpl
|
|
routeImpl
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * Screen title
|
|
|
|
|
- */
|
|
|
|
|
open val titleResId: Int = -1
|
|
open val titleResId: Int = -1
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * Screen arguments if any
|
|
|
|
|
- */
|
|
|
|
|
open val args: List<NamedNavArgument> = emptyList()
|
|
open val args: List<NamedNavArgument> = emptyList()
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * Menu string resource id
|
|
|
|
|
- * menu is generated only if it returns id > 0
|
|
|
|
|
- */
|
|
|
|
|
open val menuTitleResId: Int = -1
|
|
open val menuTitleResId: Int = -1
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * Menu icon if any
|
|
|
|
|
- */
|
|
|
|
|
open val menuIcon: ImageVector? = null
|
|
open val menuIcon: ImageVector? = null
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * Show once and hide on back pressed, remove from backstack
|
|
|
|
|
- */
|
|
|
|
|
open val showOnce = false
|
|
open val showOnce = false
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * Autogenerated menu item, if any
|
|
|
|
|
- * Generated only if [menuTitleResId] > 0
|
|
|
|
|
- */
|
|
|
|
|
|
|
+ open val backgroundColor :Color = Color.DarkGray
|
|
|
|
|
+
|
|
|
|
|
+ open val roundRadius : Dp = 0.dp
|
|
|
|
|
+
|
|
|
|
|
+ open val background : Shape = RoundedCornerShape(roundRadius)
|
|
|
|
|
+
|
|
|
val menuItem
|
|
val menuItem
|
|
|
get() = if (menuTitleResId >= 0) MenuItem(menuTitleResId, menuIcon, completeRoute)
|
|
get() = if (menuTitleResId >= 0) MenuItem(menuTitleResId, menuIcon, completeRoute)
|
|
|
else null
|
|
else null
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * Compose function.
|
|
|
|
|
- *
|
|
|
|
|
- * Helper function to preview without parameters as preview of compose needed.
|
|
|
|
|
- *
|
|
|
|
|
- * @return
|
|
|
|
|
- */
|
|
|
|
|
@TvPreview
|
|
@TvPreview
|
|
|
@Composable
|
|
@Composable
|
|
|
@CallSuper
|
|
@CallSuper
|
|
@@ -119,14 +96,6 @@ open class Screen : NavController.OnDestinationChangedListener {
|
|
|
Compose(null, null, emptyList(), mapOf())
|
|
Compose(null, null, emptyList(), mapOf())
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * Compose function for compose screen.
|
|
|
|
|
- * This should be only a method overridden in super classes.
|
|
|
|
|
- *
|
|
|
|
|
- * @param navController Nav controller
|
|
|
|
|
- * @param backStackEntry Back stack entry
|
|
|
|
|
- * @param menuItems Menu items
|
|
|
|
|
- */
|
|
|
|
|
@Composable
|
|
@Composable
|
|
|
open fun Compose(
|
|
open fun Compose(
|
|
|
navController: NavHostController?,
|
|
navController: NavHostController?,
|
|
@@ -142,14 +111,15 @@ open class Screen : NavController.OnDestinationChangedListener {
|
|
|
Column(
|
|
Column(
|
|
|
modifier = Modifier
|
|
modifier = Modifier
|
|
|
.fillMaxSize()
|
|
.fillMaxSize()
|
|
|
- .background(Color.DarkGray, RectangleShape),
|
|
|
|
|
|
|
+ .background(backgroundColor, background),
|
|
|
verticalArrangement = Arrangement.Center,
|
|
verticalArrangement = Arrangement.Center,
|
|
|
horizontalAlignment = Alignment.CenterHorizontally
|
|
horizontalAlignment = Alignment.CenterHorizontally
|
|
|
) {
|
|
) {
|
|
|
|
|
|
|
|
Text(
|
|
Text(
|
|
|
text = "Empty Screen",
|
|
text = "Empty Screen",
|
|
|
- fontSize = 32.sp,
|
|
|
|
|
|
|
+ fontSize = 64.sp,
|
|
|
|
|
+ fontWeight = FontWeight.Bold,
|
|
|
color = Color.White
|
|
color = Color.White
|
|
|
)
|
|
)
|
|
|
|
|
|
|
@@ -172,14 +142,6 @@ open class Screen : NavController.OnDestinationChangedListener {
|
|
|
val SlideInVertically = slideInVertically(animationSpec = tween(1000))
|
|
val SlideInVertically = slideInVertically(animationSpec = tween(1000))
|
|
|
val SlideOutVertically = slideOutVertically(animationSpec = tween(1000))
|
|
val SlideOutVertically = slideOutVertically(animationSpec = tween(1000))
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * Helper function to get params from route.
|
|
|
|
|
- *
|
|
|
|
|
- * @param argId Arg id
|
|
|
|
|
- * @param defaultValue Default value
|
|
|
|
|
- * @return
|
|
|
|
|
- * @receiver [NavBackStackEntry]
|
|
|
|
|
- */
|
|
|
|
|
@Suppress("UNCHECKED_CAST", "DEPRECATION")
|
|
@Suppress("UNCHECKED_CAST", "DEPRECATION")
|
|
|
private fun <T> NavBackStackEntry.arg(
|
|
private fun <T> NavBackStackEntry.arg(
|
|
|
argId: String,
|
|
argId: String,
|
|
@@ -204,7 +166,11 @@ open class Screen : NavController.OnDestinationChangedListener {
|
|
|
val currentRoute = currentRoute
|
|
val currentRoute = currentRoute
|
|
|
val equals = currentRoute?.equals(finalRoute)
|
|
val equals = currentRoute?.equals(finalRoute)
|
|
|
if (equals != true) {
|
|
if (equals != true) {
|
|
|
- navigate(finalRoute)
|
|
|
|
|
|
|
+// try {
|
|
|
|
|
+ navigate(finalRoute)
|
|
|
|
|
+// } catch (e: Exception) {
|
|
|
|
|
+// Timber.e(e)
|
|
|
|
|
+// }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -227,32 +193,18 @@ open class Screen : NavController.OnDestinationChangedListener {
|
|
|
val currentRoute = currentRoute
|
|
val currentRoute = currentRoute
|
|
|
val equals = currentRoute?.equals(finalRoute)
|
|
val equals = currentRoute?.equals(finalRoute)
|
|
|
if (equals != true) {
|
|
if (equals != true) {
|
|
|
- navigate(finalRoute)
|
|
|
|
|
|
|
+// try {
|
|
|
|
|
+ navigate(finalRoute)
|
|
|
|
|
+// } catch (e: Exception) {
|
|
|
|
|
+// Timber.e(e)
|
|
|
|
|
+// }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * Current route nav host helper
|
|
|
|
|
- *
|
|
|
|
|
- * Function returns current route that is shown.
|
|
|
|
|
- *
|
|
|
|
|
- * @return current route on screen
|
|
|
|
|
- */
|
|
|
|
|
val NavHostController.currentRoute
|
|
val NavHostController.currentRoute
|
|
|
get() = currentDestination?.route
|
|
get() = currentDestination?.route
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * Custom function to generate screen in nav graph.
|
|
|
|
|
- *
|
|
|
|
|
- * @param route Route route expected
|
|
|
|
|
- * @param isHomeScreen Is home screen, indicates that this screen will
|
|
|
|
|
- * be used as home screen. Should be used once, or in case that is defined multiple times,
|
|
|
|
|
- * the last one is used as home screen.
|
|
|
|
|
- *
|
|
|
|
|
- * @param T T Screen object generated for route.
|
|
|
|
|
- * @receiver [NavGraphBuilderEx]
|
|
|
|
|
- */
|
|
|
|
|
fun <T : Screen> NavGraphBuilderEx.screen(
|
|
fun <T : Screen> NavGraphBuilderEx.screen(
|
|
|
route: T,
|
|
route: T,
|
|
|
isHomeScreen: Boolean = false,
|
|
isHomeScreen: Boolean = false,
|