Commit 991bfac7 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

provide cached info into setings presenter

parent 16ec499c
package com.biganto.visual.roompark.domain.interactor package com.biganto.visual.roompark.domain.interactor
import android.app.Activity
import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.domain.model.CachedDataModel import com.biganto.visual.roompark.domain.model.CachedDataModel
import com.biganto.visual.roompark.domain.model.PushSwitchModel import com.biganto.visual.roompark.domain.model.PushSwitchModel
import com.biganto.visual.roompark.domain.model.SettingsModel import com.biganto.visual.roompark.domain.model.SettingsModel
import com.biganto.visual.roompark.domain.use_case.AuthUseCase import com.biganto.visual.roompark.domain.use_case.AuthUseCase
import com.biganto.visual.roompark.domain.use_case.SettingsUseCase
import io.reactivex.Observable import io.reactivex.Observable
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
import javax.inject.Inject import javax.inject.Inject
...@@ -13,9 +16,39 @@ import javax.inject.Inject ...@@ -13,9 +16,39 @@ import javax.inject.Inject
*/ */
class SettingsInteractor @Inject constructor( class SettingsInteractor @Inject constructor(
private val auth: AuthUseCase private val auth: AuthUseCase,
private val settingsUseCase: SettingsUseCase,
private val activity: Activity
){ ){
private val plans
get() = settingsUseCase.planTypesSize.map {
CachedDataModel(activity.resources.getString(R.string.plans_cache),it,1)
}
private val tours
get() = settingsUseCase.toursSize.map {
CachedDataModel(activity.resources.getString(R.string.tours_cache),it,2)
}
private val feeds
get() = settingsUseCase.feedsSize.map {
CachedDataModel(activity.resources.getString(R.string.feeds_cache),it,3)
}
private val albums
get() = settingsUseCase.albumsSize.map {
CachedDataModel(activity.resources.getString(R.string.albums_cache),it,4)
}
private val overall
get() = settingsUseCase.overallSize.map {
CachedDataModel(activity.resources.getString(R.string.overall_cache),it,0)
}
fun getCacheInfo() =
Observable.concatArray(plans, tours, feeds, albums, overall).toList().toObservable()
fun fetchSettings(): Observable<SettingsModel> = Observable.just(sampleSettings) fun fetchSettings(): Observable<SettingsModel> = Observable.just(sampleSettings)
......
...@@ -20,6 +20,6 @@ data class CachedDataModel( ...@@ -20,6 +20,6 @@ data class CachedDataModel(
data class SettingsModel( data class SettingsModel(
val pushItems:List<PushSwitchModel>, val pushItems:List<PushSwitchModel>,
val offlineStoreData:List<CachedDataModel>, var offlineStoreData:List<CachedDataModel>,
val cachedData:List<CachedDataModel> val cachedData:List<CachedDataModel>
) )
\ No newline at end of file
package com.biganto.visual.roompark.domain.use_case package com.biganto.visual.roompark.domain.use_case
import com.biganto.visual.roompark.data.data_provider.AuthContractModule import com.biganto.visual.roompark.data.data_provider.AuthContractModule
import com.biganto.visual.roompark.domain.contract.FilesContract
import io.reactivex.Observable
import javax.inject.Inject import javax.inject.Inject
/** /**
...@@ -8,9 +10,25 @@ import javax.inject.Inject ...@@ -8,9 +10,25 @@ import javax.inject.Inject
*/ */
class SettingsUseCase @Inject constructor( class SettingsUseCase @Inject constructor(
private val authContract: AuthContractModule private val authContract: AuthContractModule,
private val fileContract: FilesContract
){ ){
fun signOut() = authContract.signOut() fun signOut() = authContract.signOut()
val planTypesSize
get() = Observable.just(fileContract.getPlansSize())
val albumsSize
get() = Observable.just(fileContract.getAlbumSize())
val feedsSize
get() = Observable.just(fileContract.getFeedSize())
val toursSize
get() = Observable.just(fileContract.getToursSize())
val overallSize
get() = Observable.just(fileContract.allCacheSize())
} }
\ No newline at end of file
package com.biganto.visual.roompark.presentation.screen.settings package com.biganto.visual.roompark.presentation.screen.settings
import android.app.Activity
import com.biganto.visual.roompark.conductor.BigantoBasePresenter import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.domain.interactor.SettingsInteractor import com.biganto.visual.roompark.domain.interactor.SettingsInteractor
import com.biganto.visual.roompark.util.monades.ExceptionString import com.biganto.visual.roompark.util.monades.ExceptionString
...@@ -15,7 +16,8 @@ import javax.inject.Inject ...@@ -15,7 +16,8 @@ import javax.inject.Inject
class SettingsScreenPresenter @Inject constructor( class SettingsScreenPresenter @Inject constructor(
private val interactor: SettingsInteractor private val interactor: SettingsInteractor,
private val activity: Activity
) )
: BigantoBasePresenter<SettingsScreen, SettingsScreenViewState>() { : BigantoBasePresenter<SettingsScreen, SettingsScreenViewState>() {
...@@ -25,6 +27,10 @@ class SettingsScreenPresenter @Inject constructor( ...@@ -25,6 +27,10 @@ class SettingsScreenPresenter @Inject constructor(
override fun bindIntents() { override fun bindIntents() {
val fetchSettings = interactor.fetchSettings() val fetchSettings = interactor.fetchSettings()
.flatMap {settings ->
interactor.getCacheInfo()
.doOnNext{ settings.offlineStoreData = it }
.map { settings }}
.map { SettingsScreenViewState.LoadSettingsList(it) } .map { SettingsScreenViewState.LoadSettingsList(it) }
val onSignOut = intent(SettingsScreen::signOut) val onSignOut = intent(SettingsScreen::signOut)
......
...@@ -12,6 +12,7 @@ import com.biganto.visual.roompark.util.monades.ExceptionString ...@@ -12,6 +12,7 @@ import com.biganto.visual.roompark.util.monades.ExceptionString
sealed class SettingsScreenViewState : BigantoBaseViewState() { sealed class SettingsScreenViewState : BigantoBaseViewState() {
class Idle : SettingsScreenViewState() class Idle : SettingsScreenViewState()
class LoadSettingsList(val settings:SettingsModel) : SettingsScreenViewState() class LoadSettingsList(val settings:SettingsModel) : SettingsScreenViewState()
// class LoadCachedInfo(val cached:SettingsModel) : SettingsScreenViewState()
class SomeError(val exception: ExceptionString) : SettingsScreenViewState() class SomeError(val exception: ExceptionString) : SettingsScreenViewState()
class SignOut() : SettingsScreenViewState() class SignOut() : SettingsScreenViewState()
} }
\ No newline at end of file
...@@ -71,6 +71,11 @@ ...@@ -71,6 +71,11 @@
<string name="discounted_price">Стоимость со скидкой</string> <string name="discounted_price">Стоимость со скидкой</string>
<string name="flat_not_found">В ЭТОМ ДОМЕ НЕТ КВАРТИРЫ С ТАКИМ НОМЕРОМ</string> <string name="flat_not_found">В ЭТОМ ДОМЕ НЕТ КВАРТИРЫ С ТАКИМ НОМЕРОМ</string>
<string name="flat_ready_to_watch">СМОТРЕТЬ</string> <string name="flat_ready_to_watch">СМОТРЕТЬ</string>
<string name="plans_cache">Карточки квартир</string>
<string name="tours_cache">Виртуальные туры</string>
<string name="feeds_cache">Новости и заметки</string>
<string name="albums_cache">Фотографии</string>
<string name="overall_cache">Всего скачано</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