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
7ded7de3
Commit
7ded7de3
authored
Oct 20, 2019
by
Viktor De Pasquale
Committed by
John Wu
Oct 22, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added custom dialog for setting app's name after repackaging
parent
0f74e89b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
104 additions
and
19 deletions
+104
-19
XString.kt
app/src/main/java/com/topjohnwu/magisk/extensions/XString.kt
+2
-0
SettingsFragment.kt
...java/com/topjohnwu/magisk/ui/settings/SettingsFragment.kt
+44
-19
DataBindingAdapters.kt
...in/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt
+8
-0
dialog_custom_name.xml
app/src/main/res/layout/dialog_custom_name.xml
+46
-0
strings.xml
app/src/main/res/values/strings.xml
+4
-0
No files found.
app/src/main/java/com/topjohnwu/magisk/extensions/XString.kt
View file @
7ded7de3
...
@@ -25,3 +25,5 @@ fun String.trimEmptyToNull(): String? = if (isBlank()) null else this
...
@@ -25,3 +25,5 @@ fun String.trimEmptyToNull(): String? = if (isBlank()) null else this
fun
String
.
legalFilename
()
=
replace
(
" "
,
"_"
).
replace
(
"'"
,
""
).
replace
(
"\""
,
""
)
fun
String
.
legalFilename
()
=
replace
(
" "
,
"_"
).
replace
(
"'"
,
""
).
replace
(
"\""
,
""
)
.
replace
(
"$"
,
""
).
replace
(
"`"
,
""
).
replace
(
"*"
,
""
).
replace
(
"/"
,
"_"
)
.
replace
(
"$"
,
""
).
replace
(
"`"
,
""
).
replace
(
"*"
,
""
).
replace
(
"/"
,
"_"
)
.
replace
(
"#"
,
""
).
replace
(
"@"
,
""
).
replace
(
"\\"
,
"_"
)
.
replace
(
"#"
,
""
).
replace
(
"@"
,
""
).
replace
(
"\\"
,
"_"
)
fun
String
.
isEmptyInternal
()
=
isNullOrBlank
()
\ No newline at end of file
app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsFragment.kt
View file @
7ded7de3
...
@@ -17,6 +17,7 @@ import com.topjohnwu.magisk.*
...
@@ -17,6 +17,7 @@ import com.topjohnwu.magisk.*
import
com.topjohnwu.magisk.base.BasePreferenceFragment
import
com.topjohnwu.magisk.base.BasePreferenceFragment
import
com.topjohnwu.magisk.data.database.RepoDao
import
com.topjohnwu.magisk.data.database.RepoDao
import
com.topjohnwu.magisk.databinding.CustomDownloadDialogBinding
import
com.topjohnwu.magisk.databinding.CustomDownloadDialogBinding
import
com.topjohnwu.magisk.databinding.DialogCustomNameBinding
import
com.topjohnwu.magisk.extensions.subscribeK
import
com.topjohnwu.magisk.extensions.subscribeK
import
com.topjohnwu.magisk.extensions.toLangTag
import
com.topjohnwu.magisk.extensions.toLangTag
import
com.topjohnwu.magisk.model.download.DownloadService
import
com.topjohnwu.magisk.model.download.DownloadService
...
@@ -67,8 +68,9 @@ class SettingsFragment : BasePreferenceFragment() {
...
@@ -67,8 +68,9 @@ class SettingsFragment : BasePreferenceFragment() {
val
suCategory
=
findPreference
<
PreferenceCategory
>(
"superuser"
)
!!
val
suCategory
=
findPreference
<
PreferenceCategory
>(
"superuser"
)
!!
val
hideManager
=
findPreference
<
Preference
>(
"hide"
)
!!
val
hideManager
=
findPreference
<
Preference
>(
"hide"
)
!!
hideManager
.
setOnPreferenceClickListener
{
hideManager
.
setOnPreferenceClickListener
{
// TODO: Add UI to allow user to customize app name
showManagerNameDialog
{
PatchAPK
.
hideManager
(
requireContext
(),
"Manager"
)
PatchAPK
.
hideManager
(
requireContext
(),
"Manager"
)
}
true
true
}
}
val
restoreManager
=
findPreference
<
Preference
>(
"restore"
)
val
restoreManager
=
findPreference
<
Preference
>(
"restore"
)
...
@@ -224,26 +226,26 @@ class SettingsFragment : BasePreferenceFragment() {
...
@@ -224,26 +226,26 @@ class SettingsFragment : BasePreferenceFragment() {
private
fun
setLocalePreference
(
lp
:
ListPreference
)
{
private
fun
setLocalePreference
(
lp
:
ListPreference
)
{
lp
.
isEnabled
=
false
lp
.
isEnabled
=
false
availableLocales
.
map
{
availableLocales
.
map
{
val
names
=
mutableListOf
<
String
>()
val
names
=
mutableListOf
<
String
>()
val
values
=
mutableListOf
<
String
>()
val
values
=
mutableListOf
<
String
>()
names
.
add
(
ResourceMgr
.
getString
(
defaultLocale
,
R
.
string
.
system_default
)
)
values
.
add
(
""
)
it
.
forEach
{
locale
->
names
.
add
(
names
.
add
(
locale
.
getDisplayName
(
locale
)
)
ResourceMgr
.
getString
(
defaultLocale
,
R
.
string
.
system_default
)
values
.
add
(
locale
.
toLangTag
()
)
)
}
values
.
add
(
""
)
Pair
(
names
.
toTypedArray
(),
values
.
toTypedArray
())
it
.
forEach
{
locale
->
}.
subscribeK
{
(
names
,
values
)
->
names
.
add
(
locale
.
getDisplayName
(
locale
))
lp
.
isEnabled
=
true
values
.
add
(
locale
.
toLangTag
())
lp
.
entries
=
names
lp
.
entryValues
=
values
lp
.
summary
=
currentLocale
.
getDisplayName
(
currentLocale
)
}
}
Pair
(
names
.
toTypedArray
(),
values
.
toTypedArray
())
}.
subscribeK
{
(
names
,
values
)
->
lp
.
isEnabled
=
true
lp
.
entries
=
names
lp
.
entryValues
=
values
lp
.
summary
=
currentLocale
.
getDisplayName
(
currentLocale
)
}
}
}
private
fun
setSummary
(
key
:
String
)
{
private
fun
setSummary
(
key
:
String
)
{
...
@@ -327,4 +329,27 @@ class SettingsFragment : BasePreferenceFragment() {
...
@@ -327,4 +329,27 @@ class SettingsFragment : BasePreferenceFragment() {
.
setNegativeButton
(
R
.
string
.
close
,
null
)
.
setNegativeButton
(
R
.
string
.
close
,
null
)
.
show
()
.
show
()
}
}
private
inline
fun
showManagerNameDialog
(
crossinline
onSuccess
:
(
String
)
->
Unit
)
{
val
data
=
ManagerNameData
()
val
view
=
DialogCustomNameBinding
.
inflate
(
LayoutInflater
.
from
(
requireContext
()))
.
also
{
it
.
data
=
data
}
AlertDialog
.
Builder
(
requireActivity
())
.
setTitle
(
R
.
string
.
settings_app_name
)
.
setView
(
view
.
root
)
.
setPositiveButton
(
R
.
string
.
ok
)
{
_
,
_
->
if
(
view
.
dialogNameInput
.
error
.
isNullOrBlank
())
{
onSuccess
(
data
.
name
.
value
)
}
}
.
show
()
}
inner
class
ManagerNameData
{
val
name
=
KObservableField
(
resources
.
getString
(
R
.
string
.
re_app_name
))
}
}
}
app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt
View file @
7ded7de3
...
@@ -16,6 +16,7 @@ import androidx.recyclerview.widget.RecyclerView
...
@@ -16,6 +16,7 @@ import androidx.recyclerview.widget.RecyclerView
import
androidx.viewpager.widget.ViewPager
import
androidx.viewpager.widget.ViewPager
import
com.google.android.material.floatingactionbutton.FloatingActionButton
import
com.google.android.material.floatingactionbutton.FloatingActionButton
import
com.google.android.material.navigation.NavigationView
import
com.google.android.material.navigation.NavigationView
import
com.google.android.material.textfield.TextInputLayout
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.extensions.replaceRandomWithSpecial
import
com.topjohnwu.magisk.extensions.replaceRandomWithSpecial
import
com.topjohnwu.magisk.extensions.subscribeK
import
com.topjohnwu.magisk.extensions.subscribeK
...
@@ -220,4 +221,11 @@ fun getScrollPosition(view: RecyclerView) = (view.layoutManager as? LinearLayout
...
@@ -220,4 +221,11 @@ fun getScrollPosition(view: RecyclerView) = (view.layoutManager as? LinearLayout
@BindingAdapter
(
"isEnabled"
)
@BindingAdapter
(
"isEnabled"
)
fun
setEnabled
(
view
:
View
,
isEnabled
:
Boolean
)
{
fun
setEnabled
(
view
:
View
,
isEnabled
:
Boolean
)
{
view
.
isEnabled
=
isEnabled
view
.
isEnabled
=
isEnabled
}
@BindingAdapter
(
"error"
)
fun
TextInputLayout
.
setErrorString
(
error
:
String
)
{
val
newError
=
error
.
let
{
if
(
it
.
isEmpty
())
null
else
it
}
if
(
this
.
error
==
null
&&
newError
==
null
)
return
this
.
error
=
newError
}
}
\ No newline at end of file
app/src/main/res/layout/dialog_custom_name.xml
0 → 100644
View file @
7ded7de3
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
>
<data>
<import
type=
"com.topjohnwu.magisk.extensions.XStringKt"
/>
<variable
name=
"data"
type=
"com.topjohnwu.magisk.ui.settings.SettingsFragment.ManagerNameData"
/>
</data>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:clipToPadding=
"false"
android:orientation=
"vertical"
android:paddingStart=
"@dimen/margin_generic"
android:paddingTop=
"@dimen/margin_generic"
android:paddingEnd=
"@dimen/margin_generic"
>
<com.google.android.material.textfield.TextInputLayout
android:id=
"@+id/dialog_name_input"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:hint=
"@string/settings_app_name_hint"
app:counterEnabled=
"true"
app:counterMaxLength=
"14"
app:counterOverflowTextColor=
"@color/colorError"
app:error=
"@{data.name.length() > 14 || data.name.empty || XStringKt.isEmptyInternal(data.name) ? @string/settings_app_name_error : @string/empty}"
app:errorEnabled=
"true"
app:helperText=
"@string/settings_app_name_helper"
>
<com.google.android.material.textfield.TextInputEditText
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:text=
"@={data.name}"
tools:text=
"@string/re_app_name"
/>
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
</layout>
\ No newline at end of file
app/src/main/res/values/strings.xml
View file @
7ded7de3
...
@@ -150,6 +150,10 @@
...
@@ -150,6 +150,10 @@
<string
name=
"settings_hosts_summary"
>
Systemless hosts support for Adblock apps.
</string>
<string
name=
"settings_hosts_summary"
>
Systemless hosts support for Adblock apps.
</string>
<string
name=
"settings_hosts_toast"
>
Added systemless hosts module
</string>
<string
name=
"settings_hosts_toast"
>
Added systemless hosts module
</string>
<string
name=
"settings_app_name"
>
Type desired app name
</string>
<string
name=
"settings_app_name_hint"
>
New name
</string>
<string
name=
"settings_app_name_helper"
>
App will be repackaged to this name
</string>
<string
name=
"settings_app_name_error"
>
Invalid format
</string>
<string
name=
"settings_su_app_adb"
>
Apps and ADB
</string>
<string
name=
"settings_su_app_adb"
>
Apps and ADB
</string>
<string
name=
"settings_su_app"
>
Apps only
</string>
<string
name=
"settings_su_app"
>
Apps only
</string>
<string
name=
"settings_su_adb"
>
ADB only
</string>
<string
name=
"settings_su_adb"
>
ADB only
</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