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
d1dfda40
Commit
d1dfda40
authored
Jun 03, 2019
by
Viktor De Pasquale
Committed by
John Wu
Jun 04, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed Kotpref and replaced it with PreferenceModel
parent
28efded6
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
268 additions
and
27 deletions
+268
-27
build.gradle
app/build.gradle
+0
-1
App.kt
app/src/main/java/com/topjohnwu/magisk/App.kt
+0
-7
KConfig.kt
app/src/main/java/com/topjohnwu/magisk/KConfig.kt
+13
-10
ApplicationModule.kt
...rc/main/java/com/topjohnwu/magisk/di/ApplicationModule.kt
+0
-8
BooleanProperty.kt
.../com/topjohnwu/magisk/model/preference/BooleanProperty.kt
+30
-0
FloatProperty.kt
...va/com/topjohnwu/magisk/model/preference/FloatProperty.kt
+30
-0
IntProperty.kt
...java/com/topjohnwu/magisk/model/preference/IntProperty.kt
+30
-0
LongProperty.kt
...ava/com/topjohnwu/magisk/model/preference/LongProperty.kt
+30
-0
PreferenceModel.kt
.../com/topjohnwu/magisk/model/preference/PreferenceModel.kt
+51
-0
Property.kt
...in/java/com/topjohnwu/magisk/model/preference/Property.kt
+21
-0
StringProperty.kt
...a/com/topjohnwu/magisk/model/preference/StringProperty.kt
+30
-0
StringSetProperty.kt
...om/topjohnwu/magisk/model/preference/StringSetProperty.kt
+30
-0
XString.kt
app/src/main/java/com/topjohnwu/magisk/utils/XString.kt
+3
-1
No files found.
app/build.gradle
View file @
d1dfda40
...
...
@@ -59,7 +59,6 @@ dependencies {
implementation
'com.jakewharton.timber:timber:4.7.1'
implementation
'com.github.skoumalcz:teanity:0.3.3'
implementation
'com.ncapdevi:frag-nav:3.2.0'
implementation
'com.chibatching.kotpref:kotpref:2.8.0'
def
vMarkwon
=
'3.0.1'
implementation
"ru.noties.markwon:core:${vMarkwon}"
...
...
app/src/main/java/com/topjohnwu/magisk/App.kt
View file @
d1dfda40
...
...
@@ -10,7 +10,6 @@ import android.os.Build
import
android.os.Bundle
import
androidx.appcompat.app.AppCompatDelegate
import
androidx.multidex.MultiDex
import
com.chibatching.kotpref.Kotpref
import
com.topjohnwu.magisk.di.koinModules
import
com.topjohnwu.magisk.utils.LocaleManager
import
com.topjohnwu.magisk.utils.RootUtils
...
...
@@ -29,12 +28,6 @@ open class App : Application(), Application.ActivityLifecycleCallbacks {
@Volatile
private
var
foreground
:
Activity
?
=
null
override
fun
onCreate
()
{
super
.
onCreate
()
Kotpref
.
init
(
this
)
}
override
fun
attachBaseContext
(
base
:
Context
)
{
super
.
attachBaseContext
(
base
)
if
(
BuildConfig
.
DEBUG
)
...
...
app/src/main/java/com/topjohnwu/magisk/KConfig.kt
View file @
d1dfda40
package
com.topjohnwu.magisk
import
com.chibatching.kotpref.ContextProvider
import
com.chibatching.kotpref.KotprefModel
import
android.content.Context
import
com.topjohnwu.magisk.KConfig.UpdateChannel.STABLE
import
com.topjohnwu.magisk.utils.get
import
com.topjohnwu.magisk.di.Protected
import
com.topjohnwu.magisk.model.preference.PreferenceModel
import
com.topjohnwu.magisk.utils.inject
object
KConfig
:
KotprefModel
(
get
<
ContextProvider
>())
{
override
val
kotprefName
:
String
=
"${context.packageName}_preferences"
object
KConfig
:
PreferenceModel
()
{
private
var
internalUpdateChannel
by
intPref
(
STABLE
.
id
,
"updateChannel"
)
var
useCustomTabs
by
booleanPref
(
true
,
"useCustomTabs"
)
override
val
context
:
Context
by
inject
(
Protected
)
override
val
fileName
:
String
=
"${context.packageName}_preferences"
private
var
internalUpdateChannel
by
preference
(
Config
.
Key
.
UPDATE_CHANNEL
,
STABLE
.
id
.
toString
())
var
useCustomTabs
by
preference
(
"useCustomTabs"
,
true
)
@JvmStatic
var
customUpdateChannel
by
stringPref
(
""
,
"custom_channel
"
)
var
customUpdateChannel
by
preference
(
Config
.
Key
.
CUSTOM_CHANNEL
,
"
"
)
@JvmStatic
var
updateChannel
:
UpdateChannel
get
()
=
UpdateChannel
.
byId
(
internalUpdateChannel
)
get
()
=
UpdateChannel
.
byId
(
internalUpdateChannel
.
toIntOrNull
()
?:
STABLE
.
id
)
set
(
value
)
{
internalUpdateChannel
=
value
.
id
internalUpdateChannel
=
value
.
id
.
toString
()
}
internal
const
val
DEFAULT_CHANNEL
=
"topjohnwu/magisk_files"
...
...
app/src/main/java/com/topjohnwu/magisk/di/ApplicationModule.kt
View file @
d1dfda40
...
...
@@ -2,7 +2,6 @@ package com.topjohnwu.magisk.di
import
android.content.Context
import
androidx.preference.PreferenceManager
import
com.chibatching.kotpref.ContextProvider
import
com.skoumal.teanity.rxbus.RxBus
import
com.topjohnwu.magisk.App
import
org.koin.dsl.module
...
...
@@ -16,11 +15,4 @@ val applicationModule = module {
factory
(
Protected
)
{
get
<
App
>().
protectedContext
}
single
(
SUTimeout
)
{
get
<
Context
>(
Protected
).
getSharedPreferences
(
"su_timeout"
,
0
)
}
single
{
PreferenceManager
.
getDefaultSharedPreferences
(
get
<
Context
>(
Protected
))
}
single
{
createContextProvider
(
get
(
Protected
))
as
ContextProvider
}
}
private
fun
createContextProvider
(
context
:
Context
)
=
object
:
ContextProvider
{
override
fun
getApplicationContext
():
Context
{
return
context
}
}
\ No newline at end of file
app/src/main/java/com/topjohnwu/magisk/model/preference/BooleanProperty.kt
0 → 100644
View file @
d1dfda40
package
com.topjohnwu.magisk.model.preference
import
androidx.core.content.edit
import
com.topjohnwu.magisk.utils.trimEmptyToNull
import
kotlin.properties.ReadWriteProperty
import
kotlin.reflect.KProperty
class
BooleanProperty
(
private
val
name
:
String
,
private
val
default
:
Boolean
,
private
val
commit
:
Boolean
)
:
Property
(),
ReadWriteProperty
<
PreferenceModel
,
Boolean
>
{
override
operator
fun
getValue
(
thisRef
:
PreferenceModel
,
property
:
KProperty
<
*
>
):
Boolean
{
val
prefName
=
name
.
trimEmptyToNull
()
?:
property
.
name
return
runCatching
{
thisRef
.
prefs
.
get
(
prefName
,
default
)
}.
getOrNull
()
?:
default
}
override
operator
fun
setValue
(
thisRef
:
PreferenceModel
,
property
:
KProperty
<
*
>,
value
:
Boolean
)
{
val
prefName
=
name
.
trimEmptyToNull
()
?:
property
.
name
thisRef
.
prefs
.
edit
(
commit
)
{
put
(
prefName
,
value
)
}
}
}
\ No newline at end of file
app/src/main/java/com/topjohnwu/magisk/model/preference/FloatProperty.kt
0 → 100644
View file @
d1dfda40
package
com.topjohnwu.magisk.model.preference
import
androidx.core.content.edit
import
com.topjohnwu.magisk.utils.trimEmptyToNull
import
kotlin.properties.ReadWriteProperty
import
kotlin.reflect.KProperty
class
FloatProperty
(
private
val
name
:
String
,
private
val
default
:
Float
,
private
val
commit
:
Boolean
)
:
Property
(),
ReadWriteProperty
<
PreferenceModel
,
Float
>
{
override
operator
fun
getValue
(
thisRef
:
PreferenceModel
,
property
:
KProperty
<
*
>
):
Float
{
val
prefName
=
name
.
trimEmptyToNull
()
?:
property
.
name
return
runCatching
{
thisRef
.
prefs
.
get
(
prefName
,
default
)
}.
getOrNull
()
?:
default
}
override
operator
fun
setValue
(
thisRef
:
PreferenceModel
,
property
:
KProperty
<
*
>,
value
:
Float
)
{
val
prefName
=
name
.
trimEmptyToNull
()
?:
property
.
name
thisRef
.
prefs
.
edit
(
commit
)
{
put
(
prefName
,
value
)
}
}
}
\ No newline at end of file
app/src/main/java/com/topjohnwu/magisk/model/preference/IntProperty.kt
0 → 100644
View file @
d1dfda40
package
com.topjohnwu.magisk.model.preference
import
androidx.core.content.edit
import
com.topjohnwu.magisk.utils.trimEmptyToNull
import
kotlin.properties.ReadWriteProperty
import
kotlin.reflect.KProperty
class
IntProperty
(
private
val
name
:
String
,
private
val
default
:
Int
,
private
val
commit
:
Boolean
)
:
Property
(),
ReadWriteProperty
<
PreferenceModel
,
Int
>
{
override
operator
fun
getValue
(
thisRef
:
PreferenceModel
,
property
:
KProperty
<
*
>
):
Int
{
val
prefName
=
name
.
trimEmptyToNull
()
?:
property
.
name
return
runCatching
{
thisRef
.
prefs
.
get
(
prefName
,
default
)
}.
getOrNull
()
?:
default
}
override
operator
fun
setValue
(
thisRef
:
PreferenceModel
,
property
:
KProperty
<
*
>,
value
:
Int
)
{
val
prefName
=
name
.
trimEmptyToNull
()
?:
property
.
name
thisRef
.
prefs
.
edit
(
commit
)
{
put
(
prefName
,
value
)
}
}
}
\ No newline at end of file
app/src/main/java/com/topjohnwu/magisk/model/preference/LongProperty.kt
0 → 100644
View file @
d1dfda40
package
com.topjohnwu.magisk.model.preference
import
androidx.core.content.edit
import
com.topjohnwu.magisk.utils.trimEmptyToNull
import
kotlin.properties.ReadWriteProperty
import
kotlin.reflect.KProperty
class
LongProperty
(
private
val
name
:
String
,
private
val
default
:
Long
,
private
val
commit
:
Boolean
)
:
Property
(),
ReadWriteProperty
<
PreferenceModel
,
Long
>
{
override
operator
fun
getValue
(
thisRef
:
PreferenceModel
,
property
:
KProperty
<
*
>
):
Long
{
val
prefName
=
name
.
trimEmptyToNull
()
?:
property
.
name
return
runCatching
{
thisRef
.
prefs
.
get
(
prefName
,
default
)
}.
getOrNull
()
?:
default
}
override
operator
fun
setValue
(
thisRef
:
PreferenceModel
,
property
:
KProperty
<
*
>,
value
:
Long
)
{
val
prefName
=
name
.
trimEmptyToNull
()
?:
property
.
name
thisRef
.
prefs
.
edit
(
commit
)
{
put
(
prefName
,
value
)
}
}
}
\ No newline at end of file
app/src/main/java/com/topjohnwu/magisk/model/preference/PreferenceModel.kt
0 → 100644
View file @
d1dfda40
package
com.topjohnwu.magisk.model.preference
import
android.content.Context
import
kotlin.properties.ReadWriteProperty
abstract
class
PreferenceModel
(
private
val
commitPrefs
:
Boolean
=
false
)
{
protected
abstract
val
fileName
:
String
protected
abstract
val
context
:
Context
internal
val
prefs
get
()
=
context
.
getSharedPreferences
(
fileName
,
Context
.
MODE_PRIVATE
)
protected
fun
preference
(
name
:
String
,
default
:
Boolean
,
commit
:
Boolean
=
commitPrefs
):
ReadWriteProperty
<
PreferenceModel
,
Boolean
>
=
BooleanProperty
(
name
,
default
,
commit
)
protected
fun
preference
(
name
:
String
,
default
:
Float
,
commit
:
Boolean
=
commitPrefs
):
ReadWriteProperty
<
PreferenceModel
,
Float
>
=
FloatProperty
(
name
,
default
,
commit
)
protected
fun
preference
(
name
:
String
,
default
:
Int
,
commit
:
Boolean
=
commitPrefs
):
ReadWriteProperty
<
PreferenceModel
,
Int
>
=
IntProperty
(
name
,
default
,
commit
)
protected
fun
preference
(
name
:
String
,
default
:
Long
,
commit
:
Boolean
=
commitPrefs
):
ReadWriteProperty
<
PreferenceModel
,
Long
>
=
LongProperty
(
name
,
default
,
commit
)
protected
fun
preference
(
name
:
String
,
default
:
String
,
commit
:
Boolean
=
commitPrefs
):
ReadWriteProperty
<
PreferenceModel
,
String
>
=
StringProperty
(
name
,
default
,
commit
)
protected
fun
preference
(
name
:
String
,
default
:
Set
<
String
>,
commit
:
Boolean
=
commitPrefs
):
ReadWriteProperty
<
PreferenceModel
,
Set
<
String
>>
=
StringSetProperty
(
name
,
default
,
commit
)
}
\ No newline at end of file
app/src/main/java/com/topjohnwu/magisk/model/preference/Property.kt
0 → 100644
View file @
d1dfda40
package
com.topjohnwu.magisk.model.preference
import
android.content.SharedPreferences
abstract
class
Property
{
fun
SharedPreferences
.
Editor
.
put
(
name
:
String
,
value
:
Boolean
)
=
putBoolean
(
name
,
value
)
fun
SharedPreferences
.
Editor
.
put
(
name
:
String
,
value
:
Float
)
=
putFloat
(
name
,
value
)
fun
SharedPreferences
.
Editor
.
put
(
name
:
String
,
value
:
Int
)
=
putInt
(
name
,
value
)
fun
SharedPreferences
.
Editor
.
put
(
name
:
String
,
value
:
Long
)
=
putLong
(
name
,
value
)
fun
SharedPreferences
.
Editor
.
put
(
name
:
String
,
value
:
String
)
=
putString
(
name
,
value
)
fun
SharedPreferences
.
Editor
.
put
(
name
:
String
,
value
:
Set
<
String
>)
=
putStringSet
(
name
,
value
)
fun
SharedPreferences
.
get
(
name
:
String
,
value
:
Boolean
)
=
getBoolean
(
name
,
value
)
fun
SharedPreferences
.
get
(
name
:
String
,
value
:
Float
)
=
getFloat
(
name
,
value
)
fun
SharedPreferences
.
get
(
name
:
String
,
value
:
Int
)
=
getInt
(
name
,
value
)
fun
SharedPreferences
.
get
(
name
:
String
,
value
:
Long
)
=
getLong
(
name
,
value
)
fun
SharedPreferences
.
get
(
name
:
String
,
value
:
String
)
=
getString
(
name
,
value
)
?:
value
fun
SharedPreferences
.
get
(
name
:
String
,
value
:
Set
<
String
>)
=
getStringSet
(
name
,
value
)
?:
value
}
\ No newline at end of file
app/src/main/java/com/topjohnwu/magisk/model/preference/StringProperty.kt
0 → 100644
View file @
d1dfda40
package
com.topjohnwu.magisk.model.preference
import
androidx.core.content.edit
import
com.topjohnwu.magisk.utils.trimEmptyToNull
import
kotlin.properties.ReadWriteProperty
import
kotlin.reflect.KProperty
class
StringProperty
(
private
val
name
:
String
,
private
val
default
:
String
,
private
val
commit
:
Boolean
)
:
Property
(),
ReadWriteProperty
<
PreferenceModel
,
String
>
{
override
operator
fun
getValue
(
thisRef
:
PreferenceModel
,
property
:
KProperty
<
*
>
):
String
{
val
prefName
=
name
.
trimEmptyToNull
()
?:
property
.
name
return
runCatching
{
thisRef
.
prefs
.
get
(
prefName
,
default
)
}.
getOrNull
()
?:
default
}
override
operator
fun
setValue
(
thisRef
:
PreferenceModel
,
property
:
KProperty
<
*
>,
value
:
String
)
{
val
prefName
=
name
.
trimEmptyToNull
()
?:
property
.
name
thisRef
.
prefs
.
edit
(
commit
)
{
put
(
prefName
,
value
)
}
}
}
\ No newline at end of file
app/src/main/java/com/topjohnwu/magisk/model/preference/StringSetProperty.kt
0 → 100644
View file @
d1dfda40
package
com.topjohnwu.magisk.model.preference
import
androidx.core.content.edit
import
com.topjohnwu.magisk.utils.trimEmptyToNull
import
kotlin.properties.ReadWriteProperty
import
kotlin.reflect.KProperty
class
StringSetProperty
(
private
val
name
:
String
,
private
val
default
:
Set
<
String
>,
private
val
commit
:
Boolean
)
:
Property
(),
ReadWriteProperty
<
PreferenceModel
,
Set
<
String
>>
{
override
operator
fun
getValue
(
thisRef
:
PreferenceModel
,
property
:
KProperty
<
*
>
):
Set
<
String
>
{
val
prefName
=
name
.
trimEmptyToNull
()
?:
property
.
name
return
runCatching
{
thisRef
.
prefs
.
get
(
prefName
,
default
)
}.
getOrNull
()
?:
default
}
override
operator
fun
setValue
(
thisRef
:
PreferenceModel
,
property
:
KProperty
<
*
>,
value
:
Set
<
String
>
)
{
val
prefName
=
name
.
trimEmptyToNull
()
?:
property
.
name
thisRef
.
prefs
.
edit
(
commit
)
{
put
(
prefName
,
value
)
}
}
}
\ No newline at end of file
app/src/main/java/com/topjohnwu/magisk/utils/XString.kt
View file @
d1dfda40
...
...
@@ -18,4 +18,6 @@ fun StringBuilder.appendIf(condition: Boolean, builder: StringBuilder.() -> Unit
fun
Int
.
res
(
vararg
args
:
Any
):
String
{
val
resources
:
Resources
by
inject
()
return
resources
.
getString
(
this
,
*
args
)
}
\ No newline at end of file
}
fun
String
.
trimEmptyToNull
():
String
?
=
if
(
isBlank
())
null
else
this
\ No newline at end of file
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