Commit 18718e87 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

fetch articles

parent 4ad06ff2
...@@ -117,6 +117,7 @@ dependencies { ...@@ -117,6 +117,7 @@ dependencies {
//RxBinding //RxBinding
implementation "com.jakewharton.rxbinding3:rxbinding:$rxBindingVersion" implementation "com.jakewharton.rxbinding3:rxbinding:$rxBindingVersion"
implementation "com.jakewharton.rxbinding3:rxbinding-recyclerview:$rxBindingVersion" implementation "com.jakewharton.rxbinding3:rxbinding-recyclerview:$rxBindingVersion"
implementation "com.jakewharton.rxbinding3:rxbinding-material:$rxBindingVersion"
//Tests //Tests
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
......
package com.biganto.visual.roompark.presentation.screen.feeds package com.biganto.visual.roompark.presentation.screen.feeds
import com.biganto.visual.roompark.conductor.BigantoBaseContract import com.biganto.visual.roompark.conductor.BigantoBaseContract
import io.reactivex.Observable
/** /**
* Created by Vladislav Bogdashkin on 30.09.2019. * Created by Vladislav Bogdashkin on 30.09.2019.
*/ */
interface FeedsScreen : BigantoBaseContract<FeedsScreenViewState> { interface FeedsScreen : BigantoBaseContract<FeedsScreenViewState> {
fun feedsTabSelected(): Observable<Int>
} }
...@@ -7,9 +7,12 @@ import com.biganto.visual.roompark.R ...@@ -7,9 +7,12 @@ import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.base.RoomParkApplication import com.biganto.visual.roompark.base.RoomParkApplication
import com.biganto.visual.roompark.base.RoomParkMainActivity import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.conductor.BigantoBaseController import com.biganto.visual.roompark.conductor.BigantoBaseController
import com.biganto.visual.roompark.presentation.screen.feeds.utils.FeedsPagerAdapter import com.biganto.visual.roompark.domain.model.FeedModel
import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayout
import com.jakewharton.rxbinding3.material.selections
import io.reactivex.Observable
import timber.log.Timber import timber.log.Timber
import java.util.concurrent.TimeUnit
import javax.inject.Inject import javax.inject.Inject
/** /**
...@@ -22,6 +25,12 @@ class FeedsScreenController : ...@@ -22,6 +25,12 @@ class FeedsScreenController :
, FeedsScreenPresenter>() , FeedsScreenPresenter>()
, FeedsScreen { , FeedsScreen {
override fun feedsTabSelected(): Observable<Int>
= feedsTabs.selections().map { it.position }
.debounce (200L, TimeUnit.MILLISECONDS)
.map { storedFeedsList[it].feedId }
override fun injectDependencies() { override fun injectDependencies() {
getComponent() getComponent()
} }
...@@ -29,7 +38,8 @@ class FeedsScreenController : ...@@ -29,7 +38,8 @@ class FeedsScreenController :
@BindView(R.id.feedsTabs) @BindView(R.id.feedsTabs)
lateinit var feedsTabs:TabLayout lateinit var feedsTabs:TabLayout
val feedsAdapter = FeedsPagerAdapter()
private var storedFeedsList:List<FeedModel> = arrayListOf()
@Inject @Inject
override lateinit var injectedPresenter: FeedsScreenPresenter override lateinit var injectedPresenter: FeedsScreenPresenter
...@@ -45,6 +55,7 @@ class FeedsScreenController : ...@@ -45,6 +55,7 @@ class FeedsScreenController :
when(viewState){ when(viewState){
is FeedsScreenViewState.Idle -> render(viewState) is FeedsScreenViewState.Idle -> render(viewState)
is FeedsScreenViewState.FeedsPages -> render(viewState) is FeedsScreenViewState.FeedsPages -> render(viewState)
is FeedsScreenViewState.GetFeedArticlesPreview -> render(viewState)
} }
} }
...@@ -68,7 +79,12 @@ class FeedsScreenController : ...@@ -68,7 +79,12 @@ class FeedsScreenController :
} }
feedsTabs.addTab(tab) feedsTabs.addTab(tab)
} }
storedFeedsList = viewState.items
}
private fun render(viewState: FeedsScreenViewState.GetFeedArticlesPreview){
snackbar.showSnackBar(viewState.items.first().announce)
} }
private fun getComponent() = DaggerFeedsScreenComponent.factory() private fun getComponent() = DaggerFeedsScreenComponent.factory()
......
...@@ -23,8 +23,13 @@ class FeedsScreenPresenter @Inject constructor( ...@@ -23,8 +23,13 @@ class FeedsScreenPresenter @Inject constructor(
val fetchFeeds = interactor.fetchTopFeeds() val fetchFeeds = interactor.fetchTopFeeds()
.map {FeedsScreenViewState.FeedsPages(it.feeds.toList()) } .map {FeedsScreenViewState.FeedsPages(it.feeds.toList()) }
val getFeedArticlesPreview = intent(FeedsScreen::feedsTabSelected)
.flatMapSingle { interactor.fetchArticles(it) }
.map { FeedsScreenViewState.GetFeedArticlesPreview(it.articles.toList()) }
val state = restoreStateObservable val state = restoreStateObservable
.mergeWith(fetchFeeds) .mergeWith(fetchFeeds)
.mergeWith(getFeedArticlesPreview)
.doOnError{ Timber.e(it)} .doOnError{ Timber.e(it)}
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
......
package com.biganto.visual.roompark.presentation.screen.feeds package com.biganto.visual.roompark.presentation.screen.feeds
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.FeedModel import com.biganto.visual.roompark.domain.model.FeedModel
/** /**
...@@ -11,4 +12,5 @@ import com.biganto.visual.roompark.domain.model.FeedModel ...@@ -11,4 +12,5 @@ import com.biganto.visual.roompark.domain.model.FeedModel
sealed class FeedsScreenViewState : BigantoBaseViewState() { sealed class FeedsScreenViewState : BigantoBaseViewState() {
class Idle : FeedsScreenViewState() class Idle : FeedsScreenViewState()
class FeedsPages(val items:List<FeedModel>) : FeedsScreenViewState() class FeedsPages(val items:List<FeedModel>) : FeedsScreenViewState()
class GetFeedArticlesPreview(val items:List<ArticlePreviewModel>) : FeedsScreenViewState()
} }
\ No newline at end of file
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignEnd="@id/tab_title" android:layout_alignEnd="@id/tab_title"
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="@string/feeds_tab_divider" android:text="@string/feeds_tab_divider"
android:textColor="@color/colorInvertedNoticeText" android:textColor="@color/colorInvertedNoticeText"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
......
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