diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt index 3ec02f8c3..80a7e1901 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt @@ -52,11 +52,6 @@ class SettingsViewModel( Customization, Theme, Language ) - if (Build.VERSION.SDK_INT < 21) { - // Pre 5.0 does not support getting colors from attributes, - // making theming a pain in the ass. Just forget about it - list.remove(Theme) - } if (isRunningAsStub && ShortcutManagerCompat.isRequestPinShortcutSupported(context)) list.add(AddShortcut) diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/theme/ThemeFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/theme/ThemeFragment.kt index da751fcdb..57430b727 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/theme/ThemeFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/theme/ThemeFragment.kt @@ -1,8 +1,16 @@ 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.BaseUIFragment import com.topjohnwu.magisk.databinding.FragmentThemeMd2Binding +import com.topjohnwu.magisk.databinding.ItemThemeBindingImpl import org.koin.androidx.viewmodel.ext.android.viewModel class ThemeFragment : BaseUIFragment() { @@ -10,6 +18,46 @@ class ThemeFragment : BaseUIFragment() override val layoutRes = R.layout.fragment_theme_md2 override val viewModel by viewModel() + private fun Array.paired(): List> { + val iterator = iterator() + if (!iterator.hasNext()) return emptyList() + val result = mutableListOf>() + 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(R.id.left) + val right = c.findViewById(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 = this + } + } + + binding.themeContainer.addView(c) + } + + return binding.root + } + override fun onStart() { super.onStart() diff --git a/app/src/main/res/layout/fragment_theme_md2.xml b/app/src/main/res/layout/fragment_theme_md2.xml index 33f219e31..f5f87f703 100644 --- a/app/src/main/res/layout/fragment_theme_md2.xml +++ b/app/src/main/res/layout/fragment_theme_md2.xml @@ -22,9 +22,9 @@ android:paddingBottom="@{viewModel.insets.bottom + (int) @dimen/l1}"> @@ -34,118 +34,6 @@ layout="@layout/item_tappable_headline" listener="@{viewModel}" /> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/layout/item_theme_container.xml b/app/src/main/res/layout/item_theme_container.xml new file mode 100644 index 000000000..9f227400f --- /dev/null +++ b/app/src/main/res/layout/item_theme_container.xml @@ -0,0 +1,13 @@ + + + + + + + +