Commit 0c8af564 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

fix subscription status ui check

parent 0f60e406
...@@ -118,6 +118,7 @@ class ArticleScreenController : ...@@ -118,6 +118,7 @@ class ArticleScreenController :
when(viewState){ when(viewState){
is ArticleScreenViewState.Idle -> render(viewState) is ArticleScreenViewState.Idle -> render(viewState)
is ArticleScreenViewState.ArticleLoaded -> render(viewState) is ArticleScreenViewState.ArticleLoaded -> render(viewState)
is ArticleScreenViewState.SomeError -> render(viewState)
} }
} }
...@@ -125,6 +126,10 @@ class ArticleScreenController : ...@@ -125,6 +126,10 @@ class ArticleScreenController :
} }
private fun render(viewState: ArticleScreenViewState.SomeError) {
showError(viewState.error)
}
private fun render(viewState: ArticleScreenViewState.ArticleLoaded) { private fun render(viewState: ArticleScreenViewState.ArticleLoaded) {
title.text = viewState.item.title title.text = viewState.item.title
......
...@@ -20,6 +20,7 @@ class ArticleScreenPresenter @Inject constructor( ...@@ -20,6 +20,7 @@ class ArticleScreenPresenter @Inject constructor(
@Named(ARTICLE_SCREEN_ARTICLEID) private val selectedArticleId:Int @Named(ARTICLE_SCREEN_ARTICLEID) private val selectedArticleId:Int
) )
: BigantoBasePresenter<ArticleScreen, ArticleScreenViewState>() { : BigantoBasePresenter<ArticleScreen, ArticleScreenViewState>() {
override fun defaultErrorViewStateHandler() = override fun defaultErrorViewStateHandler() =
{e:ExceptionString -> ArticleScreenViewState.SomeError(e)} {e:ExceptionString -> ArticleScreenViewState.SomeError(e)}
...@@ -37,6 +38,7 @@ class ArticleScreenPresenter @Inject constructor( ...@@ -37,6 +38,7 @@ class ArticleScreenPresenter @Inject constructor(
.mergeWith(prefetchCards) .mergeWith(prefetchCards)
.mergeWith(setRead) .mergeWith(setRead)
.doOnError{ Timber.e(it)} .doOnError{ Timber.e(it)}
.onErrorReturn(::parseError)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
......
...@@ -15,6 +15,7 @@ import com.biganto.visual.roompark.conductor.BigantoBaseController ...@@ -15,6 +15,7 @@ import com.biganto.visual.roompark.conductor.BigantoBaseController
import com.biganto.visual.roompark.presentation.screen.article.ArticleScreenController import com.biganto.visual.roompark.presentation.screen.article.ArticleScreenController
import com.biganto.visual.roompark.presentation.screen.feed_list.util.ArticlesAdapter import com.biganto.visual.roompark.presentation.screen.feed_list.util.ArticlesAdapter
import com.biganto.visual.roompark.util.extensions.setGone import com.biganto.visual.roompark.util.extensions.setGone
import com.biganto.visual.roompark.util.monades.ExceptionString
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.switchmaterial.SwitchMaterial
...@@ -56,10 +57,23 @@ class ArticlesScreenController : ...@@ -56,10 +57,23 @@ class ArticlesScreenController :
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
override fun feedSubscription(): Observable<Boolean> = override fun feedSubscription(): Observable<Boolean> =
toolBar.headerToolbar.findViewById<SwitchMaterial>(R.id.switch1).checkedChanges() toolBar.headerToolbar.findViewById<SwitchMaterial>(R.id.switch1)
.checkedChanges()
.filter { Timber.d("silentCheck: $silentCheck")
if (!silentCheck) return@filter !silentCheck
else silentCheck = false
silentCheck
}
.doOnNext { }
.debounce(600L, TimeUnit.MILLISECONDS) .debounce(600L, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
private var silentCheck = true
set(value) {
Timber.d("silent value: old: $field new $value")
field = value
}
override fun injectDependencies() { override fun injectDependencies() {
...@@ -136,6 +150,7 @@ class ArticlesScreenController : ...@@ -136,6 +150,7 @@ class ArticlesScreenController :
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) is ArticlesScreenViewState.SubscriptionStatus -> render(viewState)
is ArticlesScreenViewState.SubscriptionError -> render(viewState)
} }
} }
...@@ -151,11 +166,28 @@ class ArticlesScreenController : ...@@ -151,11 +166,28 @@ class ArticlesScreenController :
} }
private fun render(viewState: ArticlesScreenViewState.SubscriptionStatus) { private fun render(viewState: ArticlesScreenViewState.SubscriptionStatus) {
Timber.d("got state: ${viewState.subState}") val sw = toolBar.headerToolbar.findViewById<SwitchMaterial>(R.id.switch1)
toolBar.headerToolbar.findViewById<SwitchMaterial>(R.id.switch1).isChecked = if (sw.isChecked != viewState.subState)
viewState.subState {
silentCheck = true
sw.isChecked != sw.isChecked
}
}
private fun render(viewState: ArticlesScreenViewState.SubscriptionError) {
val sw = toolBar.headerToolbar.findViewById<SwitchMaterial>(R.id.switch1)
if (sw.isChecked != viewState.subState)
{
silentCheck = true
} }
sw.isChecked = viewState.subState
if (viewState.subState)
showError(ExceptionString(R.string.unsubscribe_error_message,null))
else showError(ExceptionString(R.string.subscribe_error_message,null))
}
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}")
......
...@@ -38,11 +38,12 @@ class ArticlesScreenPresenter @Inject constructor( ...@@ -38,11 +38,12 @@ class ArticlesScreenPresenter @Inject constructor(
Timber.d("feedId : $feedId") Timber.d("feedId : $feedId")
val onSubChecked = intent(ArticlesScreen::feedSubscription) val onSubChecked = intent(ArticlesScreen::feedSubscription)
.skip(1) // .skip(1)
.filter { restoreModel.sub!=null } .filter { restoreModel.sub!=null }
.flatMap { newState -> .flatMap { newState ->
interactor.switchSubscription(restoreModel.sub!!,newState) interactor.switchSubscription(restoreModel.sub!!,newState)
.andThen(Observable.just<ArticlesScreenViewState>(ArticlesScreenViewState.SubscriptionStatus(newState))) .andThen(Observable.just<ArticlesScreenViewState>(ArticlesScreenViewState.SubscriptionStatus(newState)))
.onErrorReturn { ArticlesScreenViewState.SubscriptionError(!newState) }
} }
...@@ -51,7 +52,8 @@ class ArticlesScreenPresenter @Inject constructor( ...@@ -51,7 +52,8 @@ class ArticlesScreenPresenter @Inject constructor(
.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()
...@@ -61,6 +63,7 @@ class ArticlesScreenPresenter @Inject constructor( ...@@ -61,6 +63,7 @@ class ArticlesScreenPresenter @Inject constructor(
ArticlesScreenViewState.ArticlesScrollPage(articlePage.articles.toList()) ArticlesScreenViewState.ArticlesScrollPage(articlePage.articles.toList())
} }
.onErrorReturn(::parseError) .onErrorReturn(::parseError)
}
val fetchSubscription = interactor.getSubscriptions(feedId) val fetchSubscription = interactor.getSubscriptions(feedId)
.doOnNext { Timber.w("got smthng: $it") } .doOnNext { Timber.w("got smthng: $it") }
......
...@@ -17,6 +17,7 @@ sealed class ArticlesScreenViewState : BigantoBaseViewState() { ...@@ -17,6 +17,7 @@ sealed class ArticlesScreenViewState : BigantoBaseViewState() {
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() class SubscriptionStatus(val subState: Boolean) : ArticlesScreenViewState()
class SubscriptionError(val subState: Boolean) : ArticlesScreenViewState()
} }
......
...@@ -92,6 +92,8 @@ ...@@ -92,6 +92,8 @@
<string name="tour_not_allowed">Запуск туров пока недоступен!</string> <string name="tour_not_allowed">Запуск туров пока недоступен!</string>
<string name="content_description_close">Close</string> <string name="content_description_close">Close</string>
<string name="share_house_photo">Поделиться изображением</string> <string name="share_house_photo">Поделиться изображением</string>
<string name="unsubscribe_error_message">При попытке отписаться произошла ошибка!</string>
<string name="subscribe_error_message">Ошибка! Подписаться не удалось!</string>
<!--endregion--> <!--endregion-->
</resources> </resources>
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