mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 23:28:42 +03:00
Merge pull request #12050 from nextcloud/feature/use-m3-StoragePermissionDialogFragment
Use Material Design 3 for StoragePermissionDialogFragment
This commit is contained in:
commit
1b30013311
3 changed files with 30 additions and 95 deletions
Binary file not shown.
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
|
@ -24,15 +24,14 @@ import android.app.Dialog
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import android.view.View
|
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.core.os.bundleOf
|
import androidx.core.os.bundleOf
|
||||||
import androidx.fragment.app.DialogFragment
|
import androidx.fragment.app.DialogFragment
|
||||||
|
import com.google.android.material.button.MaterialButton
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import com.nextcloud.client.di.Injectable
|
import com.nextcloud.client.di.Injectable
|
||||||
import com.owncloud.android.R
|
import com.owncloud.android.R
|
||||||
import com.owncloud.android.databinding.StoragePermissionDialogBinding
|
|
||||||
import com.owncloud.android.utils.theme.ViewThemeUtils
|
import com.owncloud.android.utils.theme.ViewThemeUtils
|
||||||
import kotlinx.parcelize.Parcelize
|
import kotlinx.parcelize.Parcelize
|
||||||
import javax.inject.Inject
|
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)
|
* Allows choosing "full access" (MANAGE_ALL_FILES) or "read-only media" (READ_EXTERNAL_STORAGE)
|
||||||
*/
|
*/
|
||||||
@RequiresApi(Build.VERSION_CODES.R)
|
@RequiresApi(Build.VERSION_CODES.R)
|
||||||
class StoragePermissionDialogFragment :
|
class StoragePermissionDialogFragment : DialogFragment(), Injectable {
|
||||||
DialogFragment(), Injectable {
|
|
||||||
|
|
||||||
private lateinit var binding: StoragePermissionDialogBinding
|
|
||||||
|
|
||||||
private var permissionRequired = false
|
private var permissionRequired = false
|
||||||
|
|
||||||
|
@ -64,51 +60,48 @@ class StoragePermissionDialogFragment :
|
||||||
super.onStart()
|
super.onStart()
|
||||||
dialog?.let {
|
dialog?.let {
|
||||||
val alertDialog = it as AlertDialog
|
val alertDialog = it as AlertDialog
|
||||||
viewThemeUtils.platform.colorTextButtons(alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE))
|
|
||||||
|
val positiveButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE) as MaterialButton
|
||||||
|
viewThemeUtils.material.colorMaterialButtonPrimaryTonal(positiveButton)
|
||||||
|
|
||||||
|
val negativeButton = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE) as MaterialButton
|
||||||
|
viewThemeUtils.material.colorMaterialButtonPrimaryBorderless(negativeButton)
|
||||||
|
|
||||||
|
val neutralButton = alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL) as MaterialButton
|
||||||
|
viewThemeUtils.material.colorMaterialButtonPrimaryBorderless(neutralButton)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
// Inflate the layout for the dialog
|
val title = when {
|
||||||
val inflater = requireActivity().layoutInflater
|
permissionRequired -> R.string.file_management_permission
|
||||||
binding = StoragePermissionDialogBinding.inflate(inflater, null, false)
|
else -> R.string.file_management_permission_optional
|
||||||
|
}
|
||||||
val view: View = binding.root
|
|
||||||
val explanationResource = when {
|
val explanationResource = when {
|
||||||
permissionRequired -> R.string.file_management_permission_text
|
permissionRequired -> R.string.file_management_permission_text
|
||||||
else -> R.string.file_management_permission_optional_text
|
else -> R.string.file_management_permission_optional_text
|
||||||
}
|
}
|
||||||
binding.storagePermissionExplanation.text = getString(explanationResource, getString(R.string.app_name))
|
val message = getString(explanationResource, getString(R.string.app_name))
|
||||||
|
|
||||||
// Setup layout
|
val dialogBuilder = MaterialAlertDialogBuilder(requireContext())
|
||||||
viewThemeUtils.material.colorMaterialButtonPrimaryFilled(binding.btnFullAccess)
|
.setTitle(title)
|
||||||
binding.btnFullAccess.setOnClickListener {
|
.setMessage(message)
|
||||||
setResult(Result.FULL_ACCESS)
|
.setPositiveButton(R.string.storage_permission_full_access) { _, _ ->
|
||||||
dismiss()
|
setResult(Result.FULL_ACCESS)
|
||||||
}
|
dismiss()
|
||||||
viewThemeUtils.platform.colorTextButtons(binding.btnReadOnly)
|
}
|
||||||
binding.btnReadOnly.setOnClickListener {
|
.setNegativeButton(R.string.storage_permission_media_read_only) { _, _ ->
|
||||||
setResult(Result.MEDIA_READ_ONLY)
|
setResult(Result.MEDIA_READ_ONLY)
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
|
.setNeutralButton(R.string.common_cancel) { _, _ ->
|
||||||
// Build the dialog
|
|
||||||
val titleResource = when {
|
|
||||||
permissionRequired -> R.string.file_management_permission
|
|
||||||
else -> R.string.file_management_permission_optional
|
|
||||||
}
|
|
||||||
|
|
||||||
val builder = MaterialAlertDialogBuilder(binding.btnReadOnly.context)
|
|
||||||
.setTitle(titleResource)
|
|
||||||
.setView(view)
|
|
||||||
.setNegativeButton(R.string.common_cancel) { _, _ ->
|
|
||||||
setResult(Result.CANCEL)
|
setResult(Result.CANCEL)
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
viewThemeUtils.dialog.colorMaterialAlertDialogBackground(binding.btnReadOnly.context, builder)
|
viewThemeUtils.dialog.colorMaterialAlertDialogBackground(requireContext(), dialogBuilder)
|
||||||
|
|
||||||
return builder.create()
|
return dialogBuilder.create()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setResult(result: Result) {
|
private fun setResult(result: Result) {
|
||||||
|
|
|
@ -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>
|
|
Loading…
Reference in a new issue