Commit 463ed781 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

cache update info etc

parent d9a1127f
...@@ -28,6 +28,7 @@ import dagger.Component ...@@ -28,6 +28,7 @@ import dagger.Component
import dagger.Module import dagger.Module
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import timber.log.Timber import timber.log.Timber
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import javax.inject.Inject import javax.inject.Inject
...@@ -43,7 +44,7 @@ class StartToursDownloadingDialogController : Controller { ...@@ -43,7 +44,7 @@ class StartToursDownloadingDialogController : Controller {
constructor(args: Bundle) : super(args) constructor(args: Bundle) : super(args)
constructor(size:Long) : super(Bundle().apply { putLong(TOTAL_SIZE_DOWNLOAD_KEY,size) } ) constructor(size:Long) : super( Bundle().apply { putLong(TOTAL_SIZE_DOWNLOAD_KEY,size) } )
private val detachDisposable = CompositeDisposable() private val detachDisposable = CompositeDisposable()
...@@ -98,10 +99,20 @@ class StartToursDownloadingDialogController : Controller { ...@@ -98,10 +99,20 @@ class StartToursDownloadingDialogController : Controller {
detachDisposable.add( detachDisposable.add(
view.findViewById<Button>(R.id.alert_ok_button) view.findViewById<Button>(R.id.alert_ok_button)
.clicks() .clicks()
.debounce(200,TimeUnit.MILLISECONDS) .debounce(200, TimeUnit.MILLISECONDS)
.observeOn(
Schedulers.io())
.flatMap{ downloader.startToursDownloading()
// .subscribeOn(Schedulers.computation())
.doOnComplete { Timber.d(" C ") }
}
.doOnComplete { Timber.d(" X ") }
// .subscribeOn(AndroidSchedulers.mainThread())
.doOnComplete { Timber.d(" Xss ") }
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.flatMapCompletable { downloader.startToursDownloading() }
.subscribe ({ .subscribe ({
Timber.d(" SUBSCRIBER ")
snackbar.showSnackBar(R.string.download_all_tours_start_snackbar_message) snackbar.showSnackBar(R.string.download_all_tours_start_snackbar_message)
handleBack() handleBack()
},{ },{
...@@ -112,8 +123,8 @@ class StartToursDownloadingDialogController : Controller { ...@@ -112,8 +123,8 @@ class StartToursDownloadingDialogController : Controller {
) )
) )
// view.findViewById<View>(R.id.close_current_button).setOnClickListener { handleBack() } view.findViewById<View>(R.id.close_current_button).setOnClickListener { handleBack() }
view.setOnClickListener { handleBack() } // view.setOnClickListener { handleBack() }
return view return view
} }
......
...@@ -67,14 +67,19 @@ class SettingsInteractor @Inject constructor( ...@@ -67,14 +67,19 @@ class SettingsInteractor @Inject constructor(
} }
} }
fun startToursDownloading(): Completable = fun startToursDownloading() =
toursUc.downloadAllDeelsAndEstates() toursUc.downloadAllDeelsAndEstates()
.doOnNext { Timber.d(" gonna startService") } .doOnNext { Timber.d(" gonna startService") }
.doOnNext { this.startDownloadService() } .doOnNext { this.startDownloadService() }
.delay(100,TimeUnit.MILLISECONDS) .delay(100,TimeUnit.MILLISECONDS)
.doOnNext { Timber.d(" gonna startServic222e") }
.doOnNext { tours -> .doOnNext { tours ->
startDownloadService(tours.map { tour -> tour.id }) startDownloadService(tours.map { tour -> tour.id })
}.ignoreElements() }
.doOnNext { Timber.d(" gonna startServsdfsfdsice") }
// .doOnComplete { Timber.w(" azzaza complete") }
fun getSubscriptions() = fun getSubscriptions() =
......
...@@ -132,9 +132,9 @@ class SettingsScreenController : ...@@ -132,9 +132,9 @@ class SettingsScreenController :
@OnClick(R.id.downloadToursIcon) @OnClick(R.id.downloadToursIcon)
fun startDownloadingDialog(){ fun startDownloadingDialog(){
router.setRoot(RouterTransaction.with(StartToursDownloadingDialogController(tempToursSize)) router.pushController(RouterTransaction.with(StartToursDownloadingDialogController(tempToursSize))
.pushChangeHandler(FadeChangeHandler()) .pushChangeHandler(DialogChangeHandler())
.popChangeHandler(FadeChangeHandler()) .popChangeHandler(DialogChangeHandler())
) )
} }
......
...@@ -7,6 +7,7 @@ import com.biganto.visual.roompark.domain.model.CachedDataModel ...@@ -7,6 +7,7 @@ import com.biganto.visual.roompark.domain.model.CachedDataModel
import com.biganto.visual.roompark.domain.model.SubscriptionModel import com.biganto.visual.roompark.domain.model.SubscriptionModel
import com.biganto.visual.roompark.domain.model.TitledSubscriptionModel import com.biganto.visual.roompark.domain.model.TitledSubscriptionModel
import com.biganto.visual.roompark.util.monades.ExceptionString import com.biganto.visual.roompark.util.monades.ExceptionString
import com.jakewharton.rxrelay2.PublishRelay
import io.reactivex.Observable import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
...@@ -37,15 +38,27 @@ class SettingsScreenPresenter @Inject constructor( ...@@ -37,15 +38,27 @@ class SettingsScreenPresenter @Inject constructor(
override fun defaultErrorViewStateHandler() = override fun defaultErrorViewStateHandler() =
{ e: ExceptionString -> SettingsScreenViewState.SomeError(e) } { e: ExceptionString -> SettingsScreenViewState.SomeError(e) }
override fun bindIntents() { private val cacheSizeRefresher = PublishRelay.create<Int>()
val fetchToursSize = interactor.fetchToursSizes() private val cahcObs =
cacheSizeRefresher.flatMap {
Observable.merge(
arrayListOf(
fetchToursSize, fetchPlansSize
)
)
}
private val fetchToursSize: Observable<SettingsScreenViewState> = interactor.fetchToursSizes()
.map { SettingsScreenViewState.OnSizePrefetch(it) } .map { SettingsScreenViewState.OnSizePrefetch(it) }
val fetchPlansSize = interactor.fetchPlanTypesSizes() private val fetchPlansSize: Observable<SettingsScreenViewState> = interactor.fetchPlanTypesSizes()
.map { it* TYPICAL_PLAN_SIZE } .map { it* TYPICAL_PLAN_SIZE }
.map { SettingsScreenViewState.OnPlanTypesPrefetch(it) } .map { SettingsScreenViewState.OnPlanTypesPrefetch(it) }
override fun bindIntents() {
// val onDownloadTours = intent(SettingsScreen::downloadAllTours) // val onDownloadTours = intent(SettingsScreen::downloadAllTours)
// .flatMap { interactor.startToursDownloading() // .flatMap { interactor.startToursDownloading()
// .andThen(Observable.just(SettingsScreenViewState.Idle())) // .andThen(Observable.just(SettingsScreenViewState.Idle()))
...@@ -88,6 +101,7 @@ class SettingsScreenPresenter @Inject constructor( ...@@ -88,6 +101,7 @@ class SettingsScreenPresenter @Inject constructor(
.doOnNext { cached -> cached.sortBy { it.id } } .doOnNext { cached -> cached.sortBy { it.id } }
.doOnNext { restoreModel.cacheInfo = it } .doOnNext { restoreModel.cacheInfo = it }
.map { SettingsScreenViewState.LoadCachInfo(it) } .map { SettingsScreenViewState.LoadCachInfo(it) }
.doOnNext {cacheSizeRefresher.accept(1) }
val fetchSubscriptions = interactor.getSubscriptions() val fetchSubscriptions = interactor.getSubscriptions()
.doOnNext { restoreModel.subs = it.toMutableList() } .doOnNext { restoreModel.subs = it.toMutableList() }
...@@ -109,28 +123,35 @@ class SettingsScreenPresenter @Inject constructor( ...@@ -109,28 +123,35 @@ class SettingsScreenPresenter @Inject constructor(
interactor.deleteCacheFiles() interactor.deleteCacheFiles()
.map<SettingsScreenViewState> { .map<SettingsScreenViewState> {
Timber.d(" got progress: ${it.first} / ${it.second.toFloat()}") Timber.d(" got progress: ${it.first} / ${it.second.toFloat()}")
if (it.first == it.second)
cacheSizeRefresher.accept(1)
SettingsScreenViewState.OnCacheDeleting( SettingsScreenViewState.OnCacheDeleting(
it.first / it.second.toFloat() it.first / it.second.toFloat()
) )
} }
.delay(600,TimeUnit.MILLISECONDS) .delay(600,TimeUnit.MILLISECONDS)
.startWith(SettingsScreenViewState.OnCacheDeleting(0f)) .startWith(SettingsScreenViewState.OnCacheDeleting(0f))
.doOnError { Timber.e(it) } .doOnError { Timber.e(it) }
.subscribeOn(Schedulers.io())
} }
val state = Observable.mergeDelayError( val state = Observable.mergeDelayError(
arrayListOf( arrayListOf(
restoreStateObservable, restoreStateObservable,
fetchPlansSize, cahcObs,
// fetchPlansSize,
fetchSettings, fetchSettings,
onSignOut, onSignOut,
onClearCache, onClearCache,
refreshInfo, refreshInfo,
fetchSubscriptions, fetchSubscriptions,
fetchCache, fetchCache,
onSubChecked, onSubChecked
// onDownloadTours, // onDownloadTours,
fetchToursSize // fetchToursSize
) )
) )
.doOnError { Timber.e(it) } .doOnError { Timber.e(it) }
......
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="8dp"
android:orientation="vertical"> android:orientation="vertical">
<com.google.android.material.textview.MaterialTextView <com.google.android.material.textview.MaterialTextView
...@@ -40,8 +42,6 @@ ...@@ -40,8 +42,6 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="2dp" android:layout_margin="2dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:text="@string/download_all_tours_size_title" /> android:text="@string/download_all_tours_size_title" />
...@@ -51,8 +51,6 @@ ...@@ -51,8 +51,6 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="2dp" android:layout_margin="2dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:text="@string/download_all_tours_disk_size_title" /> android:text="@string/download_all_tours_disk_size_title" />
<LinearLayout <LinearLayout
......
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