@@ -21,40 +21,40 @@ internal class DownloadableModelRemoteDataSource(
21
21
.map(List <DownloadableModelResponse >::mapRawToDomain)
22
22
23
23
override fun download (id : String , url : String ): Observable <DownloadState > =
24
- // Completable
25
- // .fromAction {
26
- // val dir = File("${fileProviderDescriptor.localModelDirPath}/${id}")
27
- // val destination = File(getDestinationPath(id))
28
- // if (destination.exists()) destination.delete()
29
- // if (!dir.exists()) dir.mkdirs()
30
- // }
31
- // .andThen(
24
+ Completable
25
+ .fromAction {
26
+ val dir = File (" ${fileProviderDescriptor.localModelDirPath} /${id} " )
27
+ val destination = File (getDestinationPath(id))
28
+ if (destination.exists()) destination.delete()
29
+ if (! dir.exists()) dir.mkdirs()
30
+ }
31
+ .andThen(
32
32
api.downloadModel(
33
33
remoteUrl = url,
34
34
localPath = getDestinationPath(id),
35
35
stateProgress = DownloadState ::Downloading ,
36
36
stateComplete = DownloadState ::Complete ,
37
37
stateFailed = DownloadState ::Error ,
38
38
)
39
- // )
40
- // .flatMap { state ->
41
- // val chain = Observable.just(state)
42
- // if (state is DownloadState.Complete) {
43
- // Completable
44
- // .create { emitter ->
45
- // try {
46
- // state.file.unzip()
47
- // emitter.onComplete()
48
- // } catch (e: Exception) {
49
- // emitter.onError(e)
50
- // }
51
- // }
52
- // .andThen(Completable.fromAction { File(getDestinationPath(id)).delete() })
53
- // .andThen(chain)
54
- // } else {
55
- // chain
56
- // }
57
- // }
39
+ )
40
+ .flatMap { state ->
41
+ val chain = Observable .just(state)
42
+ if (state is DownloadState .Complete ) {
43
+ Completable
44
+ .create { emitter ->
45
+ try {
46
+ state.file.unzip()
47
+ emitter.onComplete()
48
+ } catch (e: Exception ) {
49
+ emitter.onError(e)
50
+ }
51
+ }
52
+ .andThen(Completable .fromAction { File (getDestinationPath(id)).delete() })
53
+ .andThen(chain)
54
+ } else {
55
+ chain
56
+ }
57
+ }
58
58
59
59
private fun getDestinationPath (id : String ): String {
60
60
return " ${fileProviderDescriptor.localModelDirPath} /${id} /model.zip"
0 commit comments