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

refactore adapters

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