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

fix pagination request index

parent 12e9333a
...@@ -47,16 +47,20 @@ class FeedsContractModule @Inject constructor( ...@@ -47,16 +47,20 @@ class FeedsContractModule @Inject constructor(
private fun fetchArticlessApi(feedId:Int,pageSize:Int, startIndex:Int): Observable<List<ArticleEntity>>? { private fun fetchArticlessApi(feedId:Int,pageSize:Int, startIndex:Int): Observable<List<ArticleEntity>>? {
val feed = db.getFeed(feedId)?.firstOrNull() val feed = db.getFeed(feedId).firstOrNull()
if (feed == null) { if (feed == null) {
e("Unknown feedId: $feedId - cann't resolve feed_alias!") e("Unknown feedId: $feedId - cann't resolve feed_alias!")
throw CustomApiException.UnknownCustomApiException(-1,null,"Unknown Feed!") throw CustomApiException.UnknownCustomApiException(-1,null,"Unknown Feed!")
} }
else { else {
return api.getArticlesPage(feed.alias, pageSize, floor(startIndex.toDouble()/pageSize.toDouble()).toInt()) Timber.d("page index: " +
"${startIndex.toDouble()/pageSize.toDouble()} -- -" +
"${floor(startIndex.toDouble()/pageSize.toDouble()).toInt()+1}")
return api.getArticlesPage(feed.alias, pageSize, floor(startIndex.toDouble()/pageSize.toDouble()).toInt()+1)
.doOnNext { Timber.d("raw0 $it") } .doOnNext { Timber.d("raw0 $it") }
.map { it.items } .map { it.items }
.map { fromRaw(it, feedId) } .map { fromRaw(it, feedId) }
.doOnNext { Timber.d("raw enitites $it") }
.doOnNext(db::blockingUpsert) .doOnNext(db::blockingUpsert)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
} }
...@@ -64,13 +68,15 @@ class FeedsContractModule @Inject constructor( ...@@ -64,13 +68,15 @@ class FeedsContractModule @Inject constructor(
private fun fetchArticlesDb(feedId:Int,pageSize:Int, startIndex:Int): Observable<MutableList<ArticleEntity>>? { private fun fetchArticlesDb(feedId:Int,pageSize:Int, startIndex:Int): Observable<MutableList<ArticleEntity>>? {
val feed = db.getFeed(feedId)?.firstOrNull() val feed = db.getFeed(feedId).firstOrNull()
Timber.d("db startindex: $startIndex")
if (feed == null) { if (feed == null) {
e("Unknown feedId: $feedId - cann't resolve feed_alias!") e("Unknown feedId: $feedId - cann't resolve feed_alias!")
throw CustomApiException.UnknownCustomApiException(-1, null, "Unknown Feed!") throw CustomApiException.UnknownCustomApiException(-1, null, "Unknown Feed!")
} else return db.fetchArticles(feed.alias, pageSize, startIndex) } else return db.fetchArticles(feed.alias, pageSize, startIndex)
.toList() .toList()
.toObservable() .toObservable()
.doOnNext { Timber.d("db items: ${it.size}") }
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
} }
......
...@@ -33,9 +33,9 @@ class UserSessionService @Inject constructor( ...@@ -33,9 +33,9 @@ class UserSessionService @Inject constructor(
local.recentUserObs() local.recentUserObs()
.doOnNext { Timber.w("got new user $it") } .doOnNext { Timber.w("got new user $it") }
.flatMap { db.userObservableResult(it.toInt()) .flatMap { db.userObservableResult(it.toInt())
?.doOnNext { Timber.w("obs db user $it") } .doOnNext { Timber.w("obs db user $it") }
?.flatMap{ reactiveResult -> reactiveResult.observable() .flatMap{ reactiveResult -> reactiveResult.observable()
?.doOnNext { Timber.w("flatmapUser db user $it") } } .doOnNext { Timber.w("flatmapUser db user $it") } }
} }
.doOnNext { Timber.w("subscribe user $it") } .doOnNext { Timber.w("subscribe user $it") }
.subscribe { _token = it.authToken } .subscribe { _token = it.authToken }
......
...@@ -20,7 +20,13 @@ data class ArticlePreviewModel( ...@@ -20,7 +20,13 @@ data class ArticlePreviewModel(
val announce:String, val announce:String,
val previewUrl:String, val previewUrl:String,
val isRead:Boolean val isRead:Boolean
) ){
override fun equals(other: Any?): Boolean {
if (other is ArticlePreviewModel)
return this.articleId == other.articleId
return super.equals(other)
}
}
data class ArticlesPreviewModel(val parentFeedId:Int,val articles:List<ArticlePreviewModel>) data class ArticlesPreviewModel(val parentFeedId:Int,val articles:List<ArticlePreviewModel>)
......
...@@ -181,6 +181,7 @@ class FeedsScreenController : ...@@ -181,6 +181,7 @@ class FeedsScreenController :
} }
private fun render(viewState: FeedsScreenViewState.ArticlesScrollPage){ private fun render(viewState: FeedsScreenViewState.ArticlesScrollPage){
Timber.d("got items: ${viewState.items.size}")
(feedsRecyclerView.adapter as ArticlesPreviewAdapter).addItems(viewState.items) (feedsRecyclerView.adapter as ArticlesPreviewAdapter).addItems(viewState.items)
} }
......
...@@ -77,6 +77,7 @@ class FeedsScreenPresenter @Inject constructor( ...@@ -77,6 +77,7 @@ class FeedsScreenPresenter @Inject constructor(
.flatMap { interactor.fetchArticles(it.first.feedId, FEED_PREVIEW_PAGE_SIZE,it.second) } .flatMap { interactor.fetchArticles(it.first.feedId, FEED_PREVIEW_PAGE_SIZE,it.second) }
.map<FeedsScreenViewState> { .map<FeedsScreenViewState> {
restoreModel.articles = it.articles restoreModel.articles = it.articles
Timber.d("arrived list: ${it.articles.size}")
FeedsScreenViewState.ArticlesScrollPage(it.articles.toList()) FeedsScreenViewState.ArticlesScrollPage(it.articles.toList())
} }
.onErrorReturn (::parseError) .onErrorReturn (::parseError)
......
...@@ -34,16 +34,19 @@ abstract class CommonRecyclerAdapter<VH:CommonViewHolder<M>,M:Any> : RecyclerVie ...@@ -34,16 +34,19 @@ abstract class CommonRecyclerAdapter<VH:CommonViewHolder<M>,M:Any> : RecyclerVie
private var list: MutableList<M> = mutableListOf() private var list: MutableList<M> = mutableListOf()
fun setItems(list:List<M>){ fun setItems(items:List<M>){
this.list.clear() this.list.clear()
this.list.addAll(list) this.list.addAll(items)
notifyDataSetChanged() notifyDataSetChanged()
} }
fun addItems(items:List<M>){ fun addItems(items:List<M>){
this.list.addAll(list) items.asSequence().filter { !list.contains(it) }.toList().let {uniqueItems->
notifyItemRangeInserted(list.size-items.size,items.size) this.list.addAll(uniqueItems)
notifyItemRangeInserted(list.size-uniqueItems.size,uniqueItems.size)
} }
}
protected abstract val vhKlazz : KClass<VH> protected abstract val vhKlazz : KClass<VH>
......
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