-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PlatformImage Add ios support - but not working yet as images are no found in resources.
- Loading branch information
1 parent
2ceb8d3
commit 1c315bd
Showing
18 changed files
with
260 additions
and
55 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
17 changes: 17 additions & 0 deletions
17
shared/domain/src/androidMain/kotlin/network/bisq/mobile/PlatformImage.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,17 @@ | ||
@file:Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING") | ||
|
||
package network.bisq.mobile | ||
|
||
import android.graphics.Bitmap | ||
import androidx.compose.ui.graphics.ImageBitmap | ||
import androidx.compose.ui.graphics.asImageBitmap | ||
import network.bisq.mobile.utils.ImageUtil | ||
|
||
// FIXME if ImageBitmap is used it gives a compile error | ||
actual typealias PlatformImage = Any | ||
|
||
actual fun ByteArray.toImageBitmap(): PlatformImage { | ||
val bitmap:Bitmap = ImageUtil.decodePngToImageBitmap(this) | ||
val asImageBitmap: ImageBitmap = bitmap.asImageBitmap() | ||
return asImageBitmap | ||
} |
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
2 changes: 2 additions & 0 deletions
2
shared/domain/src/appleMain/kotlin/network/bisq/mobile/service/IosImageUtil.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,2 @@ | ||
package network.bisq.mobile.service | ||
|
7 changes: 7 additions & 0 deletions
7
shared/domain/src/commonMain/kotlin/network/bisq/mobile/PlatformImage.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 network.bisq.mobile | ||
|
||
@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING") | ||
|
||
expect class PlatformImage | ||
|
||
expect fun ByteArray.toImageBitmap(): PlatformImage |
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
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
29 changes: 29 additions & 0 deletions
29
shared/domain/src/iosMain/kotlin/network/bisq/mobile/PlatformImage.ios.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,29 @@ | ||
@file:Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING") | ||
@file:OptIn(BetaInteropApi::class) | ||
|
||
package network.bisq.mobile | ||
|
||
import kotlinx.cinterop.BetaInteropApi | ||
import kotlinx.cinterop.ExperimentalForeignApi | ||
import kotlinx.cinterop.addressOf | ||
import kotlinx.cinterop.usePinned | ||
import platform.Foundation.NSData | ||
import platform.Foundation.create | ||
import platform.UIKit.UIImage | ||
|
||
|
||
actual typealias PlatformImage = UIImage | ||
|
||
@OptIn(ExperimentalForeignApi::class) | ||
actual fun ByteArray.toImageBitmap(): PlatformImage { | ||
// Pin the ByteArray to get a stable memory address | ||
val nsData = this.usePinned { pinnedByteArray -> | ||
NSData.create( | ||
bytes = pinnedByteArray.addressOf(0), | ||
length = this.size.toULong() | ||
) | ||
} | ||
val uiImage = UIImage(data = nsData) ?: throw IllegalArgumentException("Failed to decode image") | ||
return uiImage | ||
} | ||
|
31 changes: 24 additions & 7 deletions
31
shared/domain/src/iosMain/kotlin/network/bisq/mobile/service/IosClientCatHashService.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 |
---|---|---|
@@ -1,19 +1,36 @@ | ||
package network.bisq.mobile.service | ||
|
||
import network.bisq.mobile.client.cathash.ClientCatHashService | ||
import network.bisq.mobile.utils.getFilesDir | ||
import platform.UIKit.UIImage | ||
|
||
// TODO Implement | ||
class IosClientCatHashService() : | ||
ClientCatHashService<Any?>("Bisq2_mobile") { | ||
const val PATH_TO_DRAWABLE = | ||
"composeResources/bisqapps/shared/presentation/generated/resources/drawable/" | ||
|
||
override fun composeImage(paths: Array<String>, size: Int): Any? { | ||
return null | ||
const val CAT_HASH_PATH = /*PATH_TO_DRAWABLE +*/ "drawable/cathash/" | ||
|
||
class IosClientCatHashService : ClientCatHashService<ByteArray>("${getFilesDir()}/Bisq2_mobile") { | ||
|
||
override fun composeImage(paths: Array<String>, size: Int): ByteArray { | ||
val profileIcon: UIImage? = IosImageUtil.composeImage( | ||
CAT_HASH_PATH, | ||
paths, | ||
size, | ||
size | ||
) | ||
val uiImageToPngByteArray = | ||
profileIcon?.let { IosImageUtil.uiImageToPngByteArray(profileIcon) } | ||
return uiImageToPngByteArray ?: ByteArray(0) | ||
} | ||
|
||
override fun writeRawImage(image: Any?, iconFilePath: String) { | ||
override fun writeRawImage(image: ByteArray, iconFilePath: String) { | ||
//todo | ||
} | ||
|
||
override fun readRawImage(iconFilePath: String): Any? { | ||
override fun readRawImage(iconFilePath: String): ByteArray? { | ||
//todo | ||
return null | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.