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
This commit is contained in:
parent
de5b72e472
commit
9e66ccf4a6
4 changed files with 51 additions and 34 deletions
|
@ -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)
|
||||
|
||||
|
|
38
app/src/main/res/layout/dialog_image_description.xml
Normal file
38
app/src/main/res/layout/dialog_image_description.xml
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="0dp">
|
||||
|
||||
<com.github.chrisbanes.photoview.PhotoView
|
||||
android:id="@+id/imageDescriptionView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:contentDescription="@string/post_media_image"/>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
style="@style/TuskyTextInput"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginStart="?dialogPreferredPadding"
|
||||
android:layout_marginTop="?dialogPreferredPadding"
|
||||
android:layout_marginEnd="?dialogPreferredPadding"
|
||||
app:hintEnabled="false"
|
||||
app:counterEnabled="false"
|
||||
app:counterTextColor="?android:textColorTertiary">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/imageDescriptionText"
|
||||
android:inputType="textCapSentences|textMultiLine|textAutoCorrect"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:hint="@string/hint_description"
|
||||
android:gravity="start"
|
||||
android:importantForAutofill="no" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
</LinearLayout>
|
|
@ -132,6 +132,7 @@
|
|||
<string name="hint_display_name">Anzeigename</string>
|
||||
<string name="hint_note">Über mich</string>
|
||||
<string name="hint_search">Suchen …</string>
|
||||
<string name="hint_description">Beschreibung</string>
|
||||
<string name="hint_media_description_missing">Medien sollten Beschreibungen haben.</string>
|
||||
<string name="search_no_results">Keine Ergebnisse</string>
|
||||
<string name="label_quick_reply">Antworten …</string>
|
||||
|
@ -262,10 +263,8 @@
|
|||
<string name="compose_active_account_description">Veröffentlichen als %1$s</string>
|
||||
<string name="error_failed_set_caption">Fehler beim Speichern der Beschreibung</string>
|
||||
<plurals name="hint_describe_for_visually_impaired">
|
||||
<item quantity="one">Für Mensch mit Sehbehinderung beschreiben
|
||||
\n(%d Zeichen)</item>
|
||||
<item quantity="other">Für Menschen mit Sehbehinderung beschreiben
|
||||
\n(%d Zeichen)</item>
|
||||
<item quantity="one">Inhalte für Mensch mit Sehbehinderung beschreiben (%d Zeichen)</item>
|
||||
<item quantity="other">Inhalte für Menschen mit Sehbehinderung beschreiben (%d Zeichen)</item>
|
||||
</plurals>
|
||||
<string name="action_set_caption">Beschreibung eingeben</string>
|
||||
<string name="action_remove">Entfernen</string>
|
||||
|
@ -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.</string>
|
||||
</resources>
|
||||
|
||||
|
|
|
@ -230,6 +230,7 @@
|
|||
<string name="hint_display_name">Display name</string>
|
||||
<string name="hint_note">Bio</string>
|
||||
<string name="hint_search">Search…</string>
|
||||
<string name="hint_description">Description</string>
|
||||
<string name="hint_media_description_missing">Media should have a description.</string>
|
||||
|
||||
<string name="search_no_results">No results</string>
|
||||
|
@ -406,6 +407,7 @@
|
|||
|
||||
<string name="post_share_content">Share content of post</string>
|
||||
<string name="post_share_link">Share link to post</string>
|
||||
<string name="post_media_image">Image</string>
|
||||
<string name="post_media_images">Images</string>
|
||||
<string name="post_media_video">Video</string>
|
||||
<string name="post_media_audio">Audio</string>
|
||||
|
@ -472,7 +474,7 @@
|
|||
<string name="error_failed_set_caption">Failed to set caption</string>
|
||||
<string name="error_failed_set_focus">Failed to set focus point</string>
|
||||
<plurals name="hint_describe_for_visually_impaired">
|
||||
<item quantity="other">Describe for visually impaired\n(%d character limit)</item>
|
||||
<item quantity="other">Describe contents for visually impaired (%d character limit)</item>
|
||||
</plurals>
|
||||
<string name="set_focus_description">Tap or drag the circle to choose the focal point which will always be visible in thumbnails.</string>
|
||||
<string name="action_set_caption">Set caption</string>
|
||||
|
|
Loading…
Reference in a new issue