mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-29 02:39:27 +00:00
Added custom dialog for download location only
This commit is contained in:
committed by
John Wu
parent
e83f40d5c5
commit
f6045bf8b5
@@ -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() }
|
||||
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user