mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-19 08:45:27 +02:00
LargeTopAppBar is now reusable (preparing to add more screens).
This commit is contained in:
parent
b0fa313ac1
commit
4ecb29d7b5
@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
package com.sadellie.unitto.screens.about
|
package com.sadellie.unitto.screens.about
|
||||||
|
|
||||||
import androidx.compose.animation.rememberSplineBasedDecay
|
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
@ -26,27 +25,19 @@ import androidx.compose.foundation.layout.fillMaxWidth
|
|||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.material.icons.Icons
|
|
||||||
import androidx.compose.material.icons.outlined.Close
|
|
||||||
import androidx.compose.material3.Icon
|
|
||||||
import androidx.compose.material3.IconButton
|
|
||||||
import androidx.compose.material3.LargeTopAppBar
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.OutlinedCard
|
import androidx.compose.material3.OutlinedCard
|
||||||
import androidx.compose.material3.Scaffold
|
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TopAppBarDefaults
|
|
||||||
import androidx.compose.material3.rememberTopAppBarScrollState
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.Stable
|
import androidx.compose.runtime.Stable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.sadellie.unitto.R
|
import com.sadellie.unitto.R
|
||||||
import com.sadellie.unitto.data.ALL_LIBRARIES
|
import com.sadellie.unitto.data.ALL_LIBRARIES
|
||||||
|
import com.sadellie.unitto.screens.common.UnittoLargeTopAppBar
|
||||||
import com.sadellie.unitto.screens.openLink
|
import com.sadellie.unitto.screens.openLink
|
||||||
|
|
||||||
|
|
||||||
@ -61,27 +52,10 @@ fun AboutScreen(
|
|||||||
navigateUpAction: () -> Unit = {}
|
navigateUpAction: () -> Unit = {}
|
||||||
) {
|
) {
|
||||||
val mContext = LocalContext.current
|
val mContext = LocalContext.current
|
||||||
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior(rememberSplineBasedDecay(), rememberTopAppBarScrollState())
|
|
||||||
|
|
||||||
Scaffold(
|
UnittoLargeTopAppBar(
|
||||||
modifier = Modifier
|
title = stringResource(id = R.string.third_party_licenses),
|
||||||
.nestedScroll(scrollBehavior.nestedScrollConnection),
|
navigateUpAction = navigateUpAction
|
||||||
topBar = {
|
|
||||||
LargeTopAppBar(
|
|
||||||
title = {
|
|
||||||
Text(text = stringResource(id = R.string.third_party_licenses))
|
|
||||||
},
|
|
||||||
navigationIcon = {
|
|
||||||
IconButton(onClick = navigateUpAction) {
|
|
||||||
Icon(
|
|
||||||
Icons.Outlined.Close,
|
|
||||||
contentDescription = stringResource(id = R.string.navigate_up_description)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
scrollBehavior = scrollBehavior
|
|
||||||
)
|
|
||||||
},
|
|
||||||
) { padding ->
|
) { padding ->
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
Modifier.padding(horizontal = 16.dp),
|
Modifier.padding(horizontal = 16.dp),
|
||||||
|
@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* Unitto is a unit converter for Android
|
||||||
|
* Copyright (c) 2022 Elshan Agaev
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.sadellie.unitto.screens.common
|
||||||
|
|
||||||
|
import androidx.compose.animation.rememberSplineBasedDecay
|
||||||
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.outlined.ArrowBack
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.IconButton
|
||||||
|
import androidx.compose.material3.LargeTopAppBar
|
||||||
|
import androidx.compose.material3.Scaffold
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TopAppBarDefaults
|
||||||
|
import androidx.compose.material3.rememberTopAppBarScrollState
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import com.sadellie.unitto.R
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Commonly used LargeTopAppBar with scroll behavior.
|
||||||
|
*
|
||||||
|
* @param title Text that is displayed in top bar.
|
||||||
|
* @param navigateUpAction Action when user click arrow button at the top.
|
||||||
|
* @param content Content that can be scrolled. Don't forget to use padding values.
|
||||||
|
*/
|
||||||
|
@Composable
|
||||||
|
fun UnittoLargeTopAppBar(
|
||||||
|
title: String,
|
||||||
|
navigateUpAction: () -> Unit,
|
||||||
|
content: @Composable (PaddingValues) -> Unit
|
||||||
|
) {
|
||||||
|
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior(
|
||||||
|
rememberSplineBasedDecay(),
|
||||||
|
rememberTopAppBarScrollState()
|
||||||
|
)
|
||||||
|
Scaffold(
|
||||||
|
modifier = Modifier
|
||||||
|
.nestedScroll(scrollBehavior.nestedScrollConnection),
|
||||||
|
topBar = {
|
||||||
|
LargeTopAppBar(
|
||||||
|
title = {
|
||||||
|
Text(text = title)
|
||||||
|
},
|
||||||
|
navigationIcon = {
|
||||||
|
IconButton(onClick = navigateUpAction) {
|
||||||
|
Icon(Icons.Outlined.ArrowBack, stringResource(R.string.navigate_up_description))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
scrollBehavior = scrollBehavior
|
||||||
|
)
|
||||||
|
},
|
||||||
|
content = content
|
||||||
|
)
|
||||||
|
}
|
@ -19,34 +19,24 @@
|
|||||||
package com.sadellie.unitto.screens.setttings
|
package com.sadellie.unitto.screens.setttings
|
||||||
|
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.compose.animation.rememberSplineBasedDecay
|
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.material.icons.Icons
|
|
||||||
import androidx.compose.material.icons.outlined.ArrowBack
|
|
||||||
import androidx.compose.material3.Icon
|
|
||||||
import androidx.compose.material3.IconButton
|
|
||||||
import androidx.compose.material3.LargeTopAppBar
|
|
||||||
import androidx.compose.material3.Scaffold
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.material3.TopAppBarDefaults
|
|
||||||
import androidx.compose.material3.rememberTopAppBarScrollState
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.saveable.rememberSaveable
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import com.sadellie.unitto.BuildConfig
|
import com.sadellie.unitto.BuildConfig
|
||||||
import com.sadellie.unitto.R
|
import com.sadellie.unitto.R
|
||||||
import com.sadellie.unitto.data.NavRoutes.ABOUT_SCREEN
|
import com.sadellie.unitto.data.NavRoutes.ABOUT_SCREEN
|
||||||
|
import com.sadellie.unitto.data.NavRoutes.THEMES_SCREEN
|
||||||
import com.sadellie.unitto.data.preferences.APP_THEMES
|
import com.sadellie.unitto.data.preferences.APP_THEMES
|
||||||
import com.sadellie.unitto.data.preferences.OUTPUT_FORMAT
|
import com.sadellie.unitto.data.preferences.OUTPUT_FORMAT
|
||||||
import com.sadellie.unitto.data.preferences.PRECISIONS
|
import com.sadellie.unitto.data.preferences.PRECISIONS
|
||||||
import com.sadellie.unitto.data.preferences.SEPARATORS
|
import com.sadellie.unitto.data.preferences.SEPARATORS
|
||||||
import com.sadellie.unitto.screens.MainViewModel
|
import com.sadellie.unitto.screens.MainViewModel
|
||||||
|
import com.sadellie.unitto.screens.common.UnittoLargeTopAppBar
|
||||||
import com.sadellie.unitto.screens.openLink
|
import com.sadellie.unitto.screens.openLink
|
||||||
import com.sadellie.unitto.screens.setttings.components.AlertDialogWithList
|
import com.sadellie.unitto.screens.setttings.components.AlertDialogWithList
|
||||||
import com.sadellie.unitto.screens.setttings.components.SettingsHeader
|
import com.sadellie.unitto.screens.setttings.components.SettingsHeader
|
||||||
@ -59,35 +49,14 @@ fun SettingsScreen(
|
|||||||
navControllerAction: (String) -> Unit
|
navControllerAction: (String) -> Unit
|
||||||
) {
|
) {
|
||||||
val mContext = LocalContext.current
|
val mContext = LocalContext.current
|
||||||
// Scrollable
|
|
||||||
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior(
|
|
||||||
rememberSplineBasedDecay(),
|
|
||||||
rememberTopAppBarScrollState()
|
|
||||||
)
|
|
||||||
var dialogState: DialogState by rememberSaveable {
|
var dialogState: DialogState by rememberSaveable {
|
||||||
mutableStateOf(DialogState.NONE)
|
mutableStateOf(DialogState.NONE)
|
||||||
}
|
}
|
||||||
|
|
||||||
Scaffold(
|
UnittoLargeTopAppBar(
|
||||||
modifier = Modifier
|
title = stringResource(id = R.string.settings_screen),
|
||||||
.nestedScroll(scrollBehavior.nestedScrollConnection),
|
navigateUpAction = navigateUpAction
|
||||||
topBar = {
|
) { padding ->
|
||||||
LargeTopAppBar(
|
|
||||||
title = {
|
|
||||||
Text(text = stringResource(id = R.string.settings_screen))
|
|
||||||
},
|
|
||||||
navigationIcon = {
|
|
||||||
IconButton(onClick = navigateUpAction) {
|
|
||||||
Icon(
|
|
||||||
Icons.Outlined.ArrowBack,
|
|
||||||
contentDescription = stringResource(id = R.string.navigate_up_description)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
scrollBehavior = scrollBehavior
|
|
||||||
)
|
|
||||||
},
|
|
||||||
content = { padding ->
|
|
||||||
LazyColumn(contentPadding = padding) {
|
LazyColumn(contentPadding = padding) {
|
||||||
|
|
||||||
// GENERAL GROUP
|
// GENERAL GROUP
|
||||||
@ -182,8 +151,8 @@ fun SettingsScreen(
|
|||||||
) {}
|
) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to reset currently displayed dialog.
|
* Function to reset currently displayed dialog.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user