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
7d6eebda
Commit
7d6eebda
authored
Oct 29, 2019
by
Viktor De Pasquale
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed unreasonable change resulting in major breakage all around the app
parent
f11bb609
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
11 deletions
+34
-11
BaseViewModel.kt
...java/com/topjohnwu/magisk/base/viewmodel/BaseViewModel.kt
+2
-6
KObservableField.kt
.../main/java/com/topjohnwu/magisk/utils/KObservableField.kt
+32
-5
No files found.
app/src/main/java/com/topjohnwu/magisk/base/viewmodel/BaseViewModel.kt
View file @
7d6eebda
...
...
@@ -5,7 +5,7 @@ import com.topjohnwu.magisk.extensions.doOnSubscribeUi
import
com.topjohnwu.magisk.model.events.BackPressEvent
import
com.topjohnwu.magisk.model.events.PermissionEvent
import
com.topjohnwu.magisk.model.events.ViewActionEvent
import
com.topjohnwu.magisk.
utils.KObservableField
import
com.topjohnwu.magisk.
model.observer.Observer
import
io.reactivex.Observable
import
io.reactivex.subjects.PublishSubject
import
com.topjohnwu.magisk.Info.isConnected
as
gIsConnected
...
...
@@ -15,11 +15,7 @@ abstract class BaseViewModel(
initialState
:
State
=
State
.
LOADING
)
:
LoadingViewModel
(
initialState
)
{
val
isConnected
=
object
:
KObservableField
<
Boolean
>(
gIsConnected
.
value
,
gIsConnected
)
{
override
fun
get
():
Boolean
{
return
gIsConnected
.
value
}
}
val
isConnected
=
Observer
(
gIsConnected
)
{
gIsConnected
.
value
}
fun
withView
(
action
:
Activity
.()
->
Unit
)
{
ViewActionEvent
(
action
).
publish
()
...
...
app/src/main/java/com/topjohnwu/magisk/utils/KObservableField.kt
View file @
7d6eebda
...
...
@@ -2,18 +2,30 @@ package com.topjohnwu.magisk.utils
import
androidx.databinding.Observable
import
androidx.databinding.ObservableField
import
com.topjohnwu.magisk.model.observer.Observer
import
java.io.Serializable
/**
* Kotlin version of [ObservableField].
* You can define if wrapped type is Nullable or not.
* You can use kotlin get/set syntax for value
*
* ## Notes
* This stays final for fuck's sake. Too many things depend on it, so you just cannot go around and
* change it randomly. Even though you think you're improving the design, you might be fucking this
* up in unimaginable ways. So DON'T TOUCH THIS.
*
* In order to have value-less observer you need - you guessed it - **a fucking [Observer]**!
*/
open
class
KObservableField
<
T
>
:
ObservableField
<
T
>,
Serializable
{
class
KObservableField
<
T
>
:
ObservableField
<
T
>,
Serializable
{
var
value
:
T
get
()
=
get
()
set
(
value
)
{
set
(
value
)
}
set
(
value
)
{
if
(
field
!=
value
)
{
field
=
value
notifyChange
()
}
}
constructor
(
init
:
T
)
{
value
=
init
...
...
@@ -23,8 +35,23 @@ open class KObservableField<T> : ObservableField<T>, Serializable {
value
=
init
}
@Suppress
(
"UNCHECKED_CAST"
)
@Deprecated
(
message
=
"Needed for data binding, use KObservableField.value syntax from code"
,
replaceWith
=
ReplaceWith
(
"value"
)
)
override
fun
get
():
T
{
return
super
.
get
()
as
T
return
value
}
@Deprecated
(
message
=
"Needed for data binding, use KObservableField.value = ... syntax from code"
,
replaceWith
=
ReplaceWith
(
"value = newValue"
)
)
override
fun
set
(
newValue
:
T
)
{
value
=
newValue
}
override
fun
toString
():
String
{
return
"KObservableField(value=$value)"
}
}
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