Skip to content

Commit 5c35ccd

Browse files
committed
Unit Testing | Patch 17
1 parent 277d70a commit 5c35ccd

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

data/src/main/java/com/shifthackz/aisdv1/data/remote/DownloadableModelRemoteDataSource.kt

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,40 +21,40 @@ internal class DownloadableModelRemoteDataSource(
2121
.map(List<DownloadableModelResponse>::mapRawToDomain)
2222

2323
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(
3232
api.downloadModel(
3333
remoteUrl = url,
3434
localPath = getDestinationPath(id),
3535
stateProgress = DownloadState::Downloading,
3636
stateComplete = DownloadState::Complete,
3737
stateFailed = DownloadState::Error,
3838
)
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+
}
5858

5959
private fun getDestinationPath(id: String): String {
6060
return "${fileProviderDescriptor.localModelDirPath}/${id}/model.zip"

0 commit comments

Comments
 (0)