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
067248da
Commit
067248da
authored
Sep 01, 2021
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup RvItems
parent
f5c98235
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
116 additions
and
157 deletions
+116
-157
Helpers.kt
app/src/main/java/com/topjohnwu/magisk/arch/Helpers.kt
+8
-16
LocalModule.kt
...ava/com/topjohnwu/magisk/core/model/module/LocalModule.kt
+9
-7
RecyclerViewItems.kt
...ava/com/topjohnwu/magisk/databinding/RecyclerViewItems.kt
+38
-19
ConsoleItem.kt
...rc/main/java/com/topjohnwu/magisk/ui/flash/ConsoleItem.kt
+6
-5
HideRvItems.kt
...src/main/java/com/topjohnwu/magisk/ui/hide/HideRvItems.kt
+4
-3
LogRvItem.kt
app/src/main/java/com/topjohnwu/magisk/ui/log/LogRvItem.kt
+5
-12
ModuleRvItem.kt
.../main/java/com/topjohnwu/magisk/ui/module/ModuleRvItem.kt
+11
-19
ModuleViewModel.kt
...in/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt
+4
-4
BaseSettingsItem.kt
...java/com/topjohnwu/magisk/ui/settings/BaseSettingsItem.kt
+2
-5
SettingsViewModel.kt
...ava/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt
+1
-2
PolicyRvItem.kt
...in/java/com/topjohnwu/magisk/ui/superuser/PolicyRvItem.kt
+4
-4
SuperuserViewModel.kt
...a/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt
+5
-5
DiffObservableList.kt
...ain/java/com/topjohnwu/magisk/utils/DiffObservableList.kt
+11
-40
MagiskDialog.kt
app/src/main/java/com/topjohnwu/magisk/view/MagiskDialog.kt
+4
-5
TappableHeadlineItem.kt
...in/java/com/topjohnwu/magisk/view/TappableHeadlineItem.kt
+2
-8
TextItem.kt
app/src/main/java/com/topjohnwu/magisk/view/TextItem.kt
+2
-3
No files found.
app/src/main/java/com/topjohnwu/magisk/arch/Helpers.kt
View file @
067248da
package
com.topjohnwu.magisk.arch
import
androidx.databinding.ViewDataBinding
import
com.topjohnwu.magisk.databinding.ComparableRvItem
import
com.topjohnwu.magisk.databinding.AnyDiffRvItem
import
com.topjohnwu.magisk.databinding.DiffRvItem
import
com.topjohnwu.magisk.databinding.RvItem
import
com.topjohnwu.magisk.utils.DiffObservableList
import
com.topjohnwu.magisk.utils.FilterableDiffObservableList
...
...
@@ -9,23 +10,14 @@ import me.tatarka.bindingcollectionadapter2.BindingRecyclerViewAdapter
import
me.tatarka.bindingcollectionadapter2.ItemBinding
import
me.tatarka.bindingcollectionadapter2.OnItemBind
fun
<
T
:
ComparableRvItem
<*
>
>
diffListOf
(
vararg
newItems
:
T
)
=
diffListOf
(
newItems
.
toList
())
fun
<
T
:
AnyDiffRvItem
>
diffListOf
()
=
DiffObservableList
(
DiffRvItem
.
callback
<
T
>())
fun
<
T
:
ComparableRvItem
<*
>
>
diffListOf
(
newItems
:
List
<
T
>
)
=
DiffObservableList
(
object
:
DiffObservableList
.
Callback
<
T
>
{
override
fun
areItemsTheSame
(
oldItem
:
T
,
newItem
:
T
)
=
oldItem
.
genericItemSameAs
(
newItem
)
override
fun
areContentsTheSame
(
oldItem
:
T
,
newItem
:
T
)
=
oldItem
.
genericContentSameAs
(
newItem
)
}).
also
{
it
.
update
(
newItems
)
}
fun
<
T
:
AnyDiffRvItem
>
diffListOf
(
newItems
:
List
<
T
>)
=
DiffObservableList
(
DiffRvItem
.
callback
<
T
>()).
also
{
it
.
update
(
newItems
)
}
fun
<
T
:
ComparableRvItem
<*
>
>
filterableListOf
(
vararg
newItems
:
T
)
=
FilterableDiffObservableList
(
object
:
DiffObservableList
.
Callback
<
T
>
{
override
fun
areItemsTheSame
(
oldItem
:
T
,
newItem
:
T
)
=
oldItem
.
genericItemSameAs
(
newItem
)
override
fun
areContentsTheSame
(
oldItem
:
T
,
newItem
:
T
)
=
oldItem
.
genericContentSameAs
(
newItem
)
}).
also
{
it
.
update
(
newItems
.
toList
())
}
fun
<
T
:
AnyDiffRvItem
>
filterableListOf
()
=
FilterableDiffObservableList
(
DiffRvItem
.
callback
<
T
>())
fun
<
T
:
RvItem
>
adapterOf
()
=
object
:
BindingRecyclerViewAdapter
<
T
>()
{
override
fun
onBindBinding
(
...
...
app/src/main/java/com/topjohnwu/magisk/core/model/module/LocalModule.kt
View file @
067248da
...
...
@@ -7,13 +7,15 @@ import kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.withContext
import
java.util.*
class
LocalModule
(
path
:
String
)
:
Module
()
{
override
var
id
:
String
=
""
override
var
name
:
String
=
""
override
var
author
:
String
=
""
override
var
version
:
String
=
""
override
var
versionCode
:
Int
=
-
1
override
var
description
:
String
=
""
data class
LocalModule
(
private
val
path
:
String
,
override
var
id
:
String
=
""
,
override
var
name
:
String
=
""
,
override
var
author
:
String
=
""
,
override
var
version
:
String
=
""
,
override
var
versionCode
:
Int
=
-
1
,
override
var
description
:
String
=
""
,
)
:
Module
()
{
private
val
removeFile
=
SuFile
(
path
,
"remove"
)
private
val
disableFile
=
SuFile
(
path
,
"disable"
)
...
...
app/src/main/java/com/topjohnwu/magisk/databinding/RecyclerViewItems.kt
View file @
067248da
...
...
@@ -26,38 +26,57 @@ abstract class RvItem {
open
fun
onBindingBound
(
binding
:
ViewDataBinding
)
{}
}
abstract
class
ComparableRvItem
<
in
T
>
:
RvItem
()
{
// Use Any.equals by default
open
fun
itemSameAs
(
other
:
T
)
=
this
==
other
interface
RvContainer
<
E
>
{
val
item
:
E
}
// Use compareTo if this is Comparable or assume not same
interface
ComparableRv
<
T
>
:
Comparable
<
T
>
{
@Suppress
(
"UNCHECKED_CAST"
)
open
fun
contentSameAs
(
other
:
T
)
=
(
this
as
?
Comparable
<
T
>)
?.
run
{
compareTo
(
other
)
==
0
}
?:
false
fun
comparableEqual
(
o
:
Any
?)
=
o
!=
null
&&
o
::
class
==
this
::
class
&&
compareTo
(
o
as
T
)
==
0
}
@Suppress
(
"UNCHECKED_CAST"
)
open
fun
genericItemSameAs
(
other
:
Any
):
Boolean
=
other
::
class
==
this
::
class
&&
itemSameAs
(
other
as
T
)
abstract
class
DiffRvItem
<
T
>
:
RvItem
()
{
@Suppress
(
"UNCHECKED_CAST"
)
open
fun
genericContentSameAs
(
other
:
Any
):
Boolean
=
other
::
class
==
this
::
class
&&
contentSameAs
(
other
as
T
)
// Defer to contentSameAs by default
open
fun
itemSameAs
(
other
:
T
)
=
true
open
fun
contentSameAs
(
other
:
T
)
=
when
(
this
)
{
is
RvContainer
<*>
->
item
==
(
other
as
RvContainer
<*>).
item
is
ComparableRv
<*>
->
comparableEqual
(
other
)
else
->
this
==
other
}
companion
object
{
val
callback
=
object
:
DiffObservableList
.
Callback
<
ComparableRvItem
<*
>>
{
private
val
callback
=
object
:
DiffObservableList
.
Callback
<
DiffRvItem
<
Any
>>
{
override
fun
areItemsTheSame
(
oldItem
:
ComparableRvItem
<
*
>,
newItem
:
ComparableRvItem
<
*
>
)
=
oldItem
.
genericItemSameAs
(
newItem
)
oldItem
:
DiffRvItem
<
Any
>,
newItem
:
DiffRvItem
<
Any
>
):
Boolean
{
return
oldItem
::
class
==
newItem
::
class
&&
oldItem
.
itemSameAs
(
newItem
)
}
override
fun
areContentsTheSame
(
oldItem
:
ComparableRvItem
<
*
>,
newItem
:
ComparableRvItem
<
*
>
)
=
oldItem
.
genericContentSameAs
(
newItem
)
oldItem
:
DiffRvItem
<
Any
>,
newItem
:
DiffRvItem
<
Any
>
):
Boolean
{
return
oldItem
.
contentSameAs
(
newItem
)
}
}
@Suppress
(
"UNCHECKED_CAST"
)
fun
<
T
:
AnyDiffRvItem
>
callback
()
=
callback
as
DiffObservableList
.
Callback
<
T
>
}
}
abstract
class
ObservableItem
<
T
>
:
ComparableRvItem
<
T
>(),
ObservableHost
{
typealias
AnyDiffRvItem
=
DiffRvItem
<*>
abstract
class
ObservableDiffRvItem
<
T
>
:
DiffRvItem
<
T
>(),
ObservableHost
{
override
var
callbacks
:
PropertyChangeRegistry
?
=
null
}
abstract
class
ObservableRvItem
:
RvItem
(),
ObservableHost
{
override
var
callbacks
:
PropertyChangeRegistry
?
=
null
}
...
...
app/src/main/java/com/topjohnwu/magisk/ui/flash/ConsoleItem.kt
View file @
067248da
...
...
@@ -6,11 +6,15 @@ import androidx.core.view.updateLayoutParams
import
androidx.databinding.ViewDataBinding
import
androidx.recyclerview.widget.RecyclerView
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.databinding.
Comparable
RvItem
import
com.topjohnwu.magisk.databinding.
Diff
RvItem
import
com.topjohnwu.magisk.databinding.LenientRvItem
import
com.topjohnwu.magisk.databinding.RvContainer
import
kotlin.math.max
class
ConsoleItem
(
val
item
:
String
)
:
ComparableRvItem
<
ConsoleItem
>(),
LenientRvItem
{
class
ConsoleItem
(
override
val
item
:
String
)
:
DiffRvItem
<
ConsoleItem
>(),
LenientRvItem
,
RvContainer
<
String
>
{
override
val
layoutRes
=
R
.
layout
.
item_console_md2
private
var
parentWidth
=
-
1
...
...
@@ -31,7 +35,4 @@ class ConsoleItem(val item: String) : ComparableRvItem<ConsoleItem>(), LenientRv
recyclerView
.
requestLayout
()
}
}
override
fun
contentSameAs
(
other
:
ConsoleItem
)
=
itemSameAs
(
other
)
override
fun
itemSameAs
(
other
:
ConsoleItem
)
=
item
==
other
.
item
}
app/src/main/java/com/topjohnwu/magisk/ui/hide/HideRvItems.kt
View file @
067248da
...
...
@@ -5,7 +5,8 @@ import android.view.ViewGroup
import
androidx.databinding.Bindable
import
com.topjohnwu.magisk.BR
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.databinding.ObservableItem
import
com.topjohnwu.magisk.databinding.ComparableRv
import
com.topjohnwu.magisk.databinding.ObservableDiffRvItem
import
com.topjohnwu.magisk.ktx.startAnimations
import
com.topjohnwu.magisk.utils.addOnPropertyChangedCallback
import
com.topjohnwu.magisk.utils.set
...
...
@@ -14,7 +15,7 @@ import kotlin.math.roundToInt
class
HideRvItem
(
val
info
:
HideAppInfo
)
:
Observable
Item
<
HideRvItem
>(),
Comparable
<
HideRvItem
>
{
)
:
Observable
DiffRvItem
<
HideRvItem
>(),
ComparableRv
<
HideRvItem
>
{
override
val
layoutRes
get
()
=
R
.
layout
.
item_hide_md2
...
...
@@ -89,7 +90,7 @@ class HideRvItem(
class
HideProcessRvItem
(
val
process
:
HideProcessInfo
)
:
ObservableItem
<
HideProcessRvItem
>()
{
)
:
Observable
DiffRv
Item
<
HideProcessRvItem
>()
{
override
val
layoutRes
get
()
=
R
.
layout
.
item_hide_process_md2
...
...
app/src/main/java/com/topjohnwu/magisk/ui/log/LogRvItem.kt
View file @
067248da
...
...
@@ -4,12 +4,15 @@ import androidx.databinding.Bindable
import
com.topjohnwu.magisk.BR
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.core.model.su.SuLog
import
com.topjohnwu.magisk.databinding.ObservableItem
import
com.topjohnwu.magisk.databinding.ObservableDiffRvItem
import
com.topjohnwu.magisk.databinding.RvContainer
import
com.topjohnwu.magisk.ktx.timeDateFormat
import
com.topjohnwu.magisk.ktx.toTime
import
com.topjohnwu.magisk.utils.set
class
LogRvItem
(
val
item
:
SuLog
)
:
ObservableItem
<
LogRvItem
>()
{
class
LogRvItem
(
override
val
item
:
SuLog
)
:
ObservableDiffRvItem
<
LogRvItem
>(),
RvContainer
<
SuLog
>
{
override
val
layoutRes
=
R
.
layout
.
item_log_access_md2
...
...
@@ -24,14 +27,4 @@ class LogRvItem(val item: SuLog) : ObservableItem<LogRvItem>() {
set
(
value
)
=
set
(
value
,
field
,
{
field
=
it
},
BR
.
bottom
)
override
fun
itemSameAs
(
other
:
LogRvItem
)
=
item
.
appName
==
other
.
item
.
appName
override
fun
contentSameAs
(
other
:
LogRvItem
)
=
item
.
fromUid
==
other
.
item
.
fromUid
&&
item
.
toUid
==
other
.
item
.
toUid
&&
item
.
fromPid
==
other
.
item
.
fromPid
&&
item
.
packageName
==
other
.
item
.
packageName
&&
item
.
command
==
other
.
item
.
command
&&
item
.
action
==
other
.
item
.
action
&&
item
.
time
==
other
.
item
.
time
&&
isTop
==
other
.
isTop
&&
isBottom
==
other
.
isBottom
}
app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleRvItem.kt
View file @
067248da
...
...
@@ -5,22 +5,20 @@ import com.topjohnwu.magisk.BR
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.core.model.module.LocalModule
import
com.topjohnwu.magisk.core.model.module.OnlineModule
import
com.topjohnwu.magisk.databinding.ComparableRvItem
import
com.topjohnwu.magisk.databinding.ObservableItem
import
com.topjohnwu.magisk.databinding.DiffRvItem
import
com.topjohnwu.magisk.databinding.ObservableDiffRvItem
import
com.topjohnwu.magisk.databinding.RvContainer
import
com.topjohnwu.magisk.utils.set
object
InstallModule
:
Comparable
RvItem
<
InstallModule
>()
{
object
InstallModule
:
Diff
RvItem
<
InstallModule
>()
{
override
val
layoutRes
=
R
.
layout
.
item_module_download
override
fun
contentSameAs
(
other
:
InstallModule
)
=
this
==
other
override
fun
itemSameAs
(
other
:
InstallModule
)
=
this
===
other
}
class
SectionTitle
(
val
title
:
Int
,
_button
:
Int
=
0
,
_icon
:
Int
=
0
)
:
ObservableItem
<
SectionTitle
>()
{
)
:
Observable
DiffRv
Item
<
SectionTitle
>()
{
override
val
layoutRes
=
R
.
layout
.
item_section_md2
@get
:
Bindable
...
...
@@ -34,12 +32,11 @@ class SectionTitle(
@get
:
Bindable
var
hasButton
=
_button
!=
0
&&
_icon
!=
0
set
(
value
)
=
set
(
value
,
field
,
{
field
=
it
},
BR
.
hasButton
)
override
fun
itemSameAs
(
other
:
SectionTitle
):
Boolean
=
this
===
other
override
fun
contentSameAs
(
other
:
SectionTitle
):
Boolean
=
this
===
other
}
class
OnlineModuleRvItem
(
val
item
:
OnlineModule
)
:
ObservableItem
<
OnlineModuleRvItem
>()
{
class
OnlineModuleRvItem
(
override
val
item
:
OnlineModule
)
:
ObservableDiffRvItem
<
OnlineModuleRvItem
>(),
RvContainer
<
OnlineModule
>
{
override
val
layoutRes
:
Int
=
R
.
layout
.
item_repo_md2
@get
:
Bindable
...
...
@@ -48,12 +45,12 @@ class OnlineModuleRvItem(val item: OnlineModule) : ObservableItem<OnlineModuleRv
var
hasUpdate
=
false
override
fun
contentSameAs
(
other
:
OnlineModuleRvItem
):
Boolean
=
item
==
other
.
item
override
fun
itemSameAs
(
other
:
OnlineModuleRvItem
):
Boolean
=
item
.
id
==
other
.
item
.
id
}
class
LocalModuleRvItem
(
val
item
:
LocalModule
)
:
ObservableItem
<
LocalModuleRvItem
>()
{
class
LocalModuleRvItem
(
override
val
item
:
LocalModule
)
:
ObservableDiffRvItem
<
LocalModuleRvItem
>(),
RvContainer
<
LocalModule
>
{
override
val
layoutRes
=
R
.
layout
.
item_module_md2
...
...
@@ -81,10 +78,5 @@ class LocalModuleRvItem(val item: LocalModule) : ObservableItem<LocalModuleRvIte
viewModel
.
updateActiveState
()
}
override
fun
contentSameAs
(
other
:
LocalModuleRvItem
):
Boolean
=
item
.
version
==
other
.
item
.
version
&&
item
.
versionCode
==
other
.
item
.
versionCode
&&
item
.
description
==
other
.
item
.
description
&&
item
.
name
==
other
.
item
.
name
override
fun
itemSameAs
(
other
:
LocalModuleRvItem
):
Boolean
=
item
.
id
==
other
.
item
.
id
}
app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt
View file @
067248da
...
...
@@ -9,7 +9,7 @@ import com.topjohnwu.magisk.arch.*
import
com.topjohnwu.magisk.core.Info
import
com.topjohnwu.magisk.core.model.module.LocalModule
import
com.topjohnwu.magisk.core.model.module.OnlineModule
import
com.topjohnwu.magisk.databinding.
Comparable
RvItem
import
com.topjohnwu.magisk.databinding.
AnyDiff
RvItem
import
com.topjohnwu.magisk.databinding.RvItem
import
com.topjohnwu.magisk.events.OpenReadmeEvent
import
com.topjohnwu.magisk.events.SelectModuleEvent
...
...
@@ -44,8 +44,8 @@ class ModuleViewModel : BaseViewModel(), Queryable {
var
searchLoading
=
false
set
(
value
)
=
set
(
value
,
field
,
{
field
=
it
},
BR
.
searchLoading
)
val
itemsSearch
=
diffListOf
<
ComparableRvItem
<*>
>()
val
itemSearchBinding
=
itemBindingOf
<
ComparableRvItem
<*>
>
{
val
itemsSearch
=
diffListOf
<
AnyDiffRvItem
>()
val
itemSearchBinding
=
itemBindingOf
<
AnyDiffRvItem
>
{
it
.
bindExtra
(
BR
.
viewModel
,
this
)
}
...
...
@@ -110,7 +110,7 @@ class ModuleViewModel : BaseViewModel(), Queryable {
// ---
private
suspend
fun
queryInternal
(
query
:
String
):
List
<
ComparableRvItem
<*
>
>
{
private
suspend
fun
queryInternal
(
query
:
String
):
List
<
AnyDiffRvItem
>
{
return
if
(
query
.
isBlank
())
{
itemsSearch
.
clear
()
listOf
()
...
...
app/src/main/java/com/topjohnwu/magisk/ui/settings/BaseSettingsItem.kt
View file @
067248da
...
...
@@ -7,12 +7,12 @@ import androidx.annotation.CallSuper
import
androidx.databinding.Bindable
import
com.topjohnwu.magisk.BR
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.databinding.ObservableItem
import
com.topjohnwu.magisk.databinding.Observable
Rv
Item
import
com.topjohnwu.magisk.utils.TextHolder
import
com.topjohnwu.magisk.utils.set
import
com.topjohnwu.magisk.view.MagiskDialog
sealed
class
BaseSettingsItem
:
Observable
Item
<
BaseSettingsItem
>
()
{
sealed
class
BaseSettingsItem
:
Observable
RvItem
()
{
override
val
layoutRes
get
()
=
R
.
layout
.
item_settings
...
...
@@ -42,9 +42,6 @@ sealed class BaseSettingsItem : ObservableItem<BaseSettingsItem>() {
open
fun
refresh
()
{}
override
fun
itemSameAs
(
other
:
BaseSettingsItem
)
=
this
===
other
override
fun
contentSameAs
(
other
:
BaseSettingsItem
)
=
itemSameAs
(
other
)
// ---
interface
Callback
{
...
...
app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt
View file @
067248da
...
...
@@ -10,7 +10,6 @@ import com.topjohnwu.magisk.BuildConfig
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.arch.BaseViewModel
import
com.topjohnwu.magisk.arch.adapterOf
import
com.topjohnwu.magisk.arch.diffListOf
import
com.topjohnwu.magisk.arch.itemBindingOf
import
com.topjohnwu.magisk.core.Const
import
com.topjohnwu.magisk.core.Info
...
...
@@ -32,7 +31,7 @@ class SettingsViewModel(
val
adapter
=
adapterOf
<
BaseSettingsItem
>()
val
itemBinding
=
itemBindingOf
<
BaseSettingsItem
>
{
it
.
bindExtra
(
BR
.
callback
,
this
)
}
val
items
=
diffListOf
(
createItems
()
)
val
items
=
createItems
(
)
init
{
viewModelScope
.
launch
{
...
...
app/src/main/java/com/topjohnwu/magisk/ui/superuser/PolicyRvItem.kt
View file @
067248da
...
...
@@ -5,14 +5,15 @@ import androidx.databinding.Bindable
import
com.topjohnwu.magisk.BR
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.core.model.su.SuPolicy
import
com.topjohnwu.magisk.databinding.ObservableItem
import
com.topjohnwu.magisk.databinding.ObservableDiffRvItem
import
com.topjohnwu.magisk.databinding.RvContainer
import
com.topjohnwu.magisk.utils.set
class
PolicyRvItem
(
val
item
:
SuPolicy
,
override
val
item
:
SuPolicy
,
val
icon
:
Drawable
,
val
viewModel
:
SuperuserViewModel
)
:
Observable
Item
<
PolicyRvItem
>()
{
)
:
Observable
DiffRvItem
<
PolicyRvItem
>(),
RvContainer
<
SuPolicy
>
{
override
val
layoutRes
=
R
.
layout
.
item_policy_md2
@get
:
Bindable
...
...
@@ -64,7 +65,6 @@ class PolicyRvItem(
viewModel
.
deletePressed
(
this
)
}
override
fun
contentSameAs
(
other
:
PolicyRvItem
)
=
itemSameAs
(
other
)
override
fun
itemSameAs
(
other
:
PolicyRvItem
)
=
item
.
uid
==
other
.
item
.
uid
}
app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt
View file @
067248da
...
...
@@ -13,7 +13,7 @@ import com.topjohnwu.magisk.core.magiskdb.PolicyDao
import
com.topjohnwu.magisk.core.model.su.SuPolicy
import
com.topjohnwu.magisk.core.utils.BiometricHelper
import
com.topjohnwu.magisk.core.utils.currentLocale
import
com.topjohnwu.magisk.databinding.
Comparable
RvItem
import
com.topjohnwu.magisk.databinding.
AnyDiff
RvItem
import
com.topjohnwu.magisk.events.SnackbarEvent
import
com.topjohnwu.magisk.events.dialog.BiometricEvent
import
com.topjohnwu.magisk.events.dialog.SuperuserRevokeDialog
...
...
@@ -35,13 +35,13 @@ class SuperuserViewModel(
private
val
itemsPolicies
=
diffListOf
<
PolicyRvItem
>()
private
val
itemsHelpers
=
ObservableArrayList
<
TextItem
>()
val
adapter
=
adapterOf
<
ComparableRvItem
<*>
>()
val
items
=
MergeObservableList
<
ComparableRvItem
<*>
>().
apply
{
val
adapter
=
adapterOf
<
AnyDiffRvItem
>()
val
items
=
MergeObservableList
<
AnyDiffRvItem
>().
apply
{
if
(
Config
.
magiskHide
)
insertItem
(
TappableHeadlineItem
.
Hide
)
}.
insertList
(
itemsHelpers
)
.
insertList
(
itemsPolicies
)
val
itemBinding
=
itemBindingOf
<
ComparableRvItem
<*>
>
{
val
itemBinding
=
itemBindingOf
<
AnyDiffRvItem
>
{
it
.
bindExtra
(
BR
.
listener
,
this
)
}
...
...
@@ -84,7 +84,7 @@ class SuperuserViewModel(
fun
deletePressed
(
item
:
PolicyRvItem
)
{
fun
updateState
()
=
viewModelScope
.
launch
{
db
.
delete
(
item
.
item
.
uid
)
itemsPolicies
.
removeAll
{
it
.
genericI
temSameAs
(
item
)
}
itemsPolicies
.
removeAll
{
it
.
i
temSameAs
(
item
)
}
if
(
itemsPolicies
.
isEmpty
()
&&
itemsHelpers
.
isEmpty
())
{
itemsHelpers
.
add
(
itemNoData
)
}
...
...
app/src/main/java/com/topjohnwu/magisk/utils/DiffObservableList.kt
View file @
067248da
...
...
@@ -13,11 +13,10 @@ import kotlin.collections.ArrayList
* @param detectMoves True if DiffUtil should try to detect moved items, false otherwise.
*/
open
class
DiffObservableList
<
T
>(
private
val
callback
:
Callback
<
T
>,
private
val
detectMoves
:
Boolean
=
true
private
val
callback
:
Callback
<
T
>,
private
val
detectMoves
:
Boolean
=
true
)
:
AbstractList
<
T
>(),
ObservableList
<
T
>
{
private
val
LIST_LOCK
=
Object
()
protected
var
list
:
MutableList
<
T
>
=
ArrayList
()
private
val
listeners
=
ListChangeRegistry
()
protected
val
listCallback
=
ObservableListUpdateCallback
()
...
...
@@ -32,27 +31,25 @@ open class DiffObservableList<T>(
* list into the given one.
*/
fun
calculateDiff
(
newItems
:
List
<
T
>):
DiffUtil
.
DiffResult
{
val
frozenList
=
synchronized
(
LIST_LOCK
)
{
ArrayList
(
list
)
}
val
frozenList
=
ArrayList
(
list
)
return
doCalculateDiff
(
frozenList
,
newItems
)
}
protected
fun
doCalculateDiff
(
oldItems
:
List
<
T
>,
newItems
:
List
<
T
>
?
):
DiffUtil
.
DiffResult
{
protected
fun
doCalculateDiff
(
oldItems
:
List
<
T
>,
newItems
:
List
<
T
>):
DiffUtil
.
DiffResult
{
return
DiffUtil
.
calculateDiff
(
object
:
DiffUtil
.
Callback
()
{
override
fun
getOldListSize
()
=
oldItems
.
size
override
fun
getNewListSize
()
=
newItems
?.
size
?:
0
override
fun
getNewListSize
()
=
newItems
.
size
override
fun
areItemsTheSame
(
oldItemPosition
:
Int
,
newItemPosition
:
Int
):
Boolean
{
val
oldItem
=
oldItems
[
oldItemPosition
]
val
newItem
=
newItems
!!
[
newItemPosition
]
val
newItem
=
newItems
[
newItemPosition
]
return
callback
.
areItemsTheSame
(
oldItem
,
newItem
)
}
override
fun
areContentsTheSame
(
oldItemPosition
:
Int
,
newItemPosition
:
Int
):
Boolean
{
val
oldItem
=
oldItems
[
oldItemPosition
]
val
newItem
=
newItems
!!
[
newItemPosition
]
val
newItem
=
newItems
[
newItemPosition
]
return
callback
.
areContentsTheSame
(
oldItem
,
newItem
)
}
},
detectMoves
)
...
...
@@ -67,9 +64,7 @@ open class DiffObservableList<T>(
*/
@MainThread
fun
update
(
newItems
:
List
<
T
>,
diffResult
:
DiffUtil
.
DiffResult
)
{
synchronized
(
LIST_LOCK
)
{
list
=
newItems
.
toMutableList
()
}
list
=
newItems
.
toMutableList
()
diffResult
.
dispatchUpdatesTo
(
listCallback
)
}
...
...
@@ -97,29 +92,14 @@ open class DiffObservableList<T>(
listeners
.
remove
(
listener
)
}
override
fun
get
(
index
:
Int
):
T
{
return
list
[
index
]
}
override
fun
add
(
element
:
T
):
Boolean
{
list
.
add
(
element
)
notifyAdd
(
size
-
1
,
1
)
return
true
}
override
fun
get
(
index
:
Int
)
=
list
[
index
]
override
fun
add
(
index
:
Int
,
element
:
T
)
{
list
.
add
(
index
,
element
)
notifyAdd
(
index
,
1
)
}
override
fun
addAll
(
elements
:
Collection
<
T
>):
Boolean
{
val
oldSize
=
size
val
added
=
list
.
addAll
(
elements
)
if
(
added
)
{
notifyAdd
(
oldSize
,
size
-
oldSize
)
}
return
added
}
override
fun
addAll
(
elements
:
Collection
<
T
>)
=
addAll
(
size
,
elements
)
override
fun
addAll
(
index
:
Int
,
elements
:
Collection
<
T
>):
Boolean
{
val
added
=
list
.
addAll
(
index
,
elements
)
...
...
@@ -153,14 +133,6 @@ open class DiffObservableList<T>(
return
element
}
fun
removeLast
():
T
?
{
if
(
size
>
0
)
{
val
index
=
size
-
1
return
removeAt
(
index
)
}
return
null
}
override
fun
set
(
index
:
Int
,
element
:
T
):
T
{
val
old
=
list
.
set
(
index
,
element
)
listeners
.
notifyChanged
(
this
,
index
,
1
)
...
...
@@ -228,6 +200,5 @@ open class DiffObservableList<T>(
modCount
+=
1
listeners
.
notifyRemoved
(
this
@DiffObservableList
,
position
,
count
)
}
}
}
\ No newline at end of file
}
app/src/main/java/com/topjohnwu/magisk/view/MagiskDialog.kt
View file @
067248da
...
...
@@ -23,8 +23,9 @@ import com.google.android.material.shape.MaterialShapeDrawable
import
com.topjohnwu.magisk.BR
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.arch.itemBindingOf
import
com.topjohnwu.magisk.databinding.
Comparable
RvItem
import
com.topjohnwu.magisk.databinding.
Diff
RvItem
import
com.topjohnwu.magisk.databinding.DialogMagiskBaseBinding
import
com.topjohnwu.magisk.databinding.RvContainer
import
com.topjohnwu.magisk.utils.ObservableHost
import
com.topjohnwu.magisk.utils.set
import
me.tatarka.bindingcollectionadapter2.BindingRecyclerViewAdapters
...
...
@@ -188,12 +189,10 @@ class MagiskDialog(
}
class
DialogItem
(
val
item
:
CharSequence
,
override
val
item
:
CharSequence
,
val
position
:
Int
)
:
ComparableRvItem
<
DialogItem
>()
{
)
:
DiffRvItem
<
DialogItem
>(),
RvContainer
<
CharSequence
>
{
override
val
layoutRes
=
R
.
layout
.
item_list_single_line
override
fun
itemSameAs
(
other
:
DialogItem
)
=
item
==
other
.
item
override
fun
contentSameAs
(
other
:
DialogItem
)
=
itemSameAs
(
other
)
}
interface
ActualOnDialogClickListener
{
...
...
app/src/main/java/com/topjohnwu/magisk/view/TappableHeadlineItem.kt
View file @
067248da
package
com.topjohnwu.magisk.view
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.databinding.
Comparable
RvItem
import
com.topjohnwu.magisk.databinding.
Diff
RvItem
sealed
class
TappableHeadlineItem
:
Comparable
RvItem
<
TappableHeadlineItem
>()
{
sealed
class
TappableHeadlineItem
:
Diff
RvItem
<
TappableHeadlineItem
>()
{
abstract
val
title
:
Int
abstract
val
icon
:
Int
override
val
layoutRes
=
R
.
layout
.
item_tappable_headline
override
fun
itemSameAs
(
other
:
TappableHeadlineItem
)
=
this
===
other
override
fun
contentSameAs
(
other
:
TappableHeadlineItem
)
=
title
==
other
.
title
&&
icon
==
other
.
icon
// --- listener
interface
Listener
{
...
...
app/src/main/java/com/topjohnwu/magisk/view/TextItem.kt
View file @
067248da
package
com.topjohnwu.magisk.view
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.databinding.
Comparable
RvItem
import
com.topjohnwu.magisk.databinding.
Diff
RvItem
class
TextItem
(
val
text
:
Int
)
:
Comparable
RvItem
<
TextItem
>()
{
class
TextItem
(
val
text
:
Int
)
:
Diff
RvItem
<
TextItem
>()
{
override
val
layoutRes
=
R
.
layout
.
item_text
override
fun
contentSameAs
(
other
:
TextItem
)
=
text
==
other
.
text
override
fun
itemSameAs
(
other
:
TextItem
)
=
contentSameAs
(
other
)
}
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