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
e4bcdbd0
Commit
e4bcdbd0
authored
Jan 17, 2020
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make settings page more reasonable
parent
cae43b26
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
52 deletions
+60
-52
CompatHelpers.kt
...c/main/java/com/topjohnwu/magisk/ui/base/CompatHelpers.kt
+5
-1
SettingsItems.kt
...in/java/com/topjohnwu/magisk/ui/settings/SettingsItems.kt
+2
-38
SettingsViewModel.kt
...ava/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt
+53
-13
No files found.
app/src/main/java/com/topjohnwu/magisk/ui/base/CompatHelpers.kt
View file @
e4bcdbd0
...
@@ -10,10 +10,14 @@ import me.tatarka.bindingcollectionadapter2.OnItemBind
...
@@ -10,10 +10,14 @@ import me.tatarka.bindingcollectionadapter2.OnItemBind
inline
fun
<
T
:
ComparableRvItem
<*
>
>
diffListOf
(
inline
fun
<
T
:
ComparableRvItem
<*
>
>
diffListOf
(
vararg
newItems
:
T
vararg
newItems
:
T
)
=
diffListOf
(
newItems
.
toList
())
inline
fun
<
T
:
ComparableRvItem
<*
>
>
diffListOf
(
newItems
:
List
<
T
>
)
=
DiffObservableList
(
object
:
DiffObservableList
.
Callback
<
T
>
{
)
=
DiffObservableList
(
object
:
DiffObservableList
.
Callback
<
T
>
{
override
fun
areItemsTheSame
(
oldItem
:
T
,
newItem
:
T
)
=
oldItem
.
genericItemSameAs
(
newItem
)
override
fun
areItemsTheSame
(
oldItem
:
T
,
newItem
:
T
)
=
oldItem
.
genericItemSameAs
(
newItem
)
override
fun
areContentsTheSame
(
oldItem
:
T
,
newItem
:
T
)
=
oldItem
.
genericContentSameAs
(
newItem
)
override
fun
areContentsTheSame
(
oldItem
:
T
,
newItem
:
T
)
=
oldItem
.
genericContentSameAs
(
newItem
)
}).
also
{
it
.
update
(
newItems
.
toList
()
)
}
}).
also
{
it
.
update
(
newItems
)
}
inline
fun
<
T
:
ComparableRvItem
<*
>
>
filterableListOf
(
inline
fun
<
T
:
ComparableRvItem
<*
>
>
filterableListOf
(
vararg
newItems
:
T
vararg
newItems
:
T
...
...
app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsItems.kt
View file @
e4bcdbd0
...
@@ -91,10 +91,6 @@ object Hide : SettingsItem.Input() {
...
@@ -91,10 +91,6 @@ object Hide : SettingsItem.Input() {
override
fun
getView
(
context
:
Context
)
=
DialogSettingsAppNameBinding
override
fun
getView
(
context
:
Context
)
=
DialogSettingsAppNameBinding
.
inflate
(
LayoutInflater
.
from
(
context
)).
also
{
it
.
data
=
this
}.
root
.
inflate
(
LayoutInflater
.
from
(
context
)).
also
{
it
.
data
=
this
}.
root
override
fun
refresh
()
{
isEnabled
=
Info
.
env
.
isActive
}
}
}
object
Restore
:
SettingsItem
.
Blank
()
{
object
Restore
:
SettingsItem
.
Blank
()
{
...
@@ -183,10 +179,6 @@ object UpdateChecker : SettingsItem.Toggle() {
...
@@ -183,10 +179,6 @@ object UpdateChecker : SettingsItem.Toggle() {
object
SystemlessHosts
:
SettingsItem
.
Blank
()
{
object
SystemlessHosts
:
SettingsItem
.
Blank
()
{
override
val
title
=
R
.
string
.
settings_hosts_title
.
asTransitive
()
override
val
title
=
R
.
string
.
settings_hosts_title
.
asTransitive
()
override
val
description
=
R
.
string
.
settings_hosts_summary
.
asTransitive
()
override
val
description
=
R
.
string
.
settings_hosts_summary
.
asTransitive
()
override
fun
refresh
()
{
isEnabled
=
Info
.
env
.
isActive
}
}
}
object
Biometrics
:
SettingsItem
.
Toggle
()
{
object
Biometrics
:
SettingsItem
.
Toggle
()
{
...
@@ -195,7 +187,7 @@ object Biometrics : SettingsItem.Toggle() {
...
@@ -195,7 +187,7 @@ object Biometrics : SettingsItem.Toggle() {
override
var
description
=
R
.
string
.
settings_su_biometric_summary
.
asTransitive
()
override
var
description
=
R
.
string
.
settings_su_biometric_summary
.
asTransitive
()
override
fun
refresh
()
{
override
fun
refresh
()
{
isEnabled
=
BiometricHelper
.
isSupported
&&
Utils
.
showSuperUser
()
isEnabled
=
BiometricHelper
.
isSupported
if
(!
isEnabled
)
{
if
(!
isEnabled
)
{
value
=
false
value
=
false
description
=
R
.
string
.
no_biometric
.
asTransitive
()
description
=
R
.
string
.
no_biometric
.
asTransitive
()
...
@@ -232,10 +224,6 @@ object SafeMode : SettingsItem.Toggle() {
...
@@ -232,10 +224,6 @@ object SafeMode : SettingsItem.Toggle() {
}
}
Utils
.
toast
(
R
.
string
.
settings_reboot_toast
,
Toast
.
LENGTH_LONG
)
Utils
.
toast
(
R
.
string
.
settings_reboot_toast
,
Toast
.
LENGTH_LONG
)
}
}
override
fun
refresh
()
{
isEnabled
=
Info
.
env
.
isActive
}
}
}
object
MagiskHide
:
SettingsItem
.
Toggle
()
{
object
MagiskHide
:
SettingsItem
.
Toggle
()
{
...
@@ -248,10 +236,6 @@ object MagiskHide : SettingsItem.Toggle() {
...
@@ -248,10 +236,6 @@ object MagiskHide : SettingsItem.Toggle() {
else
->
Shell
.
su
(
"magiskhide --disable"
).
submit
()
else
->
Shell
.
su
(
"magiskhide --disable"
).
submit
()
}
}
}
}
override
fun
refresh
()
{
isEnabled
=
Info
.
env
.
isActive
}
}
}
// --- Superuser
// --- Superuser
...
@@ -268,10 +252,6 @@ object AccessMode : SettingsItem.Selector() {
...
@@ -268,10 +252,6 @@ object AccessMode : SettingsItem.Selector() {
override
var
value
by
bindableValue
(
Config
.
rootMode
)
{
override
var
value
by
bindableValue
(
Config
.
rootMode
)
{
Config
.
rootMode
=
entryValues
[
it
].
toInt
()
Config
.
rootMode
=
entryValues
[
it
].
toInt
()
}
}
override
fun
refresh
()
{
isEnabled
=
Utils
.
showSuperUser
()
}
}
}
object
MultiuserMode
:
SettingsItem
.
Selector
()
{
object
MultiuserMode
:
SettingsItem
.
Selector
()
{
...
@@ -288,7 +268,7 @@ object MultiuserMode : SettingsItem.Selector() {
...
@@ -288,7 +268,7 @@ object MultiuserMode : SettingsItem.Selector() {
get
()
=
descArray
[
value
].
asTransitive
()
get
()
=
descArray
[
value
].
asTransitive
()
override
fun
refresh
()
{
override
fun
refresh
()
{
isEnabled
=
Const
.
USER_ID
<=
0
&&
Utils
.
showSuperUser
()
isEnabled
=
Const
.
USER_ID
==
0
}
}
}
}
...
@@ -304,10 +284,6 @@ object MountNamespaceMode : SettingsItem.Selector() {
...
@@ -304,10 +284,6 @@ object MountNamespaceMode : SettingsItem.Selector() {
override
val
description
override
val
description
get
()
=
descArray
[
value
].
asTransitive
()
get
()
=
descArray
[
value
].
asTransitive
()
override
fun
refresh
()
{
isEnabled
=
Utils
.
showSuperUser
()
}
}
}
object
AutomaticResponse
:
SettingsItem
.
Selector
()
{
object
AutomaticResponse
:
SettingsItem
.
Selector
()
{
...
@@ -318,10 +294,6 @@ object AutomaticResponse : SettingsItem.Selector() {
...
@@ -318,10 +294,6 @@ object AutomaticResponse : SettingsItem.Selector() {
override
var
value
by
bindableValue
(
Config
.
suAutoReponse
)
{
override
var
value
by
bindableValue
(
Config
.
suAutoReponse
)
{
Config
.
suAutoReponse
=
entryValues
[
it
].
toInt
()
Config
.
suAutoReponse
=
entryValues
[
it
].
toInt
()
}
}
override
fun
refresh
()
{
isEnabled
=
Utils
.
showSuperUser
()
}
}
}
object
RequestTimeout
:
SettingsItem
.
Selector
()
{
object
RequestTimeout
:
SettingsItem
.
Selector
()
{
...
@@ -335,10 +307,6 @@ object RequestTimeout : SettingsItem.Selector() {
...
@@ -335,10 +307,6 @@ object RequestTimeout : SettingsItem.Selector() {
private
val
selected
:
Int
private
val
selected
:
Int
get
()
=
entryValues
.
indexOfFirst
{
it
.
toInt
()
==
Config
.
suDefaultTimeout
}
get
()
=
entryValues
.
indexOfFirst
{
it
.
toInt
()
==
Config
.
suDefaultTimeout
}
override
fun
refresh
()
{
isEnabled
=
Utils
.
showSuperUser
()
}
}
}
object
SUNotification
:
SettingsItem
.
Selector
()
{
object
SUNotification
:
SettingsItem
.
Selector
()
{
...
@@ -349,8 +317,4 @@ object SUNotification : SettingsItem.Selector() {
...
@@ -349,8 +317,4 @@ object SUNotification : SettingsItem.Selector() {
override
var
value
by
bindableValue
(
Config
.
suNotification
)
{
override
var
value
by
bindableValue
(
Config
.
suNotification
)
{
Config
.
suNotification
=
entryValues
[
it
].
toInt
()
Config
.
suNotification
=
entryValues
[
it
].
toInt
()
}
}
override
fun
refresh
()
{
isEnabled
=
Utils
.
showSuperUser
()
}
}
}
app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt
View file @
e4bcdbd0
package
com.topjohnwu.magisk.ui.settings
package
com.topjohnwu.magisk.ui.settings
import
android.Manifest
import
android.Manifest
import
android.os.Build
import
android.view.View
import
android.view.View
import
android.widget.Toast
import
android.widget.Toast
import
com.topjohnwu.magisk.BR
import
com.topjohnwu.magisk.BR
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.core.Const
import
com.topjohnwu.magisk.core.Info
import
com.topjohnwu.magisk.core.download.DownloadService
import
com.topjohnwu.magisk.core.download.DownloadService
import
com.topjohnwu.magisk.core.utils.PatchAPK
import
com.topjohnwu.magisk.core.utils.PatchAPK
import
com.topjohnwu.magisk.core.utils.Utils
import
com.topjohnwu.magisk.data.database.RepoDao
import
com.topjohnwu.magisk.data.database.RepoDao
import
com.topjohnwu.magisk.extensions.subscribeK
import
com.topjohnwu.magisk.extensions.subscribeK
import
com.topjohnwu.magisk.model.entity.internal.Configuration
import
com.topjohnwu.magisk.model.entity.internal.Configuration
...
@@ -20,7 +24,6 @@ import com.topjohnwu.magisk.ui.base.BaseViewModel
...
@@ -20,7 +24,6 @@ import com.topjohnwu.magisk.ui.base.BaseViewModel
import
com.topjohnwu.magisk.ui.base.adapterOf
import
com.topjohnwu.magisk.ui.base.adapterOf
import
com.topjohnwu.magisk.ui.base.diffListOf
import
com.topjohnwu.magisk.ui.base.diffListOf
import
com.topjohnwu.magisk.ui.base.itemBindingOf
import
com.topjohnwu.magisk.ui.base.itemBindingOf
import
com.topjohnwu.magisk.core.utils.Utils
import
com.topjohnwu.superuser.Shell
import
com.topjohnwu.superuser.Shell
import
io.reactivex.Completable
import
io.reactivex.Completable
import
io.reactivex.subjects.PublishSubject
import
io.reactivex.subjects.PublishSubject
...
@@ -32,21 +35,58 @@ class SettingsViewModel(
...
@@ -32,21 +35,58 @@ class SettingsViewModel(
val
adapter
=
adapterOf
<
SettingsItem
>()
val
adapter
=
adapterOf
<
SettingsItem
>()
val
itemBinding
=
itemBindingOf
<
SettingsItem
>
{
it
.
bindExtra
(
BR
.
callback
,
this
)
}
val
itemBinding
=
itemBindingOf
<
SettingsItem
>
{
it
.
bindExtra
(
BR
.
callback
,
this
)
}
val
items
=
diffListOf
(
val
items
=
diffListOf
(
createItems
())
Customization
,
Theme
,
Language
,
DownloadPath
,
GridSize
,
private
fun
createItems
():
List
<
SettingsItem
>
{
// Customization
val
list
=
mutableListOf
(
Customization
,
Theme
,
Language
,
GridSize
)
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
)
}
// Manager
list
.
addAll
(
listOf
(
Manager
,
UpdateChannel
,
UpdateChannelUrl
,
UpdateChecker
,
DownloadPath
))
if
(
Info
.
env
.
isActive
)
{
list
.
add
(
ClearRepoCache
)
if
(
Const
.
USER_ID
==
0
&&
Info
.
isConnected
.
value
)
list
.
add
(
HideOrRestore
())
}
Manager
,
// Magisk
UpdateChannel
,
UpdateChannelUrl
,
ClearRepoCache
,
HideOrRestore
(),
UpdateChecker
,
if
(
Info
.
env
.
isActive
)
{
Biometrics
,
Reauthenticate
,
list
.
addAll
(
listOf
(
Magisk
,
MagiskHide
,
SystemlessHosts
,
SafeMode
))
}
Magisk
,
// Superuser
SafeMode
,
MagiskHide
,
SystemlessHosts
,
if
(
Utils
.
showSuperUser
())
{
list
.
addAll
(
listOf
(
Superuser
,
Biometrics
,
AccessMode
,
MultiuserMode
,
MountNamespaceMode
,
AutomaticResponse
,
RequestTimeout
,
SUNotification
))
if
(
Build
.
VERSION
.
SDK_INT
<
23
)
{
// Biometric is only available on 6.0+
list
.
remove
(
Biometrics
)
}
if
(
Build
.
VERSION
.
SDK_INT
<
26
)
{
// Re-authenticate is not feasible on 8.0+
list
.
add
(
Reauthenticate
)
}
}
Superuser
,
return
list
AccessMode
,
MultiuserMode
,
MountNamespaceMode
,
AutomaticResponse
,
RequestTimeout
,
}
SUNotification
)
override
fun
onItemPressed
(
view
:
View
,
item
:
SettingsItem
)
=
when
(
item
)
{
override
fun
onItemPressed
(
view
:
View
,
item
:
SettingsItem
)
=
when
(
item
)
{
is
DownloadPath
->
requireRWPermission
()
is
DownloadPath
->
requireRWPermission
()
...
...
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