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
fe5c65d7
Commit
fe5c65d7
authored
Nov 01, 2019
by
Viktor De Pasquale
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed use of RxBus for toggling policies
parent
253f3cf1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
22 deletions
+62
-22
PolicyRvItem.kt
...om/topjohnwu/magisk/model/entity/recycler/PolicyRvItem.kt
+48
-5
SuperuserViewModel.kt
...topjohnwu/magisk/redesign/superuser/SuperuserViewModel.kt
+10
-13
item_policy_md2.xml
app/src/main/res/layout/item_policy_md2.xml
+4
-4
No files found.
app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/PolicyRvItem.kt
View file @
fe5c65d7
...
...
@@ -3,7 +3,6 @@ package com.topjohnwu.magisk.model.entity.recycler
import
android.graphics.drawable.Drawable
import
android.view.View
import
android.view.ViewGroup
import
com.topjohnwu.magisk.Config
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.databinding.ComparableRvItem
import
com.topjohnwu.magisk.extensions.addOnPropertyChangedCallback
...
...
@@ -12,6 +11,7 @@ import com.topjohnwu.magisk.extensions.toggle
import
com.topjohnwu.magisk.model.entity.MagiskPolicy
import
com.topjohnwu.magisk.model.events.PolicyEnableEvent
import
com.topjohnwu.magisk.model.events.PolicyUpdateEvent
import
com.topjohnwu.magisk.redesign.superuser.SuperuserViewModel
import
com.topjohnwu.magisk.utils.KObservableField
import
com.topjohnwu.magisk.utils.RxBus
import
com.topjohnwu.magisk.utils.rotationTo
...
...
@@ -19,10 +19,7 @@ import com.topjohnwu.magisk.utils.setRevealed
class
PolicyRvItem
(
val
item
:
MagiskPolicy
,
val
icon
:
Drawable
)
:
ComparableRvItem
<
PolicyRvItem
>()
{
override
val
layoutRes
:
Int
=
when
{
Config
.
redesign
->
R
.
layout
.
item_policy_md2
else
->
R
.
layout
.
item_policy
}
override
val
layoutRes
=
R
.
layout
.
item_policy
val
isExpanded
=
KObservableField
(
false
)
val
isEnabled
=
KObservableField
(
item
.
policy
==
MagiskPolicy
.
ALLOW
)
...
...
@@ -75,3 +72,49 @@ class PolicyRvItem(val item: MagiskPolicy, val icon: Drawable) : ComparableRvIte
override
fun
contentSameAs
(
other
:
PolicyRvItem
):
Boolean
=
itemSameAs
(
other
)
override
fun
itemSameAs
(
other
:
PolicyRvItem
):
Boolean
=
item
.
uid
==
other
.
item
.
uid
}
class
PolicyItem
(
val
item
:
MagiskPolicy
,
val
icon
:
Drawable
)
:
ComparableRvItem
<
PolicyItem
>()
{
override
val
layoutRes
=
R
.
layout
.
item_policy_md2
val
isExpanded
=
KObservableField
(
false
)
val
isEnabled
=
KObservableField
(
item
.
policy
==
MagiskPolicy
.
ALLOW
)
val
shouldNotify
=
KObservableField
(
item
.
notification
)
val
shouldLog
=
KObservableField
(
item
.
logging
)
private
val
updatedPolicy
get
()
=
item
.
copy
(
policy
=
if
(
isEnabled
.
value
)
MagiskPolicy
.
ALLOW
else
MagiskPolicy
.
DENY
,
notification
=
shouldNotify
.
value
,
logging
=
shouldLog
.
value
)
fun
toggle
(
viewModel
:
SuperuserViewModel
)
{
if
(
isExpanded
.
value
)
{
return
}
isEnabled
.
toggle
()
viewModel
.
togglePolicy
(
this
,
isEnabled
.
value
)
}
fun
toggle
(
view
:
View
)
{
isExpanded
.
toggle
()
view
.
rotationTo
(
if
(
isExpanded
.
value
)
225
else
180
)
(
view
.
parent
as
ViewGroup
)
.
findViewById
<
View
>(
R
.
id
.
expand_layout
)
.
setRevealed
(
isExpanded
.
value
)
}
fun
toggleNotify
(
viewModel
:
SuperuserViewModel
)
{
shouldNotify
.
toggle
()
viewModel
.
updatePolicy
(
PolicyUpdateEvent
.
Notification
(
updatedPolicy
))
}
fun
toggleLog
(
viewModel
:
SuperuserViewModel
)
{
shouldLog
.
toggle
()
viewModel
.
updatePolicy
(
PolicyUpdateEvent
.
Log
(
updatedPolicy
))
}
override
fun
contentSameAs
(
other
:
PolicyItem
)
=
itemSameAs
(
other
)
override
fun
itemSameAs
(
other
:
PolicyItem
)
=
item
.
uid
==
other
.
item
.
uid
}
\ No newline at end of file
app/src/main/java/com/topjohnwu/magisk/redesign/superuser/SuperuserViewModel.kt
View file @
fe5c65d7
...
...
@@ -10,8 +10,7 @@ import com.topjohnwu.magisk.extensions.applySchedulers
import
com.topjohnwu.magisk.extensions.subscribeK
import
com.topjohnwu.magisk.extensions.toggle
import
com.topjohnwu.magisk.model.entity.MagiskPolicy
import
com.topjohnwu.magisk.model.entity.recycler.PolicyRvItem
import
com.topjohnwu.magisk.model.events.PolicyEnableEvent
import
com.topjohnwu.magisk.model.entity.recycler.PolicyItem
import
com.topjohnwu.magisk.model.events.PolicyUpdateEvent
import
com.topjohnwu.magisk.model.events.SnackbarEvent
import
com.topjohnwu.magisk.model.events.dialog.FingerprintDialog
...
...
@@ -22,6 +21,7 @@ import com.topjohnwu.magisk.redesign.home.itemBindingOf
import
com.topjohnwu.magisk.utils.DiffObservableList
import
com.topjohnwu.magisk.utils.FingerprintHelper
import
com.topjohnwu.magisk.utils.RxBus
import
com.topjohnwu.magisk.utils.currentLocale
import
io.reactivex.Single
class
SuperuserViewModel
(
...
...
@@ -31,15 +31,12 @@ class SuperuserViewModel(
private
val
resources
:
Resources
)
:
CompatViewModel
()
{
val
items
=
diffListOf
<
Policy
Rv
Item
>()
val
itemBinding
=
itemBindingOf
<
Policy
Rv
Item
>
{
val
items
=
diffListOf
<
PolicyItem
>()
val
itemBinding
=
itemBindingOf
<
PolicyItem
>
{
it
.
bindExtra
(
BR
.
viewModel
,
this
)
}
init
{
rxBus
.
register
<
PolicyEnableEvent
>()
.
subscribeK
{
togglePolicy
(
it
.
item
,
it
.
enable
)
}
.
add
()
rxBus
.
register
<
PolicyUpdateEvent
>()
.
subscribeK
{
updatePolicy
(
it
)
}
.
add
()
...
...
@@ -50,11 +47,11 @@ class SuperuserViewModel(
override
fun
refresh
()
=
db
.
fetchAll
()
.
flattenAsFlowable
{
it
}
.
parallel
()
.
map
{
Policy
Rv
Item
(
it
,
it
.
applicationInfo
.
loadIcon
(
packageManager
))
}
.
map
{
PolicyItem
(
it
,
it
.
applicationInfo
.
loadIcon
(
packageManager
))
}
.
sequential
()
.
sorted
{
o1
,
o2
->
compareBy
<
Policy
Rv
Item
>(
{
it
.
item
.
appName
.
toLowerCase
()
},
compareBy
<
PolicyItem
>(
{
it
.
item
.
appName
.
toLowerCase
(
currentLocale
)
},
{
it
.
item
.
packageName
}
).
compare
(
o1
,
o2
)
}
...
...
@@ -69,7 +66,7 @@ class SuperuserViewModel(
fun
safetynetPressed
()
=
Navigation
.
safetynet
().
publish
()
fun
hidePressed
()
=
Navigation
.
hide
().
publish
()
fun
deletePressed
(
item
:
Policy
Rv
Item
)
{
fun
deletePressed
(
item
:
PolicyItem
)
{
fun
updateState
()
=
deletePolicy
(
item
.
item
)
.
subscribeK
{
items
.
removeAll
{
it
.
itemSameAs
(
item
)
}
}
.
add
()
...
...
@@ -88,7 +85,7 @@ class SuperuserViewModel(
//---
private
fun
updatePolicy
(
it
:
PolicyUpdateEvent
)
=
when
(
it
)
{
fun
updatePolicy
(
it
:
PolicyUpdateEvent
)
=
when
(
it
)
{
is
PolicyUpdateEvent
.
Notification
->
updatePolicy
(
it
.
item
).
map
{
when
{
it
.
notification
->
R
.
string
.
su_snack_notif_on
...
...
@@ -105,7 +102,7 @@ class SuperuserViewModel(
.
subscribeK
{
SnackbarEvent
(
it
).
publish
()
}
.
add
()
private
fun
togglePolicy
(
item
:
PolicyRv
Item
,
enable
:
Boolean
)
{
fun
togglePolicy
(
item
:
Policy
Item
,
enable
:
Boolean
)
{
fun
updateState
()
{
val
policy
=
if
(
enable
)
MagiskPolicy
.
ALLOW
else
MagiskPolicy
.
DENY
val
app
=
item
.
item
.
copy
(
policy
=
policy
)
...
...
app/src/main/res/layout/item_policy_md2.xml
View file @
fe5c65d7
...
...
@@ -7,7 +7,7 @@
<variable
name=
"item"
type=
"com.topjohnwu.magisk.model.entity.recycler.Policy
Rv
Item"
/>
type=
"com.topjohnwu.magisk.model.entity.recycler.PolicyItem"
/>
<variable
name=
"viewModel"
...
...
@@ -21,7 +21,7 @@
android:layout_height=
"wrap_content"
android:layout_gravity=
"center"
android:alpha=
"@{item.isEnabled() ? 1f : .5f}"
android:onClick=
"@{() -> item.toggle
Enabled(
)}"
android:onClick=
"@{() -> item.toggle
(viewModel
)}"
tools:layout_marginBottom=
"@dimen/l1"
tools:layout_marginEnd=
"@dimen/l1"
>
...
...
@@ -93,7 +93,7 @@
android:id=
"@+id/bell"
style=
"?styleIconNormal"
isSelected=
"@{item.shouldNotify}"
android:onClick=
"@{() -> item.toggleNotify()}"
android:onClick=
"@{() -> item.toggleNotify(
viewModel
)}"
app:layout_constraintBottom_toTopOf=
"@+id/delete"
app:layout_constraintEnd_toStartOf=
"@+id/bug"
app:layout_constraintHorizontal_chainStyle=
"packed"
...
...
@@ -107,7 +107,7 @@
android:id=
"@+id/bug"
style=
"?styleIconNormal"
isSelected=
"@{item.shouldLog}"
android:onClick=
"@{() -> item.toggleLog()}"
android:onClick=
"@{() -> item.toggleLog(
viewModel
)}"
app:layout_constraintBottom_toBottomOf=
"@+id/bell"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toEndOf=
"@+id/bell"
...
...
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