Commit f177ab7f authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

added article preview adapter and viewholder

parent 18718e87
package com.biganto.visual.roompark.presentation.screen.feeds.utils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import butterknife.BindView
import butterknife.ButterKnife
import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.domain.model.ArticlePreviewModel
import com.squareup.picasso.Picasso
import java.text.SimpleDateFormat
import java.util.*
/**
* Created by Vladislav Bogdashkin on 15.10.2019.
*/
class ArticlesPreviewAdapter : RecyclerView.Adapter<ArticlePreviewViewHolder>() {
private var list: MutableList<ArticlePreviewModel> = mutableListOf()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ArticlePreviewViewHolder =
ArticlePreviewViewHolder(
LayoutInflater.from(parent.context)
.inflate(com.biganto.visual.roompark.R.layout.feed_direct_viewholder, parent, false)
)
override fun getItemCount(): Int = list.size
override fun onBindViewHolder(holder: ArticlePreviewViewHolder, position: Int) {
}
}
class ArticlePreviewViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
private val dateFormatter = SimpleDateFormat("dd / MM / yyyy", Locale.getDefault())
@BindView(R.id.imageHolder) lateinit var preview:ImageView
@BindView(R.id.feed_date_text_view) lateinit var articleDate:TextView
@BindView(R.id.feed_title_info_text_view) lateinit var articleTitle:TextView
@BindView(R.id.feed_text_info_text_view) lateinit var articleDescription:TextView
@BindView(R.id.feed_read) lateinit var articleIsRead:View
init {
ButterKnife.bind(this, itemView)
}
fun bindModel(model: ArticlePreviewModel){
articleDate.text = dateFormatter.format(model.published)
articleTitle.text = model.title
articleDescription.text = model.announce
articleIsRead.setGone(model.isRead)
Picasso.get()
.load(model.previewUrl)
.into(preview)
}
}
fun View.setGone(isGone:Boolean){
this.visibility = if (isGone) View.GONE else View.VISIBLE
}
\ No newline at end of file
......@@ -8,7 +8,7 @@
android:orientation="vertical">
<FrameLayout
android:id="@+id/frameLayout"
android:id="@+id/feed_read"
android:layout_width="12dp"
android:layout_height="12dp"
android:layout_marginStart="16dp"
......@@ -28,10 +28,10 @@
android:includeFontPadding="false"
android:text="СВОБОДНА"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="@+id/frameLayout"
app:layout_constraintBottom_toBottomOf="@+id/feed_read"
app:layout_constraintEnd_toStartOf="@+id/object_plan_icon"
app:layout_constraintStart_toEndOf="@+id/frameLayout"
app:layout_constraintTop_toTopOf="@+id/frameLayout" />
app:layout_constraintStart_toEndOf="@+id/feed_read"
app:layout_constraintTop_toTopOf="@+id/feed_read" />
<ImageView
android:id="@+id/object_plan_icon"
......
......@@ -30,7 +30,7 @@
app:layout_constraintGuide_begin="144dp" />
<FrameLayout
android:id="@+id/frameLayout"
android:id="@+id/feed_read"
android:layout_width="8dp"
android:layout_height="8dp"
android:layout_marginTop="18dp"
......
......@@ -28,7 +28,7 @@
app:layout_constraintGuide_begin="76dp" />
<FrameLayout
android:id="@+id/frameLayout"
android:id="@+id/feed_read"
android:layout_width="8dp"
android:layout_height="8dp"
android:layout_marginTop="2dp"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment