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

update to unity master

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