[Android] Dialogs to material 3
Dmitry
git at videolan.org
Mon Feb 20 10:30:00 UTC 2023
vlc-android | branch: master | Dmitry <dgyudin at gmail.com> | Thu Feb 16 23:36:16 2023 +0100| [4b961c84b45b394a6b8a312335d221da80587c8a] | committer: Nicolas Pomepuy
Dialogs to material 3
> https://code.videolan.org/videolan/vlc-android/commit/4b961c84b45b394a6b8a312335d221da80587c8a
---
.../org/videolan/vlc/gui/browser/MLStorageBrowserFragment.kt | 9 +++++----
.../src/org/videolan/vlc/gui/browser/StorageBrowserFragment.kt | 9 +++++----
.../vlc-android/src/org/videolan/vlc/gui/dialogs/VlcDialog.kt | 3 +++
.../vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt | 10 +++++-----
.../vlc-android/src/org/videolan/vlc/util/Permissions.kt | 6 +++---
5 files changed, 21 insertions(+), 16 deletions(-)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/browser/MLStorageBrowserFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/browser/MLStorageBrowserFragment.kt
index 815271c89e..2961132d81 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/browser/MLStorageBrowserFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/browser/MLStorageBrowserFragment.kt
@@ -30,10 +30,11 @@ import android.text.InputType
import android.view.*
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.view.ActionMode
-import androidx.appcompat.widget.AppCompatEditText
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.RecyclerView
+import com.google.android.material.dialog.MaterialAlertDialogBuilder
+import com.google.android.material.textfield.TextInputEditText
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.launch
import org.videolan.medialibrary.MLServiceLocator
@@ -197,9 +198,9 @@ class MLStorageBrowserFragment : BaseFragment(), IStorageFragmentDelegate by Sto
}
private fun showAddDirectoryDialog() {
- val context = activity
- val builder = AlertDialog.Builder(context!!)
- val input = AppCompatEditText(context)
+ val context = requireContext()
+ val builder = MaterialAlertDialogBuilder(context)
+ val input = TextInputEditText(context)
input.inputType = InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
builder.setTitle(R.string.add_custom_path)
builder.setMessage(R.string.add_custom_path_description)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.kt
index 20700f09af..5e13ead851 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.kt
@@ -32,10 +32,11 @@ import android.view.Menu
import android.view.MenuItem
import android.view.View
import androidx.appcompat.app.AlertDialog
-import androidx.appcompat.widget.AppCompatEditText
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
+import com.google.android.material.dialog.MaterialAlertDialogBuilder
+import com.google.android.material.textfield.TextInputEditText
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@@ -183,9 +184,9 @@ class StorageBrowserFragment : FileBrowserFragment(), BrowserContainer<MediaLibr
override fun onMainActionClick(v: View, position: Int, item: MediaLibraryItem) {}
private fun showAddDirectoryDialog() {
- val context = activity
- val builder = AlertDialog.Builder(context!!)
- val input = AppCompatEditText(context)
+ val context = requireContext()
+ val builder = MaterialAlertDialogBuilder(context)
+ val input = TextInputEditText(context)
input.inputType = InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
builder.setTitle(R.string.add_custom_path)
builder.setMessage(R.string.add_custom_path_description)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/VlcDialog.kt b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/VlcDialog.kt
index db363641ff..ceb85ab988 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/VlcDialog.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/VlcDialog.kt
@@ -32,6 +32,7 @@ import androidx.databinding.ViewDataBinding
import androidx.fragment.app.DialogFragment
import org.videolan.libvlc.Dialog
import org.videolan.vlc.BR
+import org.videolan.vlc.R
import org.videolan.vlc.gui.DialogActivity
abstract class VlcDialog<T : Dialog, B : ViewDataBinding> : DialogFragment() {
@@ -41,6 +42,8 @@ abstract class VlcDialog<T : Dialog, B : ViewDataBinding> : DialogFragment() {
protected abstract val layout: Int
+ override fun getTheme() = R.style.ThemeOverlay_MaterialAlertDialog
+
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
binding = DataBindingUtil.inflate(inflater, layout, container, false)
binding.setVariable(BR.dialog, vlcDialog)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt b/application/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt
index 9259f2d915..fed976d43d 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt
@@ -48,7 +48,6 @@ import android.widget.TextView
import androidx.annotation.IdRes
import androidx.annotation.RequiresApi
import androidx.annotation.StringRes
-import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.appcompat.view.ActionMode
@@ -66,6 +65,7 @@ import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
+import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar
import kotlinx.coroutines.*
import nl.dionsegijn.konfetti.KonfettiView
@@ -662,7 +662,7 @@ object UiTools {
}
fun confirmExit(activity: Activity) {
- AlertDialog.Builder(activity)
+ MaterialAlertDialogBuilder(activity)
.setMessage(R.string.exit_app_msg)
.setTitle(R.string.exit_app)
.setPositiveButton(R.string.ok) { _, _ -> activity.finish() }
@@ -678,7 +678,7 @@ object UiTools {
val si = Intent(ACTION_DISCOVER_DEVICE, null, activity, MediaParsingService::class.java)
.putExtra(EXTRA_PATH, path)
if (activity is AppCompatActivity) {
- val builder = AlertDialog.Builder(activity)
+ val builder = MaterialAlertDialogBuilder(activity)
.setTitle(R.string.ml_external_storage_title)
.setCancelable(false)
.setMessage(message)
@@ -743,7 +743,7 @@ object UiTools {
fun restartDialog(context: Context) {
- AlertDialog.Builder(context)
+ MaterialAlertDialogBuilder(context)
.setTitle(context.resources.getString(R.string.restart_vlc))
.setMessage(context.resources.getString(R.string.restart_message))
.setPositiveButton(R.string.restart_message_OK) { _, _ -> android.os.Process.killProcess(android.os.Process.myPid()) }
@@ -755,7 +755,7 @@ object UiTools {
fun deleteSubtitleDialog(context: Context, positiveListener: DialogInterface.OnClickListener, negativeListener: DialogInterface.OnClickListener) {
- AlertDialog.Builder(context)
+ MaterialAlertDialogBuilder(context)
.setTitle(context.resources.getString(R.string.delete_sub_title))
.setMessage(context.resources.getString(R.string.delete_sub_message))
.setPositiveButton(R.string.delete, positiveListener)
diff --git a/application/vlc-android/src/org/videolan/vlc/util/Permissions.kt b/application/vlc-android/src/org/videolan/vlc/util/Permissions.kt
index 4fd9c2c819..709dc7eaea 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/Permissions.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/Permissions.kt
@@ -33,7 +33,6 @@ import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
-import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
@@ -41,6 +40,7 @@ import androidx.core.content.edit
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
+import com.google.android.material.dialog.MaterialAlertDialogBuilder
import org.videolan.libvlc.util.AndroidUtil
import org.videolan.medialibrary.interfaces.media.MediaWrapper
import org.videolan.resources.AndroidDevices
@@ -225,7 +225,7 @@ object Permissions {
}
private fun createDialogCompat(activity: FragmentActivity, exit: Boolean): Dialog {
- val dialogBuilder = AlertDialog.Builder(activity)
+ val dialogBuilder = MaterialAlertDialogBuilder(activity)
.setTitle(activity.getString(R.string.allow_storage_access_title))
.setMessage(activity.getString(R.string.allow_storage_access_description))
.setIcon(R.drawable.ic_warning)
@@ -285,7 +285,7 @@ object Permissions {
}
}
val finalAction = action
- val dialogBuilder = AlertDialog.Builder(activity)
+ val dialogBuilder = MaterialAlertDialogBuilder(activity)
.setTitle(activity.getString(titleId))
.setMessage(activity.getString(textId))
.setIcon(R.drawable.ic_warning)
More information about the Android
mailing list