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

update to unity master

parent 8bd9691c
...@@ -30,7 +30,7 @@ import javax.inject.Inject ...@@ -30,7 +30,7 @@ import javax.inject.Inject
*/ */
private const val DATABASE_VERSION = 15 private const val DATABASE_VERSION = 16
@Module @Module
class DbModule{ class DbModule{
...@@ -59,7 +59,7 @@ class RequeryRepository @Inject constructor( ...@@ -59,7 +59,7 @@ class RequeryRepository @Inject constructor(
override fun refreshEstatesWithTours(): Completable = override fun refreshEstatesWithTours(): Completable =
store.select(EstateEntity::class) store.select(EstateEntity::class)
.where(EstateEntity::multitourId.notNull()) .where(EstateEntity.MULTITOUR_ID.notNull())
.get() .get()
.observable() .observable()
.toList() .toList()
......
...@@ -8,13 +8,21 @@ import com.biganto.visual.roompark.data.repository.db.requrey.utils.RevisionStri ...@@ -8,13 +8,21 @@ import com.biganto.visual.roompark.data.repository.db.requrey.utils.RevisionStri
import com.biganto.visual.roompark.data.repository.file.FileModule import com.biganto.visual.roompark.data.repository.file.FileModule
import io.requery.* import io.requery.*
import java.io.File import java.io.File
import java.math.BigInteger
import java.security.MessageDigest
/** /**
* Created by Vladislav Bogdashkin on 15.06.2018. * Created by Vladislav Bogdashkin on 15.06.2018.
*/ */
val domainPredicthMatcher = "^(http|https)://".toRegex() val domainPredicthMatcher = "^(http|https)://".toRegex()
fun toInitialName(fullPath:String) = fullPath.hashCode().toString() fun toInitialName(fullPath: String) = String.format(
"%032x"
, BigInteger(
1
, MessageDigest.getInstance("MD5").digest(fullPath.toByteArray(Charsets.UTF_8))
)
)
@Entity @Entity
interface File :Persistable { interface File :Persistable {
...@@ -59,7 +67,7 @@ fun fromRaw(raw: TourFileRaw, meta: LiteTourMetaRaw):FileEntity { ...@@ -59,7 +67,7 @@ fun fromRaw(raw: TourFileRaw, meta: LiteTourMetaRaw):FileEntity {
entity.setDestination( entity.setDestination(
if (domainPredicthMatcher.containsMatchIn(raw.url)) raw.url if (domainPredicthMatcher.containsMatchIn(raw.url)) raw.url
else BASE_URL+raw.url else BASE_URL.plus(raw.url)
) )
return entity return entity
......
...@@ -4,6 +4,7 @@ import com.biganto.visual.roompark.data.repository.api.biganto.raw.TourPreviewRa ...@@ -4,6 +4,7 @@ import com.biganto.visual.roompark.data.repository.api.biganto.raw.TourPreviewRa
import com.biganto.visual.roompark.data.repository.db.requrey.RevisionString import com.biganto.visual.roompark.data.repository.db.requrey.RevisionString
import com.biganto.visual.roompark.data.repository.db.requrey.model.Estate import com.biganto.visual.roompark.data.repository.db.requrey.model.Estate
import com.biganto.visual.roompark.data.repository.db.requrey.model.EstateEntity import com.biganto.visual.roompark.data.repository.db.requrey.model.EstateEntity
import com.biganto.visual.roompark.data.repository.db.requrey.model.domainPredicthMatcher
import com.biganto.visual.roompark.data.repository.db.requrey.utils.IntListConverter import com.biganto.visual.roompark.data.repository.db.requrey.utils.IntListConverter
import com.biganto.visual.roompark.data.repository.db.requrey.utils.IsoDateConverter import com.biganto.visual.roompark.data.repository.db.requrey.utils.IsoDateConverter
import com.biganto.visual.roompark.data.repository.db.requrey.utils.RevisionStringConverter import com.biganto.visual.roompark.data.repository.db.requrey.utils.RevisionStringConverter
...@@ -72,8 +73,15 @@ fun fromRaw(raw: TourPreviewRaw, parentId:Int, baseUrl:String, userResolution:In ...@@ -72,8 +73,15 @@ fun fromRaw(raw: TourPreviewRaw, parentId:Int, baseUrl:String, userResolution:In
tour.setUpdated(raw.updated) tour.setUpdated(raw.updated)
tour.setType(raw.type) tour.setType(raw.type)
tour.setTitle(raw.title) tour.setTitle(raw.title)
tour.setPreview("$baseUrl${raw.preview}") tour.setPreview(
tour.setScreen("$baseUrl${raw.screen}") if (domainPredicthMatcher.containsMatchIn(raw.preview)) raw.preview
else "$baseUrl${raw.preview}"
)
tour.setScreen(
if (domainPredicthMatcher.containsMatchIn(raw.screen)) raw.screen
else "$baseUrl${raw.screen}"
)
tour.setHidden(raw.hidden) tour.setHidden(raw.hidden)
tour.resolutions= if (raw.resolutions != null && !raw.resolutions.isNullOrEmpty()) ArrayList(raw.resolutions) tour.resolutions= if (raw.resolutions != null && !raw.resolutions.isNullOrEmpty()) ArrayList(raw.resolutions)
else ArrayList(1024) else ArrayList(1024)
......
...@@ -41,7 +41,7 @@ class FileModule @Inject constructor(val context: Application) { ...@@ -41,7 +41,7 @@ class FileModule @Inject constructor(val context: Application) {
if (fileUri.contains("/")) if (fileUri.contains("/"))
fileUri.substring(0, fileUri.lastIndexOf("/")) fileUri.substring(0, fileUri.lastIndexOf("/"))
else "" else ""
val directory = File(assetsFile(context), fileDir) val directory = File(rootFolder, fileDir)
directory.mkdirs() directory.mkdirs()
val file = File(directory, fileName) val file = File(directory, fileName)
......
...@@ -592,6 +592,7 @@ class DownloadManagerService @Inject constructor( ...@@ -592,6 +592,7 @@ class DownloadManagerService @Inject constructor(
Timber.e(e) Timber.e(e)
} }
} }
tour
} }
.flatMap { db.upsertTourPreview(it) } .flatMap { db.upsertTourPreview(it) }
.map { tour.id } .map { tour.id }
......
...@@ -27,7 +27,8 @@ data class TourModel ( ...@@ -27,7 +27,8 @@ data class TourModel (
var downloadState: DownloadState =DownloadState.MetaPreparation, var downloadState: DownloadState =DownloadState.MetaPreparation,
val downloadedSize: Long=-1L, val downloadedSize: Long=-1L,
val totalTourSize : Long=-1L, val totalTourSize : Long=-1L,
val targetResolution : Int val targetResolution : Int,
val footageUri : String?
) : Parcelable { ) : Parcelable {
constructor(parcel: Parcel) : this( constructor(parcel: Parcel) : this(
...@@ -44,7 +45,8 @@ data class TourModel ( ...@@ -44,7 +45,8 @@ data class TourModel (
DownloadState.valueOf(parcel.readString()), DownloadState.valueOf(parcel.readString()),
parcel.readLong(), parcel.readLong(),
parcel.readLong(), parcel.readLong(),
parcel.readInt()) parcel.readInt(),
parcel.readString())
val metaPredict : String val metaPredict : String
get() = metaUri?.removeSuffix("$tour_id.json") ?: "" get() = metaUri?.removeSuffix("$tour_id.json") ?: ""
...@@ -64,6 +66,7 @@ data class TourModel ( ...@@ -64,6 +66,7 @@ data class TourModel (
parcel.writeLong(downloadedSize) parcel.writeLong(downloadedSize)
parcel.writeLong(totalTourSize) parcel.writeLong(totalTourSize)
parcel.writeInt(targetResolution) parcel.writeInt(targetResolution)
parcel.writeString(footageUri)
} }
override fun describeContents(): Int { override fun describeContents(): Int {
...@@ -140,7 +143,8 @@ fun fromEntity(entity: TourPreviewEntity) = TourModel( ...@@ -140,7 +143,8 @@ fun fromEntity(entity: TourPreviewEntity) = TourModel(
downloadState = entity.isDownloaded,//calcDownloadState(entity.tour as TourEntity?) downloadState = entity.isDownloaded,//calcDownloadState(entity.tour as TourEntity?)
downloadedSize = entity.downloadedSize?:-1L, downloadedSize = entity.downloadedSize?:-1L,
totalTourSize = max(entity.overallSize?:0L,entity.tempSize?:0L), totalTourSize = max(entity.overallSize?:0L,entity.tempSize?:0L),
targetResolution = entity.targetResolution targetResolution = entity.targetResolution,
footageUri = entity.footageBaseUrl
) )
fun fromEntity(raw: List<TourPreviewEntity>):List<TourModel> =List(raw.size) { index-> fromEntity(raw[index])} fun fromEntity(raw: List<TourPreviewEntity>):List<TourModel> =List(raw.size) { index-> fromEntity(raw[index])}
......
...@@ -4,16 +4,20 @@ package com.biganto.visual.roompark.domain.use_case ...@@ -4,16 +4,20 @@ package com.biganto.visual.roompark.domain.use_case
import android.app.Application import android.app.Application
import android.media.MediaScannerConnection import android.media.MediaScannerConnection
import com.biganto.visual.roompark.data.repository.api.biganto.IBigantoApi import com.biganto.visual.roompark.data.repository.api.biganto.IBigantoApi
import com.biganto.visual.roompark.data.repository.api.biganto.raw.LiteTourMetaRaw
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.RevisionString import com.biganto.visual.roompark.data.repository.db.requrey.RevisionString
import com.biganto.visual.roompark.data.repository.db.requrey.model.FileEntity import com.biganto.visual.roompark.data.repository.db.requrey.model.FileEntity
import com.biganto.visual.roompark.data.repository.db.requrey.model.TourFileJunctionEntity import com.biganto.visual.roompark.data.repository.db.requrey.model.TourFileJunctionEntity
import com.biganto.visual.roompark.data.repository.db.requrey.model.fromRaw import com.biganto.visual.roompark.data.repository.db.requrey.model.fromRaw
import com.biganto.visual.roompark.data.repository.db.requrey.model.toInitialName
import com.biganto.visual.roompark.data.repository.file.FileModule import com.biganto.visual.roompark.data.repository.file.FileModule
import com.biganto.visual.roompark.data.service.download.TourFileData import com.biganto.visual.roompark.data.service.download.TourFileData
import com.biganto.visual.roompark.domain.contract.AuthContract import com.biganto.visual.roompark.domain.contract.AuthContract
import com.biganto.visual.roomparkvr.data.repository.db.requery.model.DownloadState import com.biganto.visual.roomparkvr.data.repository.db.requery.model.DownloadState
import com.biganto.visual.roomparkvr.data.repository.db.requery.model.TourPreviewEntity import com.biganto.visual.roomparkvr.data.repository.db.requery.model.TourPreviewEntity
import com.google.gson.Gson
import com.google.gson.JsonParser
import io.reactivex.BackpressureStrategy import io.reactivex.BackpressureStrategy
import io.reactivex.Flowable import io.reactivex.Flowable
import io.reactivex.Observable import io.reactivex.Observable
...@@ -155,7 +159,9 @@ class DownloadUseCase @Inject constructor( ...@@ -155,7 +159,9 @@ class DownloadUseCase @Inject constructor(
.map { raw -> .map { raw ->
var downloadedSize = 0L var downloadedSize = 0L
var totalSize = 0L var totalSize = 0L
val fileEntities = raw.files.map(::fromRaw)
val meta = getLocalMeta(tour)
val fileEntities = fromRaw(raw.files,meta)
mergeFiles(fileEntities) mergeFiles(fileEntities)
val jlist = db.getTourFilesJunction(tour.id).toList() val jlist = db.getTourFilesJunction(tour.id).toList()
...@@ -205,7 +211,7 @@ class DownloadUseCase @Inject constructor( ...@@ -205,7 +211,7 @@ class DownloadUseCase @Inject constructor(
hashMapOf(Pair("Range", "bytes=${model.fileDownloadedSize}-")) hashMapOf(Pair("Range", "bytes=${model.fileDownloadedSize}-"))
else null else null
api.downloadFile(model.fileUrl.revisionUri(), header) api.downloadFile(model.destination, header)
.flatMap<TourFileData> { .flatMap<TourFileData> {
writeFile(it, model, token) writeFile(it, model, token)
.toFlowable(BackpressureStrategy.BUFFER) .toFlowable(BackpressureStrategy.BUFFER)
...@@ -255,26 +261,58 @@ class DownloadUseCase @Inject constructor( ...@@ -255,26 +261,58 @@ class DownloadUseCase @Inject constructor(
.doOnError(Timber::e) .doOnError(Timber::e)
.flatMap { observableTourDownloading(it, cancellataionToken) } .flatMap { observableTourDownloading(it, cancellataionToken) }
private fun getMeta(tour: TourPreviewEntity) = private fun getMeta(tour: TourPreviewEntity) =
api.getTourMetaAsString(tour.id) api.getTourMetaAsString(tour.id)
.map { meta -> .map { meta ->
tour.apply { tour.apply {
val metaUri = try {
RevisionString("$META_PREDICTION${tour.id}$META_FILE_TYPE")
setMetaFileEntityId(metaUri) val jMeta = JsonParser().parse(meta).asJsonArray.first()
fileModule.saveFileToDisk(
File(FileModule.assetsDirectory(context).plus(metaUri.uri())) val metaLite = Gson().fromJson(jMeta, LiteTourMetaRaw::class.java)
, meta
)
val metaUri = RevisionString("${META_PREDICTION}${tour.id}${META_FILE_TYPE}")
setMetaFileEntityId(metaUri)
setFootageBaseUrl(toInitialName(metaLite.baseurl))
setTourBaseUrl(toInitialName(metaLite.tour_baseurl))
fileModule.saveFileToDisk(
fileModule.getAssetFile(
File.separator
.plus(tour.footageBaseUrl)
.plus(metaUri.uri())
)
, meta
)
} catch (e: Exception) {
Timber.e(e)
}
} }
tour
} }
.flatMap { db.upsertTourPreview(it) }
.onErrorReturn { .onErrorReturn {
tour.isDownloaded = DownloadState.Crushed tour.isDownloaded = DownloadState.Crushed
db.upsertTourPreview(tour).blockingSubscribe() db.upsertTourPreview(tour).blockingSubscribe()
tour tour
} }
private fun getLocalMeta(tour: TourPreviewEntity): LiteTourMetaRaw {
return Gson().fromJson(
JsonParser().parse(
fileModule.getAssetFile(
File.separator
.plus(tour.footageBaseUrl)
.plus(File.separator)
.plus(tour.metaFileEntityId?.uri())
).readText()
).asJsonArray.first()
, LiteTourMetaRaw::class.java
)
}
//#endregion oldMethod //#endregion oldMethod
private fun refreshGallery(file: File) { private fun refreshGallery(file: File) {
......
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