Added implementations for iOS
This commit is contained in:
parent
f5a93bdddd
commit
4fa7adeeb1
|
@ -98,7 +98,7 @@ kotlin {
|
|||
implementation(libs.favre.bcrypt)
|
||||
}
|
||||
|
||||
nativeMain.dependencies {
|
||||
iosMain.dependencies {
|
||||
implementation(libs.sqldelight.native.driver)
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import net.codinux.banking.dataaccess.BankmeisterDb
|
|||
import net.codinux.banking.ui.config.DI
|
||||
|
||||
fun MainViewController() = ComposeUIViewController {
|
||||
DI.setRepository(NativeSqliteDriver(Database.Schema.synchronous(), "Bankmeister.db"))
|
||||
DI.setRepository(NativeSqliteDriver(BankmeisterDb.Schema.synchronous(), "Bankmeister.db"))
|
||||
|
||||
App()
|
||||
}
|
|
@ -1,6 +1,36 @@
|
|||
package net.codinux.banking.ui
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.unit.dp
|
||||
import kotlinx.cinterop.ExperimentalForeignApi
|
||||
import kotlinx.cinterop.useContents
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.IO
|
||||
import platform.CoreGraphics.CGRect
|
||||
import platform.UIKit.UIDevice
|
||||
import platform.UIKit.UIScreen
|
||||
|
||||
actual val Dispatchers.IOorDefault: CoroutineDispatcher
|
||||
get() = Dispatchers.IO
|
||||
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
@Composable
|
||||
actual fun rememberScreenSizeInfo(): ScreenSizeInfo {
|
||||
val density = LocalDensity.current
|
||||
val screenBounds: CGRect = UIScreen.mainScreen.bounds.useContents { this }
|
||||
val screenWidth = screenBounds.size.width
|
||||
val screenHeight = screenBounds.size.height
|
||||
|
||||
return remember(density, screenWidth, screenHeight) {
|
||||
ScreenSizeInfo(
|
||||
heightDp = with(density) { screenHeight.dp },
|
||||
widthDp = with(density) { screenWidth.dp }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
class IOSPlatform: Platform {
|
||||
override val name: String = UIDevice.currentDevice.systemName() + " " + UIDevice.currentDevice.systemVersion
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package net.codinux.banking.ui.service
|
||||
|
||||
import androidx.compose.ui.graphics.ImageBitmap
|
||||
import androidx.compose.ui.graphics.toComposeImageBitmap
|
||||
import kotlinx.cinterop.ExperimentalForeignApi
|
||||
import kotlinx.cinterop.readBytes
|
||||
import org.jetbrains.skia.Image
|
||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||
import platform.Foundation.*
|
||||
import kotlin.coroutines.resume
|
||||
import kotlin.coroutines.resumeWithException
|
||||
|
||||
actual fun createImageBitmap(imageBytes: ByteArray): ImageBitmap =
|
||||
Image.makeFromEncoded(imageBytes).toComposeImageBitmap()
|
||||
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
actual suspend fun fetchBytesFromUrl(url: String): ByteArray {
|
||||
val nsUrl = NSURL(string = url) ?: throw IllegalArgumentException("Invalid URL")
|
||||
|
||||
return suspendCancellableCoroutine { continuation ->
|
||||
val request = NSURLRequest.requestWithURL(nsUrl)
|
||||
val session = NSURLSession.sharedSession
|
||||
val task = session.dataTaskWithRequest(request) { data, response, error ->
|
||||
when {
|
||||
error != null -> continuation.resumeWithException(Exception(error.localizedDescription))
|
||||
data != null -> continuation.resume(data.bytes!!.readBytes(data.length.toInt()))
|
||||
else -> continuation.resumeWithException(Exception("Unknown error"))
|
||||
}
|
||||
}
|
||||
|
||||
continuation.invokeOnCancellation {
|
||||
task.cancel() // Cancel the task if the coroutine is cancelled
|
||||
}
|
||||
|
||||
task.resume()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue