Commit 2a134b93 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

sub state to view

parent ac3cacd0
......@@ -105,7 +105,7 @@ class RoomParkMainActivity(
headerToolbarBack.text = it.backTitle?:""
headerToolbar.toolbar_title.text = it.title?:""
headerToolbar.include13.setGone(!(it.switcher?:false))
headerToolbar.subsciption_switcher.setGone(!(it.switcher?:false))
}
status?.let {
statusToolbar.status_icon.setGone(it.state == null)
......
package com.biganto.visual.roompark.domain.interactor
import com.biganto.visual.roompark.domain.model.SubscriptionTopic
import com.biganto.visual.roompark.domain.use_case.FeedUseCase
import com.biganto.visual.roompark.domain.use_case.SubscriptionTopic
import com.biganto.visual.roompark.domain.use_case.SubscriptionUseCase
import javax.inject.Inject
......
......@@ -17,6 +17,7 @@ import com.biganto.visual.roompark.presentation.screen.feed_list.util.ArticlesAd
import com.biganto.visual.roompark.util.extensions.setGone
import com.biganto.visual.roompark.util.view_utils.grid.CeilsDecoration
import com.bluelinelabs.conductor.RouterTransaction
import com.google.android.material.switchmaterial.SwitchMaterial
import com.google.android.material.textview.MaterialTextView
import com.jakewharton.rxbinding3.recyclerview.scrollStateChanges
import io.reactivex.Observable
......@@ -70,6 +71,7 @@ class ArticlesScreenController :
lateinit var emptyListNotice: MaterialTextView
private fun setToolbar() {
articlesRecyclerView.isNestedScrollingEnabled = false
......@@ -125,6 +127,7 @@ class ArticlesScreenController :
is ArticlesScreenViewState.ArticlesScrollPage -> render(viewState)
is ArticlesScreenViewState.RestoreView -> render(viewState)
is ArticlesScreenViewState.SomeError -> render(viewState)
is ArticlesScreenViewState.SubscriptionStatus -> render(viewState)
}
}
......@@ -139,6 +142,11 @@ class ArticlesScreenController :
progressBar.setGone(true)
}
private fun render(viewState: ArticlesScreenViewState.SubscriptionStatus) {
toolBar.headerToolbar.findViewById<SwitchMaterial>(R.id.switch1).isChecked =
viewState.subState
}
private fun render(viewState: ArticlesScreenViewState.ArticlesScrollPage){
Timber.d("got items: ${viewState.items.size}")
......
......@@ -23,7 +23,7 @@ class ArticlesScreenPresenter @Inject constructor(
)
: BigantoBasePresenter<ArticlesScreen, ArticlesScreenViewState>() {
private val restoreModel = RestoreModel(mutableListOf())
private val restoreModel = RestoreModel(mutableListOf(), null)
override fun detachView() {
super.detachView()
......@@ -32,31 +32,38 @@ class ArticlesScreenPresenter @Inject constructor(
override fun defaultErrorViewStateHandler() =
{e: ExceptionString -> ArticlesScreenViewState.SomeError(e)}
{ e: ExceptionString -> ArticlesScreenViewState.SomeError(e) }
override fun bindIntents() {
Timber.d("feedId : $feedId")
val prefetchCards = interactor.fetchArticles(feedId)
.map<ArticlesScreenViewState>{ ArticlesScreenViewState.ArticlesLoaded(it.articles) }
.map<ArticlesScreenViewState> { ArticlesScreenViewState.ArticlesLoaded(it.articles) }
.startWith(Observable.just<ArticlesScreenViewState>(ArticlesScreenViewState.Idle()))
val getNewArticlesPage = intent(ArticlesScreen::requsetsNewArticles)
.flatMap { interactor.fetchArticlesPage(feedId, FEED_PAGE_SIZE,it) }
.map<ArticlesScreenViewState> {articlePage ->
.flatMap { interactor.fetchArticlesPage(feedId, FEED_PAGE_SIZE, it) }
.map<ArticlesScreenViewState> { articlePage ->
articlePage.articles
.asSequence()
.filter { !restoreModel.articles.contains(it) }
.toList()
.let {uniqueItems->restoreModel.articles.addAll(uniqueItems)}
.let { uniqueItems -> restoreModel.articles.addAll(uniqueItems) }
ArticlesScreenViewState.ArticlesScrollPage(articlePage.articles.toList())
}
.onErrorReturn (::parseError)
.onErrorReturn(::parseError)
val fetchSubscription = interactor.getSubscriptions(feedId)
.doAfterNext { restoreModel.sub = it }
.map<ArticlesScreenViewState> { ArticlesScreenViewState.SubscriptionStatus(it.state) }
.startWith(Observable.just<ArticlesScreenViewState>(ArticlesScreenViewState.Idle()))
val state = restoreStateObservable
.mergeWith(prefetchCards)
.mergeWith(getNewArticlesPage)
.doOnError{ Timber.e(it)}
.mergeWith(fetchSubscription)
.doOnError { Timber.e(it) }
.onErrorReturn(::parseError)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
......
......@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.feed_list
import com.biganto.visual.roompark.conductor.BigantoBaseViewState
import com.biganto.visual.roompark.domain.model.ArticlePreviewModel
import com.biganto.visual.roompark.domain.model.SubscriptionModel
import com.biganto.visual.roompark.util.monades.ExceptionString
/**
......@@ -15,9 +16,11 @@ sealed class ArticlesScreenViewState : BigantoBaseViewState() {
class SomeError(val exception: ExceptionString) : ArticlesScreenViewState()
class ArticlesScrollPage(val items:List<ArticlePreviewModel>) : ArticlesScreenViewState()
class RestoreView(val restore:RestoreModel) : ArticlesScreenViewState()
class SubscriptionStatus(val subState: Boolean) : ArticlesScreenViewState()
}
data class RestoreModel(
var articles:MutableList<ArticlePreviewModel>
var articles:MutableList<ArticlePreviewModel>,
var sub: SubscriptionModel?
)
\ No newline at end of file
......@@ -35,13 +35,12 @@
android:includeFontPadding="true"
android:textAlignment="gravity"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/include13"
app:layout_constraintEnd_toStartOf="@+id/subsciption_switcher"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="@id/back_button_chevron"
app:layout_constraintTop_toTopOf="parent" />
<include
android:id="@+id/include13"
layout="@layout/bell_switch_view"
android:layout_width="wrap_content"
......
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