fix layout

This commit is contained in:
Mateusz Hinc 2020-01-24 19:07:03 +01:00
parent bd164ff832
commit 962c5df78e
2 changed files with 33 additions and 17 deletions

View File

@ -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,27 +57,42 @@ class PostDetailsRecycler(
holder.imagesContainer.apply { holder.imagesContainer.apply {
removeAllViews() removeAllViews()
post.images.forEach {
val imageView = ImageView(context)
addView(imageView)
imageView.apply {
(layoutParams as ViewGroup.MarginLayoutParams) post {
.apply {
marginEnd = 10 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( class ViewHolder(
root: ConstraintLayout, root: ConstraintLayout,
val dateTime: TextView, val dateTime: TextView,

View File

@ -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"