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 {
...
@@ -23,12 +23,10 @@ val viewModelModules = module {
viewModel
{
ModuleViewModel
(
get
(),
get
())
}
viewModel
{
ModuleViewModel
(
get
(),
get
())
}
viewModel
{
SafetynetViewModel
()
}
viewModel
{
SafetynetViewModel
()
}
viewModel
{
SettingsViewModel
(
get
())
}
viewModel
{
SettingsViewModel
(
get
())
}
viewModel
{
SuperuserViewModel
(
get
()
,
get
()
)
}
viewModel
{
SuperuserViewModel
(
get
())
}
viewModel
{
ThemeViewModel
()
}
viewModel
{
ThemeViewModel
()
}
viewModel
{
InstallViewModel
(
get
())
}
viewModel
{
InstallViewModel
(
get
())
}
viewModel
{
MainViewModel
()
}
viewModel
{
MainViewModel
()
}
// Legacy
viewModel
{
(
args
:
FlashFragmentArgs
)
->
FlashViewModel
(
args
)
}
viewModel
{
(
args
:
FlashFragmentArgs
)
->
FlashViewModel
(
args
)
}
viewModel
{
SuRequestViewModel
(
get
(),
get
(),
get
(
SUTimeout
),
get
())
}
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
...
@@ -7,31 +7,32 @@ import com.topjohnwu.magisk.arch.ActivityExecutor
import
com.topjohnwu.magisk.arch.BaseUIActivity
import
com.topjohnwu.magisk.arch.BaseUIActivity
import
com.topjohnwu.magisk.arch.ViewEvent
import
com.topjohnwu.magisk.arch.ViewEvent
import
com.topjohnwu.magisk.utils.TransitiveText
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
msg
:
TransitiveText
,
private
val
length
:
Int
,
private
val
length
:
Int
=
Snackbar
.
LENGTH_SHORT
,
private
val
builder
:
Snackbar
.()
->
Unit
private
val
builder
:
Snackbar
.()
->
Unit
=
{}
)
:
ViewEvent
(),
ActivityExecutor
{
)
:
ViewEvent
(),
ActivityExecutor
{
constructor
(
constructor
(
@StringRes
res
:
Int
,
@StringRes
res
:
Int
,
length
:
Int
=
Snackbar
.
LENGTH_SHORT
,
length
:
Int
=
Snackbar
.
LENGTH_SHORT
,
builder
:
Snackbar
.()
->
Unit
=
{}
builder
:
Snackbar
.()
->
Unit
=
{}
)
:
this
(
TransitiveText
.
Res
(
res
),
length
,
builder
)
)
:
this
(
res
.
asTransitive
(
),
length
,
builder
)
constructor
(
constructor
(
m
essage
:
String
,
m
sg
:
String
,
length
:
Int
=
Snackbar
.
LENGTH_SHORT
,
length
:
Int
=
Snackbar
.
LENGTH_SHORT
,
builder
:
Snackbar
.()
->
Unit
=
{}
builder
:
Snackbar
.()
->
Unit
=
{}
)
:
this
(
TransitiveText
.
String
(
message
),
length
,
builder
)
)
:
this
(
msg
.
asTransitive
(
),
length
,
builder
)
private
fun
snackbar
(
private
fun
snackbar
(
view
:
View
,
view
:
View
,
message
:
String
,
message
:
String
,
length
:
Int
=
Snackbar
.
LENGTH_SHORT
,
length
:
Int
,
builder
:
Snackbar
.()
->
Unit
=
{}
builder
:
Snackbar
.()
->
Unit
)
=
Snackbar
.
make
(
view
,
message
,
length
).
apply
(
builder
).
show
()
)
=
Snackbar
.
make
(
view
,
message
,
length
).
apply
(
builder
).
show
()
override
fun
invoke
(
activity
:
BaseUIActivity
<
*
,
*
>)
{
override
fun
invoke
(
activity
:
BaseUIActivity
<
*
,
*
>)
{
...
@@ -39,5 +40,4 @@ class SnackbarEvent private constructor(
...
@@ -39,5 +40,4 @@ class SnackbarEvent private constructor(
msg
.
getText
(
activity
.
resources
).
toString
(),
msg
.
getText
(
activity
.
resources
).
toString
(),
length
,
builder
)
length
,
builder
)
}
}
}
}
app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt
View file @
0f95a7ba
package
com.topjohnwu.magisk.ui.superuser
package
com.topjohnwu.magisk.ui.superuser
import
android.content.res.Resources
import
androidx.databinding.ObservableArrayList
import
androidx.databinding.ObservableArrayList
import
androidx.lifecycle.viewModelScope
import
androidx.lifecycle.viewModelScope
import
com.topjohnwu.magisk.BR
import
com.topjohnwu.magisk.BR
...
@@ -19,6 +18,7 @@ import com.topjohnwu.magisk.events.SnackbarEvent
...
@@ -19,6 +18,7 @@ import com.topjohnwu.magisk.events.SnackbarEvent
import
com.topjohnwu.magisk.events.dialog.BiometricEvent
import
com.topjohnwu.magisk.events.dialog.BiometricEvent
import
com.topjohnwu.magisk.events.dialog.SuperuserRevokeDialog
import
com.topjohnwu.magisk.events.dialog.SuperuserRevokeDialog
import
com.topjohnwu.magisk.utils.Utils
import
com.topjohnwu.magisk.utils.Utils
import
com.topjohnwu.magisk.utils.asTransitive
import
com.topjohnwu.magisk.view.TappableHeadlineItem
import
com.topjohnwu.magisk.view.TappableHeadlineItem
import
com.topjohnwu.magisk.view.TextItem
import
com.topjohnwu.magisk.view.TextItem
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.Dispatchers
...
@@ -27,8 +27,7 @@ import kotlinx.coroutines.withContext
...
@@ -27,8 +27,7 @@ import kotlinx.coroutines.withContext
import
me.tatarka.bindingcollectionadapter2.collections.MergeObservableList
import
me.tatarka.bindingcollectionadapter2.collections.MergeObservableList
class
SuperuserViewModel
(
class
SuperuserViewModel
(
private
val
db
:
PolicyDao
,
private
val
db
:
PolicyDao
private
val
resources
:
Resources
)
:
BaseViewModel
(),
TappableHeadlineItem
.
Listener
{
)
:
BaseViewModel
(),
TappableHeadlineItem
.
Listener
{
private
val
itemNoData
=
TextItem
(
R
.
string
.
superuser_policy_none
)
private
val
itemNoData
=
TextItem
(
R
.
string
.
superuser_policy_none
)
...
@@ -107,7 +106,7 @@ class SuperuserViewModel(
...
@@ -107,7 +106,7 @@ class SuperuserViewModel(
fun
updatePolicy
(
policy
:
SuPolicy
,
isLogging
:
Boolean
)
=
viewModelScope
.
launch
{
fun
updatePolicy
(
policy
:
SuPolicy
,
isLogging
:
Boolean
)
=
viewModelScope
.
launch
{
db
.
update
(
policy
)
db
.
update
(
policy
)
val
str
=
when
{
val
res
=
when
{
isLogging
->
when
{
isLogging
->
when
{
policy
.
logging
->
R
.
string
.
su_snack_log_on
policy
.
logging
->
R
.
string
.
su_snack_log_on
else
->
R
.
string
.
su_snack_log_off
else
->
R
.
string
.
su_snack_log_off
...
@@ -117,7 +116,7 @@ class SuperuserViewModel(
...
@@ -117,7 +116,7 @@ class SuperuserViewModel(
else
->
R
.
string
.
su_snack_notif_off
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
)
{
fun
togglePolicy
(
item
:
PolicyRvItem
,
enable
:
Boolean
)
{
...
@@ -131,7 +130,7 @@ class SuperuserViewModel(
...
@@ -131,7 +130,7 @@ class SuperuserViewModel(
db
.
update
(
app
)
db
.
update
(
app
)
val
res
=
if
(
app
.
policy
==
SuPolicy
.
ALLOW
)
R
.
string
.
su_snack_grant
val
res
=
if
(
app
.
policy
==
SuPolicy
.
ALLOW
)
R
.
string
.
su_snack_grant
else
R
.
string
.
su_snack_deny
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 {
...
@@ -37,7 +37,6 @@ sealed class TransitiveText {
companion
object
{
companion
object
{
val
EMPTY
=
String
(
""
)
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