Remove Theme screen and related dead code

Theme selection is no longer needed with Compose theming. Remove
ThemeFragment, ThemeViewModel, DarkThemeDialog, TappableHeadlineItem,
and associated XML layouts. Remove theme navigation from Settings.

Made-with: Cursor
This commit is contained in:
LoveSy
2026-03-03 12:57:47 +08:00
committed by topjohnwu
parent 08d0b9be27
commit e000607d71
11 changed files with 0 additions and 492 deletions
@@ -1,41 +0,0 @@
package com.topjohnwu.magisk.dialog
import android.app.Activity
import androidx.appcompat.app.AppCompatDelegate
import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.arch.UIActivity
import com.topjohnwu.magisk.core.Config
import com.topjohnwu.magisk.events.DialogBuilder
import com.topjohnwu.magisk.view.MagiskDialog
import com.topjohnwu.magisk.core.R as CoreR
class DarkThemeDialog : DialogBuilder {
override fun build(dialog: MagiskDialog) {
val activity = dialog.ownerActivity!!
dialog.apply {
setTitle(CoreR.string.settings_dark_mode_title)
setMessage(CoreR.string.settings_dark_mode_message)
setButton(MagiskDialog.ButtonType.POSITIVE) {
text = CoreR.string.settings_dark_mode_light
icon = R.drawable.ic_day
onClick { selectTheme(AppCompatDelegate.MODE_NIGHT_NO, activity) }
}
setButton(MagiskDialog.ButtonType.NEUTRAL) {
text = CoreR.string.settings_dark_mode_system
icon = R.drawable.ic_day_night
onClick { selectTheme(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM, activity) }
}
setButton(MagiskDialog.ButtonType.NEGATIVE) {
text = CoreR.string.settings_dark_mode_dark
icon = R.drawable.ic_night
onClick { selectTheme(AppCompatDelegate.MODE_NIGHT_YES, activity) }
}
}
}
private fun selectTheme(mode: Int, activity: Activity) {
Config.darkTheme = mode
(activity as UIActivity<*>).delegate.localNightMode = mode
}
}
@@ -78,11 +78,6 @@ private fun CustomizationSection(viewModel: SettingsViewModel) {
SmallTitle(text = stringResource(CoreR.string.settings_customization))
Card(modifier = Modifier.fillMaxWidth()) {
SuperArrow(
title = stringResource(CoreR.string.section_theme),
onClick = { viewModel.navigateToTheme() }
)
if (LocaleSetting.useLocaleManager) {
val locale = LocaleSetting.instance.appLocale
val summary = locale?.getDisplayName(locale) ?: stringResource(CoreR.string.system_default)
@@ -27,10 +27,6 @@ class SettingsViewModel : BaseViewModel() {
val zygiskMismatch get() = Config.zygisk != Info.isZygiskEnabled
fun navigateToTheme() {
SettingsFragmentDirections.actionSettingsFragmentToThemeFragment().navigate()
}
fun navigateToDenyList() {
SettingsFragmentDirections.actionSettingsFragmentToDenyFragment().navigate()
}
@@ -1,68 +0,0 @@
package com.topjohnwu.magisk.ui.theme
import android.os.Bundle
import android.view.ContextThemeWrapper
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import com.topjohnwu.magisk.BR
import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.arch.BaseFragment
import com.topjohnwu.magisk.arch.viewModel
import com.topjohnwu.magisk.databinding.FragmentThemeMd2Binding
import com.topjohnwu.magisk.databinding.ItemThemeBindingImpl
import com.topjohnwu.magisk.core.R as CoreR
class ThemeFragment : BaseFragment<FragmentThemeMd2Binding>() {
override val layoutRes = R.layout.fragment_theme_md2
override val viewModel by viewModel<ThemeViewModel>()
private fun <T> Array<T>.paired(): List<Pair<T, T?>> {
val iterator = iterator()
if (!iterator.hasNext()) return emptyList()
val result = mutableListOf<Pair<T, T?>>()
while (iterator.hasNext()) {
val a = iterator.next()
val b = if (iterator.hasNext()) iterator.next() else null
result.add(a to b)
}
return result
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
super.onCreateView(inflater, container, savedInstanceState)
for ((a, b) in Theme.values().paired()) {
val c = inflater.inflate(R.layout.item_theme_container, null, false)
val left = c.findViewById<FrameLayout>(R.id.left)
val right = c.findViewById<FrameLayout>(R.id.right)
for ((theme, view) in listOf(a to left, b to right)) {
theme ?: continue
val themed = ContextThemeWrapper(activity, theme.themeRes)
ItemThemeBindingImpl.inflate(LayoutInflater.from(themed), view, true).also {
it.setVariable(BR.viewModel, viewModel)
it.setVariable(BR.theme, theme)
it.lifecycleOwner = viewLifecycleOwner
}
}
binding.themeContainer.addView(c)
}
return binding.root
}
override fun onStart() {
super.onStart()
activity?.title = getString(CoreR.string.section_theme)
}
}
@@ -1,23 +0,0 @@
package com.topjohnwu.magisk.ui.theme
import com.topjohnwu.magisk.arch.BaseViewModel
import com.topjohnwu.magisk.core.Config
import com.topjohnwu.magisk.dialog.DarkThemeDialog
import com.topjohnwu.magisk.events.RecreateEvent
import com.topjohnwu.magisk.view.TappableHeadlineItem
class ThemeViewModel : BaseViewModel(), TappableHeadlineItem.Listener {
val themeHeadline = TappableHeadlineItem.ThemeMode
override fun onItemPressed(item: TappableHeadlineItem) = when (item) {
is TappableHeadlineItem.ThemeMode -> DarkThemeDialog().show()
}
fun saveTheme(theme: Theme) {
if (!theme.isSelected) {
Config.themeOrdinal = theme.ordinal
RecreateEvent().publish()
}
}
}
@@ -1,30 +0,0 @@
package com.topjohnwu.magisk.view
import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.databinding.DiffItem
import com.topjohnwu.magisk.databinding.RvItem
import com.topjohnwu.magisk.core.R as CoreR
sealed class TappableHeadlineItem : RvItem(), DiffItem<TappableHeadlineItem> {
abstract val title: Int
abstract val icon: Int
override val layoutRes = R.layout.item_tappable_headline
// --- listener
interface Listener {
fun onItemPressed(item: TappableHeadlineItem)
}
// --- objects
object ThemeMode : TappableHeadlineItem() {
override val title = CoreR.string.settings_dark_mode_title
override val icon = R.drawable.ic_day_night
}
}
@@ -1,44 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<import type="com.topjohnwu.magisk.ui.theme.Theme" />
<variable
name="viewModel"
type="com.topjohnwu.magisk.ui.theme.ThemeViewModel" />
</data>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:fillViewport="true"
android:paddingStart="@dimen/l1"
android:paddingTop="@dimen/internal_action_bar_size"
android:paddingEnd="@dimen/l1"
android:paddingBottom="@dimen/l1"
app:fitsSystemWindowsInsets="top|bottom">
<LinearLayout
android:id="@+id/theme_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="@dimen/l1"
android:useDefaultMargins="true">
<include
android:id="@+id/theme_card_dark"
item="@{viewModel.themeHeadline}"
layout="@layout/item_tappable_headline"
listener="@{viewModel}" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</layout>
@@ -1,67 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="item"
type="com.topjohnwu.magisk.view.TappableHeadlineItem" />
<variable
name="listener"
type="com.topjohnwu.magisk.view.TappableHeadlineItem.Listener" />
</data>
<com.google.android.material.card.MaterialCardView
style="@style/WidgetFoundation.Card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="@{() -> listener.onItemPressed(item)}"
tools:layout_gravity="center">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/tappable_icon"
style="@style/WidgetFoundation.Icon"
android:background="@null"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@{item.icon}"
tools:srcCompat="@drawable/ic_day_night" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:requiresFadingEdge="horizontal"
android:singleLine="true"
android:text="@{item.title}"
android:textAppearance="@style/AppearanceFoundation.Body"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/headline_icon_pointer"
app:layout_constraintStart_toEndOf="@+id/tappable_icon"
app:layout_constraintTop_toTopOf="parent"
tools:text="@string/settings_dark_mode_title" />
<ImageView
android:id="@+id/headline_icon_pointer"
style="@style/WidgetFoundation.Icon"
android:background="@null"
android:rotation="180"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_back_md2" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
</layout>
-183
View File
@@ -1,183 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="viewModel"
type="com.topjohnwu.magisk.ui.theme.ThemeViewModel" />
<variable
name="theme"
type="com.topjohnwu.magisk.ui.theme.Theme" />
</data>
<com.google.android.material.card.MaterialCardView
style="@style/WidgetFoundation.Card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="@{() -> viewModel.saveTheme(theme)}"
app:cardBackgroundColor="@android:color/transparent"
app:strokeColor="?colorPrimaryVariant"
app:strokeWidth="1.5dp"
tools:layout_gravity="center">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?colorSurface">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/theme_appbar"
style="@style/WidgetFoundation.Appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.appbar.MaterialToolbar
style="@style/WidgetFoundation.Toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:layout_width="100dp"
android:layout_height="17sp"
android:layout_gravity="center_vertical|start"
android:background="?colorOnSurface" />
<View
android:layout_width="70dp"
android:layout_height="12sp"
android:layout_gravity="center_vertical|start"
android:layout_marginTop="@dimen/l_25"
android:background="?colorOnSurfaceVariant" />
</LinearLayout>
</com.google.android.material.appbar.MaterialToolbar>
</com.google.android.material.appbar.AppBarLayout>
<com.google.android.material.card.MaterialCardView
android:id="@+id/theme_card_bottom"
style="@style/WidgetFoundation.Card"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/l1"
android:layout_marginTop="@dimen/l1"
android:layout_marginEnd="@dimen/l1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/theme_appbar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/l1">
<View
android:layout_width="match_parent"
android:layout_height="17sp"
android:background="?colorOnSurface" />
<View
android:layout_width="40dp"
android:layout_height="11sp"
android:layout_marginTop="@dimen/l_25"
android:background="?colorOnSurfaceVariant" />
<View
android:layout_width="30dp"
android:layout_height="11sp"
android:layout_marginTop="@dimen/l_25"
android:background="?colorOnSurfaceVariant" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
<LinearLayout
android:id="@+id/theme_primary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/l1"
android:background="?colorPrimary"
android:orientation="vertical"
android:padding="@dimen/l1"
app:layout_constraintTop_toBottomOf="@+id/theme_card_bottom">
<TextView
android:layout_width="125dp"
android:layout_height="wrap_content"
android:text="@{theme.themeName}"
android:textAppearance="@style/AppearanceFoundation.Title.OnPrimary"
android:textStyle="bold"
tools:text="Default" />
<View
android:layout_width="match_parent"
android:layout_height="12sp"
android:background="?colorOnPrimaryVariant" />
<View
android:layout_width="75dp"
android:layout_height="12sp"
android:layout_marginTop="@dimen/l_25"
android:background="?colorOnPrimaryVariant" />
</LinearLayout>
<com.google.android.material.card.MaterialCardView
android:id="@+id/theme_navigation"
style="@style/WidgetFoundation.Card.Elevated"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/l1"
android:layout_marginBottom="@dimen/l1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/theme_primary">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="@dimen/l1">
<View
style="@style/WidgetFoundation.Image.Small"
android:background="?colorSecondary" />
<View
style="@style/WidgetFoundation.Image.Small"
android:layout_marginStart="@dimen/l1"
android:background="?colorDisabled" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</androidx.constraintlayout.widget.ConstraintLayout>
<ImageView
style="@style/WidgetFoundation.Icon.OnPrimary"
gone="@{!theme.isSelected}"
android:layout_gravity="end|top"
android:layout_margin="@dimen/l_50"
android:background="@drawable/bg_selection_circle_green"
app:srcCompat="@drawable/ic_check_md2"
app:tint="#fff" />
</com.google.android.material.card.MaterialCardView>
</layout>
@@ -1,13 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/W.Theme.Container">
<FrameLayout
android:id="@+id/left"
style="@style/W.Theme.Left" />
<FrameLayout
android:id="@+id/right"
style="@style/W.Theme.Right" />
</LinearLayout>
-14
View File
@@ -76,14 +76,6 @@
android:name="com.topjohnwu.magisk.ui.settings.SettingsFragment"
android:label="SettingsFragment">
<action
android:id="@+id/action_settingsFragment_to_themeFragment"
app:destination="@id/themeFragment"
app:enterAnim="@anim/fragment_enter"
app:exitAnim="@anim/fragment_exit"
app:popEnterAnim="@anim/fragment_enter_pop"
app:popExitAnim="@anim/fragment_exit_pop" />
<action
android:id="@+id/action_settingsFragment_to_denyFragment"
app:destination="@id/denyFragment"
@@ -99,12 +91,6 @@
android:name="com.topjohnwu.magisk.ui.superuser.SuperuserFragment"
android:label="SuperuserFragment" />
<fragment
android:id="@+id/themeFragment"
android:name="com.topjohnwu.magisk.ui.theme.ThemeFragment"
android:label="ThemeFragment"
tools:layout="@layout/fragment_theme_md2" />
<action
android:id="@+id/action_homeFragment"
app:destination="@id/homeFragment"