Commit 6478b8b0 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

added restore model to albums screeen

parent a9d211a1
......@@ -22,6 +22,8 @@ import com.biganto.visual.roompark.presentation.screen.photo.PhotoScreenControll
import com.biganto.visual.roompark.util.extensions.scaleCenterCrop
import com.biganto.visual.roompark.util.view_utils.grid.CeilsDecoration
import com.bluelinelabs.conductor.RouterTransaction
import com.bluelinelabs.conductor.changehandler.FadeChangeHandler
import com.bluelinelabs.conductor.changehandler.VerticalChangeHandler
import com.google.android.material.textview.MaterialTextView
import com.squareup.picasso.Picasso
import io.reactivex.Observable
......@@ -140,6 +142,7 @@ class AlbumsScreenController :
is AlbumsScreenViewState.HeaderAlbumChoosed-> render(viewState)
is AlbumsScreenViewState.PhotoSelected -> render(viewState)
is AlbumsScreenViewState.SomeError -> render(viewState)
is AlbumsScreenViewState.RestoreView -> render(viewState)
}
}
......@@ -148,7 +151,11 @@ class AlbumsScreenController :
}
private fun render(viewState: AlbumsScreenViewState.PhotoSelected){
router.pushController(RouterTransaction.with(PhotoScreenController(viewState.photoId)))
router.pushController(RouterTransaction.with(PhotoScreenController(viewState.photoId))
.pushChangeHandler(VerticalChangeHandler())
.popChangeHandler(FadeChangeHandler(false))
)
}
private fun render(viewState: AlbumsScreenViewState.SomeError) =
......@@ -199,6 +206,32 @@ class AlbumsScreenController :
)
}
private fun render(viewState: AlbumsScreenViewState.RestoreView){
(albumsRecyclerView.adapter as AlbumListAdapter).setItems(
viewState.restore.albumList.asSequence().sortedByDescending { it.published }.toList()
)
(headersRecyclerView.adapter as AlbumsHeaderAdapter).setItems(
viewState.restore.albumsPreview.asSequence().sortedByDescending { it.published }.toList()
)
headersRecyclerView.let {
it.scrollToPosition(
(it.adapter as AlbumsHeaderAdapter).getItemPosition(viewState.restore.currentIndex)
)
}
viewState.restore.albumsPreview.first { it.albumId == viewState.restore.currentIndex}
.let {
currentAlbomTitle.text = it.title
picassoAsync
.load(it.previewUrl)
.transform(BlurTransformation(activity, 13, 2))
.transform(ColorFilterTransformation(0xCC000000.toInt()))
.into(photosBackgroundTarget)
}
}
override fun onAlbumSelected(): Observable<AlbumPreviewModel>
= (headersRecyclerView.adapter as AlbumsHeaderAdapter)
.onItemClicked
......
......@@ -2,6 +2,8 @@ package com.biganto.visual.roompark.presentation.screen.albums
import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.domain.interactor.AlbumsInteractor
import com.biganto.visual.roompark.domain.model.AlbumPreviewModel
import com.biganto.visual.roompark.domain.model.AlbumSortedModel
import com.biganto.visual.roompark.util.monades.ExceptionString
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
......@@ -13,32 +15,35 @@ import javax.inject.Named
* Created by Vladislav Bogdashkin on 30.09.2019.
*/
class AlbumsScreenPresenter @Inject constructor(
private val interactor: AlbumsInteractor
,@Named(SELECTED_ALBUM_INDEX_KEY) private var selectedIndex:Int
)
: BigantoBasePresenter<AlbumsScreen, AlbumsScreenViewState>() {
private var restoreModel = RestoreModel(listOf(), listOf(),selectedIndex)
override fun defaultErrorViewStateHandler() =
{e: ExceptionString -> AlbumsScreenViewState.SomeError(e) }
private fun requestAlbum(id:Int):Observable<AlbumsScreenViewState> =
interactor.fetchAlbumPhotos(id)
.filter { !it.isNullOrEmpty() }
.map { AlbumsScreenViewState.AlbumsSelected(it)}
.doOnNext{ restoreModel.albumList = it }
.map { AlbumsScreenViewState.AlbumsSelected(it)}
override fun bindIntents() {
val fetchParents = interactor.fetchHeaderAlbums()
.filter { !it.isNullOrEmpty() }
.doOnNext{ restoreModel.albumsPreview = it }
.map { AlbumsScreenViewState.AlbumsListLoaded(it, selectedIndex) }
val fetchSelected = requestAlbum(selectedIndex)
val headerItemSelected = intent(AlbumsScreen::onAlbumSelected)
.doOnNext { selectedIndex = it.albumId }
.doOnNext { restoreModel.currentIndex = it.albumId }
.flatMap<AlbumsScreenViewState> { model ->
requestAlbum(model.albumId)
.startWith(Observable.just(AlbumsScreenViewState.HeaderAlbumChoosed(item = model)))
......@@ -47,9 +52,6 @@ class AlbumsScreenPresenter @Inject constructor(
val photoSelected = intent(AlbumsScreen::onPhotoSelected)
.map { AlbumsScreenViewState.PhotoSelected(it.photoId) }
val state = restoreStateObservable
.mergeWith(fetchParents)
.mergeWith(fetchSelected)
......@@ -60,4 +62,12 @@ class AlbumsScreenPresenter @Inject constructor(
subscribeViewState(state.cast(AlbumsScreenViewState::class.java), AlbumsScreen::render)
}
}
\ No newline at end of file
override fun detachView() {
super.detachView()
restoreStateObservable.accept(AlbumsScreenViewState.RestoreView(restoreModel))
}
}
data class RestoreModel(var albumList:List<AlbumSortedModel>
,var albumsPreview:List<AlbumPreviewModel>
, var currentIndex:Int)
\ No newline at end of file
......@@ -17,4 +17,5 @@ sealed class AlbumsScreenViewState : BigantoBaseViewState() {
class HeaderAlbumChoosed(val item:AlbumPreviewModel) : AlbumsScreenViewState()
class PhotoSelected(val photoId:Int) : AlbumsScreenViewState()
class SomeError(val exception: ExceptionString) : AlbumsScreenViewState()
class RestoreView(val restore:RestoreModel) : AlbumsScreenViewState()
}
\ No newline at end of file
......@@ -45,4 +45,11 @@ class PhotoScreenPresenter @Inject constructor(
.observeOn(AndroidSchedulers.mainThread())
subscribeViewState(state.cast(PhotoScreenViewState::class.java), PhotoScreen::render)
}
override fun detachView() {
super.detachView()
restoreStateObservable.accept(PhotoScreenViewState.Idle())
}
}
\ No newline at end of file
......@@ -321,7 +321,6 @@ class RendererThread(val context: Context, val surface: SurfaceTexture)
timerDecay(SLEEP_THRESHOLD)
if (bmpCache.size>0) calcBorders()
Timber.d("bmpCache ${bmpCache.size}")
bmpCache.forEachIndexed { index, bitmap ->
// Timber.d("bitmap ${bitmap} / $index")
bitmap?.let {
......
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