fix layout
This commit is contained in:
parent
bd164ff832
commit
962c5df78e
@ -49,7 +49,7 @@ class PostDetailsRecycler(
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val post = posts[position]
|
||||
holder.dateTime.text = post.dateTime
|
||||
holder.dateTime.text = formatDate(post.dateTime)
|
||||
holder.postContent.text = post.content
|
||||
holder.postContent.visibility = if (post.content.isBlank()) View.GONE else View.VISIBLE
|
||||
|
||||
@ -57,27 +57,42 @@ class PostDetailsRecycler(
|
||||
|
||||
holder.imagesContainer.apply {
|
||||
removeAllViews()
|
||||
post.images.forEach {
|
||||
val imageView = ImageView(context)
|
||||
addView(imageView)
|
||||
|
||||
imageView.apply {
|
||||
(layoutParams as ViewGroup.MarginLayoutParams)
|
||||
.apply {
|
||||
marginEnd = 10
|
||||
}
|
||||
|
||||
post {
|
||||
|
||||
val imgWidth = (parent as ConstraintLayout).width / post.images.size - 10
|
||||
post.images.forEach {
|
||||
val imageView = ImageView(context)
|
||||
addView(imageView)
|
||||
|
||||
imageView.apply {
|
||||
(layoutParams as ViewGroup.MarginLayoutParams)
|
||||
.apply {
|
||||
marginEnd = 10
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Picasso.with(context)
|
||||
.load(it)
|
||||
.placeholder(android.R.drawable.ic_menu_gallery)
|
||||
.resize(imgWidth, imgWidth)
|
||||
.centerCrop()
|
||||
.into(imageView)
|
||||
}
|
||||
|
||||
Picasso.with(context)
|
||||
.load(it)
|
||||
.placeholder(android.R.drawable.ic_menu_gallery)
|
||||
.resize(250, 250)
|
||||
.centerCrop()
|
||||
.into(imageView)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun formatDate(str: String): String {
|
||||
val regex = """(\d+-\d+-\d+)T(\d+:\d+:\d+)""".toRegex()
|
||||
val matchResult = regex.find(str)
|
||||
val (date, time) = matchResult!!.destructured
|
||||
|
||||
return "$date $time"
|
||||
}
|
||||
|
||||
class ViewHolder(
|
||||
root: ConstraintLayout,
|
||||
val dateTime: TextView,
|
||||
|
@ -46,10 +46,11 @@
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/imagesContainer"
|
||||
android:layout_width="0dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:orientation="horizontal"
|
||||
android:layout_gravity="center"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
Loading…
Reference in New Issue
Block a user