Add UI for image-attachment "focus" (#2620)
* Attempt-zero implementation of a "focus" feature for image attachments. Choose "Set focus" in the attachment menu, tap once to select focus point (no visual feedback currently), tap "OK". Works in tests. * Remove code duplication between 'update description' and 'update focus' * Fix ktlint/bitrise failures * Make updateMediaItem private * When focus is set on a post attachment the preview focuses correctly. ProgressImageView now inherits from MediaPreviewImageView. * Replace use of PointF for Focus where focus is represented, fix ktlint * Substitute 'focus' for 'focus point' in strings * First attempt draw focus point. Only updates on initial load. Modeled on code from RoundedCorners builtin from Glide * Redraw focus after each tap * Dark curtain where focus isn't (now looks like mastosoc) * Correct ktlint for FocusDialog * draft: switch to overlay for focus indicator * Draw focus circle, but ImageView and FocusIndicatorView seem to share a single canvas * Switch focus circle to path approach * Correctly scale, save and load focuses. Clamp to visible area. Focus editor looks and feels right * ktlint fixes and comments * Focus indicator drawing should use device-independent pixels * Shrink focus window when it gets unattractively tall (no linting, misbehaves on wide aspect ratio screens) * Correct max-height behavior for screens in landscape mode * Focus attachment result is are flipped on x axis; fix this * Correctly thread focus through on scheduled posts, redrafted posts, and drafts (but draft focus is lost on post) * More focus ktlint fixes * Fix specific case where a draft is given a focus, then deleted, then posted in that order * Fix accidental file change in focus PR * ktLint fix * Fix property style warnings in focus * Fix remaining style warnings from focus PR Co-authored-by: Conny Duck <k.pozniak@gmx.at>
This commit is contained in:
parent
5d09a67b52
commit
7684f06938
17 changed files with 358 additions and 26 deletions
|
@ -25,6 +25,7 @@ import com.keylesspalace.tusky.BuildConfig
|
|||
import com.keylesspalace.tusky.db.AppDatabase
|
||||
import com.keylesspalace.tusky.db.DraftAttachment
|
||||
import com.keylesspalace.tusky.db.DraftEntity
|
||||
import com.keylesspalace.tusky.entity.Attachment
|
||||
import com.keylesspalace.tusky.entity.NewPoll
|
||||
import com.keylesspalace.tusky.entity.Status
|
||||
import com.keylesspalace.tusky.util.IOUtils
|
||||
|
@ -59,6 +60,7 @@ class DraftHelper @Inject constructor(
|
|||
visibility: Status.Visibility,
|
||||
mediaUris: List<String>,
|
||||
mediaDescriptions: List<String?>,
|
||||
mediaFocus: List<Attachment.Focus?>,
|
||||
poll: NewPoll?,
|
||||
failedToSend: Boolean,
|
||||
scheduledAt: String?,
|
||||
|
@ -103,6 +105,7 @@ class DraftHelper @Inject constructor(
|
|||
DraftAttachment(
|
||||
uriString = uris[i].toString(),
|
||||
description = mediaDescriptions[i],
|
||||
focus = mediaFocus[i],
|
||||
type = types[i]
|
||||
)
|
||||
)
|
||||
|
|
|
@ -17,7 +17,6 @@ package com.keylesspalace.tusky.components.drafts
|
|||
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import androidx.appcompat.widget.AppCompatImageView
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
|
@ -26,6 +25,7 @@ import com.bumptech.glide.Glide
|
|||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||
import com.keylesspalace.tusky.R
|
||||
import com.keylesspalace.tusky.db.DraftAttachment
|
||||
import com.keylesspalace.tusky.view.MediaPreviewImageView
|
||||
|
||||
class DraftMediaAdapter(
|
||||
private val attachmentClick: () -> Unit
|
||||
|
@ -42,24 +42,34 @@ class DraftMediaAdapter(
|
|||
) {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DraftMediaViewHolder {
|
||||
return DraftMediaViewHolder(AppCompatImageView(parent.context))
|
||||
return DraftMediaViewHolder(MediaPreviewImageView(parent.context))
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: DraftMediaViewHolder, position: Int) {
|
||||
getItem(position)?.let { attachment ->
|
||||
if (attachment.type == DraftAttachment.Type.AUDIO) {
|
||||
holder.imageView.clearFocus()
|
||||
holder.imageView.setImageResource(R.drawable.ic_music_box_preview_24dp)
|
||||
} else {
|
||||
Glide.with(holder.itemView.context)
|
||||
if (attachment.focus != null)
|
||||
holder.imageView.setFocalPoint(attachment.focus)
|
||||
else
|
||||
holder.imageView.clearFocus()
|
||||
var glide = Glide.with(holder.itemView.context)
|
||||
.load(attachment.uri)
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.dontAnimate()
|
||||
.into(holder.imageView)
|
||||
.centerInside()
|
||||
|
||||
if (attachment.focus != null)
|
||||
glide = glide.addListener(holder.imageView)
|
||||
|
||||
glide.into(holder.imageView)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inner class DraftMediaViewHolder(val imageView: ImageView) :
|
||||
inner class DraftMediaViewHolder(val imageView: MediaPreviewImageView) :
|
||||
RecyclerView.ViewHolder(imageView) {
|
||||
init {
|
||||
val thumbnailViewSize =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue