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

fetch articles

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