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
aabc36f8
Commit
aabc36f8
authored
Jun 10, 2022
by
topjohnwu
Committed by
John Wu
Jun 10, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Maintain separate flash screen state
parent
e0d5d902
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
24 deletions
+25
-24
FlashFragment.kt
.../main/java/com/topjohnwu/magisk/ui/flash/FlashFragment.kt
+12
-8
FlashViewModel.kt
...main/java/com/topjohnwu/magisk/ui/flash/FlashViewModel.kt
+10
-13
fragment_flash_md2.xml
app/src/main/res/layout/fragment_flash_md2.xml
+3
-3
No files found.
app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashFragment.kt
View file @
aabc36f8
...
@@ -35,13 +35,16 @@ class FlashFragment : BaseFragment<FragmentFlashMd2Binding>() {
...
@@ -35,13 +35,16 @@ class FlashFragment : BaseFragment<FragmentFlashMd2Binding>() {
setHasOptionsMenu
(
true
)
setHasOptionsMenu
(
true
)
activity
?.
setTitle
(
R
.
string
.
flash_screen_title
)
activity
?.
setTitle
(
R
.
string
.
flash_screen_title
)
viewModel
.
subtitle
.
observe
(
this
)
{
viewModel
.
flashState
.
observe
(
this
)
{
activity
?.
supportActionBar
?.
setSubtitle
(
it
)
activity
?.
supportActionBar
?.
setSubtitle
(
}
when
(
it
)
{
FlashViewModel
.
State
.
FLASHING
->
R
.
string
.
flashing
viewModel
.
flashResult
.
observe
(
this
)
{
success
->
FlashViewModel
.
State
.
SUCCESS
->
R
.
string
.
done
binding
.
restartBtn
.
apply
{
FlashViewModel
.
State
.
FAILED
->
R
.
string
.
failure
if
(
success
&&
viewModel
.
showReboot
)
{
}
)
if
(
it
==
FlashViewModel
.
State
.
SUCCESS
&&
viewModel
.
showReboot
)
{
binding
.
restartBtn
.
apply
{
if
(!
this
.
isVisible
)
this
.
show
()
if
(!
this
.
isVisible
)
this
.
show
()
if
(!
this
.
isFocused
)
this
.
requestFocus
()
if
(!
this
.
isFocused
)
this
.
requestFocus
()
}
}
...
@@ -84,7 +87,8 @@ class FlashFragment : BaseFragment<FragmentFlashMd2Binding>() {
...
@@ -84,7 +87,8 @@ class FlashFragment : BaseFragment<FragmentFlashMd2Binding>() {
}
}
override
fun
onBackPressed
():
Boolean
{
override
fun
onBackPressed
():
Boolean
{
if
(
viewModel
.
loading
)
return
true
if
(
viewModel
.
flashing
.
value
==
true
)
return
true
return
super
.
onBackPressed
()
return
super
.
onBackPressed
()
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashViewModel.kt
View file @
aabc36f8
...
@@ -4,6 +4,7 @@ import android.view.MenuItem
...
@@ -4,6 +4,7 @@ import android.view.MenuItem
import
androidx.databinding.Bindable
import
androidx.databinding.Bindable
import
androidx.lifecycle.LiveData
import
androidx.lifecycle.LiveData
import
androidx.lifecycle.MutableLiveData
import
androidx.lifecycle.MutableLiveData
import
androidx.lifecycle.Transformations
import
androidx.lifecycle.viewModelScope
import
androidx.lifecycle.viewModelScope
import
com.topjohnwu.magisk.BR
import
com.topjohnwu.magisk.BR
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.R
...
@@ -27,17 +28,18 @@ import kotlinx.coroutines.launch
...
@@ -27,17 +28,18 @@ import kotlinx.coroutines.launch
class
FlashViewModel
:
BaseViewModel
()
{
class
FlashViewModel
:
BaseViewModel
()
{
enum
class
State
{
FLASHING
,
SUCCESS
,
FAILED
}
private
val
_flashState
=
MutableLiveData
(
State
.
FLASHING
)
val
flashState
:
LiveData
<
State
>
get
()
=
_flashState
val
flashing
=
Transformations
.
map
(
flashState
)
{
it
==
State
.
FLASHING
}
@get
:
Bindable
@get
:
Bindable
var
showReboot
=
Info
.
isRooted
var
showReboot
=
Info
.
isRooted
set
(
value
)
=
set
(
value
,
field
,
{
field
=
it
},
BR
.
showReboot
)
set
(
value
)
=
set
(
value
,
field
,
{
field
=
it
},
BR
.
showReboot
)
private
val
_subtitle
=
MutableLiveData
(
R
.
string
.
flashing
)
val
subtitle
get
()
=
_subtitle
as
LiveData
<
Int
>
private
val
_flashResult
=
MutableLiveData
<
Boolean
>()
val
flashResult
:
LiveData
<
Boolean
>
get
()
=
_flashResult
val
items
=
diffListOf
<
ConsoleItem
>()
val
items
=
diffListOf
<
ConsoleItem
>()
lateinit
var
args
:
FlashFragmentArgs
lateinit
var
args
:
FlashFragmentArgs
...
@@ -87,12 +89,7 @@ class FlashViewModel : BaseViewModel() {
...
@@ -87,12 +89,7 @@ class FlashViewModel : BaseViewModel() {
}
}
private
fun
onResult
(
success
:
Boolean
)
{
private
fun
onResult
(
success
:
Boolean
)
{
state
=
if
(
success
)
State
.
LOADED
else
State
.
LOADING_FAILED
_flashState
.
value
=
if
(
success
)
State
.
SUCCESS
else
State
.
FAILED
when
{
success
->
_subtitle
.
postValue
(
R
.
string
.
done
)
else
->
_subtitle
.
postValue
(
R
.
string
.
failure
)
}
_flashResult
.
value
=
success
}
}
fun
onMenuItemClicked
(
item
:
MenuItem
):
Boolean
{
fun
onMenuItemClicked
(
item
:
MenuItem
):
Boolean
{
...
...
app/src/main/res/layout/fragment_flash_md2.xml
View file @
aabc36f8
...
@@ -39,14 +39,14 @@
...
@@ -39,14 +39,14 @@
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id=
"@+id/restart_btn"
android:id=
"@+id/restart_btn"
gone=
"@{
!viewModel.loaded
|| !viewModel.showReboot}"
gone=
"@{
viewModel.flashing
|| !viewModel.showReboot}"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"bottom|end"
android:layout_gravity=
"bottom|end"
android:layout_margin=
"@dimen/l1"
android:layout_margin=
"@dimen/l1"
android:layout_marginBottom=
"@dimen/l1"
android:layout_marginBottom=
"@dimen/l1"
android:clickable=
"@{!viewModel.
loaded
}"
android:clickable=
"@{!viewModel.
flashing
}"
android:enabled=
"@{
viewModel.loaded
}"
android:enabled=
"@{
!viewModel.flashing
}"
android:focusable=
"true"
android:focusable=
"true"
android:onClick=
"@{() -> viewModel.restartPressed()}"
android:onClick=
"@{() -> viewModel.restartPressed()}"
android:text=
"@string/reboot"
android:text=
"@string/reboot"
...
...
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