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
631c032e
Commit
631c032e
authored
Apr 22, 2020
by
Vladislav Bogdashkin
🎣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix csancellation
parent
d094f0e3
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
96 additions
and
35 deletions
+96
-35
PlanRepository.kt
...anto/visual/roompark/data/data_provider/PlanRepository.kt
+57
-6
FileModule.kt
...iganto/visual/roompark/data/repository/file/FileModule.kt
+6
-6
FlatPlanContract.kt
...ganto/visual/roompark/domain/contract/FlatPlanContract.kt
+5
-0
planTypesUseCase.kt
...ganto/visual/roompark/domain/use_case/planTypesUseCase.kt
+28
-23
No files found.
app/src/main/java/com/biganto/visual/roompark/data/data_provider/PlanRepository.kt
View file @
631c032e
...
...
@@ -12,6 +12,7 @@ import com.biganto.visual.roompark.domain.contract.FlatPlanContract
import
com.biganto.visual.roompark.domain.model.FeatureModel
import
com.biganto.visual.roompark.domain.model.PlanPresetModel
import
com.biganto.visual.roompark.domain.model.fromEntity
import
com.biganto.visual.roompark.domain.use_case.DownloadUseCase
import
io.reactivex.Observable
import
io.reactivex.schedulers.Schedulers
import
timber.log.Timber
...
...
@@ -47,6 +48,55 @@ class PlanRepository @Inject constructor(
.
subscribeOn
(
Schedulers
.
io
())
override
fun
getPlansObservable
(
list
:
List
<
PlanFeaturesVariant
>
,
cancellationToken
:
DownloadUseCase
.
CancellationToken
)
:
Observable
<
String
>
{
return
Observable
.
create
{
emitter
->
list
.
asSequence
()
.
chunked
(
12
)
.
also
{
System
.
gc
()
}
.
flatten
()
.
filter
{
!
cancellationToken
.
isCancelled
}
.
forEach
{
variant
->
val
file
=
FileModule
.
getDirectory
(
file
.
context
,
FileModule
.
FileDirectory
.
PlanTypeDir
(
estateId
=
variant
.
estateId
,
planId
=
variant
.
planId
,
furniture
=
variant
.
furniture
,
walls
=
variant
.
walls
,
sizes
=
variant
.
sizes
,
electric
=
variant
.
electric
))
if
(
file
.
exists
())
emitter
.
onNext
(
file
.
absolutePath
)
else
{
try
{
Timber
.
w
(
"Cancellation is: ${cancellationToken.isCancelled}"
)
if
(
cancellationToken
.
isCancelled
){
emitter
.
onComplete
()
}
file
.
parentFile
.
mkdirs
()
file
.
writeText
(
api
.
getDirectPlan
(
variant
.
estateId
,
variant
.
planId
,
variant
.
furniture
?:
false
,
variant
.
sizes
?:
false
,
variant
.
walls
?:
false
,
variant
.
electric
?:
false
).
blockingFirst
()
)
emitter
.
onNext
(
file
.
absolutePath
)
}
catch
(
e
:
Throwable
){
emitter
.
onError
(
e
)}
}
}
emitter
.
onComplete
()
}
}
override
fun
getPlanTypes
(
estateId
:
Int
):
Observable
<
List
<
PlanPresetModel
>>
=
Observable
.
mergeDelayError
(
arrayListOf
(
getPlanTypesApi
(
estateId
))
...
...
@@ -64,16 +114,17 @@ class PlanRepository @Inject constructor(
,
sizes
?:
false
,
walls
?:
false
,
electric
?:
false
)
.
flatMap
{
.
map
{
val
sFile
=
getPlanFile
(
estateId
=
estateId
,
planId
=
planId
,
furniture
=
furniture
,
walls
=
walls
,
sizes
=
sizes
,
electric
=
electric
)
file
.
saveFileToDiskObservable
(
sFile
,
it
)
.
map
{
sFile
.
path
}
electric
=
electric
)
file
.
saveFileToDisk
(
sFile
,
it
)
sFile
.
absolutePath
}
.
subscribeOn
(
Schedulers
.
io
())
...
...
@@ -88,7 +139,7 @@ class PlanRepository @Inject constructor(
electric
=
featuresVariant
.
electric
)
fun
getPlanFile
(
estateId
:
Int
private
fun
getPlanFile
(
estateId
:
Int
,
planId
:
Int
,
furniture
:
Boolean
?
=
null
,
sizes
:
Boolean
?
=
null
...
...
@@ -133,7 +184,7 @@ class PlanRepository @Inject constructor(
furniture
=
furniture
,
walls
=
walls
,
sizes
=
sizes
,
electric
=
electric
)
}.
switch
Map
{
electric
=
electric
)
}.
flat
Map
{
if
(
it
.
exists
())
Observable
.
just
(
it
.
path
)
else
getPlanApi
(
estateId
,
planId
...
...
app/src/main/java/com/biganto/visual/roompark/data/repository/file/FileModule.kt
View file @
631c032e
...
...
@@ -72,14 +72,14 @@ class FileModule @Inject constructor(val context: Application) {
val
source
=
content
.
byteInputStream
()
var
bytesRead
=
0L
sink
.
use
{
while
(
source
.
read
()>
0
)
{
bytesRead
+=
read
}
}
Timber
.
w
(
"start read "
)
file
.
writeText
(
content
)
Timber
.
w
(
"butes read "
)
// sink.flush()
System
.
gc
()
emitter
.
onNext
(
bytesRead
)
emitter
.
onComplete
()
//
emitter.onComplete()
}
}
...
...
app/src/main/java/com/biganto/visual/roompark/domain/contract/FlatPlanContract.kt
View file @
631c032e
...
...
@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.domain.contract
import
com.biganto.visual.roompark.data.data_provider.PlanFeaturesVariant
import
com.biganto.visual.roompark.domain.model.PlanPresetModel
import
com.biganto.visual.roompark.domain.use_case.DownloadUseCase
import
io.reactivex.Observable
import
java.io.File
...
...
@@ -22,4 +23,8 @@ interface FlatPlanContract{
fun
getPlanFile
(
featuresVariant
:
PlanFeaturesVariant
):
File
fun
getPlan
(
featuresVariant
:
PlanFeaturesVariant
):
Observable
<
String
>
fun
getPlansObservable
(
list
:
List
<
PlanFeaturesVariant
>,
cancellationToken
:
DownloadUseCase
.
CancellationToken
):
Observable
<
String
>
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/domain/use_case/planTypesUseCase.kt
View file @
631c032e
package
com.biganto.visual.roompark.domain.use_case
import
com.biganto.visual.roompark.data.data_provider.PlanFeaturesVariant
import
com.biganto.visual.roompark.data.data_provider.featuresVariants
import
com.biganto.visual.roompark.data.repository.db.requrey.model.EstateEntity
import
com.biganto.visual.roompark.domain.contract.AuthContract
import
com.biganto.visual.roompark.domain.contract.FlatPlanContract
import
io.reactivex.Observable
import
io.reactivex.schedulers.Schedulers
import
timber.log.Timber
import
javax.inject.Inject
/**
...
...
@@ -40,8 +37,9 @@ class PlanTypesUseCase @Inject constructor(
.
map
{
list
->
list
.
sumBy
{
if
(
planContract
.
getPlanFile
(
it
).
exists
())
0
else
1
}
}
.
scan
{
t1
:
Int
,
t2
:
Int
->
t1
+
t2
}
fun
downloadAllPlanTypes
(
cancellationToken
:
DownloadUseCase
.
CancellationToken
)
=
fetchAllPlanTypes
fun
downloadAllPlanTypes
(
cancellationToken
:
DownloadUseCase
.
CancellationToken
):
Observable
<
DownloadProgress
>
{
var
listSize
=
0
return
fetchAllPlanTypes
.
flatMapSingle
{
Observable
.
fromIterable
(
it
)
.
flatMap
{
estateEntity
->
...
...
@@ -52,31 +50,38 @@ class PlanTypesUseCase @Inject constructor(
}
.
map
{
it
.
flatten
()
}
.
filter
{
!
cancellationToken
.
isCancelled
}
.
flatMap
{
downloadPlan
(
it
,
cancellationToken
)
}
private
fun
downloadPlan
(
list
:
List
<
PlanFeaturesVariant
>
,
cancellationToken
:
DownloadUseCase
.
CancellationToken
)
:
Observable
<
DownloadProgress
>
{
return
Observable
.
fromIterable
(
list
)
.
filter
{
!
cancellationToken
.
isCancelled
}
.
flatMap
{
planContract
.
getPlan
(
it
)
.
flatMap
{
list
->
planContract
.
getPlansObservable
(
list
,
cancellationToken
)
.
map
{
1
}
.
subscribeOn
(
Schedulers
.
io
())
.
observeOn
(
Schedulers
.
computation
())
.
scan
{
t1
:
Int
,
t2
:
Int
->
t1
+
t2
}
.
map
{
completed
->
Timber
.
d
(
"downaloadods ${completed}/${list.size}"
)
.
scan
(
0
,
{
t1
,
t2
->
t1
+
t2
})
.
map
{
completed
->
DownloadProgress
(
completed
,
list
.
size
)
}
}
}
}
// private fun downloadPlan(
// list: PlanFeaturesVariant
// , cancellationToken: DownloadUseCase.CancellationToken
// )
// : Observable<DownloadProgress> {
//
// val avaliablethread = true
//
// return Observable.fromIterable(list)
//
//
// .delay(100,TimeUnit.MILLISECONDS)
// .doOnNext { Timber.w("emmited") }
// .delay { variant ->
// planContract.getPlan(variant)}
// .filter { !cancellationToken.isCancelled }
//
// }
...
...
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