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