فهرست منبع

Merge pull request #12050 from nextcloud/feature/use-m3-StoragePermissionDialogFragment

Use Material Design 3 for StoragePermissionDialogFragment
Andy Scherzinger 1 سال پیش
والد
کامیت
1b30013311

BIN
app/screenshots/gplay/debug/com.owncloud.android.ui.dialog.DialogFragmentIT_testStoragePermissionDialog.png


+ 30 - 37
app/src/main/java/com/owncloud/android/ui/dialog/StoragePermissionDialogFragment.kt

@@ -24,15 +24,14 @@ import android.app.Dialog
 import android.os.Build
 import android.os.Bundle
 import android.os.Parcelable
-import android.view.View
 import androidx.annotation.RequiresApi
 import androidx.appcompat.app.AlertDialog
 import androidx.core.os.bundleOf
 import androidx.fragment.app.DialogFragment
+import com.google.android.material.button.MaterialButton
 import com.google.android.material.dialog.MaterialAlertDialogBuilder
 import com.nextcloud.client.di.Injectable
 import com.owncloud.android.R
-import com.owncloud.android.databinding.StoragePermissionDialogBinding
 import com.owncloud.android.utils.theme.ViewThemeUtils
 import kotlinx.parcelize.Parcelize
 import javax.inject.Inject
@@ -43,10 +42,7 @@ import javax.inject.Inject
  * Allows choosing "full access" (MANAGE_ALL_FILES) or "read-only media" (READ_EXTERNAL_STORAGE)
  */
 @RequiresApi(Build.VERSION_CODES.R)
-class StoragePermissionDialogFragment :
-    DialogFragment(), Injectable {
-
-    private lateinit var binding: StoragePermissionDialogBinding
+class StoragePermissionDialogFragment : DialogFragment(), Injectable {
 
     private var permissionRequired = false
 
@@ -64,51 +60,48 @@ class StoragePermissionDialogFragment :
         super.onStart()
         dialog?.let {
             val alertDialog = it as AlertDialog
-            viewThemeUtils.platform.colorTextButtons(alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE))
-        }
-    }
 
-    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
-        // Inflate the layout for the dialog
-        val inflater = requireActivity().layoutInflater
-        binding = StoragePermissionDialogBinding.inflate(inflater, null, false)
+            val positiveButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE) as MaterialButton
+            viewThemeUtils.material.colorMaterialButtonPrimaryTonal(positiveButton)
 
-        val view: View = binding.root
-        val explanationResource = when {
-            permissionRequired -> R.string.file_management_permission_text
-            else -> R.string.file_management_permission_optional_text
-        }
-        binding.storagePermissionExplanation.text = getString(explanationResource, getString(R.string.app_name))
+            val negativeButton = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE) as MaterialButton
+            viewThemeUtils.material.colorMaterialButtonPrimaryBorderless(negativeButton)
 
-        // Setup layout
-        viewThemeUtils.material.colorMaterialButtonPrimaryFilled(binding.btnFullAccess)
-        binding.btnFullAccess.setOnClickListener {
-            setResult(Result.FULL_ACCESS)
-            dismiss()
-        }
-        viewThemeUtils.platform.colorTextButtons(binding.btnReadOnly)
-        binding.btnReadOnly.setOnClickListener {
-            setResult(Result.MEDIA_READ_ONLY)
-            dismiss()
+            val neutralButton = alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL) as MaterialButton
+            viewThemeUtils.material.colorMaterialButtonPrimaryBorderless(neutralButton)
         }
+    }
 
-        // Build the dialog
-        val titleResource = when {
+    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
+        val title = when {
             permissionRequired -> R.string.file_management_permission
             else -> R.string.file_management_permission_optional
         }
+        val explanationResource = when {
+            permissionRequired -> R.string.file_management_permission_text
+            else -> R.string.file_management_permission_optional_text
+        }
+        val message = getString(explanationResource, getString(R.string.app_name))
 
-        val builder = MaterialAlertDialogBuilder(binding.btnReadOnly.context)
-            .setTitle(titleResource)
-            .setView(view)
-            .setNegativeButton(R.string.common_cancel) { _, _ ->
+        val dialogBuilder = MaterialAlertDialogBuilder(requireContext())
+            .setTitle(title)
+            .setMessage(message)
+            .setPositiveButton(R.string.storage_permission_full_access) { _, _ ->
+                setResult(Result.FULL_ACCESS)
+                dismiss()
+            }
+            .setNegativeButton(R.string.storage_permission_media_read_only) { _, _ ->
+                setResult(Result.MEDIA_READ_ONLY)
+                dismiss()
+            }
+            .setNeutralButton(R.string.common_cancel) { _, _ ->
                 setResult(Result.CANCEL)
                 dismiss()
             }
 
-        viewThemeUtils.dialog.colorMaterialAlertDialogBackground(binding.btnReadOnly.context, builder)
+        viewThemeUtils.dialog.colorMaterialAlertDialogBackground(requireContext(), dialogBuilder)
 
-        return builder.create()
+        return dialogBuilder.create()
     }
 
     private fun setResult(result: Result) {

+ 0 - 58
app/src/main/res/layout/storage_permission_dialog.xml

@@ -1,58 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?><!--
-  ~ Nextcloud Android client application
-  ~
-  ~ @author Álvaro Brey Vilas
-  ~ Copyright (C) 2022 Álvaro Brey Vilas
-  ~ Copyright (C) 2022 Nextcloud GmbH
-  ~
-  ~ This program is free software: you can redistribute it and/or modify
-  ~ it under the terms of the GNU General Public License as published by
-  ~ the Free Software Foundation, either version 3 of the License, or
-  ~ (at your option) any later version.
-  ~
-  ~ This program is distributed in the hope that it will be useful,
-  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
-  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-  ~ GNU General Public License for more details.
-  ~
-  ~ You should have received a copy of the GNU General Public License
-  ~ along with this program. If not, see <https://www.gnu.org/licenses/>.
-  -->
-<androidx.constraintlayout.widget.ConstraintLayout 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"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    android:clickable="true"
-    android:focusable="true"
-    android:orientation="vertical"
-    android:paddingHorizontal="?dialogPreferredPadding">
-
-    <TextView
-        android:id="@+id/storage_permission_explanation"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        app:layout_constraintTop_toTopOf="parent"
-        tools:text="@string/file_management_permission_optional_text" />
-
-    <com.google.android.material.button.MaterialButton
-        android:layout_marginTop="@dimen/standard_padding"
-        android:id="@+id/btn_full_access"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:text="@string/storage_permission_full_access"
-        android:theme="@style/Button.Primary"
-        app:cornerRadius="@dimen/button_corner_radius"
-        app:layout_constraintTop_toBottomOf="@id/storage_permission_explanation" />
-
-    <com.google.android.material.button.MaterialButton
-        android:id="@+id/btn_read_only"
-        style="@style/OutlinedButton"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:text="@string/storage_permission_media_read_only"
-        app:cornerRadius="@dimen/button_corner_radius"
-        app:layout_constraintTop_toBottomOf="@id/btn_full_access" />
-
-
-</androidx.constraintlayout.widget.ConstraintLayout>