Commit 2e3f93e6 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

albums fetch , top headers items click listener

parent 4ccf07dd
package com.biganto.visual.roompark.presentation.screen.albums package com.biganto.visual.roompark.presentation.screen.albums
import com.biganto.visual.roompark.conductor.BigantoBaseContract import com.biganto.visual.roompark.conductor.BigantoBaseContract
import com.biganto.visual.roompark.domain.model.AlbumPreviewModel
import io.reactivex.Observable
/** /**
* Created by Vladislav Bogdashkin on 30.09.2019. * Created by Vladislav Bogdashkin on 30.09.2019.
*/ */
interface AlbumsScreen : BigantoBaseContract<AlbumsScreenViewState> { interface AlbumsScreen : BigantoBaseContract<AlbumsScreenViewState> {
fun onAlbumSelected(): Observable<AlbumPreviewModel>
} }
\ No newline at end of file
...@@ -15,15 +15,19 @@ import com.biganto.visual.roompark.base.IBottomNavigation ...@@ -15,15 +15,19 @@ import com.biganto.visual.roompark.base.IBottomNavigation
import com.biganto.visual.roompark.base.RoomParkApplication import com.biganto.visual.roompark.base.RoomParkApplication
import com.biganto.visual.roompark.base.RoomParkMainActivity import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.conductor.BigantoBaseController import com.biganto.visual.roompark.conductor.BigantoBaseController
import com.biganto.visual.roompark.domain.model.AlbumPreviewModel
import com.biganto.visual.roompark.presentation.screen.albums.util.AlbumsHeaderAdapter import com.biganto.visual.roompark.presentation.screen.albums.util.AlbumsHeaderAdapter
import com.biganto.visual.roompark.presentation.screen.favorites.util.AlbumListAdapter import com.biganto.visual.roompark.presentation.screen.favorites.util.AlbumListAdapter
import com.biganto.visual.roompark.util.extensions.scaleCenterCrop import com.biganto.visual.roompark.util.extensions.scaleCenterCrop
import com.biganto.visual.roompark.util.view_utils.grid.CeilsDecoration import com.biganto.visual.roompark.util.view_utils.grid.CeilsDecoration
import com.google.android.material.textview.MaterialTextView import com.google.android.material.textview.MaterialTextView
import com.squareup.picasso.Picasso import com.squareup.picasso.Picasso
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import jp.wasabeef.picasso.transformations.BlurTransformation import jp.wasabeef.picasso.transformations.BlurTransformation
import jp.wasabeef.picasso.transformations.ColorFilterTransformation import jp.wasabeef.picasso.transformations.ColorFilterTransformation
import timber.log.Timber import timber.log.Timber
import java.util.concurrent.TimeUnit
import javax.inject.Inject import javax.inject.Inject
...@@ -62,7 +66,7 @@ class AlbumsScreenController : ...@@ -62,7 +66,7 @@ class AlbumsScreenController :
private val photosBackgroundTarget = object : com.squareup.picasso.Target { private val photosBackgroundTarget = object : com.squareup.picasso.Target {
override fun onPrepareLoad(placeHolderDrawable: Drawable?) { override fun onPrepareLoad(placeHolderDrawable: Drawable?) {
nestedScrollView.background = placeHolderDrawable // nestedScrollView.background = placeHolderDrawable
} }
override fun onBitmapFailed(e: Exception?, errorDrawable: Drawable?) { override fun onBitmapFailed(e: Exception?, errorDrawable: Drawable?) {
...@@ -134,6 +138,7 @@ class AlbumsScreenController : ...@@ -134,6 +138,7 @@ class AlbumsScreenController :
is AlbumsScreenViewState.Idle -> render(viewState) is AlbumsScreenViewState.Idle -> render(viewState)
is AlbumsScreenViewState.AlbumsSelected -> render(viewState) is AlbumsScreenViewState.AlbumsSelected -> render(viewState)
is AlbumsScreenViewState.AlbumsListLoaded-> render(viewState) is AlbumsScreenViewState.AlbumsListLoaded-> render(viewState)
is AlbumsScreenViewState.HeaderAlbumChoosed-> render(viewState)
is AlbumsScreenViewState.SomeError -> render(viewState) is AlbumsScreenViewState.SomeError -> render(viewState)
} }
} }
...@@ -170,12 +175,34 @@ class AlbumsScreenController : ...@@ -170,12 +175,34 @@ class AlbumsScreenController :
} }
private fun render(viewState: AlbumsScreenViewState.HeaderAlbumChoosed) {
(headersRecyclerView.adapter as AlbumsHeaderAdapter)
.getItemPosition(viewState.item.albumId).let {
headersRecyclerView.scrollToPosition(it)
}
currentAlbomTitle.text = viewState.item.title
picassoAsync
.load(viewState.item.previewUrl)
.transform(BlurTransformation(activity, 13, 2))
.transform(ColorFilterTransformation(0xCC000000.toInt()))
.into(photosBackgroundTarget)
}
private fun render(viewState: AlbumsScreenViewState.AlbumsSelected){ private fun render(viewState: AlbumsScreenViewState.AlbumsSelected){
(albumsRecyclerView.adapter as AlbumListAdapter).setItems( (albumsRecyclerView.adapter as AlbumListAdapter).setItems(
viewState.list.asSequence().sortedByDescending { it.published }.toList() viewState.list.asSequence().sortedByDescending { it.published }.toList()
) )
} }
override fun onAlbumSelected(): Observable<AlbumPreviewModel>
= (headersRecyclerView.adapter as AlbumsHeaderAdapter)
.onItemClicked
.debounce (300L,TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
.doOnNext { (albumsRecyclerView.adapter as AlbumListAdapter).setItems(arrayListOf())}
override fun getLayoutId(): Int = R.layout.albums_screen override fun getLayoutId(): Int = R.layout.albums_screen
......
...@@ -3,6 +3,7 @@ package com.biganto.visual.roompark.presentation.screen.albums ...@@ -3,6 +3,7 @@ package com.biganto.visual.roompark.presentation.screen.albums
import com.biganto.visual.roompark.conductor.BigantoBasePresenter import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.domain.interactor.AlbumsInteractor import com.biganto.visual.roompark.domain.interactor.AlbumsInteractor
import com.biganto.visual.roompark.util.monades.ExceptionString import com.biganto.visual.roompark.util.monades.ExceptionString
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
import javax.inject.Inject import javax.inject.Inject
...@@ -22,20 +23,41 @@ class AlbumsScreenPresenter @Inject constructor( ...@@ -22,20 +23,41 @@ class AlbumsScreenPresenter @Inject constructor(
override fun defaultErrorViewStateHandler() = override fun defaultErrorViewStateHandler() =
{e: ExceptionString -> AlbumsScreenViewState.SomeError(e) } {e: ExceptionString -> AlbumsScreenViewState.SomeError(e) }
private fun requestAlbum(id:Int):Observable<AlbumsScreenViewState> =
interactor.fetchAlbumPhotos(id)
.filter { !it.isNullOrEmpty() }
.map { AlbumsScreenViewState.AlbumsSelected(it)}
override fun bindIntents() { override fun bindIntents() {
val fetchParents = interactor.fetchHeaderAlbums() val fetchParents = interactor.fetchHeaderAlbums()
.filter { !it.isNullOrEmpty() } .filter { !it.isNullOrEmpty() }
.map { AlbumsScreenViewState.AlbumsListLoaded(it,selectedIndex) } .map { AlbumsScreenViewState.AlbumsListLoaded(it, selectedIndex) }
// .concatMap<AlbumsScreenViewState> {
// Observable.just(
// AlbumsScreenViewState.HeaderAlbumChoosed(
// it.list.first { alb -> alb.albumId == selectedIndex })
// )
// }
val fetchSelected = requestAlbum(selectedIndex)
val headerItemSelected = intent(AlbumsScreen::onAlbumSelected)
.doOnNext { selectedIndex = it.albumId }
.flatMap<AlbumsScreenViewState> {model ->
requestAlbum(model.albumId)
.startWith(Observable.just(AlbumsScreenViewState.HeaderAlbumChoosed(item = model)))
}
val fetchSelected = interactor.fetchAlbumPhotos(selectedIndex)
.filter { !it.isNullOrEmpty() }
.map { AlbumsScreenViewState.AlbumsSelected(it)}
val state = restoreStateObservable val state = restoreStateObservable
.mergeWith(fetchParents) .mergeWith(fetchParents)
.mergeWith(fetchSelected) .mergeWith(fetchSelected)
.mergeWith(headerItemSelected)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
subscribeViewState(state.cast(AlbumsScreenViewState::class.java), AlbumsScreen::render) subscribeViewState(state.cast(AlbumsScreenViewState::class.java), AlbumsScreen::render)
......
...@@ -14,6 +14,7 @@ sealed class AlbumsScreenViewState : BigantoBaseViewState() { ...@@ -14,6 +14,7 @@ sealed class AlbumsScreenViewState : BigantoBaseViewState() {
class Idle : AlbumsScreenViewState() class Idle : AlbumsScreenViewState()
class AlbumsListLoaded(val list:List<AlbumPreviewModel>, val selectedAlbumId:Int) : AlbumsScreenViewState() class AlbumsListLoaded(val list:List<AlbumPreviewModel>, val selectedAlbumId:Int) : AlbumsScreenViewState()
class AlbumsSelected(val list:List<AlbumSortedModel>) : AlbumsScreenViewState() class AlbumsSelected(val list:List<AlbumSortedModel>) : AlbumsScreenViewState()
class HeaderAlbumChoosed(val item:AlbumPreviewModel) : AlbumsScreenViewState()
class PhotoSelected(val photoId:Int) : AlbumsScreenViewState() class PhotoSelected(val photoId:Int) : AlbumsScreenViewState()
class SomeError(val exception: ExceptionString) : AlbumsScreenViewState() class SomeError(val exception: ExceptionString) : AlbumsScreenViewState()
} }
\ No newline at end of file
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