Commit 0073535e authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

base recyclers adapters impl

parent bf9e19df
package com.biganto.visual.roompark.presentation.screen.web_cam
package com.biganto.visual.roompark.presentation.screen.albums
import android.os.Bundle
import android.view.View
import androidx.core.os.bundleOf
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import butterknife.BindView
import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.base.IBottomNavigation
import com.biganto.visual.roompark.base.RoomParkApplication
import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.conductor.BigantoBaseController
import com.biganto.visual.roompark.presentation.screen.albums.AlbumsScreen
import com.biganto.visual.roompark.presentation.screen.albums.AlbumsScreenPresenter
import com.biganto.visual.roompark.presentation.screen.albums.AlbumsScreenViewState
import com.google.android.exoplayer2.SimpleExoPlayer
import com.google.android.exoplayer2.ui.PlayerView
import com.biganto.visual.roompark.presentation.screen.favorites.util.AlbumListAdapter
import com.biganto.visual.roompark.presentation.screen.feeds.utils.AlbumsPreviewAdapter
import com.biganto.visual.roompark.util.view_utils.grid.CeilsDecoration
import javax.inject.Inject
......@@ -33,15 +33,39 @@ class AlbumsScreenController :
constructor(id: Int) : super(bundleOf(SELECTED_ALBUM_INDEX_KEY to id))
@BindView(R.id.webCamPlayerView)
lateinit var playerView:PlayerView
lateinit var player:SimpleExoPlayer
@BindView(R.id.headers_recycler_view)
lateinit var headersRecyclerView: RecyclerView
@BindView(R.id.albums_recycler_view)
lateinit var albumsRecyclerView: RecyclerView
private fun bindRecycler() {
headersRecyclerView.isNestedScrollingEnabled = true
headersRecyclerView.layoutManager =
LinearLayoutManager(activity, RecyclerView.HORIZONTAL, false)
headersRecyclerView.adapter = AlbumsPreviewAdapter()
headersRecyclerView.itemAnimator = null
if (headersRecyclerView.itemDecorationCount == 0)
headersRecyclerView.addItemDecoration(
CeilsDecoration(1
, resources?.getDimensionPixelSize(R.dimen.ceil_grid_padding))
)
albumsRecyclerView.isNestedScrollingEnabled = true
albumsRecyclerView.layoutManager =
LinearLayoutManager(activity, RecyclerView.VERTICAL, false)
albumsRecyclerView.adapter = AlbumListAdapter()
albumsRecyclerView.itemAnimator = null
}
override fun onViewBound(v: View) {
toolBar.hideAll()
bottomNavigation.hide()
bindRecycler()
}
override fun injectDependencies() {
......@@ -86,8 +110,14 @@ class AlbumsScreenController :
private fun render(viewState: AlbumsScreenViewState.SomeError) =
showError(viewState.exception)
private fun render(viewState: AlbumsScreenViewState.AlbumsListLoaded){
private fun render(viewState: AlbumsScreenViewState.AlbumsListLoaded) {
(headersRecyclerView.adapter as AlbumsPreviewAdapter).setItems(viewState.list)
headersRecyclerView.let {
it.scrollToPosition(
(it.adapter as AlbumsPreviewAdapter).getItemPosition(viewState.selectedAlbumId)
)
}
}
private fun render(viewState: AlbumsScreenViewState.AlbumsSelected){
......
......@@ -5,8 +5,6 @@ import com.biganto.visual.roompark.base.IBottomNavigation
import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.di.dagger.AppComponent
import com.biganto.visual.roompark.di.dagger.PerScreen
import com.biganto.visual.roompark.presentation.screen.web_cam.AlbumsScreenController
import com.biganto.visual.roompark.presentation.screen.web_cam.SELECTED_ALBUM_INDEX_KEY
import dagger.Binds
import dagger.BindsInstance
import dagger.Component
......
......@@ -2,7 +2,6 @@ package com.biganto.visual.roompark.presentation.screen.albums
import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.domain.interactor.AlbumssInteractor
import com.biganto.visual.roompark.presentation.screen.web_cam.SELECTED_ALBUM_INDEX_KEY
import com.biganto.visual.roompark.util.monades.ExceptionString
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
......
......@@ -12,7 +12,7 @@ import com.biganto.visual.roompark.util.monades.ExceptionString
sealed class AlbumsScreenViewState : BigantoBaseViewState() {
class Idle : AlbumsScreenViewState()
class AlbumsListLoaded(val list:List<AlbumPreviewModel>, val selectedCamIndex:Int) : AlbumsScreenViewState()
class AlbumsListLoaded(val list:List<AlbumPreviewModel>, val selectedAlbumId:Int) : AlbumsScreenViewState()
class AlbumsSelected(val list:List<AlbumSortedModel>) : AlbumsScreenViewState()
class PhotoSelected(val photoId:Int) : AlbumsScreenViewState()
class SomeError(val exception: ExceptionString) : AlbumsScreenViewState()
......
package com.biganto.visual.roompark.presentation.screen.favorites.util
import android.view.View
import butterknife.BindView
import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.domain.model.AlbumPhotoPreviewModel
import com.biganto.visual.roompark.presentation.screen.settings.util.CommonRecyclerAdapter
import com.biganto.visual.roompark.presentation.screen.settings.util.CommonViewHolder
import com.google.android.material.textview.MaterialTextView
/**
* Created by Vladislav Bogdashkin on 16.10.2019.
*/
class AlbumListAdapter : CommonRecyclerAdapter<AlbumViewHolder, AlbumPhotoPreviewModel>() {
override val vhKlazz = AlbumViewHolder::class
override fun getVhLayout(): Int = R.layout.date_album_viewholder
}
class AlbumViewHolder(itemView: View) : CommonViewHolder<AlbumPhotoPreviewModel>(itemView) {
@BindView(R.id.date_title_textview) lateinit var albumTitle: MaterialTextView
// @BindView(R.id.camStatus) lateinit var camStatus: MaterialTextView
// @BindView(R.id.camStatusIcon) lateinit var camStatusIcon:ImageView
override fun onViewBound(model: AlbumPhotoPreviewModel) {
albumTitle.text = model.title
// camTitle.text = model.title
// camStatus.text = if (model.streams.isNullOrEmpty()) "ОФФЛАЙН" else "ОНЛАЙН"
// camStatusIcon.visibility = if (model.streams.isNullOrEmpty()) View.GONE else View.VISIBLE
}
}
......@@ -19,9 +19,11 @@ class AlbumsPreviewAdapter : CommonRecyclerAdapter<AlbumCardViewHolder,AlbumPrev
override val vhKlazz = AlbumCardViewHolder::class
override fun getVhLayout(): Int = R.layout.estate_card_viewholder
fun getItemPosition(model:AlbumPreviewModel) = getItemPosition(model.albumId)
override fun getVhLayout(): Int = R.layout.estate_card_viewholder
fun getItemPosition(modelId:Int)= list.indexOfFirst { it.albumId == modelId }
}
......
......@@ -32,7 +32,7 @@ abstract class CommonRecyclerAdapter<VH:CommonViewHolder<M>,M:Any> : RecyclerVie
val onItemClicked : Observable<M>
get() = onModelClicked
private var list: MutableList<M> = mutableListOf()
protected var list: MutableList<M> = mutableListOf()
fun setItems(items:List<M>){
this.list.clear()
......
......@@ -13,7 +13,6 @@ import com.biganto.visual.roompark.conductor.BigantoBaseController
import com.google.android.exoplayer2.ExoPlayerFactory
import com.google.android.exoplayer2.SimpleExoPlayer
import com.google.android.exoplayer2.ext.rtmp.RtmpDataSourceFactory
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory
import com.google.android.exoplayer2.extractor.ts.DefaultTsPayloadReaderFactory
import com.google.android.exoplayer2.source.MediaSource
import com.google.android.exoplayer2.source.ProgressiveMediaSource
......
......@@ -9,7 +9,7 @@
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView2"
android:id="@+id/albums_recycler_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="16dp"
......
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