diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ec83e0b6..86a433c8 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -166,8 +166,7 @@ - + + + + + + + + + + + = Build.VERSION_CODES.S) { + prefsItem { + val supportThemedIcons = remember { + persistentListOf( + LauncherIcons.NEW_ICON, +// LauncherIcons.NEW_ICON_INVERT, + ) + } + val currentLauncherIcon by rememberPreferenceAsState( + key = stringPreferencesKey("app_icon"), + defaultValue = LauncherIcons.NEW_ICON + ) + val isCurrentSupportThemedIcon by remember { + derivedStateOf { + supportThemedIcons.contains(currentLauncherIcon) + } + } + SwitchPref( + key = "useThemedIcon", + title = stringResource(id = R.string.title_settings_use_themed_icon), + defaultChecked = false, + enabled = isCurrentSupportThemedIcon, + leadingIcon = { + LeadingIcon { + AvatarIcon( + icon = Icons.Outlined.ColorLens, + size = Sizes.Small, + contentDescription = null, + ) + } + }, + onCheckedChange = { + AppIconUtil.setIcon(isThemed = it) + }, + summary = stringResource(id = R.string.tip_settings_use_themed_icon_summary_not_supported).takeUnless { isCurrentSupportThemedIcon }, + ) + } + } prefsItem { SwitchPref( key = "follow_system_night", diff --git a/app/src/main/java/com/huanchengfly/tieba/post/utils/AppIconUtil.kt b/app/src/main/java/com/huanchengfly/tieba/post/utils/AppIconUtil.kt index 8aea70aa..8a55a183 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/utils/AppIconUtil.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/utils/AppIconUtil.kt @@ -4,17 +4,24 @@ import android.content.ComponentName import android.content.Context import android.content.pm.PackageManager import com.huanchengfly.tieba.post.App +import kotlinx.collections.immutable.persistentListOf -object Icons { +object LauncherIcons { const val NEW_ICON = "com.huanchengfly.tieba.post.MainActivityV2" + const val NEW_ICON_THEMED = "com.huanchengfly.tieba.post.MainActivityIconThemed" const val NEW_ICON_INVERT = "com.huanchengfly.tieba.post.MainActivityIconInvert" const val OLD_ICON = "com.huanchengfly.tieba.post.MainActivityIconOld" const val DISABLE = "com.huanchengfly.tieba.post.MainActivityV2Disabled" const val DEFAULT_ICON = NEW_ICON - val ICONS = listOf(NEW_ICON, NEW_ICON_INVERT, OLD_ICON) + val ICONS = persistentListOf(NEW_ICON, NEW_ICON_THEMED, NEW_ICON_INVERT, OLD_ICON) + + val SUPPORT_THEMED_ICON = persistentListOf(NEW_ICON) + val THEMED_ICON_MAPPING = mapOf( + NEW_ICON to NEW_ICON_THEMED, + ) } object AppIconUtil { @@ -26,11 +33,18 @@ object AppIconUtil { private val appPreferences: AppPreferencesUtils get() = context.appPreferences - fun setIcon(icon: String = appPreferences.appIcon ?: Icons.NEW_ICON) { - val newIcon = if (Icons.ICONS.contains(icon) || icon == Icons.DISABLE) { + fun setIcon( + icon: String = appPreferences.appIcon ?: LauncherIcons.NEW_ICON, + isThemed: Boolean = appPreferences.useThemedIcon, + ) { + val useThemedIcon = isThemed && LauncherIcons.SUPPORT_THEMED_ICON.contains(icon) + var newIcon = if (LauncherIcons.ICONS.contains(icon) || icon == LauncherIcons.DISABLE) { icon - } else Icons.DEFAULT_ICON - Icons.ICONS.forEach { + } else LauncherIcons.DEFAULT_ICON + if (useThemedIcon) { + newIcon = LauncherIcons.THEMED_ICON_MAPPING[newIcon] ?: newIcon + } + LauncherIcons.ICONS.forEach { if (it == newIcon) { context.packageManager.enableComponent(ComponentName(context, it)) } else { diff --git a/app/src/main/java/com/huanchengfly/tieba/post/utils/AppPreferencesUtils.kt b/app/src/main/java/com/huanchengfly/tieba/post/utils/AppPreferencesUtils.kt index ebc23572..4fd90522 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/utils/AppPreferencesUtils.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/utils/AppPreferencesUtils.kt @@ -53,10 +53,12 @@ open class AppPreferencesUtils private constructor(ctx: Context) { var ignoreBatteryOptimizationsDialog by DataStoreDelegates.boolean(defaultValue = false) var appIcon by DataStoreDelegates.string( - defaultValue = Icons.DEFAULT_ICON, + defaultValue = LauncherIcons.DEFAULT_ICON, key = AppIconUtil.PREF_KEY_APP_ICON ) + var useThemedIcon by DataStoreDelegates.boolean(defaultValue = false) + var autoSign by DataStoreDelegates.boolean(defaultValue = false, key = "auto_sign") var autoSignTime by DataStoreDelegates.string( diff --git a/app/src/main/res/drawable/ic_launcher_new_themed_foreground.xml b/app/src/main/res/drawable/ic_launcher_new_themed_foreground.xml new file mode 100644 index 00000000..caeede45 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_new_themed_foreground.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_new_themed.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_new_themed.xml new file mode 100644 index 00000000..903ddba2 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_new_themed.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_new_themed_round.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_new_themed_round.xml new file mode 100644 index 00000000..903ddba2 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_new_themed_round.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v31/ic_launcher_new_themed.xml b/app/src/main/res/mipmap-anydpi-v31/ic_launcher_new_themed.xml new file mode 100644 index 00000000..661e1d4f --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v31/ic_launcher_new_themed.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v31/ic_launcher_new_themed_round.xml b/app/src/main/res/mipmap-anydpi-v31/ic_launcher_new_themed_round.xml new file mode 100644 index 00000000..661e1d4f --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v31/ic_launcher_new_themed_round.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_new_themed.png b/app/src/main/res/mipmap-hdpi/ic_launcher_new_themed.png new file mode 100644 index 00000000..c9b7c8aa Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_new_themed.png differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_new_themed_round.png b/app/src/main/res/mipmap-hdpi/ic_launcher_new_themed_round.png new file mode 100644 index 00000000..5cee10ee Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_new_themed_round.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_new_themed.png b/app/src/main/res/mipmap-mdpi/ic_launcher_new_themed.png new file mode 100644 index 00000000..4efe48e7 Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher_new_themed.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_new_themed_round.png b/app/src/main/res/mipmap-mdpi/ic_launcher_new_themed_round.png new file mode 100644 index 00000000..4efe48e7 Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher_new_themed_round.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_new_themed.png b/app/src/main/res/mipmap-xhdpi/ic_launcher_new_themed.png new file mode 100644 index 00000000..4efe48e7 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher_new_themed.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_new_themed_round.png b/app/src/main/res/mipmap-xhdpi/ic_launcher_new_themed_round.png new file mode 100644 index 00000000..4efe48e7 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher_new_themed_round.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_new_themed.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher_new_themed.png new file mode 100644 index 00000000..5cee10ee Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_new_themed.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_new_themed_round.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher_new_themed_round.png new file mode 100644 index 00000000..5cee10ee Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_new_themed_round.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_new_themed.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_new_themed.png new file mode 100644 index 00000000..feac3cfc Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_new_themed.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_new_themed_round.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_new_themed_round.png new file mode 100644 index 00000000..feac3cfc Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_new_themed_round.png differ diff --git a/app/src/main/res/values-v31/colors.xml b/app/src/main/res/values-v31/colors.xml new file mode 100644 index 00000000..44a093db --- /dev/null +++ b/app/src/main/res/values-v31/colors.xml @@ -0,0 +1,6 @@ + + + @android:color/system_accent1_600 + @android:color/system_accent1_300 + @android:color/system_accent1_600 + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 8cb6cf2d..60587001 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -4,6 +4,10 @@ #FFFFFFFF #FF2E60B0 + #FF5588D7 + #FFA7C5F0 + #FF538ACE + #FFFFFFFF #FF4477E0 #FFCCCCCC @@ -13,8 +17,6 @@ #99000000 #FEE9E9E9 - #00BFA5 - #C4C4C4 #FFF diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c7653de6..7cdff28a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -727,4 +727,6 @@ 夜间模式压暗缩略图 修改重启后生效 隐藏回贴入口 + 应用图标使用动态取色 + 当前正在使用的应用图标暂不支持动态取色