Commit 3c99913b authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

on sub chagned for article list

parent 30f6e216
package com.biganto.visual.roompark.domain.interactor
import com.biganto.visual.roompark.domain.model.SubscriptionModel
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.SubscriptionUseCase
import io.reactivex.Completable
import javax.inject.Inject
/**
......@@ -23,6 +25,12 @@ class ArticlesInteractor @Inject constructor(
fun getSubscriptions(feed: String) =
subUc.getSubscriptions(feedSubType(feed))
fun switchSubscription(model:SubscriptionModel,newState: Boolean): Completable =
when(newState){
true -> subUc.subscribeTopic(model.id,model.topic)
false -> subUc.unSubscribeTopic(model.id,model.topic)
}.ignoreElements()
private fun feedSubType(feed:String) =
when(feed){
"news" -> SubscriptionTopic.News()
......
......@@ -9,5 +9,6 @@ import io.reactivex.Observable
interface ArticlesScreen : BigantoBaseContract<ArticlesScreenViewState> {
fun requsetsNewArticles(): Observable<Int>
fun feedSubscription(): Observable<Boolean>
}
......@@ -20,6 +20,7 @@ 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 com.jakewharton.rxbinding3.widget.checkedChanges
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import timber.log.Timber
......@@ -54,6 +55,13 @@ class ArticlesScreenController :
.debounce(120L, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
override fun feedSubscription(): Observable<Boolean> =
toolBar.headerToolbar.findViewById<SwitchMaterial>(R.id.switch1).checkedChanges()
.debounce(600L, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
override fun injectDependencies() {
getComponent()
}
......@@ -143,6 +151,7 @@ class ArticlesScreenController :
}
private fun render(viewState: ArticlesScreenViewState.SubscriptionStatus) {
Timber.d("got state: ${viewState.subState}")
toolBar.headerToolbar.findViewById<SwitchMaterial>(R.id.switch1).isChecked =
viewState.subState
}
......
......@@ -37,6 +37,13 @@ class ArticlesScreenPresenter @Inject constructor(
override fun bindIntents() {
Timber.d("feedId : $feedId")
val onSubChecked = intent(ArticlesScreen::feedSubscription)
.flatMap { newState ->
interactor.switchSubscription(restoreModel.sub!!,newState)
.andThen(Observable.just<ArticlesScreenViewState>(ArticlesScreenViewState.SubscriptionStatus(newState)))
}
val prefetchCards = interactor.fetchArticles(feedId)
.map<ArticlesScreenViewState> { ArticlesScreenViewState.ArticlesLoaded(it.articles) }
.startWith(Observable.just<ArticlesScreenViewState>(ArticlesScreenViewState.Idle()))
......@@ -63,6 +70,7 @@ class ArticlesScreenPresenter @Inject constructor(
.mergeWith(prefetchCards)
.mergeWith(getNewArticlesPage)
.mergeWith(fetchSubscription)
.mergeWith(onSubChecked)
.doOnError { Timber.e(it) }
.onErrorReturn(::parseError)
.subscribeOn(Schedulers.io())
......
......@@ -40,7 +40,6 @@ class ArticleViewHolder(itemView: View) : CommonViewHolder<ArticlePreviewModel>(
override fun onViewBound(model: ArticlePreviewModel) {
Timber.d("readeed?: ${model.isRead} of ${model.title}")
articleDate.text = dateFormatter.format(model.published)
articleTitle.text = model.title
articleIsRead.setGone(model.isRead)
......
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