Material dialogs

This commit is contained in:
Matthieu 2022-11-28 12:30:30 +01:00
parent 5b224976cc
commit 75ae26fa47
9 changed files with 46 additions and 44 deletions

View File

@ -9,6 +9,7 @@ import android.os.Bundle
import android.view.View import android.view.View
import android.view.inputmethod.InputMethodManager import android.view.inputmethod.InputMethodManager
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.gson.Gson import com.google.gson.Gson
import kotlinx.coroutines.Deferred import kotlinx.coroutines.Deferred
import kotlinx.coroutines.async import kotlinx.coroutines.async
@ -106,13 +107,11 @@ class LoginActivity : BaseThemedWithoutBarActivity() {
private fun whatsAnInstance() { private fun whatsAnInstance() {
val builder = AlertDialog.Builder(this) MaterialAlertDialogBuilder(this)
builder.apply { .setView(layoutInflater.inflate(R.layout.whats_an_instance_explanation, null))
setView(layoutInflater.inflate(R.layout.whats_an_instance_explanation, null)) .setPositiveButton(android.R.string.ok) { _, _ -> }
setPositiveButton(android.R.string.ok) { _, _ -> }
}
// Create the AlertDialog // Create the AlertDialog
builder.show() .show()
} }
private fun hideKeyboard() { private fun hideKeyboard() {
@ -202,7 +201,7 @@ class LoginActivity : BaseThemedWithoutBarActivity() {
if (!nodeInfo.software?.name.orEmpty().contains("pixelfed")) { if (!nodeInfo.software?.name.orEmpty().contains("pixelfed")) {
AlertDialog.Builder(this@LoginActivity).apply { MaterialAlertDialogBuilder(this@LoginActivity).apply {
setMessage(R.string.instance_not_pixelfed_warning) setMessage(R.string.instance_not_pixelfed_warning)
setPositiveButton(R.string.instance_not_pixelfed_continue) { _, _ -> setPositiveButton(R.string.instance_not_pixelfed_continue) { _, _ ->
promptOAuth(normalizedDomain, clientId) promptOAuth(normalizedDomain, clientId)
@ -213,7 +212,7 @@ class LoginActivity : BaseThemedWithoutBarActivity() {
} }
}.show() }.show()
} else if (nodeInfo.metadata?.config?.features?.mobile_apis != true) { } else if (nodeInfo.metadata?.config?.features?.mobile_apis != true) {
AlertDialog.Builder(this@LoginActivity).apply { MaterialAlertDialogBuilder(this@LoginActivity).apply {
setMessage(R.string.api_not_enabled_dialog) setMessage(R.string.api_not_enabled_dialog)
setNegativeButton(android.R.string.ok) { _, _ -> setNegativeButton(android.R.string.ok) { _, _ ->
loadingAnimation(false) loadingAnimation(false)

View File

@ -1,13 +1,14 @@
package org.pixeldroid.app.postCreation package org.pixeldroid.app.postCreation
import android.app.Activity import android.app.Activity
import android.app.AlertDialog
import android.content.ContentResolver import android.content.ContentResolver
import android.content.ContentValues import android.content.ContentValues
import android.content.Intent import android.content.Intent
import android.media.MediaScannerConnection import android.media.MediaScannerConnection
import android.net.Uri import android.net.Uri
import android.os.* import android.os.Build
import android.os.Bundle
import android.os.Environment
import android.provider.MediaStore import android.provider.MediaStore
import android.util.Log import android.util.Log
import android.view.LayoutInflater import android.view.LayoutInflater
@ -26,6 +27,7 @@ import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle import androidx.lifecycle.repeatOnLifecycle
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.pixeldroid.app.R import org.pixeldroid.app.R
@ -42,7 +44,7 @@ import org.pixeldroid.media_editor.photoEdit.VideoEditActivity
import java.io.File import java.io.File
import java.io.OutputStream import java.io.OutputStream
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.* import java.util.Locale
class PostCreationFragment : BaseFragment() { class PostCreationFragment : BaseFragment() {
@ -103,7 +105,7 @@ class PostCreationFragment : BaseFragment() {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) { viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
model.uiState.collect { uiState -> model.uiState.collect { uiState ->
uiState.userMessage?.let { uiState.userMessage?.let {
AlertDialog.Builder(binding.root.context).apply { MaterialAlertDialogBuilder(binding.root.context).apply {
setMessage(it) setMessage(it)
setNegativeButton(android.R.string.ok) { _, _ -> } setNegativeButton(android.R.string.ok) { _, _ -> }
}.show() }.show()
@ -173,8 +175,7 @@ class PostCreationFragment : BaseFragment() {
override fun handleOnBackPressed() { override fun handleOnBackPressed() {
val redraft = requireActivity().intent.getBooleanExtra(PostCreationActivity.POST_REDRAFT, false) val redraft = requireActivity().intent.getBooleanExtra(PostCreationActivity.POST_REDRAFT, false)
if (redraft) { if (redraft) {
val builder = AlertDialog.Builder(binding.root.context) MaterialAlertDialogBuilder(binding.root.context).apply {
builder.apply {
setMessage(R.string.redraft_dialog_cancel) setMessage(R.string.redraft_dialog_cancel)
setPositiveButton(android.R.string.ok) { _, _ -> setPositiveButton(android.R.string.ok) { _, _ ->
requireActivity().finish() requireActivity().finish()
@ -275,7 +276,7 @@ class PostCreationFragment : BaseFragment() {
private fun validatePost(): Boolean { private fun validatePost(): Boolean {
if (model.getPhotoData().value?.all { !it.video || it.videoEncodeComplete } == false) { if (model.getPhotoData().value?.all { !it.video || it.videoEncodeComplete } == false) {
AlertDialog.Builder(requireActivity()).apply { MaterialAlertDialogBuilder(requireActivity()).apply {
setMessage(R.string.still_encoding) setMessage(R.string.still_encoding)
setNegativeButton(android.R.string.ok) { _, _ -> } setNegativeButton(android.R.string.ok) { _, _ -> }
}.show() }.show()

View File

@ -1,6 +1,5 @@
package org.pixeldroid.app.postCreation package org.pixeldroid.app.postCreation
import android.app.AlertDialog
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.Menu import android.view.Menu
@ -17,6 +16,7 @@ import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle import androidx.lifecycle.repeatOnLifecycle
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import androidx.navigation.ui.setupWithNavController import androidx.navigation.ui.setupWithNavController
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.pixeldroid.app.R import org.pixeldroid.app.R
import org.pixeldroid.app.databinding.FragmentPostSubmissionBinding import org.pixeldroid.app.databinding.FragmentPostSubmissionBinding
@ -81,10 +81,10 @@ class PostSubmissionFragment : BaseFragment() {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) { viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
model.uiState.collect { uiState -> model.uiState.collect { uiState ->
uiState.userMessage?.let { uiState.userMessage?.let {
AlertDialog.Builder(binding.root.context).apply { MaterialAlertDialogBuilder(binding.root.context)
setMessage(it) .setMessage(it)
setNegativeButton(android.R.string.ok) { _, _ -> } .setNegativeButton(android.R.string.ok) { _, _ -> }
}.show() .show()
// Notify the ViewModel the message is displayed // Notify the ViewModel the message is displayed
model.userMessageShown() model.userMessageShown()
@ -147,7 +147,7 @@ class PostSubmissionFragment : BaseFragment() {
// Handle the menu selection // Handle the menu selection
return when (menuItem.itemId) { return when (menuItem.itemId) {
R.id.action_switch_accounts -> { R.id.action_switch_accounts -> {
AlertDialog.Builder(requireActivity()).apply { MaterialAlertDialogBuilder(requireActivity()).apply {
setIcon(R.drawable.switch_account) setIcon(R.drawable.switch_account)
setTitle(R.string.switch_accounts) setTitle(R.string.switch_accounts)
setSingleChoiceItems(accounts.map { it.username + " (${it.fullHandle})" }.toTypedArray(), selectedAccount) { dialog, which -> setSingleChoiceItems(accounts.map { it.username + " (${it.fullHandle})" }.toTypedArray(), selectedAccount) { dialog, which ->

View File

@ -18,9 +18,13 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AlertDialog import androidx.camera.core.AspectRatio
import androidx.camera.core.* import androidx.camera.core.Camera
import androidx.camera.core.CameraSelector
import androidx.camera.core.ImageCapture
import androidx.camera.core.ImageCapture.Metadata import androidx.camera.core.ImageCapture.Metadata
import androidx.camera.core.ImageCaptureException
import androidx.camera.core.Preview
import androidx.camera.lifecycle.ProcessCameraProvider import androidx.camera.lifecycle.ProcessCameraProvider
import androidx.constraintlayout.widget.ConstraintLayout import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
@ -29,6 +33,7 @@ import androidx.core.view.setPadding
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions import com.bumptech.glide.request.RequestOptions
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.pixeldroid.app.R import org.pixeldroid.app.R
@ -264,7 +269,7 @@ class CameraFragment : BaseFragment() {
if (isGranted) { if (isGranted) {
updateGalleryThumbnail() updateGalleryThumbnail()
} else if(!filePermissionDialogLaunched){ } else if(!filePermissionDialogLaunched){
AlertDialog.Builder(requireContext()) MaterialAlertDialogBuilder(requireContext())
.setMessage(getString(R.string.no_storage_permission)) .setMessage(getString(R.string.no_storage_permission))
.setPositiveButton(android.R.string.ok) { _, _ ->}.show() .setPositiveButton(android.R.string.ok) { _, _ ->}.show()
filePermissionDialogLaunched = true filePermissionDialogLaunched = true
@ -346,7 +351,7 @@ class CameraFragment : BaseFragment() {
if (isGranted) { if (isGranted) {
bindCameraUseCases() bindCameraUseCases()
} else { } else {
AlertDialog.Builder(requireContext()) MaterialAlertDialogBuilder(requireContext())
.setMessage(R.string.no_camera_permission) .setMessage(R.string.no_camera_permission)
.setPositiveButton(android.R.string.ok) { _, _ ->}.show() .setPositiveButton(android.R.string.ok) { _, _ ->}.show()
} }

View File

@ -2,7 +2,6 @@ package org.pixeldroid.app.posts
import android.Manifest import android.Manifest
import android.app.Activity import android.app.Activity
import android.app.AlertDialog
import android.content.ClipData import android.content.ClipData
import android.content.Intent import android.content.Intent
import android.graphics.Typeface import android.graphics.Typeface
@ -33,6 +32,7 @@ import com.bumptech.glide.request.target.CustomViewTarget
import com.bumptech.glide.request.transition.Transition import com.bumptech.glide.request.transition.Transition
import com.davemorrissey.labs.subscaleview.ImageSource import com.davemorrissey.labs.subscaleview.ImageSource
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import com.karumi.dexter.Dexter import com.karumi.dexter.Dexter
import com.karumi.dexter.listener.PermissionDeniedResponse import com.karumi.dexter.listener.PermissionDeniedResponse
@ -444,24 +444,21 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
true true
} }
R.id.post_more_menu_delete -> { R.id.post_more_menu_delete -> {
val builder = AlertDialog.Builder(binding.root.context) MaterialAlertDialogBuilder(binding.root.context)
builder.apply { .setMessage(R.string.delete_dialog)
setMessage(R.string.delete_dialog) .setPositiveButton(android.R.string.ok) { _, _ ->
setPositiveButton(android.R.string.ok) { _, _ ->
lifecycleScope.launch { lifecycleScope.launch {
deletePost(apiHolder.api ?: apiHolder.setToCurrentUser(), db) deletePost(apiHolder.api ?: apiHolder.setToCurrentUser(), db)
} }
} }
setNegativeButton(android.R.string.cancel) { _, _ -> } .setNegativeButton(android.R.string.cancel) { _, _ -> }
show() .show()
}
true true
} }
R.id.post_more_menu_redraft -> { R.id.post_more_menu_redraft -> {
val builder = AlertDialog.Builder(binding.root.context) MaterialAlertDialogBuilder(binding.root.context).apply {
builder.apply {
setMessage(R.string.redraft_dialog_launch) setMessage(R.string.redraft_dialog_launch)
setPositiveButton(android.R.string.ok) { _, _ -> setPositiveButton(android.R.string.ok) { _, _ ->

View File

@ -1,12 +1,12 @@
package org.pixeldroid.app.profile package org.pixeldroid.app.profile
import android.app.AlertDialog
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuInflater import android.view.MenuInflater
import android.view.MenuItem import android.view.MenuItem
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.pixeldroid.app.R import org.pixeldroid.app.R
@ -96,7 +96,7 @@ class CollectionActivity : BaseThemedWithBarActivity() {
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) { return when (item.itemId) {
R.id.delete_collection -> { R.id.delete_collection -> {
AlertDialog.Builder(this).apply { MaterialAlertDialogBuilder(this).apply {
setMessage(R.string.delete_collection_warning) setMessage(R.string.delete_collection_warning)
setPositiveButton(android.R.string.ok) { _, _ -> setPositiveButton(android.R.string.ok) { _, _ ->
// Delete collection // Delete collection

View File

@ -1,7 +1,6 @@
package org.pixeldroid.app.profile package org.pixeldroid.app.profile
import android.app.Activity import android.app.Activity
import android.app.AlertDialog
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.Menu
@ -15,6 +14,7 @@ import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle import androidx.lifecycle.repeatOnLifecycle
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions import com.bumptech.glide.request.RequestOptions
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.pixeldroid.app.R import org.pixeldroid.app.R
@ -135,7 +135,7 @@ class EditProfileActivity : BaseThemedWithBarActivity() {
@Deprecated("Deprecated in Java") @Deprecated("Deprecated in Java")
override fun onBackPressed() { override fun onBackPressed() {
if(model.madeChanges()){ if(model.madeChanges()){
AlertDialog.Builder(binding.root.context).apply { MaterialAlertDialogBuilder(binding.root.context).apply {
setMessage(getString(R.string.profile_save_changes)) setMessage(getString(R.string.profile_save_changes))
setNegativeButton(android.R.string.cancel) { _, _ -> } setNegativeButton(android.R.string.cancel) { _, _ -> }
setPositiveButton(android.R.string.ok) { _, _ -> super.onBackPressed()} setPositiveButton(android.R.string.ok) { _, _ -> super.onBackPressed()}

View File

@ -6,11 +6,11 @@ import android.text.method.LinkMovementMethod
import android.util.Log import android.util.Log
import android.view.View import android.view.View
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.viewpager2.adapter.FragmentStateAdapter import androidx.viewpager2.adapter.FragmentStateAdapter
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator import com.google.android.material.tabs.TabLayoutMediator
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -331,7 +331,7 @@ class ProfileActivity : BaseThemedWithBarActivity() {
setOnClickListener { setOnClickListener {
if(account.locked == true && requested){ if(account.locked == true && requested){
AlertDialog.Builder(context) MaterialAlertDialogBuilder(context)
.setMessage(R.string.dialog_message_cancel_follow_request) .setMessage(R.string.dialog_message_cancel_follow_request)
.setPositiveButton(android.R.string.ok) { _, _ -> .setPositiveButton(android.R.string.ok) { _, _ ->
unfollow() unfollow()

View File

@ -6,7 +6,6 @@ import android.content.SharedPreferences
import android.content.res.XmlResourceParser import android.content.res.XmlResourceParser
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatDelegate import androidx.appcompat.app.AppCompatDelegate
import androidx.core.os.LocaleListCompat import androidx.core.os.LocaleListCompat
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
@ -14,6 +13,7 @@ import androidx.preference.ListPreference
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import org.pixeldroid.app.MainActivity import org.pixeldroid.app.MainActivity
import org.pixeldroid.app.R import org.pixeldroid.app.R
import org.pixeldroid.app.utils.BaseThemedWithBarActivity import org.pixeldroid.app.utils.BaseThemedWithBarActivity
@ -150,7 +150,7 @@ class LanguageSettingFragment : DialogFragment() {
else index + 1 else index + 1
} }
return AlertDialog.Builder(requireContext()).apply { return MaterialAlertDialogBuilder(requireContext()).apply {
setIcon(R.drawable.translate_black_24dp) setIcon(R.drawable.translate_black_24dp)
setTitle(R.string.language) setTitle(R.string.language)
setSingleChoiceItems((mutableListOf(getString(R.string.default_system)) + list.map { setSingleChoiceItems((mutableListOf(getString(R.string.default_system)) + list.map {