mirror of
https://github.com/awfixers-stuff/OwnDroid.git
synced 2026-03-23 11:05:59 +00:00
Use main NavHost to navigate across all pages
Upgrade dependencies Upload dependencies to GitHub in workflow
This commit is contained in:
@@ -8,8 +8,10 @@ import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.text.selection.SelectionContainer
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.Info
|
||||
import androidx.compose.material3.*
|
||||
@@ -18,11 +20,13 @@ import androidx.compose.material3.MaterialTheme.typography
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.navigation.NavBackStackEntry
|
||||
import androidx.navigation.NavHostController
|
||||
@@ -33,9 +37,9 @@ import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@Composable
|
||||
fun SubPageItem(
|
||||
fun FunctionItem(
|
||||
@StringRes title: Int,
|
||||
desc:String,
|
||||
desc: String,
|
||||
@DrawableRes icon: Int? = null,
|
||||
operation: () -> Unit
|
||||
) {
|
||||
@@ -48,8 +52,7 @@ fun SubPageItem(
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
if(icon != null) Icon(
|
||||
painter = painterResource(icon),
|
||||
contentDescription = null,
|
||||
painter = painterResource(icon), contentDescription = null,
|
||||
modifier = Modifier.padding(top = 1.dp, end = 20.dp).offset(x = (-2).dp)
|
||||
)
|
||||
Column {
|
||||
@@ -194,25 +197,6 @@ fun SwitchItem(
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun TopBar(
|
||||
backStackEntry: NavBackStackEntry?,
|
||||
navCtrl: NavHostController,
|
||||
localNavCtrl: NavHostController,
|
||||
title: @Composable ()->Unit = {}
|
||||
) {
|
||||
TopAppBar(
|
||||
title = title,
|
||||
navigationIcon = {
|
||||
NavIcon{
|
||||
if(backStackEntry?.destination?.route == "Home") { navCtrl.navigateUp() } else { localNavCtrl.navigateUp() }
|
||||
}
|
||||
},
|
||||
colors = TopAppBarDefaults.topAppBarColors(containerColor = colorScheme.background)
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun CopyTextButton(@StringRes label: Int, content: String) {
|
||||
val context = LocalContext.current
|
||||
@@ -287,6 +271,7 @@ fun ListItem(text: String, onDelete: () -> Unit) {
|
||||
fun InfoCard(@StringRes strID: Int) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 8.dp)
|
||||
.clip(RoundedCornerShape(10))
|
||||
.background(color = colorScheme.tertiaryContainer)
|
||||
@@ -296,3 +281,53 @@ fun InfoCard(@StringRes strID: Int) {
|
||||
Text(stringResource(strID))
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun MyScaffold(
|
||||
@StringRes title: Int,
|
||||
horizonPadding: Dp,
|
||||
navCtrl: NavHostController,
|
||||
displayTitle: Boolean = true,
|
||||
content: @Composable ColumnScope.() -> Unit
|
||||
) = MyScaffold(title, horizonPadding, { navCtrl.navigateUp() }, displayTitle, content)
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun MyScaffold(
|
||||
@StringRes title: Int,
|
||||
horizonPadding: Dp,
|
||||
onNavIconClicked: () -> Unit,
|
||||
displayTitle: Boolean,
|
||||
content: @Composable ColumnScope.() -> Unit
|
||||
) {
|
||||
val scrollState = rememberScrollState()
|
||||
Scaffold(
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = {
|
||||
Text(
|
||||
text = stringResource(title),
|
||||
modifier = if(displayTitle) Modifier.alpha((maxOf(scrollState.value-90,0)).toFloat()/50) else Modifier
|
||||
)
|
||||
},
|
||||
navigationIcon = { NavIcon (onNavIconClicked) }
|
||||
)
|
||||
}
|
||||
) { paddingValues ->
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(paddingValues)
|
||||
.padding(horizontal = horizonPadding)
|
||||
.verticalScroll(scrollState)
|
||||
.padding(bottom = 80.dp)
|
||||
) {
|
||||
if(displayTitle) Text(
|
||||
text = stringResource(title),
|
||||
style = typography.headlineLarge,
|
||||
modifier = Modifier.padding(start = if(horizonPadding == 0.dp) 16.dp else 0.dp,top = 10.dp, bottom = 5.dp)
|
||||
)
|
||||
content()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user