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

fix pagination request index

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