fix layout
This commit is contained in:
parent
bd164ff832
commit
962c5df78e
@ -49,7 +49,7 @@ class PostDetailsRecycler(
|
|||||||
|
|
||||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||||
val post = posts[position]
|
val post = posts[position]
|
||||||
holder.dateTime.text = post.dateTime
|
holder.dateTime.text = formatDate(post.dateTime)
|
||||||
holder.postContent.text = post.content
|
holder.postContent.text = post.content
|
||||||
holder.postContent.visibility = if (post.content.isBlank()) View.GONE else View.VISIBLE
|
holder.postContent.visibility = if (post.content.isBlank()) View.GONE else View.VISIBLE
|
||||||
|
|
||||||
@ -57,6 +57,11 @@ class PostDetailsRecycler(
|
|||||||
|
|
||||||
holder.imagesContainer.apply {
|
holder.imagesContainer.apply {
|
||||||
removeAllViews()
|
removeAllViews()
|
||||||
|
|
||||||
|
|
||||||
|
post {
|
||||||
|
|
||||||
|
val imgWidth = (parent as ConstraintLayout).width / post.images.size - 10
|
||||||
post.images.forEach {
|
post.images.forEach {
|
||||||
val imageView = ImageView(context)
|
val imageView = ImageView(context)
|
||||||
addView(imageView)
|
addView(imageView)
|
||||||
@ -68,15 +73,25 @@ class PostDetailsRecycler(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Picasso.with(context)
|
Picasso.with(context)
|
||||||
.load(it)
|
.load(it)
|
||||||
.placeholder(android.R.drawable.ic_menu_gallery)
|
.placeholder(android.R.drawable.ic_menu_gallery)
|
||||||
.resize(250, 250)
|
.resize(imgWidth, imgWidth)
|
||||||
.centerCrop()
|
.centerCrop()
|
||||||
.into(imageView)
|
.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(
|
class ViewHolder(
|
||||||
root: ConstraintLayout,
|
root: ConstraintLayout,
|
||||||
|
@ -46,10 +46,11 @@
|
|||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/imagesContainer"
|
android:id="@+id/imagesContainer"
|
||||||
android:layout_width="0dp"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
|
android:layout_gravity="center"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
Loading…
Reference in New Issue
Block a user