Commit f7c49ad2 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

move prefetch sizes into dialog

parent 5f48d403
package com.biganto.visual.roompark.conductor.dialogs
import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.ImageView
import androidx.annotation.LayoutRes
import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.base.BaseRoomParkActivity
import com.biganto.visual.roompark.base.RoomParkApplication
import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.conductor.dialogs.change_handler.DialogChangeHandler
import com.biganto.visual.roompark.data.repository.file.FileModule
import com.biganto.visual.roompark.di.dagger.ActivityModule
import com.biganto.visual.roompark.di.dagger.AppComponent
import com.biganto.visual.roompark.di.dagger.PerScreen
import com.biganto.visual.roompark.domain.interactor.SettingsInteractor
import com.biganto.visual.roompark.domain.model.bytesToSize
import com.biganto.visual.roompark.util.view_utils.snackbar.ISnackBarProvider
import com.bluelinelabs.conductor.Controller
import com.bluelinelabs.conductor.RouterTransaction
import com.google.android.material.textview.MaterialTextView
import com.jakewharton.rxbinding3.view.clicks
import dagger.Binds
import dagger.BindsInstance
import dagger.Component
import dagger.Module
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import timber.log.Timber
import java.util.concurrent.TimeUnit
import javax.inject.Inject
/**
* Created by Vladislav Bogdashkin on 09.04.2019.
*/
private const val TYPICAL_PLAN_SIZE = (1.2f*1024L*1024L).toLong()
class StartPlansDownloadingDialogController : Controller {
constructor() : super()
constructor(args: Bundle) : super(args)
private val detachDisposable = CompositeDisposable()
override fun onDetach(view: View) {
detachDisposable.clear()
super.onDetach(view)
}
@Inject
lateinit var interactor: SettingsInteractor
@Inject
lateinit var file: FileModule
lateinit var snackbar: ISnackBarProvider
@Inject
lateinit var rpActivity: RoomParkMainActivity
override fun onContextAvailable(context: Context) {
super.onContextAvailable(context)
DaggerStartPlansDownloadingDialogScreenComponent.factory()
.create(RoomParkApplication.component,activity as RoomParkMainActivity)
.inject(this)
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup): View {
val view = inflater.inflate(getLayoutId(), container, false)
snackbar = ActivityModule.provideSnackBar(rpActivity)
file.freeSpace.bytesToSize().let {
view.findViewById<MaterialTextView>(R.id.disk_size_textView)
.text = resources?.getString(R.string.download_all_tours_disk_size_title,it)
}
view.findViewById<Button>(R.id.alert_dismiss_button)
.setOnClickListener { handleBack() }
view.findViewById<ImageView>(R.id.close_current_button)
.setOnClickListener { handleBack() }
detachDisposable.add(
interactor.fetchPlanTypesSizes()
.observeOn(AndroidSchedulers.mainThread())
.subscribe ({
view.findViewById<MaterialTextView>(R.id.all_tours_size_textView)
.text = resources?.getString(R.string.download_all_plans_size_title
,(it* TYPICAL_PLAN_SIZE).bytesToSize())
},
{err ->
Timber.e(err)
snackbar.showSnackBar(R.string.download_all_plans_errors_snackbar_message)
})
)
detachDisposable.add(
view.findViewById<Button>(R.id.alert_ok_button)
.clicks()
.debounce(200, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe {
router.replaceTopController(
RouterTransaction.with(DownloadPlansDialogController())
.pushChangeHandler(DialogChangeHandler())
.popChangeHandler(DialogChangeHandler())
)
}
)
view.findViewById<View>(R.id.close_current_button).setOnClickListener { handleBack() }
// view.setOnClickListener { handleBack() }
return view
}
@LayoutRes
fun getLayoutId() = R.layout.tours_download_dialog_screen
override fun handleBack(): Boolean {
return router.popCurrentController()
}
}
@PerScreen
@Component(
modules = [StartPlansDownloadingDialogScreenModule::class],
dependencies = [AppComponent::class])
interface StartPlansDownloadingDialogScreenComponent {
@Component.Factory
interface Factory{
fun create(
appComponent: AppComponent
,@BindsInstance activity: RoomParkMainActivity
): StartPlansDownloadingDialogScreenComponent
}
fun inject(controller: StartPlansDownloadingDialogController)
}
@Module
abstract class StartPlansDownloadingDialogScreenModule{
@PerScreen
@Binds
abstract fun provideActivity(activity: RoomParkMainActivity): BaseRoomParkActivity
}
......@@ -38,13 +38,11 @@ import javax.inject.Inject
* Created by Vladislav Bogdashkin on 09.04.2019.
*/
private const val TOTAL_SIZE_DOWNLOAD_KEY = "TOURS_TO_DOWNLOAD_OVERALL_SIZE"
class StartToursDownloadingDialogController : Controller {
constructor(args: Bundle) : super(args)
constructor(size:Long) : super( Bundle().apply { putLong(TOTAL_SIZE_DOWNLOAD_KEY,size) } )
constructor():super()
constructor(args: Bundle):super(args)
private val detachDisposable = CompositeDisposable()
......@@ -80,11 +78,6 @@ class StartToursDownloadingDialogController : Controller {
snackbar = ActivityModule.provideSnackBar(rpActivity)
args.getLong(TOTAL_SIZE_DOWNLOAD_KEY).let {
view.findViewById<MaterialTextView>(R.id.all_tours_size_textView)
.text = resources?.getString(R.string.download_all_tours_size_title,it.bytesToSize())
}
file.freeSpace.bytesToSize().let {
view.findViewById<MaterialTextView>(R.id.disk_size_textView)
.text = resources?.getString(R.string.download_all_tours_disk_size_title,it)
......@@ -96,6 +89,16 @@ class StartToursDownloadingDialogController : Controller {
view.findViewById<ImageView>(R.id.close_current_button)
.setOnClickListener { handleBack() }
detachDisposable.add(
downloader.fetchToursSizes()
.observeOn(AndroidSchedulers.mainThread())
.subscribe {
view.findViewById<MaterialTextView>(R.id.all_tours_size_textView)
.text = resources?.getString(R.string.download_all_tours_size_title
,it.bytesToSize())
}
)
detachDisposable.add(
view.findViewById<Button>(R.id.alert_ok_button)
.clicks()
......
......@@ -13,14 +13,13 @@ import com.biganto.visual.roompark.base.HeaderToolbarModel
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.conductor.dialogs.DownloadPlansDialogController
import com.biganto.visual.roompark.conductor.dialogs.StartPlansDownloadingDialogController
import com.biganto.visual.roompark.conductor.dialogs.change_handler.DialogChangeHandler
import com.biganto.visual.roompark.conductor.dialogs.tour_chooser.StartToursDownloadingDialogController
import com.biganto.visual.roompark.domain.model.SubscriptionModel
import com.biganto.visual.roompark.presentation.screen.settings.util.CahcedListAdapter
import com.biganto.visual.roompark.presentation.screen.settings.util.PushListAdapter
import com.biganto.visual.roompark.presentation.screen.splash.SplashScreenController
import com.biganto.visual.roompark.util.extensions.bytesToSize
import com.biganto.visual.roompark.util.extensions.setGone
import com.biganto.visual.roompark.util.monades.ExceptionString
import com.bluelinelabs.conductor.RouterTransaction
......@@ -112,7 +111,7 @@ class SettingsScreenController :
@OnClick(R.id.downloadFlatCardsIcon)
fun onStartTourPlans(){
router.pushController(RouterTransaction.with(DownloadPlansDialogController())
router.pushController(RouterTransaction.with(StartPlansDownloadingDialogController())
.pushChangeHandler(DialogChangeHandler())
.popChangeHandler(DialogChangeHandler())
)
......@@ -132,13 +131,12 @@ class SettingsScreenController :
@OnClick(R.id.downloadToursIcon)
fun startDownloadingDialog(){
router.pushController(RouterTransaction.with(StartToursDownloadingDialogController(tempToursSize))
router.pushController(RouterTransaction.with(StartToursDownloadingDialogController())
.pushChangeHandler(DialogChangeHandler())
.popChangeHandler(DialogChangeHandler())
)
}
private var tempToursSize = 0L
private fun bindRecycler(){
pushRecycler.isNestedScrollingEnabled = true
......@@ -157,14 +155,6 @@ class SettingsScreenController :
override fun onViewBound(v: View) {
bottomNavigationController.show()
toursDownloaderTitle.text =
resources
?.getString(R.string.download_all_tours_settings_with_size, "-")
flatDownloaderTitle.text =
resources
?.getString(R.string.download_all_plan_types_settings_with_sizes, "-")
setToolbar()
bindRecycler()
}
......@@ -195,23 +185,6 @@ class SettingsScreenController :
clearCacheButton.setGone(false)
}
private fun render(viewState: SettingsScreenViewState.OnSizePrefetch) {
tempToursSize = viewState.size
toursDownloaderTitle.text =
resources?.getString(
R.string.download_all_tours_settings_with_size
, viewState.size.bytesToSize()
)
}
private fun render(viewState: SettingsScreenViewState.OnPlanTypesPrefetch) {
flatDownloaderTitle.text =
resources?.getString(
R.string.download_all_plan_types_settings_with_sizes
, viewState.size.bytesToSize()
)
}
private fun render(viewState: SettingsScreenViewState.LoadSubscriptions){
(pushRecycler.adapter as PushListAdapter).setItems(viewState.list)
}
......
......@@ -6,7 +6,6 @@ import com.biganto.visual.roompark.domain.interactor.SettingsInteractor
import com.biganto.visual.roompark.domain.model.CachedDataModel
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
......@@ -18,8 +17,6 @@ import javax.inject.Inject
* Created by Vladislav Bogdashkin on 30.09.2019.
*/
private const val TYPICAL_PLAN_SIZE = (1.2f*1024L*1024L).toLong()
class SettingsScreenPresenter @Inject constructor(
private val interactor: SettingsInteractor,
private val activity: BaseRoomParkActivity
......@@ -37,23 +34,23 @@ class SettingsScreenPresenter @Inject constructor(
override fun defaultErrorViewStateHandler() =
{ e: ExceptionString -> SettingsScreenViewState.SomeError(e) }
private val cacheSizeRefresher = PublishRelay.create<Int>()
private val cahcObs =
cacheSizeRefresher.flatMap {
Observable.merge(
arrayListOf(
fetchToursSize, fetchPlansSize
)
)
}
// private val cacheSizeRefresher = PublishRelay.create<Int>()
private val fetchToursSize: Observable<SettingsScreenViewState> = interactor.fetchToursSizes()
.map { SettingsScreenViewState.OnSizePrefetch(it) }
// private val cahcObs =
// cacheSizeRefresher.flatMap {
// Observable.merge(
// arrayListOf(
// fetchToursSize, fetchPlansSize
// )
// )
// }
private val fetchPlansSize: Observable<SettingsScreenViewState> = interactor.fetchPlanTypesSizes()
.map { it* TYPICAL_PLAN_SIZE }
.map { SettingsScreenViewState.OnPlanTypesPrefetch(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() {
......@@ -82,7 +79,7 @@ class SettingsScreenPresenter @Inject constructor(
.doOnNext { cached -> cached.sortBy { it.id } }
.doOnNext { restoreModel.cacheInfo = it }
.map { SettingsScreenViewState.LoadCachInfo(it) }
.doOnNext {cacheSizeRefresher.accept(1) }
// .doOnNext {cacheSizeRefresher.accept(1) }
val fetchSubscriptions = interactor.getSubscriptions()
.map {list ->
......@@ -107,8 +104,8 @@ class SettingsScreenPresenter @Inject constructor(
.map<SettingsScreenViewState> {
Timber.d(" got progress: ${it.first} / ${it.second.toFloat()}")
if (it.first == it.second)
cacheSizeRefresher.accept(1)
// if (it.first == it.second)
// cacheSizeRefresher.accept(1)
SettingsScreenViewState.OnCacheDeleting(
it.first / it.second.toFloat()
......@@ -124,7 +121,7 @@ class SettingsScreenPresenter @Inject constructor(
val state = Observable.mergeDelayError(
arrayListOf(
restoreStateObservable,
cahcObs,
// cahcObs,
// fetchPlansSize,
fetchSettings,
onSignOut,
......
......@@ -40,7 +40,7 @@
<string name="api_error_2001">Тур не найден!</string>
<string name="api_error_default">Неизвестная ошибка сервера!</string>
<string name="no_network_error">No network!</string>
<string name="no_network_error">Нет сети!</string>
<string name="unknown_error">Unexpected error!</string>
<string name="cant_load_item_error">Can\'t load item!</string>
<string name="object_not_found_error">Object not found!</string>
......@@ -128,16 +128,18 @@
<string name="game_view_content_description" />
<string name="download_all_tours_settings_with_size">Скачать виртуальные туры моих квартир из избранного и сделок (%s)</string>
<string name="download_all_plan_types_settings_with_sizes">Скачать карточки моих квартир из избранного и сделок (%s)</string>
<string name="download_all_tours_settings_with_size">Скачать виртуальные туры моих квартир из избранного и сделок</string>
<string name="download_all_plan_types_settings_with_sizes">Скачать карточки моих квартир из избранного и сделок</string>
<string name="plan_types_download_completed">Загрузка планов завершена.</string>
<string name="download_plan_types_screen_title">Cкачиваются планировки</string>
<string name="download_all_tours_notice_text">Загрузить все туры?</string>
<string name="download_all_tours_size_title">Размер всех туров: %s</string>
<string name="download_all_plans_size_title">Размер всех планировок: %s</string>
<string name="download_all_tours_disk_size_title">Размер свободного места на диске: %s</string>
<string name="download_all_tours_yes_action">Скачать</string>
<string name="download_all_tours_cancel_action">Отмена</string>
<string name="download_all_tours_errors_snackbar_message">Ошибка при попытке загрузить туры!</string>
<string name="download_all_plans_errors_snackbar_message">Ошибка при попытке загрузить планировки!</string>
<string name="download_all_tours_start_snackbar_message">Загрузка туров началась!</string>
</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