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

cache update info etc

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