Skip to content

Commit

Permalink
feat(settings): move to top bar, add categories
Browse files Browse the repository at this point in the history
  • Loading branch information
aliernfrog authored Feb 24, 2024
1 parent 8c35edd commit ec72d2e
Show file tree
Hide file tree
Showing 39 changed files with 1,426 additions and 1,018 deletions.
65 changes: 57 additions & 8 deletions app/src/main/java/com/aliernfrog/pftool/Constant.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package com.aliernfrog.pftool

import android.os.Build
import android.os.Environment
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Translate
import com.aliernfrog.pftool.data.CreditsData
import com.aliernfrog.pftool.data.PrefEditItem
import com.aliernfrog.pftool.data.Social
import com.aliernfrog.pftool.util.staticutil.GeneralUtil
Expand All @@ -16,7 +19,6 @@ val externalStorageRoot = Environment.getExternalStorageDirectory().toString()+"
val supportsPerAppLanguagePreferences = Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
val folderPickerSupportsInitialUri = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
val hasAndroidDataRestrictions = Build.VERSION.SDK_INT >= Build.VERSION_CODES.R
val filesAppMightBlockAndroidData = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S

object ConfigKey {
const val PREF_NAME = "APP_CONFIG"
Expand All @@ -35,29 +37,76 @@ object ConfigKey {
}

object SettingsConstant {
val socials = listOf(
Social("Polyfield Discord", "https://discord.gg/X6WzGpCgDJ"),
Social("PF Tool GitHub", githubRepoURL),
Social("PF Tool Crowdin", crowdinURL)
)
val folders = listOf(
PrefEditItem(
labelResourceId = R.string.settings_general_folders_maps,
labelResourceId = R.string.settings_storage_folders_maps,
getValue = { it.pfMapsDir },
setValue = { newValue, prefs ->
prefs.pfMapsDir = newValue
},
default = ConfigKey.RECOMMENDED_MAPS_DIR
),
PrefEditItem(
labelResourceId = R.string.settings_general_folders_exportedMaps,
labelResourceId = R.string.settings_storage_folders_exportedMaps,
getValue = { it.exportedMapsDir },
setValue = { newValue, prefs ->
prefs.exportedMapsDir = newValue
},
default = ConfigKey.RECOMMENDED_EXPORTED_MAPS_DIR
)
)

val socials = listOf(
Social(
label = "Polyfield",
icon = R.drawable.discord,
url = "https://discord.gg/X6WzGpCgDJ"
),
Social(
label = "PF Tool",
icon = R.drawable.github,
url = githubRepoURL
),
Social(
label = "Crowdin",
icon = Icons.Default.Translate,
url = crowdinURL
)
)

val credits = listOf(
CreditsData(
name = "Mohammad Alizadeh",
description = R.string.settings_about_credits_pfDev,
url = "https://discord.gg/X6WzGpCgDJ"
),
CreditsData(
name = "alieRN",
description = R.string.settings_about_credits_pfToolDev,
url = "https://github.com/aliernfrog"
),
CreditsData(
name = "infini0083",
description = R.string.settings_about_credits_ui,
url = "https://github.com/infini0083"
),
CreditsData(
name = R.string.settings_about_credits_crowdin,
description = R.string.settings_about_credits_translations,
url = "https://crowdin.com/project/pf-tool"
),
CreditsData(
name = "Vendetta Manager",
description = R.string.settings_about_credits_inspiration,
url = "https://github.com/vendetta-mod/VendettaManager"
),
CreditsData(
name = "ReVanced Manager",
description = R.string.settings_about_credits_inspiration,
url = "https://github.com/ReVanced/revanced-manager"
)
)

val experimentalPrefOptions = listOf(
PrefEditItem(
labelResourceId = R.string.settings_experimental_updatesURL,
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/aliernfrog/pftool/data/CreditsData.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.aliernfrog.pftool.data

data class CreditsData(
val name: Any,
val description: Any,
val url: String
)
3 changes: 2 additions & 1 deletion app/src/main/java/com/aliernfrog/pftool/data/Social.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.aliernfrog.pftool.data

data class Social(
val name: String,
val label: String,
val icon: Any,
val url: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,26 @@ import com.aliernfrog.pftool.R
import com.aliernfrog.pftool.util.manager.PreferenceManager
import com.aliernfrog.pftool.util.staticutil.FileUtil

enum class FileManagementMethod(
enum class StorageAccessType(
@StringRes val label: Int,
@StringRes val description: Int,
val enable: (PreferenceManager) -> Unit
) {
SAF(
label = R.string.settings_general_fileManagementService_saf,
label = R.string.settings_storage_storageAccessType_saf,
description = R.string.settings_storage_storageAccessType_saf_description,
enable = {
it.fileManagementMethod = SAF.ordinal
it.storageAccessType = SAF.ordinal
it.pfMapsDir = FileUtil.getTreeUriForPath(it.pfMapsDir).toString()
it.exportedMapsDir = FileUtil.getTreeUriForPath(it.exportedMapsDir).toString()
}
),

SHIZUKU(
label = R.string.settings_general_fileManagementService_shizuku,
label = R.string.settings_storage_storageAccessType_shizuku,
description = R.string.settings_storage_storageAccessType_shizuku_description,
enable = {
it.fileManagementMethod = SHIZUKU.ordinal
it.storageAccessType = SHIZUKU.ordinal
it.pfMapsDir = FileUtil.getFilePath(it.pfMapsDir) ?: ConfigKey.RECOMMENDED_MAPS_DIR
it.exportedMapsDir = FileUtil.getFilePath(it.exportedMapsDir) ?: ConfigKey.RECOMMENDED_EXPORTED_MAPS_DIR
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import com.aliernfrog.pftool.R
fun AppScaffold(
topBar: @Composable (scrollBehavior: TopAppBarScrollBehavior) -> Unit,
topAppBarState: TopAppBarState = TopAppBarState(0F,0F,0F),
scrollBehavior: TopAppBarScrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior(topAppBarState),
floatingActionButton: @Composable () -> Unit = {},
content: @Composable () -> Unit
) {
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior(topAppBarState)
Scaffold(
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
topBar = { topBar(scrollBehavior) },
Expand Down Expand Up @@ -62,4 +62,32 @@ fun AppTopBar(
},
actions = actions
)
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AppSmallTopBar(
title: String,
scrollBehavior: TopAppBarScrollBehavior,
actions: @Composable RowScope.() -> Unit = {},
colors: TopAppBarColors = TopAppBarDefaults.largeTopAppBarColors(),
navigationIcon: ImageVector = Icons.AutoMirrored.Rounded.ArrowBack,
onNavigationClick: (() -> Unit)? = null
) {
TopAppBar(
title = { Text(title) },
scrollBehavior = scrollBehavior,
colors = colors,
navigationIcon = {
onNavigationClick?.let {
IconButton(onClick = it) {
Icon(
imageVector = navigationIcon,
contentDescription = stringResource(R.string.action_back)
)
}
}
},
actions = actions
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ import androidx.compose.animation.slideOutVertically
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.calculateEndPadding
import androidx.compose.foundation.layout.calculateStartPadding
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Badge
import androidx.compose.material3.BadgedBox
import androidx.compose.material3.BottomAppBar
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.NavigationBarItem
Expand All @@ -41,7 +38,6 @@ import androidx.compose.ui.draw.scale
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.Dp
Expand All @@ -62,15 +58,15 @@ fun BaseScaffold(
) {
val context = LocalContext.current
val density = LocalDensity.current
val layoutDirection = LocalLayoutDirection.current

val destinations = remember { Destination.entries.toList() }
val mainDestinations = remember { destinations.filter { it.showInNavigationBar } }
val currentRoute = navController.currentBackStackEntryAsState().value?.destination?.route
val currentDestination = destinations.find { it.route == currentRoute }

val windowSizeClass = calculateWindowSizeClass(context as Activity)
val showNavigationRail = currentDestination?.showNavigationBar != false && windowSizeClass.widthSizeClass != WindowWidthSizeClass.Compact
val showNavigationRail: Boolean? = if (mainDestinations.size <= 1) null
else currentDestination?.showNavigationBar != false && windowSizeClass.widthSizeClass != WindowWidthSizeClass.Compact
var sideBarWidth by remember { mutableStateOf(0.dp) }

fun isDestinationSelected(destination: Destination): Boolean {
Expand All @@ -92,10 +88,10 @@ fun BaseScaffold(
modifier = Modifier
.background(MaterialTheme.colorScheme.surface)
.padding(
start = if (showNavigationRail) sideBarWidth else 0.dp
start = if (showNavigationRail == true) sideBarWidth else 0.dp
),
bottomBar = {
if (!showNavigationRail) BottomBar(
if (showNavigationRail == false) BottomBar(
destinations = mainDestinations,
currentDestination = currentDestination,
isDestinationSelected = ::isDestinationSelected,
Expand All @@ -104,17 +100,10 @@ fun BaseScaffold(
},
contentWindowInsets = WindowInsets(0, 0, 0, 0)
) {
val paddingValues = if (showNavigationRail || currentDestination?.showNavigationBar != false) it
else PaddingValues(
start = it.calculateStartPadding(layoutDirection),
top = it.calculateTopPadding(),
end = it.calculateEndPadding(layoutDirection),
bottom = 0.dp
)
content(paddingValues)
content(it)
}

if (showNavigationRail) SideBarRail(
if (showNavigationRail == true) SideBarRail(
destinations = mainDestinations,
currentDestination = currentDestination,
isDestinationSelected = ::isDestinationSelected,
Expand Down Expand Up @@ -203,7 +192,6 @@ private fun SideBarRail(
}
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun NavigationItemIcon(
destination: Destination,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.aliernfrog.pftool.ui.component

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material3.Badge
import androidx.compose.material3.BadgedBox
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import com.aliernfrog.pftool.R
import com.aliernfrog.pftool.util.Destination

@Composable
fun SettingsButton(
modifier: Modifier = Modifier,
onClick: () -> Unit
) {
val hasNotification = Destination.SETTINGS.hasNotification.value

@Composable
fun SettingsIcon() {
Icon(
imageVector = Icons.Default.Settings,
contentDescription = stringResource(R.string.settings)
)
}

IconButton(
modifier = modifier,
onClick = {
onClick()
Destination.SETTINGS.hasNotification.value = false
}
) {
if (hasNotification) BadgedBox(
badge = { Badge() }
) {
SettingsIcon()
}
else SettingsIcon()
}
}
Loading

0 comments on commit ec72d2e

Please sign in to comment.