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
f941f5c0
Commit
f941f5c0
authored
Nov 06, 2019
by
Viktor De Pasquale
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed observer not being called immediately
parent
c7cad7e4
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
23 deletions
+45
-23
ModuleRvItem.kt
...om/topjohnwu/magisk/model/entity/recycler/ModuleRvItem.kt
+39
-17
item_module_md2.xml
app/src/main/res/layout/item_module_md2.xml
+6
-6
No files found.
app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/ModuleRvItem.kt
View file @
f941f5c0
...
@@ -2,6 +2,10 @@ package com.topjohnwu.magisk.model.entity.recycler
...
@@ -2,6 +2,10 @@ package com.topjohnwu.magisk.model.entity.recycler
import
android.content.res.Resources
import
android.content.res.Resources
import
androidx.annotation.StringRes
import
androidx.annotation.StringRes
import
androidx.databinding.Bindable
import
androidx.databinding.Observable
import
androidx.databinding.PropertyChangeRegistry
import
com.topjohnwu.magisk.BR
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.databinding.ComparableRvItem
import
com.topjohnwu.magisk.databinding.ComparableRvItem
import
com.topjohnwu.magisk.extensions.addOnPropertyChangedCallback
import
com.topjohnwu.magisk.extensions.addOnPropertyChangedCallback
...
@@ -75,32 +79,34 @@ class RepoRvItem(val item: Repo) : ComparableRvItem<RepoRvItem>() {
...
@@ -75,32 +79,34 @@ class RepoRvItem(val item: Repo) : ComparableRvItem<RepoRvItem>() {
override
fun
itemSameAs
(
other
:
RepoRvItem
):
Boolean
=
item
.
id
==
other
.
item
.
id
override
fun
itemSameAs
(
other
:
RepoRvItem
):
Boolean
=
item
.
id
==
other
.
item
.
id
}
}
class
ModuleItem
(
val
item
:
Module
)
:
ComparableRvItem
<
ModuleItem
>()
{
class
ModuleItem
(
val
item
:
Module
)
:
ObservableItem
<
ModuleItem
>(),
Observable
{
override
val
layoutRes
=
R
.
layout
.
item_module_md2
override
val
layoutRes
=
R
.
layout
.
item_module_md2
val
isEnabled
=
KObservableField
(
item
.
enable
)
@get
:
Bindable
val
isRemoved
=
KObservableField
(
item
.
remove
)
var
isEnabled
=
item
.
enable
val
isUpdated
get
()
=
item
.
updated
set
(
value
)
{
field
=
value
val
isModified
get
()
=
item
.
remove
||
item
.
updated
item
.
enable
=
value
notifyChange
(
BR
.
enabled
)
init
{
isEnabled
.
addOnPropertyChangedCallback
{
item
.
enable
=
it
?:
return
@addOnPropertyChangedCallback
}
isRemoved
.
addOnPropertyChangedCallback
{
item
.
remove
=
it
?:
return
@addOnPropertyChangedCallback
}
}
@get
:
Bindable
var
isRemoved
=
item
.
remove
set
(
value
)
{
field
=
value
item
.
remove
=
value
notifyChange
(
BR
.
removed
)
}
}
fun
toggle
(
viewModel
:
ModuleViewModel
)
{
val
isUpdated
get
()
=
item
.
updated
isEnabled
.
toggle
()
val
isModified
get
()
=
isRemoved
||
item
.
updated
viewModel
.
updateState
()
fun
toggle
()
{
isEnabled
=
!
isEnabled
}
}
fun
delete
(
viewModel
:
ModuleViewModel
)
{
fun
delete
(
viewModel
:
ModuleViewModel
)
{
isRemoved
.
toggle
()
isRemoved
=
!
isRemoved
viewModel
.
updateState
()
viewModel
.
updateState
()
}
}
...
@@ -112,3 +118,19 @@ class ModuleItem(val item: Module) : ComparableRvItem<ModuleItem>() {
...
@@ -112,3 +118,19 @@ class ModuleItem(val item: Module) : ComparableRvItem<ModuleItem>() {
override
fun
itemSameAs
(
other
:
ModuleItem
):
Boolean
=
item
.
id
==
other
.
item
.
id
override
fun
itemSameAs
(
other
:
ModuleItem
):
Boolean
=
item
.
id
==
other
.
item
.
id
}
}
abstract
class
ObservableItem
<
T
>
:
ComparableRvItem
<
T
>(),
Observable
{
private
val
list
=
PropertyChangeRegistry
()
override
fun
removeOnPropertyChangedCallback
(
callback
:
Observable
.
OnPropertyChangedCallback
?)
{
list
.
remove
(
callback
?:
return
)
}
override
fun
addOnPropertyChangedCallback
(
callback
:
Observable
.
OnPropertyChangedCallback
?)
{
list
.
add
(
callback
?:
return
)
}
protected
fun
notifyChange
(
id
:
Int
)
=
list
.
notifyChange
(
this
,
id
)
}
\ No newline at end of file
app/src/main/res/layout/item_module_md2.xml
View file @
f941f5c0
...
@@ -21,11 +21,11 @@
...
@@ -21,11 +21,11 @@
<com.google.android.material.card.MaterialCardView
<com.google.android.material.card.MaterialCardView
style=
"?styleCardVariant"
style=
"?styleCardVariant"
isEnabled=
"@{!Config.coreOnly && !item.
isRemoved()
}"
isEnabled=
"@{!Config.coreOnly && !item.
removed
}"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:alpha=
"@{item.
isEnabled()
&& !Config.coreOnly ? 1f : .5f}"
android:alpha=
"@{item.
enabled
&& !Config.coreOnly ? 1f : .5f}"
android:onClick=
"@{() -> item.toggle(
viewModel
)}"
android:onClick=
"@{() -> item.toggle()}"
tools:layout_gravity=
"center"
tools:layout_gravity=
"center"
tools:layout_marginBottom=
"@dimen/l1"
tools:layout_marginBottom=
"@dimen/l1"
tools:layout_marginEnd=
"@dimen/l1"
>
tools:layout_marginEnd=
"@dimen/l1"
>
...
@@ -38,8 +38,8 @@
...
@@ -38,8 +38,8 @@
<androidx.appcompat.widget.AppCompatImageView
<androidx.appcompat.widget.AppCompatImageView
android:id=
"@+id/module_state_icon"
android:id=
"@+id/module_state_icon"
style=
"?styleImageSmall"
style=
"?styleImageSmall"
gone=
"@{!item.
isR
emoved && !item.updated}"
gone=
"@{!item.
r
emoved && !item.updated}"
srcCompat=
"@{item.
isR
emoved ? R.drawable.ic_delete_md2 : R.drawable.ic_update_md2}"
srcCompat=
"@{item.
r
emoved ? R.drawable.ic_delete_md2 : R.drawable.ic_update_md2}"
android:layout_marginStart=
"@dimen/l1"
android:layout_marginStart=
"@dimen/l1"
android:background=
"@null"
android:background=
"@null"
app:layout_constraintBottom_toBottomOf=
"@+id/module_version_author"
app:layout_constraintBottom_toBottomOf=
"@+id/module_version_author"
...
@@ -89,7 +89,7 @@
...
@@ -89,7 +89,7 @@
<androidx.appcompat.widget.AppCompatImageView
<androidx.appcompat.widget.AppCompatImageView
android:id=
"@+id/module_remove"
android:id=
"@+id/module_remove"
style=
"?styleIconNormal"
style=
"?styleIconNormal"
isSelected=
"@{item.
isR
emoved}"
isSelected=
"@{item.
r
emoved}"
android:alpha=
".5"
android:alpha=
".5"
android:onClick=
"@{(v) -> item.delete(viewModel)}"
android:onClick=
"@{(v) -> item.delete(viewModel)}"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
...
...
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