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

Merge branch 'feature/settings_impr' into develop

parents 5f48d403 ce1a143c
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 io.reactivex.schedulers.Schedulers
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)
view.findViewById<MaterialTextView>(R.id.download_dialog_title)
.text = resources?.getString(R.string.download_all_plans_notice_text)
view.findViewById<MaterialTextView>(R.id.all_tours_size_textView)
.text = resources?.getString(R.string.download_all_plans_size_title
,"0")
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()
.subscribeOn(Schedulers.io())
.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 ...@@ -38,13 +38,11 @@ import javax.inject.Inject
* Created by Vladislav Bogdashkin on 09.04.2019. * Created by Vladislav Bogdashkin on 09.04.2019.
*/ */
private const val TOTAL_SIZE_DOWNLOAD_KEY = "TOURS_TO_DOWNLOAD_OVERALL_SIZE"
class StartToursDownloadingDialogController : Controller { class StartToursDownloadingDialogController : Controller {
constructor(args: Bundle) : super(args) constructor():super()
constructor(args: Bundle):super(args)
constructor(size:Long) : super( Bundle().apply { putLong(TOTAL_SIZE_DOWNLOAD_KEY,size) } )
private val detachDisposable = CompositeDisposable() private val detachDisposable = CompositeDisposable()
...@@ -78,12 +76,15 @@ class StartToursDownloadingDialogController : Controller { ...@@ -78,12 +76,15 @@ class StartToursDownloadingDialogController : Controller {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup): View { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup): View {
val view = inflater.inflate(getLayoutId(), container, false) val view = inflater.inflate(getLayoutId(), container, false)
snackbar = ActivityModule.provideSnackBar(rpActivity)
args.getLong(TOTAL_SIZE_DOWNLOAD_KEY).let { view.findViewById<MaterialTextView>(R.id.download_dialog_title)
view.findViewById<MaterialTextView>(R.id.all_tours_size_textView) .text = resources?.getString(R.string.download_all_tours_notice_text)
.text = resources?.getString(R.string.download_all_tours_size_title,it.bytesToSize())
} view.findViewById<MaterialTextView>(R.id.all_tours_size_textView)
.text = resources?.getString(R.string.download_all_tours_size_title
,"0")
snackbar = ActivityModule.provideSnackBar(rpActivity)
file.freeSpace.bytesToSize().let { file.freeSpace.bytesToSize().let {
view.findViewById<MaterialTextView>(R.id.disk_size_textView) view.findViewById<MaterialTextView>(R.id.disk_size_textView)
...@@ -96,6 +97,17 @@ class StartToursDownloadingDialogController : Controller { ...@@ -96,6 +97,17 @@ class StartToursDownloadingDialogController : Controller {
view.findViewById<ImageView>(R.id.close_current_button) view.findViewById<ImageView>(R.id.close_current_button)
.setOnClickListener { handleBack() } .setOnClickListener { handleBack() }
detachDisposable.add(
downloader.fetchToursSizes()
.subscribeOn(Schedulers.io())
.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( detachDisposable.add(
view.findViewById<Button>(R.id.alert_ok_button) view.findViewById<Button>(R.id.alert_ok_button)
.clicks() .clicks()
......
...@@ -4,11 +4,13 @@ import com.biganto.visual.androidplayer.data.repository.local.ILocalStore ...@@ -4,11 +4,13 @@ import com.biganto.visual.androidplayer.data.repository.local.ILocalStore
import com.biganto.visual.roompark.data.local.UserState import com.biganto.visual.roompark.data.local.UserState
import com.biganto.visual.roompark.data.repository.api.room_park.IRoomParkApi import com.biganto.visual.roompark.data.repository.api.room_park.IRoomParkApi
import com.biganto.visual.roompark.data.repository.db.IDb import com.biganto.visual.roompark.data.repository.db.IDb
import com.biganto.visual.roompark.data.repository.db.requrey.model.SubscriptionEntity
import com.biganto.visual.roompark.data.repository.db.requrey.model.UserEntity import com.biganto.visual.roompark.data.repository.db.requrey.model.UserEntity
import com.biganto.visual.roompark.data.repository.mapper.fromRaw import com.biganto.visual.roompark.data.repository.mapper.fromRaw
import com.biganto.visual.roompark.domain.contract.AuthContract import com.biganto.visual.roompark.domain.contract.AuthContract
import com.biganto.visual.roompark.domain.custom_exception.CustomApiException import com.biganto.visual.roompark.domain.custom_exception.CustomApiException
import com.biganto.visual.roompark.domain.model.AuthInfoModel import com.biganto.visual.roompark.domain.model.AuthInfoModel
import com.biganto.visual.roompark.domain.model.SubscriptionTopic
import com.biganto.visual.roompark.domain.model.fromEntity import com.biganto.visual.roompark.domain.model.fromEntity
import io.reactivex.Completable import io.reactivex.Completable
import io.reactivex.Observable import io.reactivex.Observable
...@@ -37,6 +39,19 @@ class AuthContractModule @Inject constructor( ...@@ -37,6 +39,19 @@ class AuthContractModule @Inject constructor(
api.authenticate(email,password) api.authenticate(email,password)
.map ( ::fromRaw ) .map ( ::fromRaw )
.flatMap{ db.upsertUser(it) } .flatMap{ db.upsertUser(it) }
.flatMap {user ->
val userSubs = user.subscriptions?.map { it as SubscriptionEntity }
var newSubs = defaultSubsList(user)
if (!userSubs.isNullOrEmpty()){
newSubs = newSubs.filter {defSub ->
!userSubs.map { it.topic }.contains(defSub.topic)
}.toList()
}
if (newSubs.isNullOrEmpty()) return@flatMap Observable.just(user)
return@flatMap db.upsert(newSubs)
.toObservable()
.flatMap { db.refreshUser(user) }
}
.doOnNext{ Timber.d("user id: ${it.uuid}")} .doOnNext{ Timber.d("user id: ${it.uuid}")}
.doOnNext { local.setRecentUser(it.uuid.toString()).blockingAwait() } .doOnNext { local.setRecentUser(it.uuid.toString()).blockingAwait() }
.map(::fromEntity) .map(::fromEntity)
...@@ -60,3 +75,41 @@ class AuthContractModule @Inject constructor( ...@@ -60,3 +75,41 @@ class AuthContractModule @Inject constructor(
} } } }
} }
private fun defaultSubsList(owner:UserEntity) : List<SubscriptionEntity> = arrayListOf(
SubscriptionEntity().apply {
setTopic(SubscriptionTopic.Progress_1().topicName)
setOwner(owner)
setState(false)
}
,SubscriptionEntity().apply {
setTopic(SubscriptionTopic.Progress_2().topicName)
setOwner(owner)
setState(false)
}
,SubscriptionEntity().apply {
setTopic(SubscriptionTopic.Progress_3().topicName)
setOwner(owner)
setState(false)
}
,SubscriptionEntity().apply {
setTopic(SubscriptionTopic.Progress_kindergarden().topicName)
setOwner(owner)
setState(false)
}
,SubscriptionEntity().apply {
setTopic(SubscriptionTopic.News().topicName)
setOwner(owner)
setState(false)
}
,SubscriptionEntity().apply {
setTopic(SubscriptionTopic.Blog().topicName)
setOwner(owner)
setState(false)
}
,SubscriptionEntity().apply {
setTopic(SubscriptionTopic.Construction().topicName)
setOwner(owner)
setState(false)
}
)
\ No newline at end of file
...@@ -80,11 +80,15 @@ class SubscriptionRepository @Inject constructor( ...@@ -80,11 +80,15 @@ class SubscriptionRepository @Inject constructor(
cachedSub.setState(apiSub.active) cachedSub.setState(apiSub.active)
newSubList.add(cachedSub) newSubList.add(cachedSub)
} }
userSubs?.filter { !newSubList.map { s ->s.id }.contains(it.id) }?.toList()
?.let { userSubs?.filter { !newSubList.map { s ->s.id }.contains(it.id) }?.forEach {
Timber.w("to delete; ${it.size}") (it as SubscriptionEntity).setState(false)
db.deleteSubscriptions(it) }
}
userSubs?.forEach {s ->
if (newSubList.firstOrNull { s.topic == it.topic && s.number == it.number} == null)
newSubList.add(s as SubscriptionEntity)
}
return db.upsert(newSubList) return db.upsert(newSubList)
.map {list -> list.map { .map {list -> list.map {
......
...@@ -36,7 +36,7 @@ private const val TIMEOUT_SECONDS=120L ...@@ -36,7 +36,7 @@ private const val TIMEOUT_SECONDS=120L
private const val WRITE_SECONDS=120L private const val WRITE_SECONDS=120L
private const val READ_SECONDS=120L private const val READ_SECONDS=120L
val INTERCEPT_LOG_LEVEL = HttpLoggingInterceptor.Level.BODY val INTERCEPT_LOG_LEVEL = HttpLoggingInterceptor.Level.NONE
@Module @Module
class RetrofitModule{ class RetrofitModule{
......
...@@ -47,6 +47,8 @@ private const val META_PREDICTION="/tourMeta_" ...@@ -47,6 +47,8 @@ private const val META_PREDICTION="/tourMeta_"
private const val META_FILE_TYPE=".json" private const val META_FILE_TYPE=".json"
const val DOWNLOAD_MANAGER_COMMAND_KEY = "TOURS_DOWNLOAD_MANAGER_COMMAND" const val DOWNLOAD_MANAGER_COMMAND_KEY = "TOURS_DOWNLOAD_MANAGER_COMMAND"
const val DOWNLOAD_MANAGER_ADD_IDS_TO_LOAD_COMMAND = "ADD_TOUR_IDS_TO_QUEUE" const val DOWNLOAD_MANAGER_ADD_IDS_TO_LOAD_COMMAND = "ADD_TOUR_IDS_TO_QUEUE"
const val DOWNLOAD_MANAGER_STOP_COMMAND = "STOP_SERVICE"
@Singleton @Singleton
class DownloadManagerService @Inject constructor( class DownloadManagerService @Inject constructor(
...@@ -117,7 +119,24 @@ class DownloadManagerService @Inject constructor( ...@@ -117,7 +119,24 @@ class DownloadManagerService @Inject constructor(
return null return null
} }
override fun onStart(intent: Intent?, startId: Int) {
Timber.d("Got intent: $intent")
val v = intent?.extras?.getString(DOWNLOAD_MANAGER_COMMAND_KEY)
Timber.d("Got intent: $v")
if (v == DOWNLOAD_MANAGER_STOP_COMMAND){
Timber.d("Got DOWNLOAD_MANAGER_STOP_COMMAND")
disposable.clear()
stopSelf()
}
super.onStart(intent, startId)
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
val v = intent?.extras?.getString(DOWNLOAD_MANAGER_COMMAND_KEY)
if (v == DOWNLOAD_MANAGER_STOP_COMMAND){
disposable.clear()
stopSelf()
}
// Timber.d(" GOT INTENT $intent with action ${intent?.action}") // Timber.d(" GOT INTENT $intent with action ${intent?.action}")
// if (intent?.action == NOTIFICATION_INTENT_STOP_SERVICE_ACTION) // if (intent?.action == NOTIFICATION_INTENT_STOP_SERVICE_ACTION)
// { // {
......
...@@ -2,6 +2,8 @@ package com.biganto.visual.roompark.data.service.notification ...@@ -2,6 +2,8 @@ package com.biganto.visual.roompark.data.service.notification
import android.annotation.TargetApi import android.annotation.TargetApi
import android.app.* import android.app.*
import android.app.PendingIntent.FLAG_ONE_SHOT
import android.app.PendingIntent.FLAG_UPDATE_CURRENT
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.graphics.BitmapFactory import android.graphics.BitmapFactory
...@@ -11,6 +13,9 @@ import androidx.core.app.NotificationCompat ...@@ -11,6 +13,9 @@ import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import com.biganto.visual.roompark.R import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.base.RoomParkMainActivity import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.data.service.download.DOWNLOAD_MANAGER_COMMAND_KEY
import com.biganto.visual.roompark.data.service.download.DOWNLOAD_MANAGER_STOP_COMMAND
import com.biganto.visual.roompark.data.service.download.DownloadManagerService
import com.biganto.visual.roomparkvr.data.repository.db.requery.model.DownloadState import com.biganto.visual.roomparkvr.data.repository.db.requery.model.DownloadState
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
...@@ -135,7 +140,7 @@ class NotificationCenter @Inject constructor(val context: Application) : INotif ...@@ -135,7 +140,7 @@ class NotificationCenter @Inject constructor(val context: Application) : INotif
val pendingIntent = PendingIntent.getActivity(context val pendingIntent = PendingIntent.getActivity(context
, PENDING_REQUEST_CODE , PENDING_REQUEST_CODE
, toDownloadsIntent , toDownloadsIntent
, PendingIntent.FLAG_ONE_SHOT , FLAG_ONE_SHOT
) )
...@@ -160,36 +165,77 @@ class NotificationCenter @Inject constructor(val context: Application) : INotif ...@@ -160,36 +165,77 @@ class NotificationCenter @Inject constructor(val context: Application) : INotif
, noty) , noty)
} }
private val cancelServicePendingIntent: NotificationCompat.Action
by lazy {
val stopServiceIntent = Intent(context, DownloadManagerService::class.java)
stopServiceIntent.putExtra(DOWNLOAD_MANAGER_COMMAND_KEY, DOWNLOAD_MANAGER_STOP_COMMAND)
val pendingStopServiceIntent = PendingIntent.getService(context
, 546
, stopServiceIntent
, FLAG_UPDATE_CURRENT
)
NotificationCompat.Action.Builder(
R.drawable.ic_back,
"Отмена",
pendingStopServiceIntent).build()
}
override fun donwloadServiceProgressNotfication(progress:Int override fun donwloadServiceProgressNotfication(progress:Int
, progressMax:Int , progressMax:Int
, indeterminate:Boolean , indeterminate:Boolean
, message: String){ , message: String){
val pendingIntent = PendingIntent.getActivity(context
val b = (if (indeterminate) updateProgressNotificationIndeterminate
else updateProgressNotification)
b.setContentText(message)
b.setProgress(progress, progressMax,indeterminate)
actualNotifyManager.notify(
(if (indeterminate) DOWNLOAD_SERVICE_ID else TOUR_INFO_SERVICE_ID)
, b.build()
)
}
private val defPendingIntent by lazy {
PendingIntent.getActivity(context
, PENDING_REQUEST_CODE , PENDING_REQUEST_CODE
, toDownloadsIntent , toDownloadsIntent
, PendingIntent.FLAG_ONE_SHOT , FLAG_UPDATE_CURRENT
) )
}
private val updateProgressNotificationIndeterminate by lazy {
val notification = builder
(if (indeterminate) builder else toursNotyBuilder)
// builder
.setOnlyAlertOnce(true) .setOnlyAlertOnce(true)
.setContentTitle(context.getString(R.string.notification_content_title)) .setContentTitle(context.getString(R.string.notification_content_title))
.setContentText(message)
.setProgress(progress, progressMax,indeterminate)
.setSmallIcon(R.mipmap.ic_launcher) .setSmallIcon(R.mipmap.ic_launcher)
.setBadgeIconType(NotificationCompat.BADGE_ICON_LARGE) .setBadgeIconType(NotificationCompat.BADGE_ICON_LARGE)
.setColor(notificationSystemColor) .setColor(notificationSystemColor)
.setLargeIcon(icon) .setLargeIcon(icon)
.setContentIntent(pendingIntent) .setContentIntent(defPendingIntent)
.addAction(cancelServicePendingIntent)
.setAutoCancel(true) .setAutoCancel(true)
.build() }
actualNotifyManager.notify( private val updateProgressNotification by lazy {
(if (indeterminate) DOWNLOAD_SERVICE_ID else TOUR_INFO_SERVICE_ID) toursNotyBuilder
, notification) .setOnlyAlertOnce(true)
.setContentTitle(context.getString(R.string.notification_content_title))
.setSmallIcon(R.mipmap.ic_launcher)
.setBadgeIconType(NotificationCompat.BADGE_ICON_LARGE)
.setColor(notificationSystemColor)
.setLargeIcon(icon)
.setContentIntent(defPendingIntent)
.addAction(cancelServicePendingIntent)
.setAutoCancel(true)
} }
@TargetApi(Build.VERSION_CODES.O) @TargetApi(Build.VERSION_CODES.O)
......
...@@ -13,14 +13,13 @@ import com.biganto.visual.roompark.base.HeaderToolbarModel ...@@ -13,14 +13,13 @@ import com.biganto.visual.roompark.base.HeaderToolbarModel
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.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.change_handler.DialogChangeHandler
import com.biganto.visual.roompark.conductor.dialogs.tour_chooser.StartToursDownloadingDialogController import com.biganto.visual.roompark.conductor.dialogs.tour_chooser.StartToursDownloadingDialogController
import com.biganto.visual.roompark.domain.model.SubscriptionModel 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.CahcedListAdapter
import com.biganto.visual.roompark.presentation.screen.settings.util.PushListAdapter import com.biganto.visual.roompark.presentation.screen.settings.util.PushListAdapter
import com.biganto.visual.roompark.presentation.screen.splash.SplashScreenController 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.extensions.setGone
import com.biganto.visual.roompark.util.monades.ExceptionString import com.biganto.visual.roompark.util.monades.ExceptionString
import com.bluelinelabs.conductor.RouterTransaction import com.bluelinelabs.conductor.RouterTransaction
...@@ -112,7 +111,7 @@ class SettingsScreenController : ...@@ -112,7 +111,7 @@ class SettingsScreenController :
@OnClick(R.id.downloadFlatCardsIcon) @OnClick(R.id.downloadFlatCardsIcon)
fun onStartTourPlans(){ fun onStartTourPlans(){
router.pushController(RouterTransaction.with(DownloadPlansDialogController()) router.pushController(RouterTransaction.with(StartPlansDownloadingDialogController())
.pushChangeHandler(DialogChangeHandler()) .pushChangeHandler(DialogChangeHandler())
.popChangeHandler(DialogChangeHandler()) .popChangeHandler(DialogChangeHandler())
) )
...@@ -132,13 +131,12 @@ class SettingsScreenController : ...@@ -132,13 +131,12 @@ class SettingsScreenController :
@OnClick(R.id.downloadToursIcon) @OnClick(R.id.downloadToursIcon)
fun startDownloadingDialog(){ fun startDownloadingDialog(){
router.pushController(RouterTransaction.with(StartToursDownloadingDialogController(tempToursSize)) router.pushController(RouterTransaction.with(StartToursDownloadingDialogController())
.pushChangeHandler(DialogChangeHandler()) .pushChangeHandler(DialogChangeHandler())
.popChangeHandler(DialogChangeHandler()) .popChangeHandler(DialogChangeHandler())
) )
} }
private var tempToursSize = 0L
private fun bindRecycler(){ private fun bindRecycler(){
pushRecycler.isNestedScrollingEnabled = true pushRecycler.isNestedScrollingEnabled = true
...@@ -157,14 +155,6 @@ class SettingsScreenController : ...@@ -157,14 +155,6 @@ class SettingsScreenController :
override fun onViewBound(v: View) { override fun onViewBound(v: View) {
bottomNavigationController.show() 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() setToolbar()
bindRecycler() bindRecycler()
} }
...@@ -195,23 +185,6 @@ class SettingsScreenController : ...@@ -195,23 +185,6 @@ class SettingsScreenController :
clearCacheButton.setGone(false) 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){ private fun render(viewState: SettingsScreenViewState.LoadSubscriptions){
(pushRecycler.adapter as PushListAdapter).setItems(viewState.list) (pushRecycler.adapter as PushListAdapter).setItems(viewState.list)
} }
......
...@@ -6,7 +6,6 @@ import com.biganto.visual.roompark.domain.interactor.SettingsInteractor ...@@ -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.CachedDataModel
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
...@@ -18,8 +17,6 @@ import javax.inject.Inject ...@@ -18,8 +17,6 @@ import javax.inject.Inject
* Created by Vladislav Bogdashkin on 30.09.2019. * Created by Vladislav Bogdashkin on 30.09.2019.
*/ */
private const val TYPICAL_PLAN_SIZE = (1.2f*1024L*1024L).toLong()
class SettingsScreenPresenter @Inject constructor( class SettingsScreenPresenter @Inject constructor(
private val interactor: SettingsInteractor, private val interactor: SettingsInteractor,
private val activity: BaseRoomParkActivity private val activity: BaseRoomParkActivity
...@@ -37,23 +34,23 @@ class SettingsScreenPresenter @Inject constructor( ...@@ -37,23 +34,23 @@ class SettingsScreenPresenter @Inject constructor(
override fun defaultErrorViewStateHandler() = override fun defaultErrorViewStateHandler() =
{ e: ExceptionString -> SettingsScreenViewState.SomeError(e) } { e: ExceptionString -> SettingsScreenViewState.SomeError(e) }
private val cacheSizeRefresher = PublishRelay.create<Int>() // private val cacheSizeRefresher = PublishRelay.create<Int>()
private val cahcObs =
cacheSizeRefresher.flatMap {
Observable.merge(
arrayListOf(
fetchToursSize, fetchPlansSize
)
)
}
private val fetchToursSize: Observable<SettingsScreenViewState> = interactor.fetchToursSizes() // private val cahcObs =
.map { SettingsScreenViewState.OnSizePrefetch(it) } // cacheSizeRefresher.flatMap {
// Observable.merge(
// arrayListOf(
// fetchToursSize, fetchPlansSize
// )
// )
// }
private val fetchPlansSize: Observable<SettingsScreenViewState> = interactor.fetchPlanTypesSizes() // private val fetchToursSize: Observable<SettingsScreenViewState> = interactor.fetchToursSizes()
.map { it* TYPICAL_PLAN_SIZE } // .map { SettingsScreenViewState.OnSizePrefetch(it) }
.map { SettingsScreenViewState.OnPlanTypesPrefetch(it) } //
// private val fetchPlansSize: Observable<SettingsScreenViewState> = interactor.fetchPlanTypesSizes()
// .map { it* TYPICAL_PLAN_SIZE }
// .map { SettingsScreenViewState.OnPlanTypesPrefetch(it) }
override fun bindIntents() { override fun bindIntents() {
...@@ -82,7 +79,7 @@ class SettingsScreenPresenter @Inject constructor( ...@@ -82,7 +79,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) } // .doOnNext {cacheSizeRefresher.accept(1) }
val fetchSubscriptions = interactor.getSubscriptions() val fetchSubscriptions = interactor.getSubscriptions()
.map {list -> .map {list ->
...@@ -107,8 +104,8 @@ class SettingsScreenPresenter @Inject constructor( ...@@ -107,8 +104,8 @@ class SettingsScreenPresenter @Inject constructor(
.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) // if (it.first == it.second)
cacheSizeRefresher.accept(1) // cacheSizeRefresher.accept(1)
SettingsScreenViewState.OnCacheDeleting( SettingsScreenViewState.OnCacheDeleting(
it.first / it.second.toFloat() it.first / it.second.toFloat()
...@@ -124,7 +121,7 @@ class SettingsScreenPresenter @Inject constructor( ...@@ -124,7 +121,7 @@ class SettingsScreenPresenter @Inject constructor(
val state = Observable.mergeDelayError( val state = Observable.mergeDelayError(
arrayListOf( arrayListOf(
restoreStateObservable, restoreStateObservable,
cahcObs, // cahcObs,
// fetchPlansSize, // fetchPlansSize,
fetchSettings, fetchSettings,
onSignOut, onSignOut,
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
android:orientation="vertical"> android:orientation="vertical">
<com.google.android.material.textview.MaterialTextView <com.google.android.material.textview.MaterialTextView
android:id="@+id/download_dialog_title"
style="@style/Default_TextView.Header_Text" style="@style/Default_TextView.Header_Text"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
<string name="api_error_2001">Тур не найден!</string> <string name="api_error_2001">Тур не найден!</string>
<string name="api_error_default">Неизвестная ошибка сервера!</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="unknown_error">Unexpected error!</string>
<string name="cant_load_item_error">Can\'t load item!</string> <string name="cant_load_item_error">Can\'t load item!</string>
<string name="object_not_found_error">Object not found!</string> <string name="object_not_found_error">Object not found!</string>
...@@ -128,16 +128,19 @@ ...@@ -128,16 +128,19 @@
<string name="game_view_content_description" /> <string name="game_view_content_description" />
<string name="download_all_tours_settings_with_size">Скачать виртуальные туры моих квартир из избранного и сделок (%s)</string> <string name="download_all_tours_settings_with_size">Скачать виртуальные туры моих квартир из избранного и сделок</string>
<string name="download_all_plan_types_settings_with_sizes">Скачать карточки моих квартир из избранного и сделок (%s)</string> <string name="download_all_plan_types_settings_with_sizes">Скачать карточки моих квартир из избранного и сделок</string>
<string name="plan_types_download_completed">Загрузка планов завершена.</string> <string name="plan_types_download_completed">Загрузка планов завершена.</string>
<string name="download_plan_types_screen_title">Cкачиваются планировки</string> <string name="download_plan_types_screen_title">Cкачиваются планировки</string>
<string name="download_all_tours_notice_text">Загрузить все туры?</string> <string name="download_all_tours_notice_text">Загрузить все туры?</string>
<string name="download_all_plans_notice_text">Загрузить все \n планировки?</string>
<string name="download_all_tours_size_title">Размер всех туров: %s</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_disk_size_title">Размер свободного места на диске: %s</string>
<string name="download_all_tours_yes_action">Скачать</string> <string name="download_all_tours_yes_action">Скачать</string>
<string name="download_all_tours_cancel_action">Отмена</string> <string name="download_all_tours_cancel_action">Отмена</string>
<string name="download_all_tours_errors_snackbar_message">Ошибка при попытке загрузить туры!</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> <string name="download_all_tours_start_snackbar_message">Загрузка туров началась!</string>
</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