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
cad189d2
Commit
cad189d2
authored
Jul 12, 2020
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove unnecessary indirection
parent
7cf3da1b
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
27 deletions
+19
-27
RecyclerViewItems.kt
...ava/com/topjohnwu/magisk/databinding/RecyclerViewItems.kt
+4
-1
BaseViewModel.kt
...c/main/java/com/topjohnwu/magisk/ui/base/BaseViewModel.kt
+4
-1
ObservableHost.kt
...rc/main/java/com/topjohnwu/magisk/utils/ObservableHost.kt
+11
-25
No files found.
app/src/main/java/com/topjohnwu/magisk/databinding/RecyclerViewItems.kt
View file @
cad189d2
package
com.topjohnwu.magisk.databinding
import
androidx.annotation.CallSuper
import
androidx.databinding.PropertyChangeRegistry
import
androidx.databinding.ViewDataBinding
import
com.topjohnwu.magisk.BR
import
com.topjohnwu.magisk.utils.DiffObservableList
...
...
@@ -48,4 +49,6 @@ abstract class ComparableRvItem<in T> : RvItem() {
}
}
abstract
class
ObservableItem
<
T
>
:
ComparableRvItem
<
T
>(),
ObservableHost
by
ObservableHost
.
impl
abstract
class
ObservableItem
<
T
>
:
ComparableRvItem
<
T
>(),
ObservableHost
{
override
var
callbacks
:
PropertyChangeRegistry
?
=
null
}
app/src/main/java/com/topjohnwu/magisk/ui/base/BaseViewModel.kt
View file @
cad189d2
...
...
@@ -5,6 +5,7 @@ import androidx.annotation.CallSuper
import
androidx.core.graphics.Insets
import
androidx.databinding.Bindable
import
androidx.databinding.Observable
import
androidx.databinding.PropertyChangeRegistry
import
androidx.lifecycle.LiveData
import
androidx.lifecycle.MutableLiveData
import
androidx.lifecycle.ViewModel
...
...
@@ -22,7 +23,9 @@ import org.koin.core.KoinComponent
abstract
class
BaseViewModel
(
initialState
:
State
=
State
.
LOADING
)
:
ViewModel
(),
ObservableHost
by
ObservableHost
.
impl
,
KoinComponent
{
)
:
ViewModel
(),
ObservableHost
,
KoinComponent
{
override
var
callbacks
:
PropertyChangeRegistry
?
=
null
enum
class
State
{
LOADED
,
LOADING
,
LOADING_FAILED
...
...
app/src/main/java/com/topjohnwu/magisk/utils/ObservableHost.kt
View file @
cad189d2
...
...
@@ -14,30 +14,29 @@ import kotlin.reflect.KProperty
* */
interface
ObservableHost
:
Observable
{
var
callbacks
:
PropertyChangeRegistry
?
/**
* Notifies all observers that something has changed. By default implementation this method is
* synchronous, hence observers will never be notified in undefined order. Observers might
* choose to refresh the view completely, which is beyond the scope of this function.
* */
fun
notifyChange
(
host
:
Observable
=
this
)
fun
notifyChange
()
{
synchronized
(
this
)
{
callbacks
?:
return
}.
notifyCallbacks
(
this
,
0
,
null
)
}
/**
* Notifies all observers about field with [fieldId] has been changed. This will happen
* synchronously before or after [notifyChange] has been called. It will never be called during
* the execution of aforementioned method.
* */
fun
notifyPropertyChanged
(
fieldId
:
Int
,
host
:
Observable
=
this
)
companion
object
{
val
impl
:
ObservableHost
get
()
=
ObservableHostImpl
()
fun
notifyPropertyChanged
(
fieldId
:
Int
)
{
synchronized
(
this
)
{
callbacks
?:
return
}.
notifyCallbacks
(
this
,
fieldId
,
null
)
}
}
private
class
ObservableHostImpl
:
ObservableHost
{
private
var
callbacks
:
PropertyChangeRegistry
?
=
null
override
fun
addOnPropertyChangedCallback
(
callback
:
Observable
.
OnPropertyChangedCallback
)
{
synchronized
(
this
)
{
...
...
@@ -50,19 +49,6 @@ private class ObservableHostImpl : ObservableHost {
callbacks
?:
return
}.
remove
(
callback
)
}
override
fun
notifyChange
(
host
:
Observable
)
{
synchronized
(
this
)
{
callbacks
?:
return
}.
notifyCallbacks
(
host
,
0
,
null
)
}
override
fun
notifyPropertyChanged
(
fieldId
:
Int
,
host
:
Observable
)
{
synchronized
(
this
)
{
callbacks
?:
return
}.
notifyCallbacks
(
host
,
fieldId
,
null
)
}
}
/**
...
...
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