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