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
45fabf8e
Commit
45fabf8e
authored
Jul 12, 2020
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update SettingsItems
parent
2c12fe6e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
57 deletions
+42
-57
Config.kt
app/src/main/java/com/topjohnwu/magisk/core/Config.kt
+8
-1
SettingsItem.kt
...om/topjohnwu/magisk/model/entity/recycler/SettingsItem.kt
+11
-21
SettingsItems.kt
...in/java/com/topjohnwu/magisk/ui/settings/SettingsItems.kt
+23
-35
No files found.
app/src/main/java/com/topjohnwu/magisk/core/Config.kt
View file @
45fabf8e
...
...
@@ -11,6 +11,7 @@ import com.topjohnwu.magisk.core.magiskdb.SettingsDao
import
com.topjohnwu.magisk.core.magiskdb.StringDao
import
com.topjohnwu.magisk.core.utils.BiometricHelper
import
com.topjohnwu.magisk.core.utils.Utils
import
com.topjohnwu.magisk.core.utils.refreshLocale
import
com.topjohnwu.magisk.data.repository.DBConfig
import
com.topjohnwu.magisk.di.Protected
import
com.topjohnwu.magisk.ktx.get
...
...
@@ -125,7 +126,13 @@ object Config : PreferenceModel, DBConfig {
var
showSystemApp
by
preference
(
Key
.
SHOW_SYSTEM_APP
,
false
)
var
customChannelUrl
by
preference
(
Key
.
CUSTOM_CHANNEL
,
""
)
var
locale
by
preference
(
Key
.
LOCALE
,
""
)
private
var
localePrefs
by
preference
(
Key
.
LOCALE
,
""
)
var
locale
get
()
=
localePrefs
set
(
value
)
{
localePrefs
=
value
refreshLocale
()
}
var
rootMode
by
dbSettings
(
Key
.
ROOT_ACCESS
,
Value
.
ROOT_ACCESS_APPS_AND_ADB
)
var
suMntNamespaceMode
by
dbSettings
(
Key
.
SU_MNT_NS
,
Value
.
NAMESPACE_MODE_REQUESTER
)
...
...
app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/SettingsItem.kt
View file @
45fabf8e
...
...
@@ -13,11 +13,10 @@ import com.topjohnwu.magisk.BR
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.databinding.ObservableItem
import
com.topjohnwu.magisk.utils.TransitiveText
import
com.topjohnwu.magisk.utils.observable
import
com.topjohnwu.magisk.view.MagiskDialog
import
org.koin.core.KoinComponent
import
org.koin.core.get
import
kotlin.properties.ObservableProperty
import
kotlin.reflect.KProperty
sealed
class
SettingsItem
:
ObservableItem
<
SettingsItem
>()
{
...
...
@@ -28,17 +27,13 @@ sealed class SettingsItem : ObservableItem<SettingsItem>() {
open
val
description
:
TransitiveText
get
()
=
TransitiveText
.
EMPTY
@get
:
Bindable
var
isEnabled
by
bind
able
(
true
,
BR
.
enabled
)
var
isEnabled
by
observ
able
(
true
,
BR
.
enabled
)
protected
open
val
isFullSpan
get
()
=
false
@CallSuper
open
fun
onPressed
(
view
:
View
,
callback
:
Callback
)
{
callback
.
onItemChanged
(
view
,
this
)
// notify only after the callback invocation; callback can invalidate the backing data,
// which wouldn't be recognized with reverse approach
notifyPropertyChanged
(
BR
.
description
)
}
open
fun
refresh
()
{}
...
...
@@ -54,17 +49,6 @@ sealed class SettingsItem : ObservableItem<SettingsItem>() {
override
fun
itemSameAs
(
other
:
SettingsItem
)
=
this
===
other
override
fun
contentSameAs
(
other
:
SettingsItem
)
=
itemSameAs
(
other
)
protected
inline
fun
<
T
>
bindable
(
initialValue
:
T
,
fieldId
:
Int
,
crossinline
setter
:
(
T
)
->
Unit
=
{}
)
=
object
:
ObservableProperty
<
T
>(
initialValue
)
{
override
fun
afterChange
(
property
:
KProperty
<
*
>,
oldValue
:
T
,
newValue
:
T
)
{
setter
(
newValue
)
notifyPropertyChanged
(
fieldId
)
}
}
// ---
interface
Callback
{
...
...
@@ -79,10 +63,11 @@ sealed class SettingsItem : ObservableItem<SettingsItem>() {
@get
:
Bindable
abstract
var
value
:
T
protected
inline
fun
bindableV
alue
(
protected
inline
fun
<
reified
T
>
v
alue
(
initialValue
:
T
,
crossinline
setter
:
(
T
)
->
Unit
)
=
bindable
(
initialValue
,
BR
.
value
,
setter
)
vararg
fieldIds
:
Int
,
crossinline
setter
:
(
T
)
->
Unit
=
{}
)
=
observable
(
initialValue
,
BR
.
value
,
*
fieldIds
,
afterChanged
=
setter
)
}
...
...
@@ -157,6 +142,11 @@ sealed class SettingsItem : ObservableItem<SettingsItem>() {
val
selectedEntry
get
()
=
entries
.
getOrNull
(
value
)
/* override */
protected
inline
fun
value
(
initialValue
:
Int
,
crossinline
setter
:
(
Int
)
->
Unit
)
=
observable
(
initialValue
,
BR
.
value
,
BR
.
selectedEntry
,
BR
.
description
,
afterChanged
=
setter
)
private
fun
Resources
.
getArrayOrEmpty
(
id
:
Int
):
Array
<
String
>
=
runCatching
{
getStringArray
(
id
)
}.
getOrDefault
(
emptyArray
())
...
...
app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsItems.kt
View file @
45fabf8e
...
...
@@ -11,13 +11,17 @@ import com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.core.Config
import
com.topjohnwu.magisk.core.Const
import
com.topjohnwu.magisk.core.Info
import
com.topjohnwu.magisk.core.utils.*
import
com.topjohnwu.magisk.core.utils.BiometricHelper
import
com.topjohnwu.magisk.core.utils.Utils
import
com.topjohnwu.magisk.core.utils.availableLocales
import
com.topjohnwu.magisk.core.utils.currentLocale
import
com.topjohnwu.magisk.databinding.DialogSettingsAppNameBinding
import
com.topjohnwu.magisk.databinding.DialogSettingsDownloadPathBinding
import
com.topjohnwu.magisk.databinding.DialogSettingsUpdateChannelBinding
import
com.topjohnwu.magisk.ktx.get
import
com.topjohnwu.magisk.model.entity.recycler.SettingsItem
import
com.topjohnwu.magisk.utils.asTransitive
import
com.topjohnwu.magisk.utils.observable
import
com.topjohnwu.superuser.Shell
import
kotlinx.coroutines.CoroutineScope
import
kotlinx.coroutines.launch
...
...
@@ -30,9 +34,8 @@ object Customization : SettingsItem.Section() {
}
object
Language
:
SettingsItem
.
Selector
()
{
override
var
value
by
bindableValue
(
0
)
{
override
var
value
by
value
(-
1
)
{
Config
.
locale
=
entryValues
[
it
]
refreshLocale
()
}
override
val
title
=
R
.
string
.
language
.
asTransitive
()
...
...
@@ -76,12 +79,7 @@ object Hide : SettingsItem.Input() {
override
val
title
=
R
.
string
.
settings_hide_manager_title
.
asTransitive
()
override
val
description
=
R
.
string
.
settings_hide_manager_summary
.
asTransitive
()
override
val
showStrip
=
false
override
var
value
:
String
=
resources
.
getString
(
R
.
string
.
re_app_name
)
set
(
value
)
{
field
=
value
notifyPropertyChanged
(
BR
.
value
)
notifyPropertyChanged
(
BR
.
error
)
}
override
var
value
by
value
(
resources
.
getString
(
R
.
string
.
re_app_name
),
BR
.
error
)
@get
:
Bindable
val
isError
get
()
=
value
.
length
>
14
||
value
.
isBlank
()
...
...
@@ -103,29 +101,23 @@ fun HideOrRestore() =
if
(
get
<
Context
>().
packageName
==
BuildConfig
.
APPLICATION_ID
)
Hide
else
Restore
object
DownloadPath
:
SettingsItem
.
Input
()
{
override
var
value
:
String
by
bindableV
alue
(
Config
.
downloadPath
)
{
Config
.
downloadPath
=
it
}
override
var
value
:
String
by
v
alue
(
Config
.
downloadPath
)
{
Config
.
downloadPath
=
it
}
override
val
title
=
R
.
string
.
settings_download_path_title
.
asTransitive
()
override
val
intermediate
:
String
?
get
()
=
if
(
Utils
.
ensureDownloadPath
(
result
)
!=
null
)
result
else
null
@get
:
Bindable
var
result
=
value
set
(
value
)
{
field
=
value
notifyPropertyChanged
(
BR
.
result
)
notifyPropertyChanged
(
BR
.
path
)
}
var
result
by
observable
(
value
,
BR
.
result
,
BR
.
path
)
@get
:
Bindable
val
path
get
()
=
File
(
Environment
.
getExternalStorageDirectory
(),
result
).
absolutePath
.
orEmpty
()
val
path
get
()
=
File
(
Environment
.
getExternalStorageDirectory
(),
result
).
absolutePath
.
orEmpty
()
override
fun
getView
(
context
:
Context
)
=
DialogSettingsDownloadPathBinding
.
inflate
(
LayoutInflater
.
from
(
context
)).
also
{
it
.
data
=
this
}.
root
}
object
UpdateChannel
:
SettingsItem
.
Selector
()
{
override
var
value
by
bindableV
alue
(
Config
.
updateChannel
)
{
Config
.
updateChannel
=
it
}
override
var
value
by
v
alue
(
Config
.
updateChannel
)
{
Config
.
updateChannel
=
it
}
override
val
title
=
R
.
string
.
settings_update_channel_title
.
asTransitive
()
override
val
entries
get
()
=
resources
.
getStringArray
(
R
.
array
.
update_channel
).
let
{
...
...
@@ -136,15 +128,11 @@ object UpdateChannel : SettingsItem.Selector() {
object
UpdateChannelUrl
:
SettingsItem
.
Input
()
{
override
val
title
=
R
.
string
.
settings_update_custom
.
asTransitive
()
override
var
value
by
bindableV
alue
(
Config
.
customChannelUrl
)
{
Config
.
customChannelUrl
=
it
}
override
var
value
by
v
alue
(
Config
.
customChannelUrl
)
{
Config
.
customChannelUrl
=
it
}
override
val
intermediate
:
String
?
get
()
=
result
@get
:
Bindable
var
result
=
value
set
(
value
)
{
field
=
value
notifyPropertyChanged
(
BR
.
result
)
}
var
result
by
observable
(
value
,
BR
.
result
)
override
fun
refresh
()
{
isEnabled
=
UpdateChannel
.
value
==
Config
.
Value
.
CUSTOM_CHANNEL
...
...
@@ -157,7 +145,7 @@ object UpdateChannelUrl : SettingsItem.Input() {
object
UpdateChecker
:
SettingsItem
.
Toggle
()
{
override
val
title
=
R
.
string
.
settings_check_update_title
.
asTransitive
()
override
val
description
=
R
.
string
.
settings_check_update_summary
.
asTransitive
()
override
var
value
by
bindableV
alue
(
Config
.
checkUpdate
)
{
override
var
value
by
v
alue
(
Config
.
checkUpdate
)
{
Config
.
checkUpdate
=
it
Utils
.
scheduleUpdateCheck
(
get
())
}
...
...
@@ -171,7 +159,7 @@ object SystemlessHosts : SettingsItem.Blank() {
object
Biometrics
:
SettingsItem
.
Toggle
()
{
override
val
title
=
R
.
string
.
settings_su_biometric_title
.
asTransitive
()
override
var
value
by
bindableV
alue
(
Config
.
suBiometric
)
{
Config
.
suBiometric
=
it
}
override
var
value
by
v
alue
(
Config
.
suBiometric
)
{
Config
.
suBiometric
=
it
}
override
var
description
=
R
.
string
.
settings_su_biometric_summary
.
asTransitive
()
override
fun
refresh
()
{
...
...
@@ -186,7 +174,7 @@ object Biometrics : SettingsItem.Toggle() {
object
Reauthenticate
:
SettingsItem
.
Toggle
()
{
override
val
title
=
R
.
string
.
settings_su_reauth_title
.
asTransitive
()
override
val
description
=
R
.
string
.
settings_su_reauth_summary
.
asTransitive
()
override
var
value
by
bindableV
alue
(
Config
.
suReAuth
)
{
Config
.
suReAuth
=
it
}
override
var
value
by
v
alue
(
Config
.
suReAuth
)
{
Config
.
suReAuth
=
it
}
override
fun
refresh
()
{
isEnabled
=
Build
.
VERSION
.
SDK_INT
<
Build
.
VERSION_CODES
.
O
&&
Utils
.
showSuperUser
()
...
...
@@ -202,7 +190,7 @@ object Magisk : SettingsItem.Section() {
object
MagiskHide
:
SettingsItem
.
Toggle
()
{
override
val
title
=
R
.
string
.
magiskhide
.
asTransitive
()
override
val
description
=
R
.
string
.
settings_magiskhide_summary
.
asTransitive
()
override
var
value
by
bindableV
alue
(
Config
.
magiskHide
)
{
override
var
value
by
v
alue
(
Config
.
magiskHide
)
{
Config
.
magiskHide
=
it
when
{
it
->
Shell
.
su
(
"magiskhide --enable"
).
submit
()
...
...
@@ -222,7 +210,7 @@ object AccessMode : SettingsItem.Selector() {
override
val
entryRes
=
R
.
array
.
su_access
override
val
entryValRes
=
R
.
array
.
value_array
override
var
value
by
bindableV
alue
(
Config
.
rootMode
)
{
override
var
value
by
v
alue
(
Config
.
rootMode
)
{
Config
.
rootMode
=
entryValues
[
it
].
toInt
()
}
}
...
...
@@ -232,7 +220,7 @@ object MultiuserMode : SettingsItem.Selector() {
override
val
entryRes
=
R
.
array
.
multiuser_mode
override
val
entryValRes
=
R
.
array
.
value_array
override
var
value
by
bindableV
alue
(
Config
.
suMultiuserMode
)
{
override
var
value
by
v
alue
(
Config
.
suMultiuserMode
)
{
Config
.
suMultiuserMode
=
entryValues
[
it
].
toInt
()
}
...
...
@@ -249,7 +237,7 @@ object MountNamespaceMode : SettingsItem.Selector() {
override
val
entryRes
=
R
.
array
.
namespace
override
val
entryValRes
=
R
.
array
.
value_array
override
var
value
by
bindableV
alue
(
Config
.
suMntNamespaceMode
)
{
override
var
value
by
v
alue
(
Config
.
suMntNamespaceMode
)
{
Config
.
suMntNamespaceMode
=
entryValues
[
it
].
toInt
()
}
...
...
@@ -262,7 +250,7 @@ object AutomaticResponse : SettingsItem.Selector() {
override
val
entryRes
=
R
.
array
.
auto_response
override
val
entryValRes
=
R
.
array
.
value_array
override
var
value
by
bindableV
alue
(
Config
.
suAutoReponse
)
{
override
var
value
by
v
alue
(
Config
.
suAutoReponse
)
{
Config
.
suAutoReponse
=
entryValues
[
it
].
toInt
()
}
}
...
...
@@ -272,7 +260,7 @@ object RequestTimeout : SettingsItem.Selector() {
override
val
entryRes
=
R
.
array
.
request_timeout
override
val
entryValRes
=
R
.
array
.
request_timeout_value
override
var
value
by
bindableV
alue
(
selected
)
{
override
var
value
by
v
alue
(
selected
)
{
Config
.
suDefaultTimeout
=
entryValues
[
it
].
toInt
()
}
...
...
@@ -285,7 +273,7 @@ object SUNotification : SettingsItem.Selector() {
override
val
entryRes
=
R
.
array
.
su_notification
override
val
entryValRes
=
R
.
array
.
value_array
override
var
value
by
bindableV
alue
(
Config
.
suNotification
)
{
override
var
value
by
v
alue
(
Config
.
suNotification
)
{
Config
.
suNotification
=
entryValues
[
it
].
toInt
()
}
}
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