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

sub state to view

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