Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
e51a3dac
Commit
e51a3dac
authored
Sep 13, 2020
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support theme switching pre SDK 21
parent
9a8a27db
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
118 deletions
+62
-118
SettingsViewModel.kt
...ava/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt
+0
-5
ThemeFragment.kt
.../main/java/com/topjohnwu/magisk/ui/theme/ThemeFragment.kt
+48
-0
fragment_theme_md2.xml
app/src/main/res/layout/fragment_theme_md2.xml
+1
-113
item_theme_container.xml
app/src/main/res/layout/item_theme_container.xml
+13
-0
No files found.
app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt
View file @
e51a3dac
...
@@ -52,11 +52,6 @@ class SettingsViewModel(
...
@@ -52,11 +52,6 @@ class SettingsViewModel(
Customization
,
Customization
,
Theme
,
Language
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
))
if
(
isRunningAsStub
&&
ShortcutManagerCompat
.
isRequestPinShortcutSupported
(
context
))
list
.
add
(
AddShortcut
)
list
.
add
(
AddShortcut
)
...
...
app/src/main/java/com/topjohnwu/magisk/ui/theme/ThemeFragment.kt
View file @
e51a3dac
package
com.topjohnwu.magisk.ui.theme
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.R
import
com.topjohnwu.magisk.arch.BaseUIFragment
import
com.topjohnwu.magisk.arch.BaseUIFragment
import
com.topjohnwu.magisk.databinding.FragmentThemeMd2Binding
import
com.topjohnwu.magisk.databinding.FragmentThemeMd2Binding
import
com.topjohnwu.magisk.databinding.ItemThemeBindingImpl
import
org.koin.androidx.viewmodel.ext.android.viewModel
import
org.koin.androidx.viewmodel.ext.android.viewModel
class
ThemeFragment
:
BaseUIFragment
<
ThemeViewModel
,
FragmentThemeMd2Binding
>()
{
class
ThemeFragment
:
BaseUIFragment
<
ThemeViewModel
,
FragmentThemeMd2Binding
>()
{
...
@@ -10,6 +18,46 @@ class ThemeFragment : BaseUIFragment<ThemeViewModel, FragmentThemeMd2Binding>()
...
@@ -10,6 +18,46 @@ class ThemeFragment : BaseUIFragment<ThemeViewModel, FragmentThemeMd2Binding>()
override
val
layoutRes
=
R
.
layout
.
fragment_theme_md2
override
val
layoutRes
=
R
.
layout
.
fragment_theme_md2
override
val
viewModel
by
viewModel
<
ThemeViewModel
>()
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
=
this
}
}
binding
.
themeContainer
.
addView
(
c
)
}
return
binding
.
root
}
override
fun
onStart
()
{
override
fun
onStart
()
{
super
.
onStart
()
super
.
onStart
()
...
...
app/src/main/res/layout/fragment_theme_md2.xml
View file @
e51a3dac
...
@@ -22,9 +22,9 @@
...
@@ -22,9 +22,9 @@
android:paddingBottom=
"@{viewModel.insets.bottom + (int) @dimen/l1}"
>
android:paddingBottom=
"@{viewModel.insets.bottom + (int) @dimen/l1}"
>
<LinearLayout
<LinearLayout
android:id=
"@+id/theme_container"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:columnCount=
"2"
android:orientation=
"vertical"
android:orientation=
"vertical"
android:useDefaultMargins=
"true"
>
android:useDefaultMargins=
"true"
>
...
@@ -34,118 +34,6 @@
...
@@ -34,118 +34,6 @@
layout=
"@layout/item_tappable_headline"
layout=
"@layout/item_tappable_headline"
listener=
"@{viewModel}"
/>
listener=
"@{viewModel}"
/>
<LinearLayout
style=
"@style/W.Theme.Container"
>
<FrameLayout
android:id=
"@+id/theme_default"
style=
"@style/W.Theme.Left"
android:theme=
"@style/ThemeFoundationMD2.Piplup"
>
<include
layout=
"@layout/item_theme"
theme=
"@{Theme.Piplup}"
viewModel=
"@{viewModel}"
/>
</FrameLayout>
<FrameLayout
android:id=
"@+id/theme_amoled"
style=
"@style/W.Theme.Right"
android:theme=
"@style/ThemeFoundationMD2.Amoled"
>
<include
layout=
"@layout/item_theme"
theme=
"@{Theme.PiplupAmoled}"
viewModel=
"@{viewModel}"
/>
</FrameLayout>
</LinearLayout>
<LinearLayout
style=
"@style/W.Theme.Container"
>
<FrameLayout
android:id=
"@+id/theme_rayquaza"
style=
"@style/W.Theme.Left"
android:theme=
"@style/ThemeFoundationMD2.Rayquaza"
>
<include
layout=
"@layout/item_theme"
theme=
"@{Theme.Rayquaza}"
viewModel=
"@{viewModel}"
/>
</FrameLayout>
<FrameLayout
android:id=
"@+id/theme_zapdos"
style=
"@style/W.Theme.Right"
android:theme=
"@style/ThemeFoundationMD2.Zapdos"
>
<include
layout=
"@layout/item_theme"
theme=
"@{Theme.Zapdos}"
viewModel=
"@{viewModel}"
/>
</FrameLayout>
</LinearLayout>
<LinearLayout
style=
"@style/W.Theme.Container"
>
<FrameLayout
android:id=
"@+id/theme_charmeleon"
style=
"@style/W.Theme.Left"
android:theme=
"@style/ThemeFoundationMD2.Charmeleon"
>
<include
layout=
"@layout/item_theme"
theme=
"@{Theme.Charmeleon}"
viewModel=
"@{viewModel}"
/>
</FrameLayout>
<FrameLayout
android:id=
"@+id/theme_mew"
style=
"@style/W.Theme.Right"
android:theme=
"@style/ThemeFoundationMD2.Mew"
>
<include
layout=
"@layout/item_theme"
theme=
"@{Theme.Mew}"
viewModel=
"@{viewModel}"
/>
</FrameLayout>
</LinearLayout>
<LinearLayout
style=
"@style/W.Theme.Container"
>
<FrameLayout
android:id=
"@+id/theme_salamence"
style=
"@style/W.Theme.Left"
android:theme=
"@style/ThemeFoundationMD2.Salamence"
>
<include
layout=
"@layout/item_theme"
theme=
"@{Theme.Salamence}"
viewModel=
"@{viewModel}"
/>
</FrameLayout>
<FrameLayout
android:id=
"@+id/theme_fraxure"
style=
"@style/W.Theme.Right"
android:theme=
"@style/ThemeFoundationMD2.Fraxure"
>
<include
layout=
"@layout/item_theme"
theme=
"@{Theme.Fraxure}"
viewModel=
"@{viewModel}"
/>
</FrameLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.core.widget.NestedScrollView>
...
...
app/src/main/res/layout/item_theme_container.xml
0 → 100644
View file @
e51a3dac
<?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>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment