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
47545b45
Commit
47545b45
authored
Jan 21, 2022
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up MagiskDialog
parent
7c9908d9
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
245 additions
and
325 deletions
+245
-325
BaseMainActivity.kt
...c/main/java/com/topjohnwu/magisk/arch/BaseMainActivity.kt
+8
-7
DarkThemeDialog.kt
...ava/com/topjohnwu/magisk/events/dialog/DarkThemeDialog.kt
+10
-18
DialogEvent.kt
...in/java/com/topjohnwu/magisk/events/dialog/DialogEvent.kt
+2
-4
EnvFixDialog.kt
...n/java/com/topjohnwu/magisk/events/dialog/EnvFixDialog.kt
+17
-13
ManagerInstallDialog.kt
...om/topjohnwu/magisk/events/dialog/ManagerInstallDialog.kt
+5
-5
MarkDownDialog.kt
...java/com/topjohnwu/magisk/events/dialog/MarkDownDialog.kt
+1
-1
ModuleInstallDialog.kt
...com/topjohnwu/magisk/events/dialog/ModuleInstallDialog.kt
+11
-13
SecondSlotWarningDialog.kt
...topjohnwu/magisk/events/dialog/SecondSlotWarningDialog.kt
+7
-5
SuperuserRevokeDialog.kt
...m/topjohnwu/magisk/events/dialog/SuperuserRevokeDialog.kt
+8
-6
UninstallDialog.kt
...ava/com/topjohnwu/magisk/events/dialog/UninstallDialog.kt
+17
-14
MainActivity.kt
app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt
+35
-33
BaseSettingsItem.kt
...java/com/topjohnwu/magisk/ui/settings/BaseSettingsItem.kt
+16
-16
MagiskDialog.kt
app/src/main/java/com/topjohnwu/magisk/view/MagiskDialog.kt
+92
-158
dialog_magisk_base.xml
app/src/main/res/layout/dialog_magisk_base.xml
+15
-31
item_list_single_line.xml
app/src/main/res/layout/item_list_single_line.xml
+1
-1
No files found.
app/src/main/java/com/topjohnwu/magisk/arch/BaseMainActivity.kt
View file @
47545b45
...
...
@@ -75,15 +75,16 @@ abstract class BaseMainActivity<VM : BaseViewModel, Binding : ViewDataBinding>
private
fun
showInvalidStateMessage
()
{
runOnUiThread
{
MagiskDialog
(
this
)
.
apply
Title
(
R
.
string
.
unsupport_nonroot_stub_title
)
.
apply
Message
(
R
.
string
.
unsupport_nonroot_stub_msg
)
.
apply
Button
(
MagiskDialog
.
ButtonType
.
POSITIVE
)
{
t
itleRes
=
R
.
string
.
install
MagiskDialog
(
this
)
.
apply
{
set
Title
(
R
.
string
.
unsupport_nonroot_stub_title
)
set
Message
(
R
.
string
.
unsupport_nonroot_stub_msg
)
set
Button
(
MagiskDialog
.
ButtonType
.
POSITIVE
)
{
t
ext
=
R
.
string
.
install
onClick
{
HideAPK
.
restore
(
this
@BaseMainActivity
)
}
}
.
cancellable
(
false
)
.
reveal
()
setCancelable
(
false
)
show
()
}
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/events/dialog/DarkThemeDialog.kt
View file @
47545b45
package
com.topjohnwu.magisk.events.dialog
import
android.app.Activity
import
android.content.Context
import
android.content.ContextWrapper
import
androidx.appcompat.app.AppCompatDelegate
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.core.Config
...
...
@@ -11,31 +9,25 @@ import com.topjohnwu.magisk.view.MagiskDialog
class
DarkThemeDialog
:
DialogEvent
()
{
override
fun
build
(
dialog
:
MagiskDialog
)
{
val
activity
=
dialog
.
context
.
unwrap
()
dialog
.
applyTitle
(
R
.
string
.
settings_dark_mode_title
)
.
applyMessage
(
R
.
string
.
settings_dark_mode_message
)
.
applyButton
(
MagiskDialog
.
ButtonType
.
POSITIVE
)
{
titleRes
=
R
.
string
.
settings_dark_mode_light
val
activity
=
dialog
.
ownerActivity
!!
dialog
.
apply
{
setTitle
(
R
.
string
.
settings_dark_mode_title
)
setMessage
(
R
.
string
.
settings_dark_mode_message
)
setButton
(
MagiskDialog
.
ButtonType
.
POSITIVE
)
{
text
=
R
.
string
.
settings_dark_mode_light
icon
=
R
.
drawable
.
ic_day
onClick
{
selectTheme
(
AppCompatDelegate
.
MODE_NIGHT_NO
,
activity
)
}
}
.
apply
Button
(
MagiskDialog
.
ButtonType
.
NEUTRAL
)
{
t
itleRes
=
R
.
string
.
settings_dark_mode_system
set
Button
(
MagiskDialog
.
ButtonType
.
NEUTRAL
)
{
t
ext
=
R
.
string
.
settings_dark_mode_system
icon
=
R
.
drawable
.
ic_day_night
onClick
{
selectTheme
(
AppCompatDelegate
.
MODE_NIGHT_FOLLOW_SYSTEM
,
activity
)
}
}
.
apply
Button
(
MagiskDialog
.
ButtonType
.
NEGATIVE
)
{
t
itleRes
=
R
.
string
.
settings_dark_mode_dark
set
Button
(
MagiskDialog
.
ButtonType
.
NEGATIVE
)
{
t
ext
=
R
.
string
.
settings_dark_mode_dark
icon
=
R
.
drawable
.
ic_night
onClick
{
selectTheme
(
AppCompatDelegate
.
MODE_NIGHT_YES
,
activity
)
}
}
}
private
fun
Context
.
unwrap
():
Activity
{
return
when
(
this
)
{
is
Activity
->
this
is
ContextWrapper
->
baseContext
.
unwrap
()
else
->
error
(
"Cannot happen"
)
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/events/dialog/DialogEvent.kt
View file @
47545b45
...
...
@@ -7,12 +7,10 @@ import com.topjohnwu.magisk.view.MagiskDialog
abstract
class
DialogEvent
:
ViewEvent
(),
ActivityExecutor
{
protected
lateinit
var
dialog
:
MagiskDialog
override
fun
invoke
(
activity
:
BaseUIActivity
<
*
,
*
>)
{
dialog
=
MagiskDialog
(
activity
)
MagiskDialog
(
activity
)
.
apply
{
setOwnerActivity
(
activity
)
}
.
apply
(
this
::
build
).
reveal
()
.
apply
(
this
::
build
).
show
()
}
abstract
fun
build
(
dialog
:
MagiskDialog
)
...
...
app/src/main/java/com/topjohnwu/magisk/events/dialog/EnvFixDialog.kt
View file @
47545b45
...
...
@@ -13,16 +13,19 @@ import kotlinx.coroutines.launch
class
EnvFixDialog
(
private
val
vm
:
HomeViewModel
)
:
DialogEvent
()
{
override
fun
build
(
dialog
:
MagiskDialog
)
{
dialog
.
applyTitle
(
R
.
string
.
env_fix_title
)
.
applyMessage
(
R
.
string
.
env_fix_msg
)
.
applyButton
(
MagiskDialog
.
ButtonType
.
POSITIVE
)
{
titleRes
=
android
.
R
.
string
.
ok
preventDismiss
=
true
dialog
.
apply
{
setTitle
(
R
.
string
.
env_fix_title
)
setMessage
(
R
.
string
.
env_fix_msg
)
setButton
(
MagiskDialog
.
ButtonType
.
POSITIVE
)
{
text
=
android
.
R
.
string
.
ok
doNotDismiss
=
true
onClick
{
dialog
.
applyTitle
(
R
.
string
.
setup_title
)
.
applyMessage
(
R
.
string
.
setup_msg
)
.
resetButtons
()
.
cancellable
(
false
)
dialog
.
apply
{
setTitle
(
R
.
string
.
setup_title
)
setMessage
(
R
.
string
.
setup_msg
)
resetButtons
()
setCancelable
(
false
)
}
(
dialog
.
ownerActivity
as
BaseActivity
).
lifecycleScope
.
launch
{
MagiskInstaller
.
FixEnv
{
dialog
.
dismiss
()
...
...
@@ -30,14 +33,15 @@ class EnvFixDialog(private val vm: HomeViewModel) : DialogEvent() {
}
}
}
.
apply
Button
(
MagiskDialog
.
ButtonType
.
NEGATIVE
)
{
t
itleRes
=
android
.
R
.
string
.
cancel
set
Button
(
MagiskDialog
.
ButtonType
.
NEGATIVE
)
{
t
ext
=
android
.
R
.
string
.
cancel
}
}
if
(
Info
.
env
.
versionCode
!=
BuildConfig
.
VERSION_CODE
||
Info
.
env
.
versionString
!=
BuildConfig
.
VERSION_NAME
)
{
dialog
.
apply
Button
(
MagiskDialog
.
ButtonType
.
POSITIVE
)
{
t
itleRes
=
android
.
R
.
string
.
ok
dialog
.
set
Button
(
MagiskDialog
.
ButtonType
.
POSITIVE
)
{
t
ext
=
android
.
R
.
string
.
ok
onClick
{
vm
.
onMagiskPressed
()
dialog
.
dismiss
()
...
...
app/src/main/java/com/topjohnwu/magisk/events/dialog/ManagerInstallDialog.kt
View file @
47545b45
...
...
@@ -25,14 +25,14 @@ class ManagerInstallDialog : MarkDownDialog() {
override
fun
build
(
dialog
:
MagiskDialog
)
{
super
.
build
(
dialog
)
with
(
dialog
)
{
dialog
.
apply
{
setCancelable
(
true
)
apply
Button
(
MagiskDialog
.
ButtonType
.
POSITIVE
)
{
t
itleRes
=
R
.
string
.
install
set
Button
(
MagiskDialog
.
ButtonType
.
POSITIVE
)
{
t
ext
=
R
.
string
.
install
onClick
{
DownloadService
.
start
(
context
,
Subject
.
Manager
())
}
}
apply
Button
(
MagiskDialog
.
ButtonType
.
NEGATIVE
)
{
t
itleRes
=
android
.
R
.
string
.
cancel
set
Button
(
MagiskDialog
.
ButtonType
.
NEGATIVE
)
{
t
ext
=
android
.
R
.
string
.
cancel
}
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/events/dialog/MarkDownDialog.kt
View file @
47545b45
...
...
@@ -22,7 +22,7 @@ abstract class MarkDownDialog : DialogEvent() {
override
fun
build
(
dialog
:
MagiskDialog
)
{
with
(
dialog
)
{
val
view
=
LayoutInflater
.
from
(
context
).
inflate
(
R
.
layout
.
markdown_window_md2
,
null
)
apply
View
(
view
)
set
View
(
view
)
(
ownerActivity
as
BaseActivity
).
lifecycleScope
.
launch
{
val
tv
=
view
.
findViewById
<
TextView
>(
R
.
id
.
md_txt
)
withContext
(
Dispatchers
.
IO
)
{
...
...
app/src/main/java/com/topjohnwu/magisk/events/dialog/ModuleInstallDialog.kt
View file @
47545b45
...
...
@@ -11,7 +11,7 @@ import com.topjohnwu.magisk.view.MagiskDialog
class
ModuleInstallDialog
(
private
val
item
:
OnlineModule
)
:
DialogEvent
()
{
override
fun
build
(
dialog
:
MagiskDialog
)
{
with
(
dialog
)
{
dialog
.
apply
{
fun
download
(
install
:
Boolean
)
{
val
action
=
if
(
install
)
Action
.
Flash
else
Action
.
Download
...
...
@@ -19,24 +19,22 @@ class ModuleInstallDialog(private val item: OnlineModule) : DialogEvent() {
DownloadService
.
start
(
context
,
subject
)
}
apply
Title
(
context
.
getString
(
R
.
string
.
repo_install_title
,
item
.
name
))
.
apply
Message
(
context
.
getString
(
R
.
string
.
repo_install_msg
,
item
.
downloadFilename
))
.
cancel
lable
(
true
)
.
apply
Button
(
MagiskDialog
.
ButtonType
.
NEGATIVE
)
{
titleRes
=
R
.
string
.
download
icon
=
R
.
drawable
.
ic_download_md2
onClick
{
download
(
false
)
}
}
set
Title
(
context
.
getString
(
R
.
string
.
repo_install_title
,
item
.
name
))
set
Message
(
context
.
getString
(
R
.
string
.
repo_install_msg
,
item
.
downloadFilename
))
setCance
lable
(
true
)
set
Button
(
MagiskDialog
.
ButtonType
.
NEGATIVE
)
{
text
=
R
.
string
.
download
icon
=
R
.
drawable
.
ic_download_md2
onClick
{
download
(
false
)
}
}
if
(
Info
.
env
.
isActive
)
{
apply
Button
(
MagiskDialog
.
ButtonType
.
POSITIVE
)
{
t
itleRes
=
R
.
string
.
install
set
Button
(
MagiskDialog
.
ButtonType
.
POSITIVE
)
{
t
ext
=
R
.
string
.
install
icon
=
R
.
drawable
.
ic_install
onClick
{
download
(
true
)
}
}
}
reveal
()
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/events/dialog/SecondSlotWarningDialog.kt
View file @
47545b45
...
...
@@ -6,11 +6,13 @@ import com.topjohnwu.magisk.view.MagiskDialog
class
SecondSlotWarningDialog
:
DialogEvent
()
{
override
fun
build
(
dialog
:
MagiskDialog
)
{
dialog
.
applyTitle
(
android
.
R
.
string
.
dialog_alert_title
)
.
applyMessage
(
R
.
string
.
install_inactive_slot_msg
)
.
applyButton
(
MagiskDialog
.
ButtonType
.
POSITIVE
)
{
titleRes
=
android
.
R
.
string
.
ok
dialog
.
apply
{
setTitle
(
android
.
R
.
string
.
dialog_alert_title
)
setMessage
(
R
.
string
.
install_inactive_slot_msg
)
setButton
(
MagiskDialog
.
ButtonType
.
POSITIVE
)
{
text
=
android
.
R
.
string
.
ok
}
.
cancellable
(
true
)
setCancelable
(
true
)
}
}
}
app/src/main/java/com/topjohnwu/magisk/events/dialog/SuperuserRevokeDialog.kt
View file @
47545b45
...
...
@@ -10,15 +10,17 @@ class SuperuserRevokeDialog(
private
val
callbacks
=
Builder
().
apply
(
builder
)
override
fun
build
(
dialog
:
MagiskDialog
)
{
dialog
.
applyTitle
(
R
.
string
.
su_revoke_title
)
.
applyMessage
(
R
.
string
.
su_revoke_msg
,
callbacks
.
appName
)
.
applyButton
(
MagiskDialog
.
ButtonType
.
POSITIVE
)
{
titleRes
=
android
.
R
.
string
.
ok
dialog
.
apply
{
setTitle
(
R
.
string
.
su_revoke_title
)
setMessage
(
R
.
string
.
su_revoke_msg
,
callbacks
.
appName
)
setButton
(
MagiskDialog
.
ButtonType
.
POSITIVE
)
{
text
=
android
.
R
.
string
.
ok
onClick
{
callbacks
.
listenerOnSuccess
()
}
}
.
apply
Button
(
MagiskDialog
.
ButtonType
.
NEGATIVE
)
{
t
itleRes
=
android
.
R
.
string
.
cancel
set
Button
(
MagiskDialog
.
ButtonType
.
NEGATIVE
)
{
t
ext
=
android
.
R
.
string
.
cancel
}
}
}
inner
class
Builder
internal
constructor
()
{
...
...
app/src/main/java/com/topjohnwu/magisk/events/dialog/UninstallDialog.kt
View file @
47545b45
package
com.topjohnwu.magisk.events.dialog
import
android.app.ProgressDialog
import
android.content.Context
import
android.widget.Toast
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.arch.BaseUIActivity
...
...
@@ -12,22 +13,24 @@ import com.topjohnwu.superuser.Shell
class
UninstallDialog
:
DialogEvent
()
{
override
fun
build
(
dialog
:
MagiskDialog
)
{
dialog
.
applyTitle
(
R
.
string
.
uninstall_magisk_title
)
.
applyMessage
(
R
.
string
.
uninstall_magisk_msg
)
.
applyButton
(
MagiskDialog
.
ButtonType
.
POSITIVE
)
{
titleRes
=
R
.
string
.
restore_img
onClick
{
restore
()
}
dialog
.
apply
{
setTitle
(
R
.
string
.
uninstall_magisk_title
)
setMessage
(
R
.
string
.
uninstall_magisk_msg
)
setButton
(
MagiskDialog
.
ButtonType
.
POSITIVE
)
{
text
=
R
.
string
.
restore_img
onClick
{
restore
(
dialog
.
context
)
}
}
.
apply
Button
(
MagiskDialog
.
ButtonType
.
NEGATIVE
)
{
t
itleRes
=
R
.
string
.
complete_uninstall
onClick
{
completeUninstall
()
}
set
Button
(
MagiskDialog
.
ButtonType
.
NEGATIVE
)
{
t
ext
=
R
.
string
.
complete_uninstall
onClick
{
completeUninstall
(
dialog
)
}
}
}
}
@Suppress
(
"DEPRECATION"
)
private
fun
restore
()
{
val
dialog
=
ProgressDialog
(
dialog
.
context
).
apply
{
setMessage
(
dialog
.
context
.
getString
(
R
.
string
.
restore_img_msg
))
private
fun
restore
(
context
:
Context
)
{
val
dialog
=
ProgressDialog
(
context
).
apply
{
setMessage
(
context
.
getString
(
R
.
string
.
restore_img_msg
))
show
()
}
...
...
@@ -41,9 +44,9 @@ class UninstallDialog : DialogEvent() {
}
}
private
fun
completeUninstall
()
{
(
dialog
.
ownerActivity
as
?
BaseUIActivity
<*,
*>)
?
.
navigation
?.
navigate
(
FlashFragment
.
uninstall
())
private
fun
completeUninstall
(
dialog
:
MagiskDialog
)
{
(
dialog
.
ownerActivity
as
BaseUIActivity
<*,
*>)
.
navigation
?.
navigate
(
FlashFragment
.
uninstall
())
}
}
app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt
View file @
47545b45
...
...
@@ -146,42 +146,42 @@ class MainActivity : BaseMainActivity<MainViewModel, ActivityMainMd2Binding>() {
private
fun
showUnsupportedMessage
()
{
if
(
Info
.
env
.
isUnsupported
)
{
MagiskDialog
(
this
)
.
apply
Title
(
R
.
string
.
unsupport_magisk_title
)
.
apply
Message
(
R
.
string
.
unsupport_magisk_msg
,
Const
.
Version
.
MIN_VERSION
)
.
applyButton
(
MagiskDialog
.
ButtonType
.
POSITIVE
)
{
titleRes
=
android
.
R
.
string
.
ok
}
.
cancel
lable
(
false
)
.
reveal
()
MagiskDialog
(
this
)
.
apply
{
set
Title
(
R
.
string
.
unsupport_magisk_title
)
set
Message
(
R
.
string
.
unsupport_magisk_msg
,
Const
.
Version
.
MIN_VERSION
)
setButton
(
MagiskDialog
.
ButtonType
.
POSITIVE
)
{
text
=
android
.
R
.
string
.
ok
}
setCance
lable
(
false
)
}.
show
()
}
if
(!
Info
.
isEmulator
&&
Info
.
env
.
isActive
&&
System
.
getenv
(
"PATH"
)
?.
split
(
':'
)
?.
filterNot
{
File
(
"$it/magisk"
).
exists
()
}
?.
any
{
File
(
"$it/su"
).
exists
()
}
==
true
)
{
MagiskDialog
(
this
)
.
apply
Title
(
R
.
string
.
unsupport_general_title
)
.
apply
Message
(
R
.
string
.
unsupport_other_su_msg
)
.
applyButton
(
MagiskDialog
.
ButtonType
.
POSITIVE
)
{
titleRes
=
android
.
R
.
string
.
ok
}
.
cancel
lable
(
false
)
.
reveal
()
MagiskDialog
(
this
)
.
apply
{
set
Title
(
R
.
string
.
unsupport_general_title
)
set
Message
(
R
.
string
.
unsupport_other_su_msg
)
setButton
(
MagiskDialog
.
ButtonType
.
POSITIVE
)
{
text
=
android
.
R
.
string
.
ok
}
setCance
lable
(
false
)
}.
show
()
}
if
(
applicationInfo
.
flags
and
ApplicationInfo
.
FLAG_SYSTEM
!=
0
)
{
MagiskDialog
(
this
)
.
apply
Title
(
R
.
string
.
unsupport_general_title
)
.
apply
Message
(
R
.
string
.
unsupport_system_app_msg
)
.
applyButton
(
MagiskDialog
.
ButtonType
.
POSITIVE
)
{
titleRes
=
android
.
R
.
string
.
ok
}
.
cancel
lable
(
false
)
.
reveal
()
MagiskDialog
(
this
)
.
apply
{
set
Title
(
R
.
string
.
unsupport_general_title
)
set
Message
(
R
.
string
.
unsupport_system_app_msg
)
setButton
(
MagiskDialog
.
ButtonType
.
POSITIVE
)
{
text
=
android
.
R
.
string
.
ok
}
setCance
lable
(
false
)
}.
show
()
}
if
(
applicationInfo
.
flags
and
ApplicationInfo
.
FLAG_EXTERNAL_STORAGE
!=
0
)
{
MagiskDialog
(
this
)
.
apply
Title
(
R
.
string
.
unsupport_general_title
)
.
apply
Message
(
R
.
string
.
unsupport_external_storage_msg
)
.
applyButton
(
MagiskDialog
.
ButtonType
.
POSITIVE
)
{
titleRes
=
android
.
R
.
string
.
ok
}
.
cancel
lable
(
false
)
.
reveal
()
MagiskDialog
(
this
)
.
apply
{
set
Title
(
R
.
string
.
unsupport_general_title
)
set
Message
(
R
.
string
.
unsupport_external_storage_msg
)
setButton
(
MagiskDialog
.
ButtonType
.
POSITIVE
)
{
text
=
android
.
R
.
string
.
ok
}
setCance
lable
(
false
)
}.
show
()
}
}
...
...
@@ -190,18 +190,20 @@ class MainActivity : BaseMainActivity<MainViewModel, ActivityMainMd2Binding>() {
ShortcutManagerCompat
.
isRequestPinShortcutSupported
(
this
))
{
// Ask and show dialog
Config
.
askedHome
=
true
MagiskDialog
(
this
)
.
applyTitle
(
R
.
string
.
add_shortcut_title
)
.
applyMessage
(
R
.
string
.
add_shortcut_msg
)
.
applyButton
(
MagiskDialog
.
ButtonType
.
NEGATIVE
)
{
titleRes
=
android
.
R
.
string
.
cancel
}.
applyButton
(
MagiskDialog
.
ButtonType
.
POSITIVE
)
{
titleRes
=
android
.
R
.
string
.
ok
MagiskDialog
(
this
).
apply
{
setTitle
(
R
.
string
.
add_shortcut_title
)
setMessage
(
R
.
string
.
add_shortcut_msg
)
setButton
(
MagiskDialog
.
ButtonType
.
NEGATIVE
)
{
text
=
android
.
R
.
string
.
cancel
}
setButton
(
MagiskDialog
.
ButtonType
.
POSITIVE
)
{
text
=
android
.
R
.
string
.
ok
onClick
{
Shortcuts
.
addHomeIcon
(
this
@MainActivity
)
}
}.
cancellable
(
true
)
.
reveal
()
}
setCancelable
(
true
)
}.
show
()
}
}
}
app/src/main/java/com/topjohnwu/magisk/ui/settings/BaseSettingsItem.kt
View file @
47545b45
...
...
@@ -110,25 +110,25 @@ sealed class BaseSettingsItem : ObservableRvItem() {
protected
abstract
val
inputResult
:
String
?
override
fun
onPressed
(
view
:
View
)
{
MagiskDialog
(
view
.
context
)
.
apply
Title
(
title
.
getText
(
view
.
resources
))
.
apply
View
(
getView
(
view
.
context
))
.
apply
Button
(
MagiskDialog
.
ButtonType
.
POSITIVE
)
{
t
itleRes
=
android
.
R
.
string
.
ok
MagiskDialog
(
view
.
context
)
.
apply
{
set
Title
(
title
.
getText
(
view
.
resources
))
set
View
(
getView
(
view
.
context
))
set
Button
(
MagiskDialog
.
ButtonType
.
POSITIVE
)
{
t
ext
=
android
.
R
.
string
.
ok
onClick
{
inputResult
?.
let
{
result
->
preven
tDismiss
=
false
doNo
tDismiss
=
false
value
=
result
it
.
dismiss
()
return
@onClick
}
preven
tDismiss
=
true
doNo
tDismiss
=
true
}
}
.
apply
Button
(
MagiskDialog
.
ButtonType
.
NEGATIVE
)
{
t
itleRes
=
android
.
R
.
string
.
cancel
set
Button
(
MagiskDialog
.
ButtonType
.
NEGATIVE
)
{
t
ext
=
android
.
R
.
string
.
cancel
}
.
reveal
()
}.
show
()
}
abstract
fun
getView
(
context
:
Context
):
View
...
...
@@ -151,15 +151,15 @@ sealed class BaseSettingsItem : ObservableRvItem() {
runCatching
{
getStringArray
(
id
)
}.
getOrDefault
(
emptyArray
())
override
fun
onPressed
(
view
:
View
)
{
MagiskDialog
(
view
.
context
)
.
apply
Title
(
title
.
getText
(
view
.
resources
))
.
apply
Button
(
MagiskDialog
.
ButtonType
.
NEGATIVE
)
{
t
itleRes
=
android
.
R
.
string
.
cancel
MagiskDialog
(
view
.
context
)
.
apply
{
set
Title
(
title
.
getText
(
view
.
resources
))
set
Button
(
MagiskDialog
.
ButtonType
.
NEGATIVE
)
{
t
ext
=
android
.
R
.
string
.
cancel
}
.
applyAdapter
(
entries
(
view
.
resources
))
{
setListItems
(
entries
(
view
.
resources
))
{
value
=
it
}
.
reveal
()
}.
show
()
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/view/MagiskDialog.kt
View file @
47545b45
...
...
@@ -15,7 +15,6 @@ import androidx.appcompat.app.AppCompatDialog
import
androidx.appcompat.content.res.AppCompatResources
import
androidx.databinding.Bindable
import
androidx.databinding.PropertyChangeRegistry
import
androidx.databinding.ViewDataBinding
import
androidx.recyclerview.widget.LinearLayoutManager
import
androidx.recyclerview.widget.RecyclerView
import
com.google.android.material.color.MaterialColors
...
...
@@ -23,9 +22,12 @@ import com.google.android.material.shape.MaterialShapeDrawable
import
com.topjohnwu.magisk.BR
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.databinding.*
import
com.topjohnwu.magisk.view.MagiskDialog.DialogClickListener
import
me.tatarka.bindingcollectionadapter2.BindingRecyclerViewAdapters
import
me.tatarka.bindingcollectionadapter2.ItemBinding
typealias
DialogButtonClickListener
=
(
DialogInterface
)
->
Unit
class
MagiskDialog
(
context
:
Context
,
theme
:
Int
=
0
)
:
AppCompatDialog
(
context
,
theme
)
{
...
...
@@ -39,25 +41,6 @@ class MagiskDialog(
setCancelable
(
true
)
}
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
super
.
setContentView
(
binding
.
root
)
val
default
=
MaterialColors
.
getColor
(
context
,
R
.
attr
.
colorSurface
,
javaClass
.
canonicalName
)
val
surfaceColor
=
MaterialColors
.
getColor
(
context
,
R
.
attr
.
colorSurfaceSurfaceVariant
,
default
)
val
materialShapeDrawable
=
MaterialShapeDrawable
(
context
,
null
,
R
.
attr
.
alertDialogStyle
,
R
.
style
.
MaterialAlertDialog_MaterialComponents
)
materialShapeDrawable
.
initializeElevationOverlay
(
context
)
materialShapeDrawable
.
fillColor
=
ColorStateList
.
valueOf
(
surfaceColor
)
materialShapeDrawable
.
elevation
=
context
.
resources
.
getDimension
(
R
.
dimen
.
margin_generic
)
materialShapeDrawable
.
setCornerSize
(
context
.
resources
.
getDimension
(
R
.
dimen
.
l_50
))
val
inset
=
context
.
resources
.
getDimensionPixelSize
(
R
.
dimen
.
appcompat_dialog_background_inset
)
window
?.
apply
{
setBackgroundDrawable
(
InsetDrawable
(
materialShapeDrawable
,
inset
,
inset
,
inset
,
inset
))
setLayout
(
ViewGroup
.
LayoutParams
.
MATCH_PARENT
,
ViewGroup
.
LayoutParams
.
WRAP_CONTENT
)
}
}
inner
class
Data
:
ObservableHost
{
override
var
callbacks
:
PropertyChangeRegistry
?
=
null
...
...
@@ -73,114 +56,109 @@ class MagiskDialog(
var
message
:
CharSequence
=
""
set
(
value
)
=
set
(
value
,
field
,
{
field
=
it
},
BR
.
message
)
val
buttonPositive
=
Button
()
val
buttonNeutral
=
Button
()
val
buttonNegative
=
Button
()
val
buttonIDGAF
=
Button
()
val
buttonPositive
=
ButtonViewModel
()
val
buttonNeutral
=
ButtonViewModel
()
val
buttonNegative
=
ButtonViewModel
()
}
enum
class
ButtonType
{
POSITIVE
,
NEUTRAL
,
NEGATIVE
,
IDGAF
POSITIVE
,
NEUTRAL
,
NEGATIVE
}
inner
class
Button
:
ObservableHost
{
interface
Button
{
var
icon
:
Int
var
text
:
Any
var
isEnabled
:
Boolean
var
doNotDismiss
:
Boolean
fun
onClick
(
listener
:
DialogButtonClickListener
)
}
inner
class
ButtonViewModel
:
Button
,
ObservableHost
{
override
var
callbacks
:
PropertyChangeRegistry
?
=
null
@get
:
Bindable
var
icon
=
0
set
(
value
)
=
set
(
value
,
field
,
{
field
=
it
},
BR
.
icon
)
override
var
icon
=
0
set
(
value
)
=
set
(
value
,
field
,
{
field
=
it
},
BR
.
icon
,
BR
.
gone
)
@get
:
Bindable
var
title
:
CharSequence
=
""
set
(
value
)
=
set
(
value
,
field
,
{
field
=
it
},
BR
.
title
)
var
message
:
String
=
""
set
(
value
)
=
set
(
value
,
field
,
{
field
=
it
},
BR
.
message
,
BR
.
gone
)
override
var
text
:
Any
get
()
=
message
set
(
value
)
{
message
=
when
(
value
)
{
is
Int
->
context
.
getText
(
value
)
else
->
value
}.
toString
()
}
@get
:
Bindable
var
isEnabled
=
true
set
(
value
)
=
set
(
value
,
field
,
{
field
=
it
},
BR
.
enabled
)
val
gone
get
()
=
icon
==
0
&&
message
.
isEmpty
()
var
onClickAction
:
OnDialogButtonClickListener
=
{}
var
preventDismiss
=
false
@get
:
Bindable
override
var
isEnabled
=
true
set
(
value
)
=
set
(
value
,
field
,
{
field
=
it
},
BR
.
enabled
)
fun
clicked
()
{
//we might not want the click to dismiss the button to begin with
var
prevention
=
preventDismiss
override
var
doNotDismiss
=
false
onClickAction
(
this
@MagiskDialog
)
private
var
onClickAction
:
DialogButtonClickListener
=
{}
//in case we don't want the dialog to close after clicking the button
//ie. the input is incorrect ...
//otherwise we disregard the request, bcs it just might reset the button in the new
//instance
if
(
preventDismiss
)
{
prevention
=
preventDismiss
}
override
fun
onClick
(
listener
:
DialogButtonClickListener
)
{
onClickAction
=
listener
}
if
(!
prevention
)
{
fun
clicked
()
{
onClickAction
(
this
@MagiskDialog
)
if
(!
doNotDismiss
)
{
dismiss
()
}
}
}
inner
class
ButtonBuilder
(
private
val
button
:
Button
)
{
var
icon
:
Int
get
()
=
button
.
icon
set
(
value
)
{
button
.
icon
=
value
}
var
title
:
CharSequence
get
()
=
button
.
title
set
(
value
)
{
button
.
title
=
value
}
var
titleRes
:
Int
get
()
=
0
set
(
value
)
{
button
.
title
=
context
.
getString
(
value
)
}
var
isEnabled
:
Boolean
get
()
=
button
.
isEnabled
set
(
value
)
{
button
.
isEnabled
=
value
}
var
preventDismiss
:
Boolean
get
()
=
button
.
preventDismiss
set
(
value
)
{
button
.
preventDismiss
=
value
}
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
super
.
setContentView
(
binding
.
root
)
fun
onClick
(
listener
:
OnDialogButtonClickListener
)
{
button
.
onClickAction
=
listener
val
default
=
MaterialColors
.
getColor
(
context
,
R
.
attr
.
colorSurface
,
javaClass
.
canonicalName
)
val
surfaceColor
=
MaterialColors
.
getColor
(
context
,
R
.
attr
.
colorSurfaceSurfaceVariant
,
default
)
val
materialShapeDrawable
=
MaterialShapeDrawable
(
context
,
null
,
R
.
attr
.
alertDialogStyle
,
R
.
style
.
MaterialAlertDialog_MaterialComponents
)
materialShapeDrawable
.
initializeElevationOverlay
(
context
)
materialShapeDrawable
.
fillColor
=
ColorStateList
.
valueOf
(
surfaceColor
)
materialShapeDrawable
.
elevation
=
context
.
resources
.
getDimension
(
R
.
dimen
.
margin_generic
)
materialShapeDrawable
.
setCornerSize
(
context
.
resources
.
getDimension
(
R
.
dimen
.
l_50
))
val
inset
=
context
.
resources
.
getDimensionPixelSize
(
R
.
dimen
.
appcompat_dialog_background_inset
)
window
?.
apply
{
setBackgroundDrawable
(
InsetDrawable
(
materialShapeDrawable
,
inset
,
inset
,
inset
,
inset
))
setLayout
(
ViewGroup
.
LayoutParams
.
MATCH_PARENT
,
ViewGroup
.
LayoutParams
.
WRAP_CONTENT
)
}
}
fun
applyTitle
(
@StringRes
stringRes
:
Int
)
=
apply
{
data
.
title
=
context
.
getString
(
stringRes
)
}
override
fun
setTitle
(
@StringRes
titleId
:
Int
)
{
data
.
title
=
context
.
getString
(
titleId
)
}
fun
applyTitle
(
title
:
CharSequence
)
=
apply
{
data
.
title
=
title
}
override
fun
setTitle
(
title
:
CharSequence
?)
{
data
.
title
=
title
?:
""
}
fun
applyMessage
(
@StringRes
stringRes
:
Int
,
vararg
args
:
Any
)
=
apply
{
data
.
message
=
context
.
getString
(
stringRes
,
*
args
)
}
fun
setMessage
(
@StringRes
msgId
:
Int
,
vararg
args
:
Any
)
{
data
.
message
=
context
.
getString
(
msgId
,
*
args
)
}
fun
applyMessage
(
message
:
CharSequence
)
=
apply
{
data
.
message
=
message
}
fun
setMessage
(
message
:
CharSequence
)
{
data
.
message
=
message
}
fun
applyIcon
(
@DrawableRes
drawableRes
:
Int
)
=
apply
{
data
.
icon
=
AppCompatResources
.
getDrawable
(
context
,
drawableRes
)
}
fun
setIcon
(
@DrawableRes
drawableRes
:
Int
)
{
data
.
icon
=
AppCompatResources
.
getDrawable
(
context
,
drawableRes
)
}
fun
applyIcon
(
drawable
:
Drawable
)
=
apply
{
data
.
icon
=
drawable
}
fun
setIcon
(
drawable
:
Drawable
)
{
data
.
icon
=
drawable
}
fun
applyButton
(
buttonType
:
ButtonType
,
builder
:
ButtonBuilder
.()
->
Unit
)
=
apply
{
fun
setButton
(
buttonType
:
ButtonType
,
builder
:
Button
.()
->
Unit
)
{
val
button
=
when
(
buttonType
)
{
ButtonType
.
POSITIVE
->
data
.
buttonPositive
ButtonType
.
NEUTRAL
->
data
.
buttonNeutral
ButtonType
.
NEGATIVE
->
data
.
buttonNegative
ButtonType
.
IDGAF
->
data
.
buttonIDGAF
}
ButtonBuilder
(
button
)
.
apply
(
builder
)
button
.
apply
(
builder
)
}
class
DialogItem
(
...
...
@@ -190,43 +168,32 @@ class MagiskDialog(
override
val
layoutRes
=
R
.
layout
.
item_list_single_line
}
interface
ActualOn
DialogClickListener
{
fun
interface
DialogClickListener
{
fun
onClick
(
position
:
Int
)
}
fun
applyAdapter
(
fun
setListItems
(
list
:
Array
<
out
CharSequence
>,
listener
:
On
DialogClickListener
)
=
apply
View
(
listener
:
DialogClickListener
)
=
set
View
(
RecyclerView
(
context
).
also
{
it
.
isNestedScrollingEnabled
=
false
it
.
layoutManager
=
LinearLayoutManager
(
context
)
val
actualListener
=
object
:
ActualOnDialogClickListener
{
override
fun
onClick
(
position
:
Int
)
{
listener
(
position
)
dismiss
()
}
}
val
items
=
list
.
mapIndexed
{
i
,
cs
->
DialogItem
(
cs
,
i
)
}
val
binding
=
itemBindingOf
<
DialogItem
>
{
it
.
bindExtra
(
BR
.
listener
,
actualListener
)
}
.
let
{
ItemBinding
.
of
(
it
)
}
val
binding
=
itemBindingOf
<
DialogItem
>
{
item
->
item
.
bindExtra
(
BR
.
listener
,
DialogClickListener
{
pos
->
listener
.
onClick
(
pos
)
dismiss
()
})
}.
let
{
b
->
ItemBinding
.
of
(
b
)
}
BindingRecyclerViewAdapters
.
setAdapter
(
it
,
binding
,
items
,
null
,
null
,
null
,
null
)
}
)
fun
cancellable
(
isCancellable
:
Boolean
)
=
apply
{
setCancelable
(
isCancellable
)
}
fun
<
Binding
:
ViewDataBinding
>
applyView
(
binding
:
Binding
,
body
:
Binding
.()
->
Unit
=
{}
)
=
applyView
(
binding
.
root
).
also
{
binding
.
apply
(
body
)
}
fun
applyView
(
view
:
View
)
=
apply
{
resetView
()
fun
setView
(
view
:
View
)
{
binding
.
dialogBaseContainer
.
removeAllViews
()
binding
.
dialogBaseContainer
.
addView
(
view
,
ViewGroup
.
LayoutParams
.
MATCH_PARENT
,
...
...
@@ -234,57 +201,24 @@ class MagiskDialog(
)
}
fun
onCancel
(
callback
:
OnDialogButtonClickListener
)
=
apply
{
setOnCancelListener
(
callback
)
}
fun
onDismiss
(
callback
:
OnDialogButtonClickListener
)
=
apply
{
setOnDismissListener
(
callback
)
}
fun
onShow
(
callback
:
OnDialogButtonClickListener
)
=
apply
{
setOnShowListener
(
callback
)
}
fun
reveal
()
=
apply
{
super
.
show
()
}
// ---
fun
resetView
()
=
apply
{
binding
.
dialogBaseContainer
.
removeAllViews
()
}
fun
resetTitle
()
=
applyTitle
(
""
)
fun
resetMessage
()
=
applyMessage
(
""
)
fun
resetIcon
()
=
apply
{
data
.
icon
=
null
}
fun
resetButtons
()
=
apply
{
fun
resetButtons
()
{
ButtonType
.
values
().
forEach
{
apply
Button
(
it
)
{
t
itle
=
""
set
Button
(
it
)
{
t
ext
=
""
icon
=
0
isEnabled
=
true
preven
tDismiss
=
false
doNo
tDismiss
=
false
onClick
{}
}
}
}
fun
reset
()
=
resetTitle
()
.
resetMessage
()
.
resetView
()
.
resetIcon
()
.
resetButtons
()
//region Deprecated Members
@Deprecated
(
"Use applyTitle instead"
,
ReplaceWith
(
"applyTitle"
))
override
fun
setTitle
(
title
:
CharSequence
?)
=
Unit
@Deprecated
(
"Use applyTitle instead"
,
ReplaceWith
(
"applyTitle"
))
override
fun
setTitle
(
titleId
:
Int
)
=
Unit
// Prevent calling setContentView
@Deprecated
(
"Use reveal()"
,
ReplaceWith
(
"reveal()"
))
override
fun
show
()
{
}
//endregion
@Deprecated
(
"Please use setView(view)"
,
level
=
DeprecationLevel
.
ERROR
)
override
fun
setContentView
(
layoutResID
:
Int
)
{}
@Deprecated
(
"Please use setView(view)"
,
level
=
DeprecationLevel
.
ERROR
)
override
fun
setContentView
(
view
:
View
)
{}
@Deprecated
(
"Please use setView(view)"
,
level
=
DeprecationLevel
.
ERROR
)
override
fun
setContentView
(
view
:
View
,
params
:
ViewGroup
.
LayoutParams
?)
{}
}
typealias
OnDialogButtonClickListener
=
(
DialogInterface
)
->
Unit
typealias
OnDialogClickListener
=
(
position
:
Int
)
->
Unit
app/src/main/res/layout/dialog_magisk_base.xml
View file @
47545b45
...
...
@@ -116,34 +116,18 @@
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
>
<Button
android:id=
"@+id/dialog_base_button_4"
style=
"@style/WidgetFoundation.Button.Text"
gone=
"@{data.buttonIDGAF.icon == 0 && data.buttonIDGAF.title.length == 0}"
isEnabled=
"@{data.buttonIDGAF.isEnabled()}"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center_horizontal"
android:clickable=
"@{data.buttonIDGAF.isEnabled()}"
android:focusable=
"@{data.buttonIDGAF.isEnabled()}"
android:onClick=
"@{() -> data.buttonIDGAF.clicked()}"
android:text=
"@{data.buttonIDGAF.title}"
app:icon=
"@{data.buttonIDGAF.icon}"
tools:icon=
"@drawable/ic_bug_md2"
tools:text=
"Button 1"
/>
<Button
android:id=
"@+id/dialog_base_button_2"
style=
"@style/WidgetFoundation.Button.Text"
gone=
"@{data.buttonNeutral.
icon == 0 && data.buttonNeutral.title.length == 0
}"
isEnabled=
"@{data.buttonNeutral.isEnabled
()
}"
gone=
"@{data.buttonNeutral.
gone
}"
isEnabled=
"@{data.buttonNeutral.isEnabled}"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center_horizontal"
android:clickable=
"@{data.buttonNeutral.isEnabled
()
}"
android:focusable=
"@{data.buttonNeutral.isEnabled
()
}"
android:clickable=
"@{data.buttonNeutral.isEnabled}"
android:focusable=
"@{data.buttonNeutral.isEnabled}"
android:onClick=
"@{() -> data.buttonNeutral.clicked()}"
android:text=
"@{data.buttonNeutral.
titl
e}"
android:text=
"@{data.buttonNeutral.
messag
e}"
app:icon=
"@{data.buttonNeutral.icon}"
app:iconGravity=
"textStart"
tools:icon=
"@drawable/ic_bug_md2"
...
...
@@ -159,15 +143,15 @@
<Button
android:id=
"@+id/dialog_base_button_3"
style=
"@style/WidgetFoundation.Button.Text"
gone=
"@{data.buttonNegative.
icon == 0 && data.buttonNegative.title.length == 0
}"
isEnabled=
"@{data.buttonNegative.isEnabled
()
}"
gone=
"@{data.buttonNegative.
gone
}"
isEnabled=
"@{data.buttonNegative.isEnabled}"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center_horizontal"
android:clickable=
"@{data.buttonNegative.isEnabled
()
}"
android:focusable=
"@{data.buttonNegative.isEnabled
()
}"
android:clickable=
"@{data.buttonNegative.isEnabled}"
android:focusable=
"@{data.buttonNegative.isEnabled}"
android:onClick=
"@{() -> data.buttonNegative.clicked()}"
android:text=
"@{data.buttonNegative.
titl
e}"
android:text=
"@{data.buttonNegative.
messag
e}"
app:icon=
"@{data.buttonNegative.icon}"
tools:icon=
"@drawable/ic_bug_md2"
tools:text=
"Button 1"
/>
...
...
@@ -175,15 +159,15 @@
<Button
android:id=
"@+id/dialog_base_button_1"
style=
"@style/WidgetFoundation.Button.Text"
gone=
"@{data.buttonPositive.
icon == 0 && data.buttonPositive.title.length == 0
}"
isEnabled=
"@{data.buttonPositive.isEnabled
()
}"
gone=
"@{data.buttonPositive.
gone
}"
isEnabled=
"@{data.buttonPositive.isEnabled}"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center_horizontal"
android:clickable=
"@{data.buttonPositive.isEnabled
()
}"
android:focusable=
"@{data.buttonPositive.isEnabled
()
}"
android:clickable=
"@{data.buttonPositive.isEnabled}"
android:focusable=
"@{data.buttonPositive.isEnabled}"
android:onClick=
"@{() -> data.buttonPositive.clicked()}"
android:text=
"@{data.buttonPositive.
titl
e}"
android:text=
"@{data.buttonPositive.
messag
e}"
app:icon=
"@{data.buttonPositive.icon}"
app:iconGravity=
"textStart"
tools:icon=
"@drawable/ic_bug_md2"
...
...
app/src/main/res/layout/item_list_single_line.xml
View file @
47545b45
...
...
@@ -10,7 +10,7 @@
<variable
name=
"listener"
type=
"com.topjohnwu.magisk.view.MagiskDialog.
ActualOn
DialogClickListener"
/>
type=
"com.topjohnwu.magisk.view.MagiskDialog.DialogClickListener"
/>
</data>
...
...
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