File tree Expand file tree Collapse file tree 1 file changed +14
-6
lines changed
app/src/main/java/com/hamzaazman/birthdayreminder/di Expand file tree Collapse file tree 1 file changed +14
-6
lines changed Original file line number Diff line number Diff line change 1- package com.hamzaazman.birthdayreminder.common
1+ package com.hamzaazman.birthdayreminder.di
22
33import android.content.Context
4+ import dagger.hilt.android.qualifiers.ApplicationContext
45import kotlinx.coroutines.CoroutineScope
56import kotlinx.coroutines.Dispatchers
67import kotlinx.coroutines.launch
@@ -10,15 +11,19 @@ import java.io.File
1011import java.io.FileOutputStream
1112import java.net.HttpURLConnection
1213import java.net.URL
14+ import javax.inject.Inject
15+ import javax.inject.Singleton
1316
14-
15- object ApkDownloader {
17+ @Singleton
18+ class ApkDownloader @Inject constructor(
19+ @ApplicationContext private val context : Context
20+ ) {
1621
1722 fun downloadApk (
18- context : Context ,
1923 url : String ,
2024 onProgress : (Int ) -> Unit ,
21- onDownloaded : (File ) -> Unit
25+ onDownloaded : (File ) -> Unit ,
26+ onError : (Exception ) -> Unit
2227 ) {
2328 CoroutineScope (Dispatchers .IO ).launch {
2429 try {
@@ -53,7 +58,10 @@ object ApkDownloader {
5358
5459 } catch (e: Exception ) {
5560 e.printStackTrace()
61+ withContext(Dispatchers .Main ) {
62+ onError(e)
63+ }
5664 }
5765 }
5866 }
59- }
67+ }
You can’t perform that action at this time.
0 commit comments