-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added platform specific download implementations
- Loading branch information
1 parent
9ce4b52
commit 7ac67dc
Showing
22 changed files
with
480 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
actual fun getPlatform(): Platform { | ||
return Platform.Android | ||
} |
14 changes: 14 additions & 0 deletions
14
composeApp/src/androidMain/kotlin/di/PlatformModule.android.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package di | ||
|
||
import org.koin.android.ext.koin.androidApplication | ||
import org.koin.core.module.Module | ||
import org.koin.dsl.module | ||
import ui.download.PlatformDownloadImage | ||
|
||
actual fun platformModule(): Module { | ||
return module { | ||
single { | ||
PlatformDownloadImage(androidApplication()) | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
composeApp/src/androidMain/kotlin/ui/download/PlatformDownloadImage.android.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package ui.download | ||
|
||
import android.app.DownloadManager | ||
import android.content.Context | ||
import android.net.Uri | ||
import android.os.Environment | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.withContext | ||
import ui.state.ImageDownloadState | ||
import kotlin.time.Duration.Companion.seconds | ||
|
||
actual class PlatformDownloadImage(private val context: Context) { | ||
actual suspend fun downloadImage(imageLink: String): ImageDownloadState { | ||
withContext(Dispatchers.Default) { | ||
delay(3.seconds) | ||
} | ||
return withContext(Dispatchers.Main) { | ||
try { | ||
val uri = Uri.parse(imageLink) | ||
val fileName = "${uri.pathSegments[0]}.jpeg" | ||
|
||
val request = DownloadManager.Request(uri) | ||
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED) | ||
.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName) | ||
|
||
(context.getSystemService(Context.DOWNLOAD_SERVICE) | ||
as DownloadManager).enqueue(request) | ||
ImageDownloadState.Successful | ||
} catch (e: Exception) { | ||
ImageDownloadState.Failure(e) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
sealed class Platform { | ||
data object Android : Platform() | ||
|
||
data object Apple : Platform() | ||
|
||
data object Desktop : Platform() | ||
} | ||
|
||
expect fun getPlatform(): Platform |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package di | ||
|
||
import org.koin.core.module.Module | ||
|
||
expect fun platformModule(): Module |
7 changes: 7 additions & 0 deletions
7
composeApp/src/commonMain/kotlin/ui/download/PlatformDownloadImage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package ui.download | ||
|
||
import ui.state.ImageDownloadState | ||
|
||
expect class PlatformDownloadImage { | ||
suspend fun downloadImage(imageLink: String): ImageDownloadState | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.