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
0f95a7ba
Commit
0f95a7ba
authored
Apr 09, 2021
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not hold resources in SuperuserViewModel
parent
7cb28068
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
19 deletions
+15
-19
ViewModelsModule.kt
...src/main/java/com/topjohnwu/magisk/di/ViewModelsModule.kt
+1
-3
SnackbarEvent.kt
...rc/main/java/com/topjohnwu/magisk/events/SnackbarEvent.kt
+9
-9
SuperuserViewModel.kt
...a/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt
+5
-6
TransitiveText.kt
...rc/main/java/com/topjohnwu/magisk/utils/TransitiveText.kt
+0
-1
No files found.
app/src/main/java/com/topjohnwu/magisk/di/ViewModelsModule.kt
View file @
0f95a7ba
...
...
@@ -23,12 +23,10 @@ val viewModelModules = module {
viewModel
{
ModuleViewModel
(
get
(),
get
())
}
viewModel
{
SafetynetViewModel
()
}
viewModel
{
SettingsViewModel
(
get
())
}
viewModel
{
SuperuserViewModel
(
get
()
,
get
()
)
}
viewModel
{
SuperuserViewModel
(
get
())
}
viewModel
{
ThemeViewModel
()
}
viewModel
{
InstallViewModel
(
get
())
}
viewModel
{
MainViewModel
()
}
// Legacy
viewModel
{
(
args
:
FlashFragmentArgs
)
->
FlashViewModel
(
args
)
}
viewModel
{
SuRequestViewModel
(
get
(),
get
(),
get
(
SUTimeout
),
get
())
}
}
app/src/main/java/com/topjohnwu/magisk/events/SnackbarEvent.kt
View file @
0f95a7ba
...
...
@@ -7,31 +7,32 @@ import com.topjohnwu.magisk.arch.ActivityExecutor
import
com.topjohnwu.magisk.arch.BaseUIActivity
import
com.topjohnwu.magisk.arch.ViewEvent
import
com.topjohnwu.magisk.utils.TransitiveText
import
com.topjohnwu.magisk.utils.asTransitive
class
SnackbarEvent
private
constructor
(
class
SnackbarEvent
constructor
(
private
val
msg
:
TransitiveText
,
private
val
length
:
Int
,
private
val
builder
:
Snackbar
.()
->
Unit
private
val
length
:
Int
=
Snackbar
.
LENGTH_SHORT
,
private
val
builder
:
Snackbar
.()
->
Unit
=
{}
)
:
ViewEvent
(),
ActivityExecutor
{
constructor
(
@StringRes
res
:
Int
,
length
:
Int
=
Snackbar
.
LENGTH_SHORT
,
builder
:
Snackbar
.()
->
Unit
=
{}
)
:
this
(
TransitiveText
.
Res
(
res
),
length
,
builder
)
)
:
this
(
res
.
asTransitive
(
),
length
,
builder
)
constructor
(
m
essage
:
String
,
m
sg
:
String
,
length
:
Int
=
Snackbar
.
LENGTH_SHORT
,
builder
:
Snackbar
.()
->
Unit
=
{}
)
:
this
(
TransitiveText
.
String
(
message
),
length
,
builder
)
)
:
this
(
msg
.
asTransitive
(
),
length
,
builder
)
private
fun
snackbar
(
view
:
View
,
message
:
String
,
length
:
Int
=
Snackbar
.
LENGTH_SHORT
,
builder
:
Snackbar
.()
->
Unit
=
{}
length
:
Int
,
builder
:
Snackbar
.()
->
Unit
)
=
Snackbar
.
make
(
view
,
message
,
length
).
apply
(
builder
).
show
()
override
fun
invoke
(
activity
:
BaseUIActivity
<
*
,
*
>)
{
...
...
@@ -39,5 +40,4 @@ class SnackbarEvent private constructor(
msg
.
getText
(
activity
.
resources
).
toString
(),
length
,
builder
)
}
}
app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt
View file @
0f95a7ba
package
com.topjohnwu.magisk.ui.superuser
import
android.content.res.Resources
import
androidx.databinding.ObservableArrayList
import
androidx.lifecycle.viewModelScope
import
com.topjohnwu.magisk.BR
...
...
@@ -19,6 +18,7 @@ import com.topjohnwu.magisk.events.SnackbarEvent
import
com.topjohnwu.magisk.events.dialog.BiometricEvent
import
com.topjohnwu.magisk.events.dialog.SuperuserRevokeDialog
import
com.topjohnwu.magisk.utils.Utils
import
com.topjohnwu.magisk.utils.asTransitive
import
com.topjohnwu.magisk.view.TappableHeadlineItem
import
com.topjohnwu.magisk.view.TextItem
import
kotlinx.coroutines.Dispatchers
...
...
@@ -27,8 +27,7 @@ import kotlinx.coroutines.withContext
import
me.tatarka.bindingcollectionadapter2.collections.MergeObservableList
class
SuperuserViewModel
(
private
val
db
:
PolicyDao
,
private
val
resources
:
Resources
private
val
db
:
PolicyDao
)
:
BaseViewModel
(),
TappableHeadlineItem
.
Listener
{
private
val
itemNoData
=
TextItem
(
R
.
string
.
superuser_policy_none
)
...
...
@@ -107,7 +106,7 @@ class SuperuserViewModel(
fun
updatePolicy
(
policy
:
SuPolicy
,
isLogging
:
Boolean
)
=
viewModelScope
.
launch
{
db
.
update
(
policy
)
val
str
=
when
{
val
res
=
when
{
isLogging
->
when
{
policy
.
logging
->
R
.
string
.
su_snack_log_on
else
->
R
.
string
.
su_snack_log_off
...
...
@@ -117,7 +116,7 @@ class SuperuserViewModel(
else
->
R
.
string
.
su_snack_notif_off
}
}
SnackbarEvent
(
res
ources
.
getString
(
str
,
policy
.
appName
)).
publish
()
SnackbarEvent
(
res
.
asTransitive
(
policy
.
appName
)).
publish
()
}
fun
togglePolicy
(
item
:
PolicyRvItem
,
enable
:
Boolean
)
{
...
...
@@ -131,7 +130,7 @@ class SuperuserViewModel(
db
.
update
(
app
)
val
res
=
if
(
app
.
policy
==
SuPolicy
.
ALLOW
)
R
.
string
.
su_snack_grant
else
R
.
string
.
su_snack_deny
SnackbarEvent
(
res
ources
.
getString
(
res
).
format
(
item
.
item
.
appName
)).
publish
()
SnackbarEvent
(
res
.
asTransitive
(
item
.
item
.
appName
)).
publish
()
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/utils/TransitiveText.kt
View file @
0f95a7ba
...
...
@@ -37,7 +37,6 @@ sealed class TransitiveText {
companion
object
{
val
EMPTY
=
String
(
""
)
}
}
...
...
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