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

sets current page as actual selected

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