diff --git a/app/src/main/java/com/sadellie/unitto/screens/about/AboutScreen.kt b/app/src/main/java/com/sadellie/unitto/screens/about/AboutScreen.kt index 4d4cf028..e707d0a7 100644 --- a/app/src/main/java/com/sadellie/unitto/screens/about/AboutScreen.kt +++ b/app/src/main/java/com/sadellie/unitto/screens/about/AboutScreen.kt @@ -18,7 +18,6 @@ package com.sadellie.unitto.screens.about -import androidx.compose.animation.rememberSplineBasedDecay import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement 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.lazy.LazyColumn 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.OutlinedCard -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.Stable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import com.sadellie.unitto.R import com.sadellie.unitto.data.ALL_LIBRARIES +import com.sadellie.unitto.screens.common.UnittoLargeTopAppBar import com.sadellie.unitto.screens.openLink @@ -61,27 +52,10 @@ fun AboutScreen( navigateUpAction: () -> Unit = {} ) { val mContext = LocalContext.current - val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior(rememberSplineBasedDecay(), rememberTopAppBarScrollState()) - Scaffold( - modifier = Modifier - .nestedScroll(scrollBehavior.nestedScrollConnection), - 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 - ) - }, + UnittoLargeTopAppBar( + title = stringResource(id = R.string.third_party_licenses), + navigateUpAction = navigateUpAction ) { padding -> LazyColumn( Modifier.padding(horizontal = 16.dp), diff --git a/app/src/main/java/com/sadellie/unitto/screens/common/UnittoLargeTopAppBar.kt b/app/src/main/java/com/sadellie/unitto/screens/common/UnittoLargeTopAppBar.kt new file mode 100644 index 00000000..c42a1574 --- /dev/null +++ b/app/src/main/java/com/sadellie/unitto/screens/common/UnittoLargeTopAppBar.kt @@ -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 . + */ + +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 + ) +} diff --git a/app/src/main/java/com/sadellie/unitto/screens/setttings/SettingsScreen.kt b/app/src/main/java/com/sadellie/unitto/screens/setttings/SettingsScreen.kt index 0d37875d..33cbaec3 100644 --- a/app/src/main/java/com/sadellie/unitto/screens/setttings/SettingsScreen.kt +++ b/app/src/main/java/com/sadellie/unitto/screens/setttings/SettingsScreen.kt @@ -19,34 +19,24 @@ package com.sadellie.unitto.screens.setttings import android.os.Build -import androidx.compose.animation.rememberSplineBasedDecay 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.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.saveable.rememberSaveable 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.res.stringResource import com.sadellie.unitto.BuildConfig import com.sadellie.unitto.R 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.OUTPUT_FORMAT import com.sadellie.unitto.data.preferences.PRECISIONS import com.sadellie.unitto.data.preferences.SEPARATORS import com.sadellie.unitto.screens.MainViewModel +import com.sadellie.unitto.screens.common.UnittoLargeTopAppBar import com.sadellie.unitto.screens.openLink import com.sadellie.unitto.screens.setttings.components.AlertDialogWithList import com.sadellie.unitto.screens.setttings.components.SettingsHeader @@ -59,131 +49,110 @@ fun SettingsScreen( navControllerAction: (String) -> Unit ) { val mContext = LocalContext.current - // Scrollable - val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior( - rememberSplineBasedDecay(), - rememberTopAppBarScrollState() - ) var dialogState: DialogState by rememberSaveable { mutableStateOf(DialogState.NONE) } - Scaffold( - modifier = Modifier - .nestedScroll(scrollBehavior.nestedScrollConnection), - topBar = { - 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) { + UnittoLargeTopAppBar( + title = stringResource(id = R.string.settings_screen), + navigateUpAction = navigateUpAction + ) { padding -> + LazyColumn(contentPadding = padding) { - // GENERAL GROUP - item { SettingsHeader(stringResource(R.string.general_settings_group)) } + // GENERAL 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 { 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 { - 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 - ) {} + 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 + ) {} + } + } + } + /** * Function to reset currently displayed dialog.