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

refactore adapters

parent ea9f64ac
package com.biganto.visual.roompark.presentation.screen.feeds
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
......@@ -52,6 +53,9 @@ class FeedsScreenController :
@BindView(R.id.cams_recycler_view)
lateinit var camsRecyclerView:RecyclerView
@BindView(R.id.feedsBlock)
lateinit var feedsBlockView:ViewGroup
private fun bindRecycler(){
feedsRecyclerView.isNestedScrollingEnabled = true
......@@ -119,15 +123,15 @@ class FeedsScreenController :
}
private fun render(viewState: FeedsScreenViewState.AlbumsPages){
(devProgressRecyclerView.adapter as AlbumsPreviewAdapter).addItems(viewState.items)
(devProgressRecyclerView.adapter as AlbumsPreviewAdapter).setItems(viewState.items)
}
private fun render(viewState: FeedsScreenViewState.GetFeedArticlesPreview){
(feedsRecyclerView.adapter as ArticlesPreviewAdapter).addItems(viewState.items)
(feedsRecyclerView.adapter as ArticlesPreviewAdapter).setItems(viewState.items)
}
private fun render(viewState: FeedsScreenViewState.CamsList){
(camsRecyclerView.adapter as CamsListAdapter).addItems(viewState.items)
(camsRecyclerView.adapter as CamsListAdapter).setItems(viewState.items)
}
private fun getComponent() = DaggerFeedsScreenComponent.factory()
......
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.biganto.visual.roompark.presentation.screen.settings.util.CommonRecyclerAdapter
import com.biganto.visual.roompark.presentation.screen.settings.util.CommonViewHolder
import com.squareup.picasso.Picasso
import java.text.SimpleDateFormat
import java.util.*
......@@ -18,34 +16,16 @@ import java.util.*
/**
* Created by Vladislav Bogdashkin on 15.10.2019.
*/
class ArticlesPreviewAdapter : RecyclerView.Adapter<ArticlePreviewViewHolder>() {
class ArticlesPreviewAdapter : CommonRecyclerAdapter<ArticlePreviewViewHolder,ArticlePreviewModel>() {
override val vhKlazz = ArticlePreviewViewHolder::class
private var list: MutableList<ArticlePreviewModel> = mutableListOf()
fun addItems(list:List<ArticlePreviewModel>){
this.list.clear()
this.list.addAll(list)
notifyDataSetChanged()
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ArticlePreviewViewHolder =
ArticlePreviewViewHolder(
LayoutInflater.from(parent.context)
.inflate(R.layout.feed_preview_viewholder, parent, false)
)
override fun getItemCount(): Int = list.size
override fun onBindViewHolder(holder: ArticlePreviewViewHolder, position: Int) {
holder.bindModel(list[position])
}
override fun getVhLayout(): Int = R.layout.feed_preview_viewholder
}
class ArticlePreviewViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
class ArticlePreviewViewHolder(itemView: View) : CommonViewHolder<ArticlePreviewModel>(itemView) {
private val dateFormatter = SimpleDateFormat("dd / MM / yyyy", Locale.getDefault())
......@@ -54,12 +34,7 @@ class ArticlePreviewViewHolder(itemView: View) : RecyclerView.ViewHolder(itemVie
@BindView(R.id.feed_title_info_text_view) lateinit var articleTitle:TextView
@BindView(R.id.feed_read) lateinit var articleIsRead:View
init {
ButterKnife.bind(this, itemView)
}
fun bindModel(model: ArticlePreviewModel){
override fun onViewBound(model: ArticlePreviewModel) {
articleDate.text = dateFormatter.format(model.published)
articleTitle.text = model.title
articleIsRead.setGone(model.isRead)
......@@ -68,9 +43,8 @@ class ArticlePreviewViewHolder(itemView: View) : RecyclerView.ViewHolder(itemVie
.load(model.previewUrl)
.into(preview)
}
}
fun View.setGone(isGone:Boolean){
private fun View.setGone(isGone:Boolean){
this.visibility = if (isGone) View.GONE else View.VISIBLE
}
\ No newline at end of file
package com.biganto.visual.roompark.presentation.screen.feeds.utils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
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.WebCamModel
import com.biganto.visual.roompark.presentation.screen.settings.util.CommonRecyclerAdapter
import com.biganto.visual.roompark.presentation.screen.settings.util.CommonViewHolder
/**
* Created by Vladislav Bogdashkin on 15.10.2019.
*/
class CamsListAdapter : RecyclerView.Adapter<CamListViewHolder>() {
class CamsListAdapter : CommonRecyclerAdapter<CamListViewHolder,WebCamModel>() {
override val vhKlazz = CamListViewHolder::class
private var list: MutableList<WebCamModel> = mutableListOf()
fun addItems(list:List<WebCamModel>){
this.list.clear()
this.list.addAll(list)
notifyDataSetChanged()
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CamListViewHolder =
CamListViewHolder(
LayoutInflater.from(parent.context)
.inflate(R.layout.cam_button_viewholder, parent, false)
)
override fun getItemCount(): Int = list.size
override fun onBindViewHolder(holder: CamListViewHolder, position: Int) {
holder.bindModel(list[position])
}
override fun getVhLayout(): Int = R.layout.cam_button_viewholder
}
class CamListViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
class CamListViewHolder(itemView: View) : CommonViewHolder<WebCamModel>(itemView) {
@BindView(R.id.camTitle) lateinit var camTitle:TextView
@BindView(R.id.camStatus) lateinit var camStatus:View
init {
ButterKnife.bind(this, itemView)
}
fun bindModel(model: WebCamModel) {
override fun onViewBound(model: WebCamModel) {
camTitle.text = model.title
}
}
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.AlbumPreviewModel
import com.biganto.visual.roompark.presentation.screen.settings.util.CommonRecyclerAdapter
import com.biganto.visual.roompark.presentation.screen.settings.util.CommonViewHolder
import com.squareup.picasso.Picasso
import java.text.SimpleDateFormat
import java.util.*
......@@ -18,31 +16,15 @@ import java.util.*
/**
* Created by Vladislav Bogdashkin on 15.10.2019.
*/
class AlbumsPreviewAdapter : RecyclerView.Adapter<AlbumCardViewHolder>() {
class AlbumsPreviewAdapter : CommonRecyclerAdapter<AlbumCardViewHolder,AlbumPreviewModel>() {
private var list: MutableList<AlbumPreviewModel> = mutableListOf()
override val vhKlazz = AlbumCardViewHolder::class
fun addItems(list:List<AlbumPreviewModel>){
this.list.clear()
this.list.addAll(list)
notifyDataSetChanged()
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AlbumCardViewHolder =
AlbumCardViewHolder(
LayoutInflater.from(parent.context)
.inflate(R.layout.estate_card_viewholder, parent, false)
)
override fun getItemCount(): Int = list.size
override fun onBindViewHolder(holder: AlbumCardViewHolder, position: Int) {
holder.bindModel(list[position])
}
override fun getVhLayout(): Int = R.layout.estate_card_viewholder
}
class AlbumCardViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
class AlbumCardViewHolder(itemView: View) : CommonViewHolder<AlbumPreviewModel>(itemView) {
private val dateFormatter = SimpleDateFormat("dd MMMM yyyy", Locale("ru"))
......@@ -50,11 +32,7 @@ class AlbumCardViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
@BindView(R.id.card_title) lateinit var articleTitle:TextView
@BindView(R.id.card_updated) lateinit var articleDate:TextView
init {
ButterKnife.bind(this, itemView)
}
fun bindModel(model: AlbumPreviewModel){
override fun onViewBound(model: AlbumPreviewModel) {
articleDate.text = dateFormatter.format(model.published)
articleTitle.text = model.title
......@@ -62,5 +40,4 @@ class AlbumCardViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
.load(model.previewUrl)
.into(preview)
}
}
......@@ -12,7 +12,7 @@
android:layout_height="match_parent">
<include
android:id="@+id/include"
android:id="@+id/feedsBlock"
layout="@layout/feeds_block_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
......@@ -29,7 +29,7 @@
android:text="ХОД\nСТРОИТЕЛЬСТВА"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/include" />
app:layout_constraintTop_toBottomOf="@+id/feedsBlock" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/dev_progress_recycler_view"
......
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