Commit 6c81fb51 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

sets current page as actual selected

parent d72a59a7
...@@ -48,7 +48,7 @@ class AlbumsScreenController : ...@@ -48,7 +48,7 @@ class AlbumsScreenController :
constructor(args: Bundle):super(args) constructor(args: Bundle):super(args)
constructor(id: Int) : super(bundleOf(com.biganto.visual.roompark.presentation.screen.photo.SELECTED_ALBUM_INDEX_KEY to id)) constructor(id: Int) : super(bundleOf(SELECTED_ALBUM_INDEX_KEY to id))
@BindView(R.id.headers_recycler_view) @BindView(R.id.headers_recycler_view)
...@@ -126,7 +126,7 @@ class AlbumsScreenController : ...@@ -126,7 +126,7 @@ class AlbumsScreenController :
fun getComponent() = DaggerAlbumsScreenComponent.factory() fun getComponent() = DaggerAlbumsScreenComponent.factory()
.create(RoomParkApplication.component .create(RoomParkApplication.component
,activity as RoomParkMainActivity ,activity as RoomParkMainActivity
,args.getInt(com.biganto.visual.roompark.presentation.screen.photo.SELECTED_ALBUM_INDEX_KEY)) ,args.getInt(SELECTED_ALBUM_INDEX_KEY))
.inject(this) .inject(this)
// @Inject // @Inject
......
...@@ -27,7 +27,7 @@ interface AlbumsScreenComponent { ...@@ -27,7 +27,7 @@ interface AlbumsScreenComponent {
fun create( fun create(
appComponent: AppComponent appComponent: AppComponent
,@BindsInstance activity: RoomParkMainActivity ,@BindsInstance activity: RoomParkMainActivity
,@BindsInstance @Named(com.biganto.visual.roompark.presentation.screen.photo.SELECTED_ALBUM_INDEX_KEY) camIndex:Int ,@BindsInstance @Named(SELECTED_ALBUM_INDEX_KEY) camIndex:Int
): AlbumsScreenComponent ): AlbumsScreenComponent
} }
......
...@@ -16,7 +16,7 @@ import javax.inject.Named ...@@ -16,7 +16,7 @@ import javax.inject.Named
class AlbumsScreenPresenter @Inject constructor( class AlbumsScreenPresenter @Inject constructor(
private val interactor: AlbumsInteractor private val interactor: AlbumsInteractor
,@Named(com.biganto.visual.roompark.presentation.screen.photo.SELECTED_ALBUM_INDEX_KEY) private var selectedIndex:Int ,@Named(SELECTED_ALBUM_INDEX_KEY) private var selectedIndex:Int
) )
: BigantoBasePresenter<AlbumsScreen, AlbumsScreenViewState>() { : BigantoBasePresenter<AlbumsScreen, AlbumsScreenViewState>() {
......
...@@ -21,7 +21,7 @@ import javax.inject.Inject ...@@ -21,7 +21,7 @@ import javax.inject.Inject
* Created by Vladislav Bogdashkin on 30.09.2019. * Created by Vladislav Bogdashkin on 30.09.2019.
*/ */
const val SELECTED_ALBUM_INDEX_KEY = "SELECTED_ALBUM_INDEX" const val SELECTED_PHOTO_KEY = "SELECTED_PHOTO_ID"
class PhotoScreenController : class PhotoScreenController :
BigantoBaseController<PhotoScreenViewState BigantoBaseController<PhotoScreenViewState
...@@ -31,7 +31,7 @@ class PhotoScreenController : ...@@ -31,7 +31,7 @@ class PhotoScreenController :
constructor(args: Bundle):super(args) constructor(args: Bundle):super(args)
constructor(id: Int) : super(bundleOf(SELECTED_ALBUM_INDEX_KEY to id)) constructor(id: Int) : super(bundleOf(SELECTED_PHOTO_KEY to id))
@BindView(R.id.photoTitle) @BindView(R.id.photoTitle)
...@@ -69,7 +69,7 @@ class PhotoScreenController : ...@@ -69,7 +69,7 @@ class PhotoScreenController :
fun getComponent() = DaggerPhotoScreenComponent.factory() fun getComponent() = DaggerPhotoScreenComponent.factory()
.create(RoomParkApplication.component .create(RoomParkApplication.component
,activity as RoomParkMainActivity ,activity as RoomParkMainActivity
,args.getInt(SELECTED_ALBUM_INDEX_KEY)) ,args.getInt(SELECTED_PHOTO_KEY))
.inject(this) .inject(this)
// @Inject // @Inject
...@@ -104,6 +104,8 @@ class PhotoScreenController : ...@@ -104,6 +104,8 @@ class PhotoScreenController :
(photoViewPager.adapter as PhotoViewerAdapter).setItems( (photoViewPager.adapter as PhotoViewerAdapter).setItems(
viewState.list.asSequence().sortedBy{it.sort}.toList() viewState.list.asSequence().sortedBy{it.sort}.toList()
) )
photoViewPager.currentItem = (photoViewPager.adapter as PhotoViewerAdapter)
.getItemPosition(viewState.selectedId)
} }
private fun render(viewState: PhotoScreenViewState.AldumFetched) { private fun render(viewState: PhotoScreenViewState.AldumFetched) {
......
...@@ -27,7 +27,7 @@ interface PhotoScreenComponent { ...@@ -27,7 +27,7 @@ interface PhotoScreenComponent {
fun create( fun create(
appComponent: AppComponent appComponent: AppComponent
,@BindsInstance activity: RoomParkMainActivity ,@BindsInstance activity: RoomParkMainActivity
,@BindsInstance @Named(SELECTED_ALBUM_INDEX_KEY) camIndex:Int ,@BindsInstance @Named(SELECTED_PHOTO_KEY) camIndex:Int
): PhotoScreenComponent ): PhotoScreenComponent
} }
......
...@@ -6,7 +6,6 @@ import com.biganto.visual.roompark.util.monades.ExceptionString ...@@ -6,7 +6,6 @@ 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
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Named import javax.inject.Named
...@@ -14,32 +13,18 @@ import javax.inject.Named ...@@ -14,32 +13,18 @@ import javax.inject.Named
* Created by Vladislav Bogdashkin on 30.09.2019. * Created by Vladislav Bogdashkin on 30.09.2019.
*/ */
class PhotoScreenPresenter @Inject constructor( class PhotoScreenPresenter @Inject constructor(
private val interactor: PhotoInteractor private val interactor: PhotoInteractor
,@Named(SELECTED_ALBUM_INDEX_KEY) private var selectedIndex:Int ,@Named(SELECTED_PHOTO_KEY) private var selectedIndex:Int
) )
: BigantoBasePresenter<PhotoScreen, PhotoScreenViewState>() { : BigantoBasePresenter<PhotoScreen, PhotoScreenViewState>() {
override fun defaultErrorViewStateHandler() = override fun defaultErrorViewStateHandler() =
{e: ExceptionString -> PhotoScreenViewState.SomeError(e) } { e: ExceptionString -> PhotoScreenViewState.SomeError(e) }
override fun bindIntents() { override fun bindIntents() {
// val fetchSelected = requestAlbum(selectedIndex)
//
//
// val headerItemSelected = intent(PhotoScreen::onAlbumSelected)
// .doOnNext { selectedIndex = it.albumId }
//
// .flatMap<PhotoScreenViewState> { model ->
// requestAlbum(model.albumId)
// }
Timber.d("fetch photoId: $selectedIndex")
val fetchAlbum = interactor.fetchPhoto(selectedIndex) val fetchAlbum = interactor.fetchPhoto(selectedIndex)
.doOnNext{Timber.d("got photo: $it")}
.flatMap { photo -> .flatMap { photo ->
Observable.merge<PhotoScreenViewState>( Observable.merge<PhotoScreenViewState>(
arrayListOf( arrayListOf(
...@@ -47,26 +32,17 @@ class PhotoScreenPresenter @Inject constructor( ...@@ -47,26 +32,17 @@ class PhotoScreenPresenter @Inject constructor(
.map { PhotoScreenViewState.AldumFetched(it) } .map { PhotoScreenViewState.AldumFetched(it) }
, ,
interactor.fetchPhotos(photo.albumId) interactor.fetchPhotos(photo.albumId)
.doOnNext{Timber.d("got photos: $it")} .map<PhotoScreenViewState> {
.map<PhotoScreenViewState> { PhotoScreenViewState.PhotoListLoaded(it) } PhotoScreenViewState.PhotoListLoaded(it,selectedIndex)
}
.startWith(Observable.just(PhotoScreenViewState.PhotoFetched(photo))) .startWith(Observable.just(PhotoScreenViewState.PhotoFetched(photo)))
)) ))
} }
val state = restoreStateObservable val state = restoreStateObservable
.mergeWith(fetchAlbum) .mergeWith(fetchAlbum)
// .mergeWith(fetchParents)
// .mergeWith(fetchSelected)
// .mergeWith(headerItemSelected)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
subscribeViewState(state.cast(PhotoScreenViewState::class.java), PhotoScreen::render) subscribeViewState(state.cast(PhotoScreenViewState::class.java), PhotoScreen::render)
} }
} }
\ No newline at end of file
...@@ -13,7 +13,7 @@ import com.biganto.visual.roompark.util.monades.ExceptionString ...@@ -13,7 +13,7 @@ import com.biganto.visual.roompark.util.monades.ExceptionString
sealed class PhotoScreenViewState : BigantoBaseViewState() { sealed class PhotoScreenViewState : BigantoBaseViewState() {
class Idle : PhotoScreenViewState() class Idle : PhotoScreenViewState()
class PhotoListLoaded(val list:List<PhotoModel>) : PhotoScreenViewState() class PhotoListLoaded(val list:List<PhotoModel>,val selectedId:Int) : PhotoScreenViewState()
class PhotoFetched(val model:PhotoModel) : PhotoScreenViewState() class PhotoFetched(val model:PhotoModel) : PhotoScreenViewState()
class PhotoSelected(val model:PhotoResolutionModel) : PhotoScreenViewState() class PhotoSelected(val model:PhotoResolutionModel) : PhotoScreenViewState()
class SomeError(val exception: ExceptionString) : PhotoScreenViewState() class SomeError(val exception: ExceptionString) : PhotoScreenViewState()
......
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