feat: 新增更换应用图标
This commit is contained in:
parent
6eef2fcf06
commit
033d7cafa5
|
|
@ -51,7 +51,8 @@ fun ListPref(
|
||||||
textColor: Color = MaterialTheme.colors.onBackground,
|
textColor: Color = MaterialTheme.colors.onBackground,
|
||||||
enabled: Boolean = true,
|
enabled: Boolean = true,
|
||||||
leadingIcon: @Composable (() -> Unit)? = null,
|
leadingIcon: @Composable (() -> Unit)? = null,
|
||||||
entries: Map<String, String> = mapOf(), //TODO: Change to List?
|
entries: Map<String, String> = emptyMap(), //TODO: Change to List?
|
||||||
|
icons: Map<String, @Composable () -> Unit> = emptyMap(),
|
||||||
) {
|
) {
|
||||||
val dialogState = rememberDialogState()
|
val dialogState = rememberDialogState()
|
||||||
val selectionKey = stringPreferencesKey(key)
|
val selectionKey = stringPreferencesKey(key)
|
||||||
|
|
@ -105,6 +106,7 @@ fun ListPref(
|
||||||
edit(current = value to title)
|
edit(current = value to title)
|
||||||
dismiss()
|
dismiss()
|
||||||
},
|
},
|
||||||
|
itemIcons = icons,
|
||||||
modifier = Modifier.padding(bottom = 16.dp)
|
modifier = Modifier.padding(bottom = 16.dp)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,14 @@
|
||||||
package com.huanchengfly.tieba.post.ui.page.settings.about
|
package com.huanchengfly.tieba.post.ui.page.settings.about
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.Image
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material.ButtonDefaults
|
import androidx.compose.material.ButtonDefaults
|
||||||
import androidx.compose.material.MaterialTheme
|
import androidx.compose.material.MaterialTheme
|
||||||
|
|
@ -13,7 +21,7 @@ import androidx.compose.ui.graphics.Color
|
||||||
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 coil.compose.AsyncImage
|
import com.google.accompanist.drawablepainter.rememberDrawablePainter
|
||||||
import com.google.accompanist.insets.ui.Scaffold
|
import com.google.accompanist.insets.ui.Scaffold
|
||||||
import com.huanchengfly.tieba.post.BuildConfig
|
import com.huanchengfly.tieba.post.BuildConfig
|
||||||
import com.huanchengfly.tieba.post.R
|
import com.huanchengfly.tieba.post.R
|
||||||
|
|
@ -48,8 +56,12 @@ fun AboutPage(
|
||||||
modifier = Modifier.weight(1f)
|
modifier = Modifier.weight(1f)
|
||||||
) {
|
) {
|
||||||
Column(modifier = Modifier.align(Alignment.Center)) {
|
Column(modifier = Modifier.align(Alignment.Center)) {
|
||||||
AsyncImage(
|
Image(
|
||||||
model = R.mipmap.ic_launcher_new,
|
painter = rememberDrawablePainter(
|
||||||
|
drawable = LocalContext.current.getDrawable(
|
||||||
|
R.mipmap.ic_launcher_new
|
||||||
|
)
|
||||||
|
),
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
modifier = Modifier.size(100.dp)
|
modifier = Modifier.size(100.dp)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,17 @@
|
||||||
package com.huanchengfly.tieba.post.ui.page.settings.custom
|
package com.huanchengfly.tieba.post.ui.page.settings.custom
|
||||||
|
|
||||||
|
import androidx.compose.foundation.Image
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.material.ExperimentalMaterialApi
|
import androidx.compose.material.ExperimentalMaterialApi
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.outlined.*
|
import androidx.compose.material.icons.outlined.Apps
|
||||||
|
import androidx.compose.material.icons.outlined.Brightness2
|
||||||
|
import androidx.compose.material.icons.outlined.BrightnessAuto
|
||||||
|
import androidx.compose.material.icons.outlined.Explore
|
||||||
|
import androidx.compose.material.icons.outlined.FontDownload
|
||||||
|
import androidx.compose.material.icons.outlined.ViewAgenda
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
|
@ -12,6 +19,7 @@ import androidx.compose.ui.graphics.Color
|
||||||
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.google.accompanist.drawablepainter.rememberDrawablePainter
|
||||||
import com.huanchengfly.tieba.post.R
|
import com.huanchengfly.tieba.post.R
|
||||||
import com.huanchengfly.tieba.post.activities.AppFontSizeActivity
|
import com.huanchengfly.tieba.post.activities.AppFontSizeActivity
|
||||||
import com.huanchengfly.tieba.post.dataStore
|
import com.huanchengfly.tieba.post.dataStore
|
||||||
|
|
@ -21,7 +29,12 @@ import com.huanchengfly.tieba.post.ui.common.prefs.widgets.ListPref
|
||||||
import com.huanchengfly.tieba.post.ui.common.prefs.widgets.SwitchPref
|
import com.huanchengfly.tieba.post.ui.common.prefs.widgets.SwitchPref
|
||||||
import com.huanchengfly.tieba.post.ui.common.prefs.widgets.TextPref
|
import com.huanchengfly.tieba.post.ui.common.prefs.widgets.TextPref
|
||||||
import com.huanchengfly.tieba.post.ui.page.settings.LeadingIcon
|
import com.huanchengfly.tieba.post.ui.page.settings.LeadingIcon
|
||||||
import com.huanchengfly.tieba.post.ui.widgets.compose.*
|
import com.huanchengfly.tieba.post.ui.widgets.compose.AvatarIcon
|
||||||
|
import com.huanchengfly.tieba.post.ui.widgets.compose.BackNavigationIcon
|
||||||
|
import com.huanchengfly.tieba.post.ui.widgets.compose.MyScaffold
|
||||||
|
import com.huanchengfly.tieba.post.ui.widgets.compose.Sizes
|
||||||
|
import com.huanchengfly.tieba.post.ui.widgets.compose.TitleCentredToolbar
|
||||||
|
import com.huanchengfly.tieba.post.utils.AppIconUtil
|
||||||
import com.huanchengfly.tieba.post.utils.ThemeUtil
|
import com.huanchengfly.tieba.post.utils.ThemeUtil
|
||||||
import com.ramcosta.composedestinations.annotation.Destination
|
import com.ramcosta.composedestinations.annotation.Destination
|
||||||
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
|
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
|
||||||
|
|
@ -89,6 +102,64 @@ fun CustomSettingsPage(
|
||||||
useSelectedAsSummary = true,
|
useSelectedAsSummary = true,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
prefsItem {
|
||||||
|
ListPref(
|
||||||
|
key = "app_icon",
|
||||||
|
title = stringResource(id = R.string.settings_app_icon),
|
||||||
|
defaultValue = com.huanchengfly.tieba.post.utils.Icons.DEFAULT_ICON,
|
||||||
|
leadingIcon = {
|
||||||
|
LeadingIcon {
|
||||||
|
AvatarIcon(
|
||||||
|
icon = Icons.Outlined.Apps,
|
||||||
|
size = Sizes.Small,
|
||||||
|
contentDescription = null,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
entries = mapOf(
|
||||||
|
com.huanchengfly.tieba.post.utils.Icons.NEW_ICON to "新图标",
|
||||||
|
com.huanchengfly.tieba.post.utils.Icons.NEW_ICON_INVERT to "新图标(反色)",
|
||||||
|
com.huanchengfly.tieba.post.utils.Icons.OLD_ICON to "旧图标",
|
||||||
|
),
|
||||||
|
icons = mapOf(
|
||||||
|
com.huanchengfly.tieba.post.utils.Icons.NEW_ICON to {
|
||||||
|
Image(
|
||||||
|
painter = rememberDrawablePainter(
|
||||||
|
drawable = LocalContext.current.getDrawable(
|
||||||
|
R.drawable.ic_launcher_new_round
|
||||||
|
)
|
||||||
|
),
|
||||||
|
contentDescription = "新图标",
|
||||||
|
modifier = Modifier.size(Sizes.Medium)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
com.huanchengfly.tieba.post.utils.Icons.NEW_ICON_INVERT to {
|
||||||
|
Image(
|
||||||
|
painter = rememberDrawablePainter(
|
||||||
|
drawable = LocalContext.current.getDrawable(
|
||||||
|
R.drawable.ic_launcher_new_invert_round
|
||||||
|
)
|
||||||
|
),
|
||||||
|
contentDescription = "新图标(反色)",
|
||||||
|
modifier = Modifier.size(Sizes.Medium)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
com.huanchengfly.tieba.post.utils.Icons.OLD_ICON to {
|
||||||
|
Image(
|
||||||
|
painter = rememberDrawablePainter(
|
||||||
|
drawable = LocalContext.current.getDrawable(
|
||||||
|
R.drawable.ic_launcher_round
|
||||||
|
)
|
||||||
|
),
|
||||||
|
contentDescription = "旧图标",
|
||||||
|
modifier = Modifier.size(Sizes.Medium)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
),
|
||||||
|
onValueChange = { AppIconUtil.setIcon(it) },
|
||||||
|
useSelectedAsSummary = true,
|
||||||
|
)
|
||||||
|
}
|
||||||
prefsItem {
|
prefsItem {
|
||||||
SwitchPref(
|
SwitchPref(
|
||||||
key = "follow_system_night",
|
key = "follow_system_night",
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.huanchengfly.tieba.post.ui.widgets.compose.picker
|
||||||
|
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
|
|
@ -28,6 +29,7 @@ fun <ItemValue> ListSinglePicker(
|
||||||
itemValues: List<ItemValue>,
|
itemValues: List<ItemValue>,
|
||||||
selectedPosition: Int,
|
selectedPosition: Int,
|
||||||
onItemSelected: (position: Int, title: String, value: ItemValue, changed: Boolean) -> Unit,
|
onItemSelected: (position: Int, title: String, value: ItemValue, changed: Boolean) -> Unit,
|
||||||
|
itemIcons: Map<ItemValue, @Composable () -> Unit> = emptyMap(),
|
||||||
selectedIndicator: @Composable () -> Unit = {
|
selectedIndicator: @Composable () -> Unit = {
|
||||||
Icon(
|
Icon(
|
||||||
imageVector = Icons.Rounded.Check,
|
imageVector = Icons.Rounded.Check,
|
||||||
|
|
@ -57,8 +59,11 @@ fun <ItemValue> ListSinglePicker(
|
||||||
it != selectedPosition
|
it != selectedPosition
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
.padding(vertical = 16.dp, horizontal = 24.dp)
|
.padding(vertical = 16.dp, horizontal = 24.dp),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(16.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
|
(itemIcons.getOrDefault(itemValues[it]) {}).invoke()
|
||||||
ProvideContentColor(
|
ProvideContentColor(
|
||||||
color = if (selected) colors.selectedItemColor(enabled).value else colors.itemColor(
|
color = if (selected) colors.selectedItemColor(enabled).value else colors.itemColor(
|
||||||
enabled
|
enabled
|
||||||
|
|
|
||||||
|
|
@ -615,4 +615,5 @@
|
||||||
<string name="hot_thread_rank_rule">(按内容热度排序,每小时更新一次)</string>
|
<string name="hot_thread_rank_rule">(按内容热度排序,每小时更新一次)</string>
|
||||||
<string name="tab_all_hot_thread">总榜</string>
|
<string name="tab_all_hot_thread">总榜</string>
|
||||||
<string name="hot_num">热度 %s</string>
|
<string name="hot_num">热度 %s</string>
|
||||||
|
<string name="settings_app_icon">应用图标</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue