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

View File

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

View File

@ -1,6 +1,5 @@
package org.pixeldroid.app.postCreation
import android.app.AlertDialog
import android.os.Bundle
import android.view.LayoutInflater
import android.view.Menu
@ -17,6 +16,7 @@ import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.navigation.fragment.findNavController
import androidx.navigation.ui.setupWithNavController
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.coroutines.launch
import org.pixeldroid.app.R
import org.pixeldroid.app.databinding.FragmentPostSubmissionBinding
@ -81,10 +81,10 @@ class PostSubmissionFragment : BaseFragment() {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
model.uiState.collect { uiState ->
uiState.userMessage?.let {
AlertDialog.Builder(binding.root.context).apply {
setMessage(it)
setNegativeButton(android.R.string.ok) { _, _ -> }
}.show()
MaterialAlertDialogBuilder(binding.root.context)
.setMessage(it)
.setNegativeButton(android.R.string.ok) { _, _ -> }
.show()
// Notify the ViewModel the message is displayed
model.userMessageShown()
@ -147,7 +147,7 @@ class PostSubmissionFragment : BaseFragment() {
// Handle the menu selection
return when (menuItem.itemId) {
R.id.action_switch_accounts -> {
AlertDialog.Builder(requireActivity()).apply {
MaterialAlertDialogBuilder(requireActivity()).apply {
setIcon(R.drawable.switch_account)
setTitle(R.string.switch_accounts)
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.ViewGroup
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AlertDialog
import androidx.camera.core.*
import androidx.camera.core.AspectRatio
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.ImageCaptureException
import androidx.camera.core.Preview
import androidx.camera.lifecycle.ProcessCameraProvider
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat
@ -29,6 +33,7 @@ import androidx.core.view.setPadding
import androidx.lifecycle.lifecycleScope
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.pixeldroid.app.R
@ -264,7 +269,7 @@ class CameraFragment : BaseFragment() {
if (isGranted) {
updateGalleryThumbnail()
} else if(!filePermissionDialogLaunched){
AlertDialog.Builder(requireContext())
MaterialAlertDialogBuilder(requireContext())
.setMessage(getString(R.string.no_storage_permission))
.setPositiveButton(android.R.string.ok) { _, _ ->}.show()
filePermissionDialogLaunched = true
@ -346,7 +351,7 @@ class CameraFragment : BaseFragment() {
if (isGranted) {
bindCameraUseCases()
} else {
AlertDialog.Builder(requireContext())
MaterialAlertDialogBuilder(requireContext())
.setMessage(R.string.no_camera_permission)
.setPositiveButton(android.R.string.ok) { _, _ ->}.show()
}

View File

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

View File

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

View File

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

View File

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

View File

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