Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Room Park Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vladislav Bogdashkin
Room Park Android
Commits
72ab65f7
Commit
72ab65f7
authored
Apr 03, 2020
by
Vladislav Bogdashkin
🎣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix import
parent
3a000574
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
283 additions
and
3 deletions
+283
-3
tours.kt
...va/com/biganto/visual/roompark/domain/interactor/tours.kt
+18
-0
TourModel.kt
...ava/com/biganto/visual/roompark/domain/model/TourModel.kt
+155
-0
tour.kt
...ain/java/com/biganto/visual/roompark/domain/model/tour.kt
+3
-3
toures.kt
...ava/com/biganto/visual/roompark/domain/use_case/toures.kt
+107
-0
No files found.
app/src/main/java/com/biganto/visual/roompark/domain/interactor/tours.kt
0 → 100644
View file @
72ab65f7
package
com.biganto.visual.roompark.domain.interactor
import
com.biganto.visual.roompark.domain.use_case.DownloadUseCase
import
javax.inject.Inject
/**
* Created by Vladislav Bogdashkin on 03.04.2020.
*/
class
ToursInteractor
@Inject
constructor
(
val
downloadUseCase
:
DownloadUseCase
){
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/domain/model/TourModel.kt
0 → 100644
View file @
72ab65f7
package
com.biganto.visual.roompark.domain.model
import
android.os.Parcel
import
android.os.Parcelable
import
com.biganto.visual.roomparkvr.data.repository.db.requery.model.DownloadState
import
com.biganto.visual.roomparkvr.data.repository.db.requery.model.TourPreviewEntity
import
java.text.DecimalFormat
import
java.util.*
import
kotlin.math.max
/**
* Created by Vladislav Bogdashkin on 30.05.2018.
*/
data class
TourModel
(
val
tour_id
:
String
=
"-1"
,
val
created
:
Date
=
Date
(),
val
updated
:
Date
=
Date
(),
val
type
:
TourType
=
TourType
.
VIRTUAL
,
val
title
:
String
=
""
,
val
previewUrl
:
String
?=
""
,
val
screen
:
String
?=
null
,
val
hidden
:
Boolean
=
false
,
val
metaUri
:
String
?,
val
parentId
:
Int
=-
1
,
var
downloadState
:
DownloadState
=
DownloadState
.
MetaPreparation
,
val
downloadedSize
:
Long
=-
1L
,
val
totalTourSize
:
Long
=-
1L
,
val
targetResolution
:
Int
)
:
Parcelable
{
constructor
(
parcel
:
Parcel
)
:
this
(
parcel
.
readString
(),
parcel
.
readSerializable
()
as
Date
,
parcel
.
readSerializable
()
as
Date
,
TourType
.
valueOf
(
parcel
.
readString
()),
parcel
.
readString
(),
parcel
.
readString
(),
parcel
.
readString
(),
parcel
.
readByte
()
!=
0
.
toByte
(),
parcel
.
readString
(),
parcel
.
readInt
(),
DownloadState
.
valueOf
(
parcel
.
readString
()),
parcel
.
readLong
(),
parcel
.
readLong
(),
parcel
.
readInt
())
val
metaPredict
:
String
get
()
=
metaUri
?.
removeSuffix
(
"$tour_id.json"
)
?:
""
override
fun
writeToParcel
(
parcel
:
Parcel
,
flags
:
Int
)
{
parcel
.
writeString
(
tour_id
)
parcel
.
writeSerializable
(
created
)
parcel
.
writeSerializable
(
updated
)
parcel
.
writeString
(
type
.
name
)
parcel
.
writeString
(
title
)
parcel
.
writeString
(
previewUrl
)
parcel
.
writeString
(
screen
)
parcel
.
writeByte
(
if
(
hidden
)
1
else
0
)
parcel
.
writeString
(
metaUri
)
parcel
.
writeInt
(
parentId
)
parcel
.
writeString
(
downloadState
.
name
)
parcel
.
writeLong
(
downloadedSize
)
parcel
.
writeLong
(
totalTourSize
)
parcel
.
writeInt
(
targetResolution
)
}
override
fun
describeContents
():
Int
{
return
0
}
companion
object
CREATOR
:
Parcelable
.
Creator
<
TourModel
>
{
override
fun
createFromParcel
(
parcel
:
Parcel
):
TourModel
{
return
TourModel
(
parcel
)
}
override
fun
newArray
(
size
:
Int
):
Array
<
TourModel
?
>
{
return
arrayOfNulls
(
size
)
}
}
}
fun
Long
.
bytesToSize
():
String
{
if
(
this
==-
1L
)
return
"~"
var
scale
=
0
var
rest
:
Long
=
this
var
least
=
0f
// Timber.d("size to gb: %s",this)
while
(
rest
>=
1024
)
{
least
=(
rest
%
1024
).
toFloat
()
rest
/=
1024
scale
++
}
least
/=
102.4f
// least*=100f
return
when
(
scale
)
{
0
->
"$rest.${least.format(0)}B"
1
->
"$rest.${least.format(0)}Kb"
2
->
"$rest.${least.format(0)}Mb"
3
->
"$rest.${least.format(0)}Gb"
4
->
"$rest.${least.format(0)}Tb"
else
->
"$rest${least.format(0)}Bb"
//BigantoByte
}
}
fun
bytesToString
(
bytes
:
Long
)=
bytes
.
bytesToSize
()
fun
Float
.
format
(
fracDigits
:
Int
):
String
{
val
df
=
DecimalFormat
()
df
.
maximumFractionDigits
=
fracDigits
return
df
.
format
(
this
)
}
enum
class
TourType
(
val
i
:
Int
)
{
VIRTUAL
(
0
),
REAL
(
1
)
}
fun
fromEntity
(
entity
:
TourPreviewEntity
)
=
TourModel
(
tour_id
=
entity
.
id
,
parentId
=
entity
.
estate
.
id
,
created
=
entity
.
created
,
updated
=
entity
.
created
,
// updated = entity.updated,
type
=
when
(
entity
.
type
){
"virtual"
->
TourType
.
VIRTUAL
"real"
->
TourType
.
REAL
else
->
TourType
.
REAL
},
title
=
entity
.
title
,
previewUrl
=
entity
.
preview
,
metaUri
=
entity
.
metaFileEntityId
?.
uri
(),
screen
=
entity
.
screen
,
hidden
=
entity
.
hidden
,
downloadState
=
entity
.
isDownloaded
,
//calcDownloadState(entity.tour as TourEntity?)
downloadedSize
=
entity
.
downloadedSize
?:
-
1L
,
totalTourSize
=
max
(
entity
.
overallSize
?:
0L
,
entity
.
tempSize
?:
0L
),
targetResolution
=
entity
.
targetResolution
)
fun
fromEntity
(
raw
:
List
<
TourPreviewEntity
>):
List
<
TourModel
>
=
List
(
raw
.
size
)
{
index
->
fromEntity
(
raw
[
index
])}
data class
TourLoadProgressModel
(
val
downloadState
:
DownloadState
,
val
downloadedSize
:
Long
=-
1L
,
val
totalTourSize
:
Long
=-
1L
)
app/src/main/java/com/biganto/visual/roompark/domain/model/tour.kt
View file @
72ab65f7
...
...
@@ -5,6 +5,6 @@ package com.biganto.visual.roompark.domain.model
*/
data class
TourRequestModel
(
val
building
:
Int
,
val
flat
:
Int
)
data class
TourResponse
(
val
response
:
List
<
TourModel
>)
data class
TourModel
(
val
tourId
:
String
,
val
title
:
Int
,
val
preview
:
String
?)
//
data class TourRequestModel(val building:Int, val flat:Int)
//
data class TourResponse(val response:List<TourModel>)
//
data class TourModel(val tourId:String, val title:Int, val preview:String?)
app/src/main/java/com/biganto/visual/roompark/domain/use_case/toures.kt
0 → 100644
View file @
72ab65f7
package
com.biganto.visual.roompark.domain.use_case
import
android.content.res.Resources
import
com.biganto.visual.roompark.data.repository.api.biganto.IBigantoApi
import
com.biganto.visual.roompark.data.repository.db.IDb
import
com.biganto.visual.roompark.domain.custom_exception.CustomApiException
import
com.biganto.visual.roompark.domain.model.TourModel
import
com.biganto.visual.roompark.domain.model.fromEntity
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.fromRaw
import
io.reactivex.Observable
import
io.reactivex.schedulers.Schedulers
import
timber.log.Timber
import
javax.inject.Inject
/**
* Created by Vladislav Bogdashkin on 19.06.2018.
*/
const
val
EMPTY_PARENT
=
-
778
class
TourPreviewsUseCase
@Inject
constructor
(
private
val
api
:
IBigantoApi
,
private
val
db
:
IDb
)
{
fun
getTourById
(
tourId
:
String
):
Observable
<
DownloadTourByIdResult
>
{
val
tour
=
retrieveTour
(
tourId
)
Timber
.
d
(
"retrieveTour $tourId / $tour"
)
if
(
tour
!=
null
)
{
if
(
tour
.
downloadState
==
DownloadState
.
Downloaded
)
return
Observable
.
just
<
DownloadTourByIdResult
>(
DownloadTourByIdResult
.
ReadyToPlay
(
tour
))
return
setTourState
(
tour
.
tour_id
,
DownloadState
.
DownloadQueue
)
.
map
<
DownloadTourByIdResult
>
{
DownloadTourByIdResult
.
DownloadStarted
(
tour
)
}
}
return
syncTour
(
tourId
,
parentId
=
EMPTY_PARENT
)
.
map
{
it
}
.
map
<
DownloadTourByIdResult
>
{
DownloadTourByIdResult
.
DownloadStarted
(
it
)
}
}
fun
retrieveTour
(
tourId
:
String
)
=
db
.
getTourPreview
(
tourId
)
.
asSequence
()
.
map
(
::
fromEntity
)
.
firstOrNull
()
private
fun
setTourState
(
tourId
:
String
,
state
:
DownloadState
):
Observable
<
Boolean
>
=
db
.
getTourPreview
(
tourId
)
.
observable
()
.
doOnNext
{
it
.
isDownloaded
=
state
}
.
flatMap
{
db
.
upsertTourPreview
(
it
)
?.
map
{
true
}
}
private
fun
syncTour
(
tourId
:
String
,
parentId
:
Int
):
Observable
<
TourModel
>
=
syncTour
(
tourId
,
parentId
,
calcTargetResolution
())
private
fun
syncTour
(
tourId
:
String
,
estateId
:
Int
,
targetResolution
:
Int
)
:
Observable
<
TourModel
>
{
val
request
=
ToursRemoteByIdRequestModel
(
arrayListOf
(
tourId
)
,
estateId
,
null
,
targetResolution
)
return
forceTourUpdate
(
request
)
.
map
{
if
(
it
.
isNullOrEmpty
())
throw
CustomApiException
.
TourByIdNotFoundException
()
it
.
first
()
}
.
doOnNext
{
it
.
isDownloaded
=
DownloadState
.
DownloadQueue
}
.
flatMap
{
db
.
upsertTourPreview
(
it
)}
.
map
(
::
fromEntity
)
.
doOnError
(
Timber
::
e
)
}
private
fun
calcTargetResolution
():
Int
{
val
w
=
Resources
.
getSystem
().
displayMetrics
.
widthPixels
val
h
=
Resources
.
getSystem
().
displayMetrics
.
heightPixels
return
w
.
coerceAtLeast
(
h
)
}
private
fun
forceTourUpdate
(
requestModel
:
ToursRemoteByIdRequestModel
):
Observable
<
List
<
TourPreviewEntity
>>
=
api
.
getToursPreviewById
(
requestModel
.
ids
)
.
subscribeOn
(
Schedulers
.
io
())
.
map
{
fromRaw
(
it
,
requestModel
.
estateId
,
api
.
provideHttpUrl
().
toString
()
,
requestModel
.
targetResolution
)
}
}
data class
TourRemoteRequestModel
(
val
estateId
:
String
,
val
token
:
String
?
=
null
,
val
targetResolution
:
Int
)
data class
ToursRemoteByIdRequestModel
(
val
ids
:
List
<
String
>,
val
estateId
:
Int
,
val
token
:
String
?
=
null
,
val
targetResolution
:
Int
)
sealed
class
DownloadTourByIdResult
{
class
ReadyToPlay
(
val
tour
:
TourModel
):
DownloadTourByIdResult
()
class
DownloadStarted
(
val
tour
:
TourModel
):
DownloadTourByIdResult
()
class
TourError
(
val
id
:
String
):
DownloadTourByIdResult
()
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment