From 413f072b8627672884e127dcb194cb5561205ead Mon Sep 17 00:00:00 2001 From: singleNeuron Date: Sun, 26 Dec 2021 17:38:55 +0800 Subject: [PATCH] Add new styles for setting (#1204) Signed-off-by: singleNeuron --- .../qn_kernel/tlb/ActivityRouter.kt | 14 ++++- .../ui/activity/Material3Activity.kt | 54 +++++++++++++++++++ .../qn_kernel/ui/activity/MaterialActivity.kt | 54 +++++++++++++++++++ libs/FerredoxinUI | 2 +- 4 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/me/singleneuron/qn_kernel/ui/activity/Material3Activity.kt create mode 100644 app/src/main/java/me/singleneuron/qn_kernel/ui/activity/MaterialActivity.kt diff --git a/app/src/main/java/me/singleneuron/qn_kernel/tlb/ActivityRouter.kt b/app/src/main/java/me/singleneuron/qn_kernel/tlb/ActivityRouter.kt index 1ec9dba6..98e6d5d2 100644 --- a/app/src/main/java/me/singleneuron/qn_kernel/tlb/ActivityRouter.kt +++ b/app/src/main/java/me/singleneuron/qn_kernel/tlb/ActivityRouter.kt @@ -31,6 +31,8 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch import me.ketal.data.ConfigData +import me.singleneuron.qn_kernel.ui.activity.Material3Activity +import me.singleneuron.qn_kernel.ui.activity.MaterialActivity import me.singleneuron.qn_kernel.ui.activity.NewSettingsActivity import me.singleneuron.qn_kernel.ui.activity.SettingActivity import nil.nadph.qnotified.R @@ -51,7 +53,7 @@ object ActivityRouter : UiChangeableItemFactory() { override var onClickListener: (Activity) -> Boolean = { MaterialAlertDialogBuilder(it, R.style.MaterialDialog) .setTitle("选择设置界面样式") - .setItems(arrayOf("QQ主题", "关怀模式")) { _: DialogInterface, i: Int -> + .setItems(arrayOf("QQ主题", "关怀模式", "Android Classic", "Material You")) { _: DialogInterface, i: Int -> when (i) { 0 -> { value.value = "QQ主题" @@ -61,6 +63,14 @@ object ActivityRouter : UiChangeableItemFactory() { value.value = "关怀模式" it.startActivity(Intent(it, SettingActivity::class.java)) } + 2 -> { + value.value = "Android Classic" + it.startActivity(Intent(it, MaterialActivity::class.java)) + } + 3 -> { + value.value = "Material You" + it.startActivity(Intent(it, Material3Activity::class.java)) + } } } .create() @@ -72,6 +82,8 @@ object ActivityRouter : UiChangeableItemFactory() { return when (value.value) { "QQ主题" -> NewSettingsActivity::class.java "关怀模式" -> SettingActivity::class.java + "Android Classic" -> MaterialActivity::class.java + "Material You" -> Material3Activity::class.java else -> NewSettingsActivity::class.java } } diff --git a/app/src/main/java/me/singleneuron/qn_kernel/ui/activity/Material3Activity.kt b/app/src/main/java/me/singleneuron/qn_kernel/ui/activity/Material3Activity.kt new file mode 100644 index 00000000..c8f43de9 --- /dev/null +++ b/app/src/main/java/me/singleneuron/qn_kernel/ui/activity/Material3Activity.kt @@ -0,0 +1,54 @@ +/* + * QNotified - An Xposed module for QQ/TIM + * Copyright (C) 2019-2021 dmca@ioctl.cc + * https://github.com/ferredoxin/QNotified + * + * This software is non-free but opensource software: you can redistribute it + * and/or modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation; either + * version 3 of the License, or any later version and our eula as published + * by ferredoxin. + * + * This software 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * and eula along with this software. If not, see + * + * . + */ + +package me.singleneuron.qn_kernel.ui.activity + +import android.os.Bundle +import androidx.appcompat.app.AppCompatDelegate +import androidx.preference.PreferenceFragmentCompat +import me.singleneuron.qn_kernel.tlb.UiTable +import nil.nadph.qnotified.ui.ResUtils +import nil.nadph.qnotified.util.Utils +import org.ferredoxin.ferredoxinui.common.activity.MaterialSettingActivity +import org.ferredoxin.ferredoxinui.common.base.TitleAble +import org.ferredoxin.ferredoxinui.common.fragment.MaterialSettingFragment + +class Material3Activity : MaterialSettingActivity() where T : PreferenceFragmentCompat, T : TitleAble { + + override val fragment: T = MaterialSettingFragment().setUiScreen(UiTable.second) as T + override val theme: MaterialTheme = MaterialTheme.You + + private val mLoader by lazy { this::class.java.classLoader } + + override fun getClassLoader() = mLoader!! + + override fun onCreate(savedInstanceState: Bundle?) { + runCatching { + AppCompatDelegate.setDefaultNightMode( + if (ResUtils.isInNightMode()) AppCompatDelegate.MODE_NIGHT_YES else AppCompatDelegate.MODE_NIGHT_NO) + }.onFailure { + Utils.log(it) + } + super.onCreate(savedInstanceState) + } + +} diff --git a/app/src/main/java/me/singleneuron/qn_kernel/ui/activity/MaterialActivity.kt b/app/src/main/java/me/singleneuron/qn_kernel/ui/activity/MaterialActivity.kt new file mode 100644 index 00000000..38e13051 --- /dev/null +++ b/app/src/main/java/me/singleneuron/qn_kernel/ui/activity/MaterialActivity.kt @@ -0,0 +1,54 @@ +/* + * QNotified - An Xposed module for QQ/TIM + * Copyright (C) 2019-2021 dmca@ioctl.cc + * https://github.com/ferredoxin/QNotified + * + * This software is non-free but opensource software: you can redistribute it + * and/or modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation; either + * version 3 of the License, or any later version and our eula as published + * by ferredoxin. + * + * This software 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * and eula along with this software. If not, see + * + * . + */ + +package me.singleneuron.qn_kernel.ui.activity + +import android.os.Bundle +import androidx.appcompat.app.AppCompatDelegate +import androidx.preference.PreferenceFragmentCompat +import me.singleneuron.qn_kernel.tlb.UiTable +import nil.nadph.qnotified.ui.ResUtils +import nil.nadph.qnotified.util.Utils +import org.ferredoxin.ferredoxinui.common.activity.MaterialSettingActivity +import org.ferredoxin.ferredoxinui.common.base.TitleAble +import org.ferredoxin.ferredoxinui.common.fragment.MaterialSettingFragment + +class MaterialActivity : MaterialSettingActivity() where T : PreferenceFragmentCompat, T : TitleAble { + + override val fragment: T = MaterialSettingFragment().setUiScreen(UiTable.second) as T + override val theme: MaterialTheme = MaterialTheme.Classic + + private val mLoader by lazy { this::class.java.classLoader } + + override fun getClassLoader() = mLoader!! + + override fun onCreate(savedInstanceState: Bundle?) { + runCatching { + AppCompatDelegate.setDefaultNightMode( + if (ResUtils.isInNightMode()) AppCompatDelegate.MODE_NIGHT_YES else AppCompatDelegate.MODE_NIGHT_NO) + }.onFailure { + Utils.log(it) + } + super.onCreate(savedInstanceState) + } + +} diff --git a/libs/FerredoxinUI b/libs/FerredoxinUI index 0f4f0bb7..f9498e18 160000 --- a/libs/FerredoxinUI +++ b/libs/FerredoxinUI @@ -1 +1 @@ -Subproject commit 0f4f0bb7b0328a22124e57b66289f36f346a7c22 +Subproject commit f9498e18c80dbef7f580e75524737d429a1045cf