Commit c8a42b8d authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

photo dialog on screen

feed screen scroller
improve scroll reachability
parent f387e3f6
...@@ -13,6 +13,10 @@ class ArticlesInteractor @Inject constructor( ...@@ -13,6 +13,10 @@ class ArticlesInteractor @Inject constructor(
fun fetchArticles(feed:String) = fun fetchArticles(feed:String) =
uc.getArticles(feed) uc.getArticles(feed)
fun fetchArticlesPage(feed:String,pageSize:Int,current:Int) =
uc.fetchArticlesPage(feed,pageSize,current)
} }
......
package com.biganto.visual.roompark.presentation.screen.article package com.biganto.visual.roompark.presentation.screen.article
import com.biganto.visual.roompark.conductor.BigantoBaseContract import com.biganto.visual.roompark.conductor.BigantoBaseContract
import com.biganto.visual.roompark.domain.model.FeedModel
import io.reactivex.Observable
/** /**
* Created by Vladislav Bogdashkin on 30.09.2019. * Created by Vladislav Bogdashkin on 30.09.2019.
......
...@@ -13,15 +13,23 @@ import com.biganto.visual.roompark.R ...@@ -13,15 +13,23 @@ import com.biganto.visual.roompark.R
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.conductor.dialogs.PhotoDialogController
import com.biganto.visual.roompark.conductor.dialogs.change_handler.DialogChangeHandler
import com.biganto.visual.roompark.domain.model.FeedModel
import com.biganto.visual.roompark.presentation.screen.article.util.ArticleBottomPhotoAdapter import com.biganto.visual.roompark.presentation.screen.article.util.ArticleBottomPhotoAdapter
import com.biganto.visual.roompark.presentation.screen.article.util.HtmlPageAdapter import com.biganto.visual.roompark.presentation.screen.article.util.HtmlPageAdapter
import com.biganto.visual.roompark.presentation.screen.article.util.HtmlTag import com.biganto.visual.roompark.presentation.screen.article.util.HtmlTag
import com.biganto.visual.roompark.util.extensions.formatToSimple import com.biganto.visual.roompark.util.extensions.formatToSimple
import com.bluelinelabs.conductor.RouterTransaction
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.google.android.material.textview.MaterialTextView import com.google.android.material.textview.MaterialTextView
import com.jakewharton.rxbinding3.recyclerview.scrollStateChanges
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import jp.wasabeef.glide.transformations.BlurTransformation import jp.wasabeef.glide.transformations.BlurTransformation
import timber.log.Timber import timber.log.Timber
import java.util.concurrent.TimeUnit
import javax.inject.Inject import javax.inject.Inject
...@@ -45,6 +53,7 @@ class ArticleScreenController : ...@@ -45,6 +53,7 @@ class ArticleScreenController :
getComponent() getComponent()
} }
@Inject @Inject
override lateinit var injectedPresenter: ArticleScreenPresenter override lateinit var injectedPresenter: ArticleScreenPresenter
...@@ -95,6 +104,16 @@ class ArticleScreenController : ...@@ -95,6 +104,16 @@ class ArticleScreenController :
toolBar.setToolbar() toolBar.setToolbar()
bottomNavigationController.hide() bottomNavigationController.hide()
bindRecycler() bindRecycler()
detachDisposable.add(
(bottomPhotosRecyclerView.adapter as ArticleBottomPhotoAdapter)
.onItemClicked
.subscribe { router.pushController(
RouterTransaction.with(PhotoDialogController(it.url))
.pushChangeHandler(DialogChangeHandler())
.popChangeHandler(DialogChangeHandler())
)
}
)
} }
override fun render(viewState: ArticleScreenViewState) { override fun render(viewState: ArticleScreenViewState) {
......
...@@ -2,6 +2,9 @@ package com.biganto.visual.roompark.presentation.screen.article ...@@ -2,6 +2,9 @@ package com.biganto.visual.roompark.presentation.screen.article
import com.biganto.visual.roompark.conductor.BigantoBasePresenter import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.domain.interactor.ArticleInteractor import com.biganto.visual.roompark.domain.interactor.ArticleInteractor
import com.biganto.visual.roompark.presentation.screen.feeds.FEED_PREVIEW_PAGE_SIZE
import com.biganto.visual.roompark.presentation.screen.feeds.FeedsScreen
import com.biganto.visual.roompark.presentation.screen.feeds.FeedsScreenViewState
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
......
package com.biganto.visual.roompark.presentation.screen.feed_list package com.biganto.visual.roompark.presentation.screen.feed_list
import com.biganto.visual.roompark.conductor.BigantoBaseContract import com.biganto.visual.roompark.conductor.BigantoBaseContract
import io.reactivex.Observable
/** /**
* Created by Vladislav Bogdashkin on 30.09.2019. * Created by Vladislav Bogdashkin on 30.09.2019.
*/ */
interface ArticlesScreen : BigantoBaseContract<ArticlesScreenViewState> { interface ArticlesScreen : BigantoBaseContract<ArticlesScreenViewState> {
fun requsetsNewArticles(): Observable<Int>
} }
...@@ -3,6 +3,7 @@ package com.biganto.visual.roompark.presentation.screen.feed_list ...@@ -3,6 +3,7 @@ package com.biganto.visual.roompark.presentation.screen.feed_list
import android.view.View import android.view.View
import android.widget.ProgressBar import android.widget.ProgressBar
import androidx.core.os.bundleOf import androidx.core.os.bundleOf
import androidx.core.view.isNotEmpty
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import butterknife.BindView import butterknife.BindView
...@@ -17,7 +18,11 @@ import com.biganto.visual.roompark.util.extensions.setGone ...@@ -17,7 +18,11 @@ import com.biganto.visual.roompark.util.extensions.setGone
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.google.android.material.textview.MaterialTextView import com.google.android.material.textview.MaterialTextView
import com.jakewharton.rxbinding3.recyclerview.scrollStateChanges
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import timber.log.Timber import timber.log.Timber
import java.util.concurrent.TimeUnit
import javax.inject.Inject import javax.inject.Inject
/** /**
...@@ -37,6 +42,17 @@ class ArticlesScreenController : ...@@ -37,6 +42,17 @@ class ArticlesScreenController :
constructor(feedAlias:String):super(bundleOf(FEED_ALIAS to feedAlias)) constructor(feedAlias:String):super(bundleOf(FEED_ALIAS to feedAlias))
override fun requsetsNewArticles(): Observable<Int> =
articlesRecyclerView.scrollStateChanges()
.filter { it == RecyclerView.SCROLL_STATE_IDLE}
.map { articlesRecyclerView.layoutManager as LinearLayoutManager }
.map { it.findLastCompletelyVisibleItemPosition() }
.filter{ articlesRecyclerView.isNotEmpty() }
.filter { it>(articlesRecyclerView.adapter?.itemCount?:0)-4 }
.map { articlesRecyclerView.adapter?.itemCount?:0 }
.debounce(120L, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
override fun injectDependencies() { override fun injectDependencies() {
getComponent() getComponent()
} }
...@@ -106,6 +122,7 @@ class ArticlesScreenController : ...@@ -106,6 +122,7 @@ class ArticlesScreenController :
when(viewState){ when(viewState){
is ArticlesScreenViewState.Idle -> render(viewState) is ArticlesScreenViewState.Idle -> render(viewState)
is ArticlesScreenViewState.ArticlesLoaded -> render(viewState) is ArticlesScreenViewState.ArticlesLoaded -> render(viewState)
is ArticlesScreenViewState.ArticlesScrollPage -> render(viewState)
is ArticlesScreenViewState.SomeError -> render(viewState) is ArticlesScreenViewState.SomeError -> render(viewState)
} }
} }
...@@ -122,6 +139,13 @@ class ArticlesScreenController : ...@@ -122,6 +139,13 @@ class ArticlesScreenController :
} }
private fun render(viewState: ArticlesScreenViewState.ArticlesScrollPage){
Timber.d("got items: ${viewState.items.size}")
(articlesRecyclerView.adapter as ArticlesAdapter).addItems(viewState.items)
}
private fun render(viewState: ArticlesScreenViewState.ArticlesLoaded) { private fun render(viewState: ArticlesScreenViewState.ArticlesLoaded) {
progressBar.setGone(true) progressBar.setGone(true)
emptyListNotice.setGone(true) emptyListNotice.setGone(true)
......
...@@ -14,6 +14,8 @@ import javax.inject.Named ...@@ -14,6 +14,8 @@ import javax.inject.Named
* Created by Vladislav Bogdashkin on 30.09.2019. * Created by Vladislav Bogdashkin on 30.09.2019.
*/ */
private const val FEED_PAGE_SIZE = 10
class ArticlesScreenPresenter @Inject constructor( class ArticlesScreenPresenter @Inject constructor(
@Named(FEED_ALIAS) private val feedId:String, @Named(FEED_ALIAS) private val feedId:String,
...@@ -31,8 +33,18 @@ class ArticlesScreenPresenter @Inject constructor( ...@@ -31,8 +33,18 @@ class ArticlesScreenPresenter @Inject constructor(
.map<ArticlesScreenViewState>{ ArticlesScreenViewState.ArticlesLoaded(it.articles) } .map<ArticlesScreenViewState>{ ArticlesScreenViewState.ArticlesLoaded(it.articles) }
.startWith(Observable.just<ArticlesScreenViewState>(ArticlesScreenViewState.Idle())) .startWith(Observable.just<ArticlesScreenViewState>(ArticlesScreenViewState.Idle()))
val getNewArticlesPage = intent(ArticlesScreen::requsetsNewArticles)
.flatMap { interactor.fetchArticlesPage(feedId, FEED_PAGE_SIZE,it) }
.map<ArticlesScreenViewState> {
// restoreModel.articles = it.articles
Timber.d("arrived list: ${it.articles.size}")
ArticlesScreenViewState.ArticlesScrollPage(it.articles.toList())
}
.onErrorReturn (::parseError)
val state = restoreStateObservable val state = restoreStateObservable
.mergeWith(prefetchCards) .mergeWith(prefetchCards)
.mergeWith(getNewArticlesPage)
.doOnError{ Timber.e(it)} .doOnError{ Timber.e(it)}
.onErrorReturn(::parseError) .onErrorReturn(::parseError)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
......
...@@ -13,4 +13,5 @@ sealed class ArticlesScreenViewState : BigantoBaseViewState() { ...@@ -13,4 +13,5 @@ sealed class ArticlesScreenViewState : BigantoBaseViewState() {
class Idle : ArticlesScreenViewState() class Idle : ArticlesScreenViewState()
class ArticlesLoaded(val items: List<ArticlePreviewModel>) : ArticlesScreenViewState() class ArticlesLoaded(val items: List<ArticlePreviewModel>) : ArticlesScreenViewState()
class SomeError(val exception: ExceptionString) : ArticlesScreenViewState() class SomeError(val exception: ExceptionString) : ArticlesScreenViewState()
class ArticlesScrollPage(val items:List<ArticlePreviewModel>) : ArticlesScreenViewState()
} }
\ No newline at end of file
...@@ -96,9 +96,8 @@ class FeedsScreenController : ...@@ -96,9 +96,8 @@ class FeedsScreenController :
.filter { it == RecyclerView.SCROLL_STATE_IDLE} .filter { it == RecyclerView.SCROLL_STATE_IDLE}
.map { feedsRecyclerView.layoutManager as LinearLayoutManager } .map { feedsRecyclerView.layoutManager as LinearLayoutManager }
.map { it.findLastCompletelyVisibleItemPosition() } .map { it.findLastCompletelyVisibleItemPosition() }
.doOnNext { Timber.d("Visible items $it of ${(feedsRecyclerView.adapter?.itemCount?:0) - 3}") }
.filter{ storedFeedsList.isNotEmpty() } .filter{ storedFeedsList.isNotEmpty() }
.filter { it>(feedsRecyclerView.adapter?.itemCount?:0)-2 } .filter { it>(feedsRecyclerView.adapter?.itemCount?:0)-4 }
.map { feedsRecyclerView.adapter?.itemCount?:0 } .map { feedsRecyclerView.adapter?.itemCount?:0 }
.map { Pair(storedFeedsList[feedsTabs.selectedTabPosition],it)} .map { Pair(storedFeedsList[feedsTabs.selectedTabPosition],it)}
.debounce(120L,TimeUnit.MILLISECONDS) .debounce(120L,TimeUnit.MILLISECONDS)
......
...@@ -13,7 +13,7 @@ import javax.inject.Inject ...@@ -13,7 +13,7 @@ import javax.inject.Inject
* Created by Vladislav Bogdashkin on 30.09.2019. * Created by Vladislav Bogdashkin on 30.09.2019.
*/ */
const val FEED_PREVIEW_PAGE_SIZE = 10 private const val FEED_PREVIEW_PAGE_SIZE = 10
class FeedsScreenPresenter @Inject constructor( class FeedsScreenPresenter @Inject constructor(
private val interactor: FeedsInteractor private val interactor: FeedsInteractor
......
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