From 27432ff8caea2fcceeadfab201049697590f4880 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Fri, 3 Nov 2023 15:28:55 +0100 Subject: [PATCH 1/2] refactor: remove AppNameTextView's in favor of dialog titles --- .../ui/dialogs/AddToPlaylistDialog.kt | 1 + .../ui/dialogs/CreatePlaylistDialog.kt | 1 + .../ui/dialogs/CustomInstanceDialog.kt | 1 + .../libretube/ui/dialogs/DownloadDialog.kt | 1 + .../github/libretube/ui/dialogs/LoginDialog.kt | 1 + .../libretube/ui/dialogs/LogoutDialog.kt | 1 + .../libretube/ui/views/AppNameTextView.kt | 18 ------------------ .../main/res/layout/dialog_add_to_playlist.xml | 8 +------- .../main/res/layout/dialog_create_playlist.xml | 12 +++--------- .../main/res/layout/dialog_custom_instance.xml | 9 ++------- .../main/res/layout/dialog_delete_account.xml | 9 ++------- app/src/main/res/layout/dialog_download.xml | 6 ------ app/src/main/res/layout/dialog_login.xml | 6 ------ app/src/main/res/layout/dialog_logout.xml | 6 ------ 14 files changed, 14 insertions(+), 66 deletions(-) delete mode 100644 app/src/main/java/com/github/libretube/ui/views/AppNameTextView.kt diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/AddToPlaylistDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/AddToPlaylistDialog.kt index 94a2647d4..358f0512e 100644 --- a/app/src/main/java/com/github/libretube/ui/dialogs/AddToPlaylistDialog.kt +++ b/app/src/main/java/com/github/libretube/ui/dialogs/AddToPlaylistDialog.kt @@ -55,6 +55,7 @@ class AddToPlaylistDialog : DialogFragment() { fetchPlaylists(binding) return MaterialAlertDialogBuilder(requireContext()) + .setTitle(R.string.addToPlaylist) .setView(binding.root) .show() } diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/CreatePlaylistDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/CreatePlaylistDialog.kt index 54c989736..d2ad9a36d 100644 --- a/app/src/main/java/com/github/libretube/ui/dialogs/CreatePlaylistDialog.kt +++ b/app/src/main/java/com/github/libretube/ui/dialogs/CreatePlaylistDialog.kt @@ -84,6 +84,7 @@ class CreatePlaylistDialog : DialogFragment() { } return MaterialAlertDialogBuilder(requireContext()) + .setTitle(R.string.createPlaylist) .setView(binding.root) .show() } diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/CustomInstanceDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/CustomInstanceDialog.kt index f56248178..88e005a32 100644 --- a/app/src/main/java/com/github/libretube/ui/dialogs/CustomInstanceDialog.kt +++ b/app/src/main/java/com/github/libretube/ui/dialogs/CustomInstanceDialog.kt @@ -46,6 +46,7 @@ class CustomInstanceDialog : DialogFragment() { } return MaterialAlertDialogBuilder(requireContext()) + .setTitle(R.string.customInstance) .setView(binding.root) .show() } diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/DownloadDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/DownloadDialog.kt index 98b98229a..27868973d 100644 --- a/app/src/main/java/com/github/libretube/ui/dialogs/DownloadDialog.kt +++ b/app/src/main/java/com/github/libretube/ui/dialogs/DownloadDialog.kt @@ -67,6 +67,7 @@ class DownloadDialog : DialogFragment() { } return MaterialAlertDialogBuilder(requireContext()) + .setTitle(R.string.download) .setView(binding.root) .setPositiveButton(R.string.download, null) .show() diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/LoginDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/LoginDialog.kt index 117d07b38..bc5b921d9 100644 --- a/app/src/main/java/com/github/libretube/ui/dialogs/LoginDialog.kt +++ b/app/src/main/java/com/github/libretube/ui/dialogs/LoginDialog.kt @@ -61,6 +61,7 @@ class LoginDialog : DialogFragment() { } return MaterialAlertDialogBuilder(requireContext()) + .setTitle(R.string.login) .setView(binding.root) .show() } diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/LogoutDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/LogoutDialog.kt index 2d0814a6b..5d34b2f50 100644 --- a/app/src/main/java/com/github/libretube/ui/dialogs/LogoutDialog.kt +++ b/app/src/main/java/com/github/libretube/ui/dialogs/LogoutDialog.kt @@ -33,6 +33,7 @@ class LogoutDialog : DialogFragment() { } return MaterialAlertDialogBuilder(requireContext()) + .setTitle(R.string.logout) .setView(binding.root) .show() } diff --git a/app/src/main/java/com/github/libretube/ui/views/AppNameTextView.kt b/app/src/main/java/com/github/libretube/ui/views/AppNameTextView.kt deleted file mode 100644 index 0ca7946f5..000000000 --- a/app/src/main/java/com/github/libretube/ui/views/AppNameTextView.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.github.libretube.ui.views - -import android.content.Context -import android.util.AttributeSet -import androidx.appcompat.widget.AppCompatTextView -import androidx.core.util.TypedValueCompat -import com.github.libretube.helpers.ThemeHelper - -class AppNameTextView : AppCompatTextView { - constructor(context: Context, attributeSet: AttributeSet?) : super(context, attributeSet) - - constructor(context: Context) : super(context, null) - - init { - text = ThemeHelper.getStyledAppName(context) - textSize = TypedValueCompat.spToPx(10f, resources.displayMetrics) - } -} diff --git a/app/src/main/res/layout/dialog_add_to_playlist.xml b/app/src/main/res/layout/dialog_add_to_playlist.xml index b4bd0004c..69fc627a3 100644 --- a/app/src/main/res/layout/dialog_add_to_playlist.xml +++ b/app/src/main/res/layout/dialog_add_to_playlist.xml @@ -6,18 +6,12 @@ android:layout_height="wrap_content" android:orientation="vertical"> - - diff --git a/app/src/main/res/layout/dialog_create_playlist.xml b/app/src/main/res/layout/dialog_create_playlist.xml index e7065b947..d909f4592 100644 --- a/app/src/main/res/layout/dialog_create_playlist.xml +++ b/app/src/main/res/layout/dialog_create_playlist.xml @@ -2,13 +2,8 @@ - - + android:orientation="vertical" + android:paddingTop="8dp"> @@ -56,7 +50,7 @@ android:id="@+id/cancel_button" style="@style/CustomDialogButton" android:layout_gravity="end" - android:layout_marginTop="10dp" + android:layout_marginTop="8dp" android:layout_marginEnd="16dp" android:text="@string/cancel" /> diff --git a/app/src/main/res/layout/dialog_custom_instance.xml b/app/src/main/res/layout/dialog_custom_instance.xml index bed6b1078..dd97bb711 100644 --- a/app/src/main/res/layout/dialog_custom_instance.xml +++ b/app/src/main/res/layout/dialog_custom_instance.xml @@ -2,13 +2,8 @@ - - + android:orientation="vertical" + android:paddingTop="8dp"> - - + android:orientation="vertical" + android:paddingTop="8dp"> - - - - diff --git a/app/src/main/res/layout/dialog_logout.xml b/app/src/main/res/layout/dialog_logout.xml index c1c2f0a35..8622c5d85 100644 --- a/app/src/main/res/layout/dialog_logout.xml +++ b/app/src/main/res/layout/dialog_logout.xml @@ -4,12 +4,6 @@ android:layout_height="wrap_content" android:orientation="vertical"> - - Date: Fri, 3 Nov 2023 15:44:27 +0100 Subject: [PATCH 2/2] refactor: use true dialog buttons everywhere instead of xml layout buttons --- .../ui/dialogs/AddToPlaylistDialog.kt | 36 ++++++---- .../ui/dialogs/CreatePlaylistDialog.kt | 5 +- .../ui/dialogs/CustomInstanceDialog.kt | 50 +++++++------- .../ui/dialogs/DeleteAccountDialog.kt | 69 +++++++++---------- .../libretube/ui/dialogs/LoginDialog.kt | 68 ++++++++++-------- .../libretube/ui/dialogs/LogoutDialog.kt | 24 +++---- .../res/layout/dialog_add_to_playlist.xml | 21 +----- .../res/layout/dialog_create_playlist.xml | 8 --- .../res/layout/dialog_custom_instance.xml | 19 ----- .../main/res/layout/dialog_delete_account.xml | 20 ------ app/src/main/res/layout/dialog_login.xml | 20 ------ app/src/main/res/layout/dialog_logout.xml | 21 ------ app/src/main/res/values/style.xml | 10 --- 13 files changed, 128 insertions(+), 243 deletions(-) delete mode 100644 app/src/main/res/layout/dialog_logout.xml diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/AddToPlaylistDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/AddToPlaylistDialog.kt index 358f0512e..f8897607a 100644 --- a/app/src/main/java/com/github/libretube/ui/dialogs/AddToPlaylistDialog.kt +++ b/app/src/main/java/com/github/libretube/ui/dialogs/AddToPlaylistDialog.kt @@ -2,6 +2,7 @@ package com.github.libretube.ui.dialogs import android.annotation.SuppressLint import android.app.Dialog +import android.content.DialogInterface import android.os.Bundle import android.util.Log import android.widget.ArrayAdapter @@ -14,6 +15,7 @@ import androidx.lifecycle.repeatOnLifecycle import com.github.libretube.R import com.github.libretube.api.PlaylistsHelper import com.github.libretube.api.RetrofitInstance +import com.github.libretube.api.obj.Playlists import com.github.libretube.constants.IntentData import com.github.libretube.databinding.DialogAddToPlaylistBinding import com.github.libretube.extensions.TAG @@ -31,6 +33,8 @@ class AddToPlaylistDialog : DialogFragment() { private var videoId: String? = null private val viewModel: PlaylistViewModel by activityViewModels() + var playlists = emptyList() + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) videoId = arguments?.getString(IntentData.videoId) @@ -48,16 +52,30 @@ class AddToPlaylistDialog : DialogFragment() { fetchPlaylists(binding) } } - binding.createPlaylist.setOnClickListener { - CreatePlaylistDialog().show(childFragmentManager, null) - } fetchPlaylists(binding) return MaterialAlertDialogBuilder(requireContext()) .setTitle(R.string.addToPlaylist) + .setNegativeButton(R.string.createPlaylist, null) + .setPositiveButton(R.string.addToPlaylist, null) .setView(binding.root) .show() + .apply { + getButton(DialogInterface.BUTTON_NEGATIVE).setOnClickListener { + CreatePlaylistDialog().show(childFragmentManager, null) + } + getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener {val index = binding.playlistsSpinner.selectedItemPosition + val playlist = playlists[index] + viewModel.lastSelectedPlaylistId = playlist.id!! + dialog?.hide() + lifecycleScope.launch { + addToPlaylist(playlist.id, playlist.name!!) + dialog?.dismiss() + } + + } + } } private fun fetchPlaylists(binding: DialogAddToPlaylistBinding) { @@ -71,7 +89,7 @@ class AddToPlaylistDialog : DialogFragment() { return@repeatOnLifecycle } - val playlists = response.filter { !it.name.isNullOrEmpty() } + playlists = response.filter { !it.name.isNullOrEmpty() } if (playlists.isEmpty()) return@repeatOnLifecycle binding.playlistsSpinner.adapter = @@ -86,16 +104,6 @@ class AddToPlaylistDialog : DialogFragment() { val latestIndex = response.indexOfFirst { it.id == id }.takeIf { it >= 0 } ?: 0 binding.playlistsSpinner.setSelection(latestIndex) } - binding.addToPlaylist.setOnClickListener { - val index = binding.playlistsSpinner.selectedItemPosition - val playlist = playlists[index] - viewModel.lastSelectedPlaylistId = playlist.id!! - dialog?.hide() - lifecycleScope.launch { - addToPlaylist(playlist.id, playlist.name!!) - dialog?.dismiss() - } - } } } } diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/CreatePlaylistDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/CreatePlaylistDialog.kt index d2ad9a36d..999d6dab9 100644 --- a/app/src/main/java/com/github/libretube/ui/dialogs/CreatePlaylistDialog.kt +++ b/app/src/main/java/com/github/libretube/ui/dialogs/CreatePlaylistDialog.kt @@ -50,10 +50,6 @@ class CreatePlaylistDialog : DialogFragment() { } } - binding.cancelButton.setOnClickListener { - dismiss() - } - binding.createNewPlaylist.setOnClickListener { val appContext = context?.applicationContext val listName = binding.playlistName.text?.toString() @@ -86,6 +82,7 @@ class CreatePlaylistDialog : DialogFragment() { return MaterialAlertDialogBuilder(requireContext()) .setTitle(R.string.createPlaylist) .setView(binding.root) + .setNegativeButton(R.string.cancel, null) .show() } diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/CustomInstanceDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/CustomInstanceDialog.kt index 88e005a32..72ae8d28b 100644 --- a/app/src/main/java/com/github/libretube/ui/dialogs/CustomInstanceDialog.kt +++ b/app/src/main/java/com/github/libretube/ui/dialogs/CustomInstanceDialog.kt @@ -18,36 +18,32 @@ class CustomInstanceDialog : DialogFragment() { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { val binding = DialogCustomInstanceBinding.inflate(layoutInflater) - binding.cancel.setOnClickListener { - dismiss() - } - - binding.addInstance.setOnClickListener { - val instanceName = binding.instanceName.text.toString() - val apiUrl = binding.instanceApiUrl.text.toString() - val frontendUrl = binding.instanceFrontendUrl.text.toString() - - if (instanceName.isNotEmpty() && apiUrl.isNotEmpty() && frontendUrl.isNotEmpty()) { - if (apiUrl.toHttpUrlOrNull() != null && frontendUrl.toHttpUrlOrNull() != null) { - lifecycleScope.launch { - Database.customInstanceDao() - .insert(CustomInstance(instanceName, apiUrl, frontendUrl)) - ActivityCompat.recreate(requireActivity()) - dismiss() - } - } else { - Toast.makeText(requireContext(), R.string.invalid_url, Toast.LENGTH_SHORT) - .show() - } - } else { - // at least one empty input - Toast.makeText(requireContext(), R.string.empty_instance, Toast.LENGTH_SHORT).show() - } - } - return MaterialAlertDialogBuilder(requireContext()) .setTitle(R.string.customInstance) .setView(binding.root) + .setPositiveButton(R.string.addInstance) { _, _ -> + val instanceName = binding.instanceName.text.toString() + val apiUrl = binding.instanceApiUrl.text.toString() + val frontendUrl = binding.instanceFrontendUrl.text.toString() + + if (instanceName.isNotEmpty() && apiUrl.isNotEmpty() && frontendUrl.isNotEmpty()) { + if (apiUrl.toHttpUrlOrNull() != null && frontendUrl.toHttpUrlOrNull() != null) { + lifecycleScope.launch { + Database.customInstanceDao() + .insert(CustomInstance(instanceName, apiUrl, frontendUrl)) + ActivityCompat.recreate(requireActivity()) + dismiss() + } + } else { + Toast.makeText(requireContext(), R.string.invalid_url, Toast.LENGTH_SHORT) + .show() + } + } else { + // at least one empty input + Toast.makeText(requireContext(), R.string.empty_instance, Toast.LENGTH_SHORT).show() + } + } + .setNegativeButton(R.string.cancel, null) .show() } } diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/DeleteAccountDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/DeleteAccountDialog.kt index 87d0b5fcb..eb6fe5385 100644 --- a/app/src/main/java/com/github/libretube/ui/dialogs/DeleteAccountDialog.kt +++ b/app/src/main/java/com/github/libretube/ui/dialogs/DeleteAccountDialog.kt @@ -1,15 +1,14 @@ package com.github.libretube.ui.dialogs import android.app.Dialog +import android.content.DialogInterface import android.os.Bundle import android.util.Log import android.widget.Toast import androidx.core.os.bundleOf import androidx.fragment.app.DialogFragment import androidx.fragment.app.setFragmentResult -import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope -import androidx.lifecycle.repeatOnLifecycle import com.github.libretube.R import com.github.libretube.api.RetrofitInstance import com.github.libretube.api.obj.DeleteUserRequest @@ -27,46 +26,46 @@ class DeleteAccountDialog : DialogFragment() { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { val binding = DialogDeleteAccountBinding.inflate(layoutInflater) - binding.cancelButton.setOnClickListener { - dialog?.dismiss() - } - - binding.deleteAccountConfirm.setOnClickListener { - val password = binding.deletePassword.text?.toString() - if (!password.isNullOrEmpty()) { - deleteAccount(password) - } else { - Toast.makeText(context, R.string.empty, Toast.LENGTH_SHORT).show() - } - } - return MaterialAlertDialogBuilder(requireContext()) .setView(binding.root) + .setPositiveButton(R.string.deleteAccount, null) + .setNegativeButton(R.string.cancel, null) .show() + .apply { + getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener { + requireDialog().hide() + + val password = binding.deletePassword.text?.toString() + if (password.isNullOrEmpty()) { + Toast.makeText(context, R.string.empty, Toast.LENGTH_SHORT).show() + return@setOnClickListener + } + + lifecycleScope.launch { + deleteAccount(password) + dismiss() + } + } + } } - private fun deleteAccount(password: String) { - lifecycleScope.launch { - repeatOnLifecycle(Lifecycle.State.CREATED) { - val token = PreferenceHelper.getToken() + private fun deleteAccount(password: String) = lifecycleScope.launch { + val token = PreferenceHelper.getToken() - try { - withContext(Dispatchers.IO) { - RetrofitInstance.authApi.deleteAccount(token, DeleteUserRequest(password)) - } - } catch (e: Exception) { - Log.e(TAG(), e.toString()) - Toast.makeText(context, R.string.unknown_error, Toast.LENGTH_SHORT).show() - return@repeatOnLifecycle - } - Toast.makeText(context, R.string.success, Toast.LENGTH_SHORT).show() - - setFragmentResult( - InstanceSettings.INSTANCE_DIALOG_REQUEST_KEY, - bundleOf(IntentData.logoutTask to true) - ) - dialog?.dismiss() + try { + withContext(Dispatchers.IO) { + RetrofitInstance.authApi.deleteAccount(token, DeleteUserRequest(password)) } + } catch (e: Exception) { + Log.e(TAG(), e.toString()) + Toast.makeText(context, R.string.unknown_error, Toast.LENGTH_SHORT).show() + return@launch } + Toast.makeText(context, R.string.success, Toast.LENGTH_SHORT).show() + + setFragmentResult( + InstanceSettings.INSTANCE_DIALOG_REQUEST_KEY, + bundleOf(IntentData.logoutTask to true) + ) } } diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/LoginDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/LoginDialog.kt index bc5b921d9..99a6a917c 100644 --- a/app/src/main/java/com/github/libretube/ui/dialogs/LoginDialog.kt +++ b/app/src/main/java/com/github/libretube/ui/dialogs/LoginDialog.kt @@ -1,6 +1,7 @@ package com.github.libretube.ui.dialogs import android.app.Dialog +import android.content.DialogInterface import android.os.Bundle import android.util.Log import android.util.Patterns @@ -30,40 +31,36 @@ class LoginDialog : DialogFragment() { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { val binding = DialogLoginBinding.inflate(layoutInflater) - binding.login.setOnClickListener { - val email = binding.username.text?.toString() - val password = binding.password.text?.toString() - - if (!email.isNullOrEmpty() && !password.isNullOrEmpty()) { - signIn(email, password) - } else { - Toast.makeText(context, R.string.empty, Toast.LENGTH_SHORT).show() - } - } - binding.register.setOnClickListener { - val email = binding.username.text?.toString().orEmpty() - val password = binding.password.text?.toString().orEmpty() - - if (isEmail(email)) { - MaterialAlertDialogBuilder(requireContext()) - .setTitle(R.string.privacy_alert) - .setMessage(R.string.username_email) - .setNegativeButton(R.string.proceed) { _, _ -> - signIn(email, password, true) - } - .setPositiveButton(R.string.cancel, null) - .show() - } else if (email.isNotEmpty() && password.isNotEmpty()) { - signIn(email, password, true) - } else { - Toast.makeText(context, R.string.empty, Toast.LENGTH_SHORT).show() - } - } - return MaterialAlertDialogBuilder(requireContext()) .setTitle(R.string.login) + .setPositiveButton(R.string.login, null) + .setNegativeButton(R.string.register, null) .setView(binding.root) .show() + .apply { + getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener { + val email = binding.username.text?.toString() + val password = binding.password.text?.toString() + + if (!email.isNullOrEmpty() && !password.isNullOrEmpty()) { + signIn(email, password) + } else { + Toast.makeText(context, R.string.empty, Toast.LENGTH_SHORT).show() + } + } + getButton(DialogInterface.BUTTON_NEGATIVE).setOnClickListener { + val email = binding.username.text?.toString().orEmpty() + val password = binding.password.text?.toString().orEmpty() + + if (isEmail(email)) { + showPrivacyAlertDialog(email, password) + } else if (email.isNotEmpty() && password.isNotEmpty()) { + signIn(email, password, true) + } else { + Toast.makeText(context, R.string.empty, Toast.LENGTH_SHORT).show() + } + } + } } private fun signIn(username: String, password: String, createNewAccount: Boolean = false) { @@ -110,6 +107,17 @@ class LoginDialog : DialogFragment() { } } + private fun showPrivacyAlertDialog(email: String, password: String) { + MaterialAlertDialogBuilder(requireContext()) + .setTitle(R.string.privacy_alert) + .setMessage(R.string.username_email) + .setNegativeButton(R.string.proceed) { _, _ -> + signIn(email, password, true) + } + .setPositiveButton(R.string.cancel, null) + .show() + } + private fun isEmail(text: String): Boolean { return Patterns.EMAIL_ADDRESS.toRegex().matches(text) } diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/LogoutDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/LogoutDialog.kt index 5d34b2f50..9f5bcb0f8 100644 --- a/app/src/main/java/com/github/libretube/ui/dialogs/LogoutDialog.kt +++ b/app/src/main/java/com/github/libretube/ui/dialogs/LogoutDialog.kt @@ -9,7 +9,6 @@ import androidx.fragment.app.DialogFragment import androidx.fragment.app.setFragmentResult import com.github.libretube.R import com.github.libretube.constants.IntentData -import com.github.libretube.databinding.DialogLogoutBinding import com.github.libretube.helpers.PreferenceHelper import com.github.libretube.ui.preferences.InstanceSettings import com.google.android.material.dialog.MaterialAlertDialogBuilder @@ -17,24 +16,19 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder class LogoutDialog : DialogFragment() { @SuppressLint("SetTextI18n") override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - val binding = DialogLogoutBinding.inflate(layoutInflater) - val user = PreferenceHelper.getUsername() - binding.user.text = binding.user.text.toString() + " ($user)" - binding.logout.setOnClickListener { - Toast.makeText(context, R.string.loggedout, Toast.LENGTH_SHORT).show() - - setFragmentResult( - InstanceSettings.INSTANCE_DIALOG_REQUEST_KEY, - bundleOf(IntentData.logoutTask to true) - ) - dialog?.dismiss() - } - return MaterialAlertDialogBuilder(requireContext()) .setTitle(R.string.logout) - .setView(binding.root) + .setMessage(getString(R.string.already_logged_in) + " ($user)") + .setPositiveButton(R.string.logout) { _, _ -> + Toast.makeText(context, R.string.loggedout, Toast.LENGTH_SHORT).show() + + setFragmentResult( + InstanceSettings.INSTANCE_DIALOG_REQUEST_KEY, + bundleOf(IntentData.logoutTask to true) + ) + } .show() } } diff --git a/app/src/main/res/layout/dialog_add_to_playlist.xml b/app/src/main/res/layout/dialog_add_to_playlist.xml index 69fc627a3..ca9075ad2 100644 --- a/app/src/main/res/layout/dialog_add_to_playlist.xml +++ b/app/src/main/res/layout/dialog_add_to_playlist.xml @@ -11,27 +11,8 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginHorizontal="24dp" - android:layout_marginVertical="8dp" + android:layout_marginTop="8dp" app:icon="@drawable/ic_playlist_add" tools:ignore="RtlSymmetry" /> - - -