mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-11 02:34:31 +00:00
Added custom dialog for setting app's name after repackaging
This commit is contained in:
parent
0f74e89b44
commit
7ded7de39a
@ -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()
|
@ -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() {
|
|||||||
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")
|
||||||
@ -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))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
@ -221,3 +222,10 @@ fun getScrollPosition(view: RecyclerView) = (view.layoutManager as? LinearLayout
|
|||||||
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
|
||||||
|
}
|
46
app/src/main/res/layout/dialog_custom_name.xml
Normal file
46
app/src/main/res/layout/dialog_custom_name.xml
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<?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>
|
@ -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>
|
||||||
|
Loading…
Reference in New Issue
Block a user