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
d7f7508f
Commit
d7f7508f
authored
Sep 11, 2020
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move setContentView out of onCreate
parent
e66b0bf3
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
28 additions
and
32 deletions
+28
-32
BaseUIActivity.kt
...src/main/java/com/topjohnwu/magisk/arch/BaseUIActivity.kt
+12
-10
ViewEvents.kt
app/src/main/java/com/topjohnwu/magisk/events/ViewEvents.kt
+6
-0
MainActivity.kt
app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt
+1
-1
SuRequestViewModel.kt
...a/com/topjohnwu/magisk/ui/surequest/SuRequestViewModel.kt
+8
-20
activity_request.xml
app/src/main/res/layout/activity_request.xml
+1
-1
No files found.
app/src/main/java/com/topjohnwu/magisk/arch/BaseUIActivity.kt
View file @
d7f7508f
...
...
@@ -48,6 +48,9 @@ abstract class BaseUIActivity<VM : BaseViewModel, Binding : ViewDataBinding> :
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
setTheme
(
themeRes
)
super
.
onCreate
(
savedInstanceState
)
startObserveEvents
()
// We need to set the window background explicitly since for whatever reason it's not
// propagated upstream
...
...
@@ -55,16 +58,6 @@ abstract class BaseUIActivity<VM : BaseViewModel, Binding : ViewDataBinding> :
.
use
{
it
.
getDrawable
(
0
)
}
.
also
{
window
.
setBackgroundDrawable
(
it
)
}
super
.
onCreate
(
savedInstanceState
)
startObserveEvents
()
binding
=
DataBindingUtil
.
setContentView
<
Binding
>(
this
,
layoutRes
).
also
{
it
.
setVariable
(
BR
.
viewModel
,
viewModel
)
it
.
lifecycleOwner
=
this
}
ensureInsets
()
directionsDispatcher
.
observe
(
this
)
{
it
?.
navigate
()
// we don't want the directions to be re-dispatched, so we preemptively set them to null
...
...
@@ -74,6 +67,15 @@ abstract class BaseUIActivity<VM : BaseViewModel, Binding : ViewDataBinding> :
}
}
fun
setContentView
()
{
binding
=
DataBindingUtil
.
setContentView
<
Binding
>(
this
,
layoutRes
).
also
{
it
.
setVariable
(
BR
.
viewModel
,
viewModel
)
it
.
lifecycleOwner
=
this
}
ensureInsets
()
}
override
fun
onResume
()
{
super
.
onResume
()
viewModel
.
requestRefresh
()
...
...
app/src/main/java/com/topjohnwu/magisk/events/ViewEvents.kt
View file @
d7f7508f
...
...
@@ -51,6 +51,12 @@ class DieEvent : ViewEvent(), ActivityExecutor {
}
}
class
ShowUIEvent
:
ViewEvent
(),
ActivityExecutor
{
override
fun
invoke
(
activity
:
BaseUIActivity
<
*
,
*
>)
{
activity
.
setContentView
()
}
}
class
RecreateEvent
:
ViewEvent
(),
ActivityExecutor
{
override
fun
invoke
(
activity
:
BaseUIActivity
<
*
,
*
>)
{
activity
.
recreate
()
...
...
app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt
View file @
d7f7508f
...
...
@@ -14,7 +14,6 @@ import androidx.core.view.setPadding
import
androidx.core.view.updateLayoutParams
import
androidx.navigation.NavDirections
import
com.google.android.material.card.MaterialCardView
import
com.topjohnwu.magisk.BuildConfig
import
com.topjohnwu.magisk.MainDirections
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.arch.BaseUIActivity
...
...
@@ -60,6 +59,7 @@ open class MainActivity : BaseUIActivity<MainViewModel, ActivityMainMd2Binding>(
return
}
setContentView
()
showUnsupportedMessage
()
askForHomeShortcut
()
...
...
app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestViewModel.kt
View file @
d7f7508f
...
...
@@ -18,9 +18,9 @@ import com.topjohnwu.magisk.core.model.su.SuPolicy.Companion.DENY
import
com.topjohnwu.magisk.core.su.SuRequestHandler
import
com.topjohnwu.magisk.core.utils.BiometricHelper
import
com.topjohnwu.magisk.events.DieEvent
import
com.topjohnwu.magisk.events.ShowUIEvent
import
com.topjohnwu.magisk.ui.superuser.SpinnerRvItem
import
com.topjohnwu.magisk.utils.set
import
com.topjohnwu.superuser.internal.UiThreadHandler
import
kotlinx.coroutines.launch
import
me.tatarka.bindingcollectionadapter2.BindingListViewAdapter
import
me.tatarka.bindingcollectionadapter2.ItemBinding
...
...
@@ -33,26 +33,14 @@ class SuRequestViewModel(
private
val
res
:
Resources
)
:
BaseViewModel
()
{
@get
:
Bindable
var
icon
:
Drawable
?
=
null
set
(
value
)
=
set
(
value
,
field
,
{
field
=
it
},
BR
.
icon
)
@get
:
Bindable
var
title
=
""
set
(
value
)
=
set
(
value
,
field
,
{
field
=
it
},
BR
.
title
)
@get
:
Bindable
var
packageName
=
""
set
(
value
)
=
set
(
value
,
field
,
{
field
=
it
},
BR
.
packageName
)
lateinit
var
icon
:
Drawable
lateinit
var
title
:
String
lateinit
var
packageName
:
String
@get
:
Bindable
var
denyText
=
res
.
getString
(
R
.
string
.
deny
)
set
(
value
)
=
set
(
value
,
field
,
{
field
=
it
},
BR
.
denyText
)
@get
:
Bindable
var
warningText
=
res
.
getString
(
R
.
string
.
su_warning
)
set
(
value
)
=
set
(
value
,
field
,
{
field
=
it
},
BR
.
warningText
)
@get
:
Bindable
var
selectedItemPosition
=
0
set
(
value
)
=
set
(
value
,
field
,
{
field
=
it
},
BR
.
selectedItemPosition
)
...
...
@@ -124,14 +112,14 @@ class SuRequestViewModel(
icon
=
policy
.
applicationInfo
.
loadIcon
(
pm
)
title
=
policy
.
appName
packageName
=
policy
.
packageName
UiThreadHandler
.
handler
.
post
{
// Delay is required to properly do selection
selectedItemPosition
=
timeoutPrefs
.
getInt
(
policy
.
packageName
,
0
)
}
selectedItemPosition
=
timeoutPrefs
.
getInt
(
policy
.
packageName
,
0
)
// Set timer
val
millis
=
SECONDS
.
toMillis
(
Config
.
suDefaultTimeout
.
toLong
())
timer
=
SuTimer
(
millis
,
1000
).
apply
{
start
()
}
// Actually show the UI
ShowUIEvent
().
publish
()
}
private
inner
class
SuTimer
(
...
...
app/src/main/res/layout/activity_request.xml
View file @
d7f7508f
...
...
@@ -109,7 +109,7 @@
android:layout_gravity=
"center_horizontal"
android:layout_margin=
"@dimen/l1"
android:gravity=
"center"
android:text=
"@
{viewModel.warningText}
"
android:text=
"@
string/su_warning
"
android:textAppearance=
"@style/AppearanceFoundation.Body"
android:textColor=
"?colorError"
android:textStyle=
"bold"
...
...
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