Commit 109c5265 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

try to resolve custom scope within singleton

parent bba046fb
...@@ -25,7 +25,7 @@ class AlbumsContractModule @Inject constructor( ...@@ -25,7 +25,7 @@ class AlbumsContractModule @Inject constructor(
override fun getProgressCards(): Observable<List<AlbumPreviewModel>> = fetchTopLevelAlbums() override fun getProgressCards(): Observable<List<AlbumPreviewModel>> = fetchTopLevelAlbums()
override fun getProgressAlbumList(albumId: Int): Observable<List<AlbumPreviewModel>> = override fun getProgressAlbumList(albumId: Int): Observable<List<AlbumPreviewModel>> =
fetchTopLevelAlbums() fetchAlbums(albumId)
override fun getAlbumPhoto(photoId: Int): Observable<PhotoModel> { override fun getAlbumPhoto(photoId: Int): Observable<PhotoModel> {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
...@@ -65,7 +65,7 @@ class AlbumsContractModule @Inject constructor( ...@@ -65,7 +65,7 @@ class AlbumsContractModule @Inject constructor(
).take(1).map { fromEntity(it,::fromEntity) } ).take(1).map { fromEntity(it,::fromEntity) }
private fun fetchAlbums(parentAlbumId:Int) = private fun fetchAlbumsApi(parentAlbumId:Int) =
api.getAlbums(parentAlbumId) api.getAlbums(parentAlbumId)
.doOnNext { Timber.d("raw0 $it") } .doOnNext { Timber.d("raw0 $it") }
.map{ fromRawList(it,::fromRaw) } .map{ fromRawList(it,::fromRaw) }
...@@ -83,5 +83,16 @@ class AlbumsContractModule @Inject constructor( ...@@ -83,5 +83,16 @@ class AlbumsContractModule @Inject constructor(
} }
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
private fun fetchAlbumsDb(parentAlbumId:Int) =
db.getChildAlbums(parentAlbumId)
.toList()
.toObservable()
.subscribeOn(Schedulers.io())
private fun fetchAlbums(parentId:Int): Observable<List<AlbumPreviewModel>> =
Observable.mergeDelayError(
arrayListOf(fetchAlbumsApi(parentId),fetchAlbumsDb(parentId))
).take(1).map { fromEntity(it,::fromEntity) }
} }
...@@ -81,7 +81,7 @@ interface IRoomParkMobileApi{ ...@@ -81,7 +81,7 @@ interface IRoomParkMobileApi{
//region GetFavorites //region GetFavorites
const val GET_ARTICLES_PAGE_METHOD="news.getArticlesList" const val GET_ARTICLES_PAGE_METHOD="news.getArticlesList"
const val ARTICLES_PAGINATION_ALIAS_PARAM="feed_alias" const val ARTICLES_PAGINATION_ALIAS_PARAM="feed_alias"
const val ARTICLES_PAGINATION_PAGE_SIZE_PARAM="pagesize " const val ARTICLES_PAGINATION_PAGE_SIZE_PARAM="pagesize"
const val ARTICLES_PAGINATION_PAGE_PARAM="page" const val ARTICLES_PAGINATION_PAGE_PARAM="page"
//endregion //endregion
......
package com.biganto.visual.roompark.di.dagger package com.biganto.visual.roompark.di.dagger
import com.biganto.visual.roompark.base.RoomParkApplication import com.biganto.visual.roompark.base.RoomParkApplication
import com.biganto.visual.roompark.data.repository.api.IRoomParkApi
import com.biganto.visual.roompark.data.repository.api.retrofit.RetrofitRepository
import com.biganto.visual.roompark.data.repository.api.retrofit.di.RetrofitModule import com.biganto.visual.roompark.data.repository.api.retrofit.di.RetrofitModule
import com.biganto.visual.roompark.data.repository.db.requrey.DbModule import com.biganto.visual.roompark.data.repository.db.requrey.DbModule
import dagger.BindsInstance
import dagger.Component import dagger.Component
import dagger.android.AndroidInjectionModule import dagger.android.AndroidInjectionModule
import dagger.android.AndroidInjector import dagger.android.AndroidInjector
...@@ -11,6 +14,8 @@ import javax.inject.Singleton ...@@ -11,6 +14,8 @@ import javax.inject.Singleton
/** /**
* Created by Vladislav Bogdashkin on 13.06.2018. * Created by Vladislav Bogdashkin on 13.06.2018.
*/ */
...@@ -52,8 +57,12 @@ interface AppComponent : AndroidInjector<RoomParkApplication>{ ...@@ -52,8 +57,12 @@ interface AppComponent : AndroidInjector<RoomParkApplication>{
@BindsInstance
fun retroApi(api: RetrofitRepository) : IRoomParkApi
} }
// retorfitModule: RetrofitModule
// fun cache(): ICachedStore // fun cache(): ICachedStore
// fun context(): Context // fun context(): Context
......
...@@ -9,6 +9,7 @@ import com.biganto.visual.roompark.data.repository.db.requrey.RequeryRepository ...@@ -9,6 +9,7 @@ import com.biganto.visual.roompark.data.repository.db.requrey.RequeryRepository
import dagger.Binds import dagger.Binds
import dagger.Component import dagger.Component
import dagger.Module import dagger.Module
import javax.inject.Singleton
@Component @Component
interface DataComponent{ interface DataComponent{
...@@ -16,6 +17,8 @@ interface DataComponent{ ...@@ -16,6 +17,8 @@ interface DataComponent{
} }
@Module @Module
abstract class DataModule { abstract class DataModule {
...@@ -30,6 +33,7 @@ abstract class DataModule { ...@@ -30,6 +33,7 @@ abstract class DataModule {
// abstract fun provideRpRetrofit(retrofit:Retrofit) : Retrofit // abstract fun provideRpRetrofit(retrofit:Retrofit) : Retrofit
// //
@Singleton
@Binds @Binds
abstract fun provideRoomParkApi(api: RetrofitRepository) : IRoomParkApi abstract fun provideRoomParkApi(api: RetrofitRepository) : IRoomParkApi
......
package com.biganto.visual.roompark.domain.interactor package com.biganto.visual.roompark.domain.interactor
import com.biganto.visual.roompark.domain.model.* import com.biganto.visual.roompark.domain.model.*
import com.biganto.visual.roompark.domain.use_case.AlbumsUseCase
import com.biganto.visual.roompark.domain.use_case.FeedUseCase import com.biganto.visual.roompark.domain.use_case.FeedUseCase
import io.reactivex.Observable import io.reactivex.Observable
import io.reactivex.Single
import io.reactivex.schedulers.Schedulers
import java.util.* import java.util.*
import javax.inject.Inject import javax.inject.Inject
...@@ -13,7 +12,8 @@ import javax.inject.Inject ...@@ -13,7 +12,8 @@ import javax.inject.Inject
*/ */
class FeedsInteractor @Inject constructor( class FeedsInteractor @Inject constructor(
private val feedsUseCase:FeedUseCase private val feedsUseCase: FeedUseCase,
private val albumsUseCase: AlbumsUseCase
) { ) {
fun fetchTopFeeds(): Observable<FeedsHeaderModel> = fun fetchTopFeeds(): Observable<FeedsHeaderModel> =
...@@ -33,9 +33,10 @@ class FeedsInteractor @Inject constructor( ...@@ -33,9 +33,10 @@ class FeedsInteractor @Inject constructor(
fun fetchArticles(feedId: Int,pageSize:Int,startIndex:Int): Observable<ArticlesPreviewModel> = fun fetchArticles(feedId: Int,pageSize:Int,startIndex:Int): Observable<ArticlesPreviewModel> =
feedsUseCase.fetchArticlesPage(feedId,pageSize,startIndex) feedsUseCase.fetchArticlesPage(feedId,pageSize,startIndex)
fun fetchAlbums(): Single<List<AlbumPreviewModel>> = Single.just(albumsPreviews) fun fetchAlbums(): Observable<List<AlbumPreviewModel>> = albumsUseCase.getProgressAlbums()
fun fetchCams(): Single<WebCamListModel> = Single.just(camsList)
fun fetchCams(): Observable<WebCamListModel> = Observable.just(camsList)
companion object { companion object {
......
package com.biganto.visual.roompark.domain.use_case
import com.biganto.visual.roompark.data.data_provider.AlbumsContractModule
import javax.inject.Inject
/**
* Created by Vladislav Bogdashkin on 24.09.2019.
*/
class AlbumsUseCase @Inject constructor(
private val contract: AlbumsContractModule
){
fun getProgressAlbums() = contract.getProgressCards()
fun getChildAlbum(parentAlbumId:Int) =
contract.getProgressAlbumList(parentAlbumId)
}
\ No newline at end of file
...@@ -7,6 +7,7 @@ import com.biganto.visual.roompark.base.IBottomNavigation ...@@ -7,6 +7,7 @@ import com.biganto.visual.roompark.base.IBottomNavigation
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.di.dagger.CoreInjectHelper
import com.biganto.visual.roompark.presentation.screen.home.home_routing.HomeBottomNavigationController import com.biganto.visual.roompark.presentation.screen.home.home_routing.HomeBottomNavigationController
import com.bluelinelabs.conductor.RouterTransaction import com.bluelinelabs.conductor.RouterTransaction
import com.google.android.material.button.MaterialButton import com.google.android.material.button.MaterialButton
...@@ -92,7 +93,9 @@ class AuthScreenController : ...@@ -92,7 +93,9 @@ class AuthScreenController :
fun getComponent() = DaggerAuthScreenComponent fun getComponent() = DaggerAuthScreenComponent
.factory() .factory()
.create(RoomParkApplication.component,activity as RoomParkMainActivity) .create(
RoomParkApplication.component
,activity as RoomParkMainActivity)
.inject(this) .inject(this)
override fun render(viewState: AuthScreenViewState) { override fun render(viewState: AuthScreenViewState) {
......
...@@ -11,29 +11,25 @@ import com.biganto.visual.roompark.di.dagger.AppModule ...@@ -11,29 +11,25 @@ import com.biganto.visual.roompark.di.dagger.AppModule
import com.biganto.visual.roompark.di.dagger.DataModule import com.biganto.visual.roompark.di.dagger.DataModule
import com.biganto.visual.roompark.di.dagger.PerScreen import com.biganto.visual.roompark.di.dagger.PerScreen
import com.biganto.visual.roompark.domain.contract.AuthContract import com.biganto.visual.roompark.domain.contract.AuthContract
import dagger.Binds import dagger.*
import dagger.BindsInstance
import dagger.Component
import dagger.Module
@PerScreen @PerScreen
@Component( @Subcomponent(
modules = [ modules = [
AuthScreenModule::class AuthScreenModule::class
,DataModule::class ,DataModule::class
,RetrofitModule::class ,RetrofitModule::class
,AppModule::class ,AppModule::class
,DbModule::class ,DbModule::class
], ])
dependencies = [AppComponent::class])
interface AuthScreenComponent { interface AuthScreenComponent {
@Component.Factory @Component.Factory
interface Factory{ interface Factory{
fun create( fun create(
appComponent: AppComponent appComponent: AppComponent,
,@BindsInstance activity: RoomParkMainActivity @BindsInstance activity: RoomParkMainActivity
): AuthScreenComponent ): AuthScreenComponent
} }
......
...@@ -19,7 +19,6 @@ import com.bluelinelabs.conductor.RouterTransaction ...@@ -19,7 +19,6 @@ import com.bluelinelabs.conductor.RouterTransaction
import com.bluelinelabs.conductor.changehandler.FadeChangeHandler import com.bluelinelabs.conductor.changehandler.FadeChangeHandler
import com.google.android.material.button.MaterialButton import com.google.android.material.button.MaterialButton
import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayout
import com.google.android.material.textview.MaterialTextView
import com.jakewharton.rxbinding3.material.selections import com.jakewharton.rxbinding3.material.selections
import com.jakewharton.rxbinding3.recyclerview.scrollStateChanges import com.jakewharton.rxbinding3.recyclerview.scrollStateChanges
import com.jakewharton.rxbinding3.view.clicks import com.jakewharton.rxbinding3.view.clicks
...@@ -45,8 +44,7 @@ class FeedsScreenController : ...@@ -45,8 +44,7 @@ class FeedsScreenController :
.map { it.position } .map { it.position }
.map { storedFeedsList[it].feedId } .map { storedFeedsList[it].feedId }
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.doOnNext { feedsBlockView.findViewById<MaterialButton>(R.id.to_feed_articles) .doOnNext { allFeedArticles.text = "ВСЕ ${allFeedName(it)} →" }
.text = "ВСЕ ${allFeedName(it)} →" }
...@@ -70,7 +68,7 @@ class FeedsScreenController : ...@@ -70,7 +68,7 @@ class FeedsScreenController :
lateinit var feedsBlockView:ViewGroup lateinit var feedsBlockView:ViewGroup
@BindView(R.id.to_feed_articles) @BindView(R.id.to_feed_articles)
lateinit var allFeedArticles:MaterialTextView lateinit var allFeedArticles: MaterialButton
......
...@@ -39,44 +39,50 @@ class FeedsScreenPresenter @Inject constructor( ...@@ -39,44 +39,50 @@ class FeedsScreenPresenter @Inject constructor(
override fun bindIntents() { override fun bindIntents() {
val fetchCams = interactor.fetchCams() val fetchCams = interactor.fetchCams()
.map { .map <FeedsScreenViewState>{
restoreModel.cams = it.items restoreModel.cams = it.items
FeedsScreenViewState.CamsList(it.items) FeedsScreenViewState.CamsList(it.items)
} }
.onErrorReturn (::parseError)
val fetchAlbums = interactor.fetchAlbums() val fetchAlbums = interactor.fetchAlbums()
.map { .map <FeedsScreenViewState>{
restoreModel.albums = it restoreModel.albums = it
FeedsScreenViewState.AlbumsPages(it) FeedsScreenViewState.AlbumsPages(it)
} }
.onErrorReturn (::parseError)
val fetchFeeds = interactor.fetchTopFeeds() val fetchFeeds = interactor.fetchTopFeeds()
.map { .map <FeedsScreenViewState>{
restoreModel.feeds = it.feeds restoreModel.feeds = it.feeds
FeedsScreenViewState.FeedsPages(it.feeds.toList()) FeedsScreenViewState.FeedsPages(it.feeds.toList())
} }
.onErrorReturn (::parseError)
val getFeedArticlesPreview = intent(FeedsScreen::feedsTabSelected) val getFeedArticlesPreview = intent(FeedsScreen::feedsTabSelected)
.flatMap { interactor.fetchArticles(it) } .flatMap { interactor.fetchArticles(it) }
.map { .map<FeedsScreenViewState> {
restoreModel.articles = it.articles restoreModel.articles = it.articles
FeedsScreenViewState.GetFeedArticlesPreview(it.articles.toList()) FeedsScreenViewState.GetFeedArticlesPreview(it.articles.toList())
} }
.onErrorReturn (::parseError)
val switchToAllArtiles = intent(FeedsScreen::onAllFeedArticles) val switchToAllArtiles = intent(FeedsScreen::onAllFeedArticles)
.map { .map<FeedsScreenViewState> {
FeedsScreenViewState.ToArticlesScreen(it.feedId) FeedsScreenViewState.ToArticlesScreen(it.feedId)
} }
.onErrorReturn (::parseError)
val getNewArticlesPage = intent(FeedsScreen::requsetsNewArticles) val getNewArticlesPage = intent(FeedsScreen::requsetsNewArticles)
.flatMap { interactor.fetchArticles(it.first.feedId, FEED_PREVIEW_PAGE_SIZE,it.second) } .flatMap { interactor.fetchArticles(it.first.feedId, FEED_PREVIEW_PAGE_SIZE,it.second) }
.map { .map<FeedsScreenViewState> {
restoreModel.articles = it.articles restoreModel.articles = it.articles
FeedsScreenViewState.ArticlesScrollPage(it.articles.toList()) FeedsScreenViewState.ArticlesScrollPage(it.articles.toList())
} }
.onErrorReturn (::parseError)
val state = restoreStateObservable val state = restoreStateObservable
.mergeWith(fetchFeeds) // .mergeWith(fetchFeeds)
.mergeWith(getFeedArticlesPreview) .mergeWith(getFeedArticlesPreview)
.mergeWith(fetchAlbums) .mergeWith(fetchAlbums)
.mergeWith(fetchCams) .mergeWith(fetchCams)
......
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