mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-19 00:35:26 +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,131 +49,110 @@ 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(
|
LazyColumn(contentPadding = padding) {
|
||||||
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) {
|
|
||||||
|
|
||||||
// GENERAL GROUP
|
// GENERAL GROUP
|
||||||
item { SettingsHeader(stringResource(R.string.general_settings_group)) }
|
item { SettingsHeader(stringResource(R.string.general_settings_group)) }
|
||||||
|
|
||||||
// PRECISION
|
// PRECISION
|
||||||
|
item {
|
||||||
|
SettingsListItem(
|
||||||
|
stringResource(R.string.precision_setting),
|
||||||
|
stringResource(R.string.precision_setting_support)
|
||||||
|
) { dialogState = DialogState.PRECISION }
|
||||||
|
}
|
||||||
|
|
||||||
|
// SEPARATOR
|
||||||
|
item {
|
||||||
|
SettingsListItem(
|
||||||
|
stringResource(R.string.separator_setting),
|
||||||
|
stringResource(R.string.separator_setting_support)
|
||||||
|
) { dialogState = DialogState.SEPARATOR }
|
||||||
|
}
|
||||||
|
|
||||||
|
// OUTPUT FORMAT
|
||||||
|
item {
|
||||||
|
SettingsListItem(
|
||||||
|
stringResource(R.string.output_format_setting),
|
||||||
|
stringResource(R.string.output_format_setting_support)
|
||||||
|
) { dialogState = DialogState.OUTPUT_FORMAT }
|
||||||
|
}
|
||||||
|
|
||||||
|
// THEME
|
||||||
|
item {
|
||||||
|
SettingsListItem(
|
||||||
|
stringResource(R.string.theme_setting),
|
||||||
|
stringResource(R.string.theme_setting_support)
|
||||||
|
) { dialogState = DialogState.THEME }
|
||||||
|
}
|
||||||
|
|
||||||
|
// CURRENCY RATE NOTE
|
||||||
|
item {
|
||||||
|
SettingsListItem(
|
||||||
|
stringResource(R.string.currency_rates_note_setting)
|
||||||
|
) { dialogState = DialogState.CURRENCY_RATE }
|
||||||
|
}
|
||||||
|
|
||||||
|
// ADDITIONAL GROUP
|
||||||
|
item { SettingsHeader(stringResource(R.string.additional_settings_group)) }
|
||||||
|
|
||||||
|
// TERMS AND CONDITIONS
|
||||||
|
item {
|
||||||
|
SettingsListItem(
|
||||||
|
stringResource(R.string.terms_and_conditions)
|
||||||
|
) { openLink(mContext, "http://sadellie.github.io/unitto/terms-app.html") }
|
||||||
|
}
|
||||||
|
|
||||||
|
// PRIVACY POLICY
|
||||||
|
item {
|
||||||
|
SettingsListItem(
|
||||||
|
stringResource(R.string.privacy_policy)
|
||||||
|
) { openLink(mContext, "http://sadellie.github.io/unitto/privacy-app.html") }
|
||||||
|
}
|
||||||
|
|
||||||
|
// ANALYTICS
|
||||||
|
item {
|
||||||
|
SettingsListItem(
|
||||||
|
stringResource(R.string.send_usage_statistics),
|
||||||
|
stringResource(R.string.send_usage_statistics_support),
|
||||||
|
mainViewModel.enableAnalytics
|
||||||
|
) { mainViewModel.updateEnableAnalytics(!it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
// THIRD PARTY
|
||||||
|
item {
|
||||||
|
SettingsListItem(
|
||||||
|
stringResource(R.string.third_party_licenses)
|
||||||
|
) { navControllerAction(ABOUT_SCREEN) }
|
||||||
|
}
|
||||||
|
|
||||||
|
// RATE THIS APP
|
||||||
|
if (BuildConfig.StoreLink.isNotEmpty()) {
|
||||||
item {
|
item {
|
||||||
SettingsListItem(
|
SettingsListItem(
|
||||||
stringResource(R.string.precision_setting),
|
stringResource(R.string.rate_this_app)
|
||||||
stringResource(R.string.precision_setting_support)
|
) { openLink(mContext, BuildConfig.StoreLink) }
|
||||||
) { dialogState = DialogState.PRECISION }
|
|
||||||
}
|
|
||||||
|
|
||||||
// SEPARATOR
|
|
||||||
item {
|
|
||||||
SettingsListItem(
|
|
||||||
stringResource(R.string.separator_setting),
|
|
||||||
stringResource(R.string.separator_setting_support)
|
|
||||||
) { dialogState = DialogState.SEPARATOR }
|
|
||||||
}
|
|
||||||
|
|
||||||
// OUTPUT FORMAT
|
|
||||||
item {
|
|
||||||
SettingsListItem(
|
|
||||||
stringResource(R.string.output_format_setting),
|
|
||||||
stringResource(R.string.output_format_setting_support)
|
|
||||||
) { dialogState = DialogState.OUTPUT_FORMAT }
|
|
||||||
}
|
|
||||||
|
|
||||||
// THEME
|
|
||||||
item {
|
|
||||||
SettingsListItem(
|
|
||||||
stringResource(R.string.theme_setting),
|
|
||||||
stringResource(R.string.theme_setting_support)
|
|
||||||
) { dialogState = DialogState.THEME }
|
|
||||||
}
|
|
||||||
|
|
||||||
// CURRENCY RATE NOTE
|
|
||||||
item {
|
|
||||||
SettingsListItem(
|
|
||||||
stringResource(R.string.currency_rates_note_setting)
|
|
||||||
) { dialogState = DialogState.CURRENCY_RATE }
|
|
||||||
}
|
|
||||||
|
|
||||||
// ADDITIONAL GROUP
|
|
||||||
item { SettingsHeader(stringResource(R.string.additional_settings_group)) }
|
|
||||||
|
|
||||||
// TERMS AND CONDITIONS
|
|
||||||
item {
|
|
||||||
SettingsListItem(
|
|
||||||
stringResource(R.string.terms_and_conditions)
|
|
||||||
) { openLink(mContext, "http://sadellie.github.io/unitto/terms-app.html") }
|
|
||||||
}
|
|
||||||
|
|
||||||
// PRIVACY POLICY
|
|
||||||
item {
|
|
||||||
SettingsListItem(
|
|
||||||
stringResource(R.string.privacy_policy)
|
|
||||||
) { openLink(mContext, "http://sadellie.github.io/unitto/privacy-app.html") }
|
|
||||||
}
|
|
||||||
|
|
||||||
// ANALYTICS
|
|
||||||
item {
|
|
||||||
SettingsListItem(
|
|
||||||
stringResource(R.string.send_usage_statistics),
|
|
||||||
stringResource(R.string.send_usage_statistics_support),
|
|
||||||
mainViewModel.enableAnalytics
|
|
||||||
) { mainViewModel.updateEnableAnalytics(!it) }
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIRD PARTY
|
|
||||||
item {
|
|
||||||
SettingsListItem(
|
|
||||||
stringResource(R.string.third_party_licenses)
|
|
||||||
) { navControllerAction(ABOUT_SCREEN) }
|
|
||||||
}
|
|
||||||
|
|
||||||
// RATE THIS APP
|
|
||||||
if (BuildConfig.StoreLink.isNotEmpty()) {
|
|
||||||
item {
|
|
||||||
SettingsListItem(
|
|
||||||
stringResource(R.string.rate_this_app)
|
|
||||||
) { openLink(mContext, BuildConfig.StoreLink) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// APP VERSION
|
|
||||||
item {
|
|
||||||
SettingsListItem(
|
|
||||||
label = stringResource(id = R.string.app_version_name_setting),
|
|
||||||
supportText = BuildConfig.VERSION_NAME
|
|
||||||
) {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
)
|
// APP VERSION
|
||||||
|
item {
|
||||||
|
SettingsListItem(
|
||||||
|
label = stringResource(id = R.string.app_version_name_setting),
|
||||||
|
supportText = BuildConfig.VERSION_NAME
|
||||||
|
) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to reset currently displayed dialog.
|
* Function to reset currently displayed dialog.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user