Added custom dialog for download location only

This commit is contained in:
Viktor De Pasquale 2019-07-17 17:28:01 +02:00 committed by John Wu
parent e83f40d5c5
commit f6045bf8b5
4 changed files with 85 additions and 7 deletions

View File

@ -0,0 +1,12 @@
package com.topjohnwu.magisk.model.entity.internal
import com.skoumal.teanity.util.KObservableField
import com.topjohnwu.magisk.Config
import com.topjohnwu.magisk.model.observer.Observer
class DownloadDialogData(initialValue: String) {
val text = KObservableField(initialValue)
val path = Observer(text) { Config.downloadsFile(text.value)?.absolutePath.orEmpty() }
}

View File

@ -8,6 +8,7 @@ import android.widget.EditText
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.core.content.edit
import androidx.databinding.DataBindingUtil
import androidx.preference.ListPreference
import androidx.preference.Preference
import androidx.preference.PreferenceCategory
@ -18,6 +19,8 @@ import com.topjohnwu.magisk.Config
import com.topjohnwu.magisk.Const
import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.data.database.RepoDatabaseHelper
import com.topjohnwu.magisk.databinding.CustomDownloadDialogBinding
import com.topjohnwu.magisk.model.entity.internal.DownloadDialogData
import com.topjohnwu.magisk.ui.base.BasePreferenceFragment
import com.topjohnwu.magisk.utils.*
import com.topjohnwu.magisk.view.dialogs.FingerprintAuthDialog
@ -88,13 +91,9 @@ class SettingsFragment : BasePreferenceFragment() {
}.setOnPreferenceClickListener { preference ->
activity.withExternalRW {
onSuccess {
showUrlDialog(Config.downloadPath) {
Config.downloadsFile(it)?.let { _ ->
Config.downloadPath = it
preference.summary = it
} ?: let {
Utils.toast(R.string.settings_download_path_error, Toast.LENGTH_SHORT)
}
showDownloadDialog {
Config.downloadPath = it
preference.summary = it
}
}
}
@ -297,4 +296,24 @@ class SettingsFragment : BasePreferenceFragment() {
.setOnCancelListener { onCancel() }
.show()
}
private inline fun showDownloadDialog(
initialValue: String = Config.downloadPath,
crossinline onSuccess: (String) -> Unit
) {
val data = DownloadDialogData(initialValue)
val binding: CustomDownloadDialogBinding = DataBindingUtil
.inflate(layoutInflater, R.layout.custom_download_dialog, null, false)
binding.also { it.data = data }
AlertDialog.Builder(requireActivity())
.setTitle(R.string.settings_download_path_title)
.setView(binding.root)
.setPositiveButton(R.string.ok) { _, _ ->
Config.downloadsFile(data.text.value)?.let { onSuccess(data.text.value) }
?: Utils.toast(R.string.settings_download_path_error, Toast.LENGTH_SHORT)
}
.setNegativeButton(R.string.close, null)
.show()
}
}

View 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>
<variable
name="data"
type="com.topjohnwu.magisk.model.entity.internal.DownloadDialogData" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/margin_generic">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/dialog_custom_download_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@{@string/settings_download_path_message(data.path)}"
tools:text="@string/settings_download_path_message" />
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_generic"
android:hint="@string/settings_download_path_title"
app:hintEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/dialog_custom_download_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textUri"
android:text="@={data.text}" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
</layout>

View File

@ -136,6 +136,7 @@
<string name="settings_download_cache_title">Download Cache</string>
<string name="settings_download_cache_summary">Enables download cache for Magisk and Module zip files.</string>
<string name="settings_download_path_title">Download path</string>
<string name="settings_download_path_message">Files will be saved to %1$s</string>
<string name="settings_clear_cache_title">Clear Repo Cache</string>
<string name="settings_clear_cache_summary">Clear the cached information for online repos. This forces the app to refresh online.</string>
<string name="settings_hide_manager_title">Hide Magisk Manager</string>