improve images in timelines
This commit is contained in:
parent
44f0dc562c
commit
f35734ce74
|
@ -27,6 +27,7 @@ import androidx.paging.ExperimentalPagingApi
|
|||
import androidx.recyclerview.widget.DividerItemDecoration
|
||||
import androidx.recyclerview.widget.SimpleItemAnimator
|
||||
import at.connyduck.pixelcat.R
|
||||
import at.connyduck.pixelcat.components.util.extension.getDisplayWidthInPx
|
||||
import at.connyduck.pixelcat.components.util.getColorForAttr
|
||||
import at.connyduck.pixelcat.dagger.ViewModelFactory
|
||||
import at.connyduck.pixelcat.databinding.FragmentTimelineBinding
|
||||
|
@ -58,7 +59,7 @@ class TimelineFragment : DaggerFragment(R.layout.fragment_timeline), TimeLineAct
|
|||
binding.timelineRecyclerView.scrollToPosition(0)
|
||||
}
|
||||
|
||||
val adapter = TimelineListAdapter(this)
|
||||
val adapter = TimelineListAdapter(view.context.getDisplayWidthInPx(), this)
|
||||
|
||||
binding.timelineRecyclerView.adapter = adapter
|
||||
(binding.timelineRecyclerView.itemAnimator as SimpleItemAnimator).supportsChangeAnimations = false
|
||||
|
|
|
@ -51,6 +51,7 @@ object TimelineDiffUtil : DiffUtil.ItemCallback<StatusEntity>() {
|
|||
}
|
||||
|
||||
class TimelineListAdapter(
|
||||
private val displayWidth: Int,
|
||||
private val listener: TimeLineActionListener
|
||||
) : PagingDataAdapter<StatusEntity, TimelineViewHolder>(TimelineDiffUtil) {
|
||||
|
||||
|
@ -58,6 +59,9 @@ class TimelineListAdapter(
|
|||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TimelineViewHolder {
|
||||
val binding = ItemStatusBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
binding.postImages.adapter = TimelineImageAdapter()
|
||||
binding.postIndicator.setViewPager(binding.postImages)
|
||||
(binding.postImages.adapter as TimelineImageAdapter).registerAdapterDataObserver(binding.postIndicator.adapterDataObserver)
|
||||
return TimelineViewHolder(binding)
|
||||
}
|
||||
|
||||
|
@ -68,6 +72,17 @@ class TimelineListAdapter(
|
|||
// TODO order the stuff here
|
||||
|
||||
(holder.binding.postImages.adapter as TimelineImageAdapter).images = status.attachments
|
||||
|
||||
val maxImageRatio = status.attachments.map {
|
||||
if(it.meta?.small?.width == null || it.meta.small.height == null) {
|
||||
1f
|
||||
} else {
|
||||
it.meta.small.height.toFloat() / it.meta.small.width.toFloat()
|
||||
}
|
||||
}.max()?.coerceAtMost(1f) ?: 1f
|
||||
|
||||
holder.binding.postImages.layoutParams.height = (displayWidth * maxImageRatio).toInt()
|
||||
|
||||
holder.binding.postAvatar.load(status.account.avatar) {
|
||||
transformations(RoundedCornersTransformation(25f))
|
||||
}
|
||||
|
@ -81,14 +96,14 @@ class TimelineListAdapter(
|
|||
|
||||
holder.binding.postLikeButton.isChecked = status.favourited
|
||||
|
||||
holder.binding.postLikeButton.setEventListener { button, buttonState ->
|
||||
holder.binding.postLikeButton.setEventListener { _, _ ->
|
||||
listener.onFavorite(status)
|
||||
true
|
||||
}
|
||||
|
||||
holder.binding.postBoostButton.isChecked = status.reblogged
|
||||
|
||||
holder.binding.postBoostButton.setEventListener { button, buttonState ->
|
||||
holder.binding.postBoostButton.setEventListener { _, _ ->
|
||||
listener.onBoost(status)
|
||||
true
|
||||
}
|
||||
|
@ -114,13 +129,4 @@ class TimelineListAdapter(
|
|||
}
|
||||
}
|
||||
|
||||
class TimelineViewHolder(val binding: ItemStatusBinding) : RecyclerView.ViewHolder(binding.root) {
|
||||
init {
|
||||
binding.postImages.adapter = TimelineImageAdapter()
|
||||
|
||||
binding.postIndicator.setViewPager(binding.postImages)
|
||||
(binding.postImages.adapter as TimelineImageAdapter).registerAdapterDataObserver(binding.postIndicator.adapterDataObserver)
|
||||
// val snapHelper = PagerSnapHelper()
|
||||
// snapHelper.attachToRecyclerView(binding.postImages)
|
||||
}
|
||||
}
|
||||
class TimelineViewHolder(val binding: ItemStatusBinding) : RecyclerView.ViewHolder(binding.root)
|
||||
|
|
|
@ -19,13 +19,10 @@
|
|||
|
||||
package at.connyduck.pixelcat.model
|
||||
|
||||
import android.os.Parcelable
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
import kotlinx.android.parcel.Parcelize
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
@Parcelize
|
||||
data class Attachment(
|
||||
val id: String,
|
||||
val url: String,
|
||||
|
@ -33,7 +30,7 @@ data class Attachment(
|
|||
val meta: MetaData?,
|
||||
val type: Type,
|
||||
val description: String?
|
||||
) : Parcelable {
|
||||
) {
|
||||
|
||||
enum class Type {
|
||||
@Json(name = "image")
|
||||
|
@ -48,28 +45,22 @@ data class Attachment(
|
|||
UNKNOWN
|
||||
}
|
||||
|
||||
/*class MediaTypeDeserializer : JsonDeserializer<Type> {
|
||||
@Throws(JsonParseException::class)
|
||||
override fun deserialize(json: JsonElement, classOfT: java.lang.reflect.Type, context: JsonDeserializationContext): Type {
|
||||
return when (json.toString()) {
|
||||
"\"image\"" -> Type.IMAGE
|
||||
"\"gifv\"" -> Type.GIFV
|
||||
"\"video\"" -> Type.VIDEO
|
||||
"\"audio\"" -> Type.AUDIO
|
||||
else -> Type.UNKNOWN
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* The meta data of an [Attachment].
|
||||
*/
|
||||
@JsonClass(generateAdapter = true)
|
||||
@Parcelize
|
||||
data class MetaData(
|
||||
val focus: Focus?,
|
||||
val duration: Float?
|
||||
) : Parcelable
|
||||
val duration: Float?,
|
||||
val small: ImageMetaData?
|
||||
)
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class ImageMetaData(
|
||||
val width: Int?,
|
||||
val height: Int?,
|
||||
val aspect: Float?
|
||||
)
|
||||
|
||||
/**
|
||||
* The Focus entity, used to specify the focal point of an image.
|
||||
|
@ -78,9 +69,8 @@ data class Attachment(
|
|||
* https://github.com/jonom/jquery-focuspoint#1-calculate-your-images-focus-point
|
||||
*/
|
||||
@JsonClass(generateAdapter = true)
|
||||
@Parcelize
|
||||
data class Focus(
|
||||
val x: Float,
|
||||
val y: Float
|
||||
) : Parcelable
|
||||
)
|
||||
}
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
|
||||
<ImageView
|
||||
android:id="@+id/timelineImageView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_height="match_parent"
|
||||
android:adjustViewBounds="true" />
|
||||
|
||||
|
|
Loading…
Reference in New Issue