From 9e66ccf4a6a61dc5c9841c6ac2da4f1783798333 Mon Sep 17 00:00:00 2001 From: UlrichKu Date: Fri, 24 Mar 2023 18:21:56 +0100 Subject: [PATCH] 3434: Make description dialog (text field) more usable (#3458) * 3434: Make description dialog (text field) more usable * 3434: Close dialog on back button * 3434: Use a TextInputLayout * 3434: Adapt German plurals text * 3434: Remove unused id * 3434: Disable counter officially --- .../compose/dialog/CaptionDialog.kt | 35 ++++------------- .../res/layout/dialog_image_description.xml | 38 +++++++++++++++++++ app/src/main/res/values-de/strings.xml | 8 ++-- app/src/main/res/values/strings.xml | 4 +- 4 files changed, 51 insertions(+), 34 deletions(-) create mode 100644 app/src/main/res/layout/dialog_image_description.xml diff --git a/app/src/main/java/com/keylesspalace/tusky/components/compose/dialog/CaptionDialog.kt b/app/src/main/java/com/keylesspalace/tusky/components/compose/dialog/CaptionDialog.kt index 3234f4be3..f6f8a495e 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/compose/dialog/CaptionDialog.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/compose/dialog/CaptionDialog.kt @@ -21,76 +21,55 @@ import android.graphics.drawable.Drawable import android.net.Uri import android.os.Bundle import android.text.InputFilter -import android.text.InputType import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.view.WindowManager import android.widget.EditText -import android.widget.LinearLayout import androidx.appcompat.app.AlertDialog import androidx.core.os.bundleOf import androidx.fragment.app.DialogFragment -import at.connyduck.sparkbutton.helpers.Utils import com.bumptech.glide.Glide import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy import com.bumptech.glide.request.target.CustomTarget import com.bumptech.glide.request.transition.Transition -import com.github.chrisbanes.photoview.PhotoView import com.keylesspalace.tusky.R +import com.keylesspalace.tusky.databinding.DialogImageDescriptionBinding // https://github.com/tootsuite/mastodon/blob/c6904c0d3766a2ea8a81ab025c127169ecb51373/app/models/media_attachment.rb#L32 private const val MEDIA_DESCRIPTION_CHARACTER_LIMIT = 1500 class CaptionDialog : DialogFragment() { - private lateinit var listener: Listener private lateinit var input: EditText override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { val context = requireContext() - val dialogLayout = LinearLayout(context) - val padding = Utils.dpToPx(context, 8) - dialogLayout.setPadding(padding, padding, padding, padding) - dialogLayout.orientation = LinearLayout.VERTICAL - val imageView = PhotoView(context).apply { - maximumScale = 6f - } + val binding = DialogImageDescriptionBinding.inflate(layoutInflater) - val margin = Utils.dpToPx(context, 4) - dialogLayout.addView(imageView) - (imageView.layoutParams as LinearLayout.LayoutParams).weight = 1f - imageView.layoutParams.height = 0 - (imageView.layoutParams as LinearLayout.LayoutParams).setMargins(0, margin, 0, 0) + input = binding.imageDescriptionText + val imageView = binding.imageDescriptionView + imageView.maximumScale = 6f - input = EditText(context) input.hint = resources.getQuantityString( R.plurals.hint_describe_for_visually_impaired, MEDIA_DESCRIPTION_CHARACTER_LIMIT, MEDIA_DESCRIPTION_CHARACTER_LIMIT ) - dialogLayout.addView(input) - (input.layoutParams as LinearLayout.LayoutParams).setMargins(margin, margin, margin, margin) - input.setLines(2) - input.inputType = ( - InputType.TYPE_CLASS_TEXT - or InputType.TYPE_TEXT_FLAG_MULTI_LINE - or InputType.TYPE_TEXT_FLAG_CAP_SENTENCES - ) input.filters = arrayOf(InputFilter.LengthFilter(MEDIA_DESCRIPTION_CHARACTER_LIMIT)) input.setText(arguments?.getString(EXISTING_DESCRIPTION_ARG)) val localId = arguments?.getInt(LOCAL_ID_ARG) ?: error("Missing localId") val dialog = AlertDialog.Builder(context) - .setView(dialogLayout) + .setView(binding.root) .setPositiveButton(android.R.string.ok) { _, _ -> listener.onUpdateDescription(localId, input.text.toString()) } .setNegativeButton(android.R.string.cancel, null) .create() - isCancelable = false + isCancelable = true val window = dialog.window window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) diff --git a/app/src/main/res/layout/dialog_image_description.xml b/app/src/main/res/layout/dialog_image_description.xml new file mode 100644 index 000000000..4d749a8f5 --- /dev/null +++ b/app/src/main/res/layout/dialog_image_description.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index d7c7c6193..fed6376b0 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -132,6 +132,7 @@ Anzeigename Über mich Suchen … + Beschreibung Medien sollten Beschreibungen haben. Keine Ergebnisse Antworten … @@ -262,10 +263,8 @@ Veröffentlichen als %1$s Fehler beim Speichern der Beschreibung - Für Mensch mit Sehbehinderung beschreiben -\n(%d Zeichen) - Für Menschen mit Sehbehinderung beschreiben -\n(%d Zeichen) + Inhalte für Mensch mit Sehbehinderung beschreiben (%d Zeichen) + Inhalte für Menschen mit Sehbehinderung beschreiben (%d Zeichen) Beschreibung eingeben Entfernen @@ -665,4 +664,3 @@ Zum Beispiel die Lokale Timeline deiner Instanz [iconics gmd_group]. Oder du kannst nach ihrem Namen suchen [iconics gmd_search]; suche z. B. nach Tusky, um unseren Mastodon-Account zu finden. - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e6526430d..89be8d2c0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -230,6 +230,7 @@ Display name Bio Search… + Description Media should have a description. No results @@ -406,6 +407,7 @@ Share content of post Share link to post + Image Images Video Audio @@ -472,7 +474,7 @@ Failed to set caption Failed to set focus point - Describe for visually impaired\n(%d character limit) + Describe contents for visually impaired (%d character limit) Tap or drag the circle to choose the focal point which will always be visible in thumbnails. Set caption