-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from stslex/dev
add images
- Loading branch information
Showing
17 changed files
with
341 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
*.iml | ||
.gradle | ||
**/build/ | ||
**/release/ | ||
xcuserdata | ||
!src/**/build/ | ||
local.properties | ||
|
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
22 changes: 22 additions & 0 deletions
22
core/ui/src/commonMain/kotlin/com/stslex/core/ui/base/image/AppKamelConfig.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,22 @@ | ||
package com.stslex.core.ui.base.image | ||
|
||
import io.kamel.core.config.KamelConfig | ||
import io.kamel.core.config.httpFetcher | ||
import io.kamel.core.config.takeFrom | ||
import io.kamel.image.config.Default | ||
import io.ktor.client.plugins.logging.LogLevel | ||
import io.ktor.client.plugins.logging.Logging | ||
|
||
object AppKamelConfig { | ||
|
||
val KamelLoggingConfig: KamelConfig | ||
get() = KamelConfig { | ||
takeFrom(KamelConfig.Default) | ||
httpFetcher { | ||
install(Logging) { | ||
logger = KamelLogger | ||
level = LogLevel.ALL | ||
} | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
core/ui/src/commonMain/kotlin/com/stslex/core/ui/base/image/ImageType.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,6 @@ | ||
package com.stslex.core.ui.base.image | ||
|
||
enum class ImageType { | ||
KAMEL, | ||
NATIVE; | ||
} |
12 changes: 12 additions & 0 deletions
12
core/ui/src/commonMain/kotlin/com/stslex/core/ui/base/image/KamelLogger.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,12 @@ | ||
package com.stslex.core.ui.base.image | ||
|
||
import io.ktor.client.plugins.logging.Logger | ||
|
||
object KamelLogger : Logger { | ||
|
||
private const val TAG = "KAMEL" | ||
|
||
override fun log(message: String) { | ||
com.stslex.core.core.Logger.debug(message, TAG) | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
core/ui/src/commonMain/kotlin/com/stslex/core/ui/base/image/KamelNetworkImage.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,32 @@ | ||
package com.stslex.core.ui.base.image | ||
|
||
import androidx.compose.foundation.layout.BoxScope | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.layout.ContentScale | ||
import io.kamel.image.KamelImage | ||
import io.kamel.image.asyncPainterResource | ||
|
||
@Composable | ||
internal fun KamelNetworkImage( | ||
url: String, | ||
contentDescription: String?, | ||
contentScale: ContentScale, | ||
modifier: Modifier = Modifier, | ||
onLoading: @Composable (BoxScope.(Float) -> Unit)? = null, | ||
onFailure: @Composable (BoxScope.(Throwable) -> Unit)? = null, | ||
) { | ||
// when(val painter = asyncPainterResource(url)){ | ||
// is Resource.Failure -> TODO() | ||
// is Resource.Loading -> TODO() | ||
// is Resource.Success -> TODO() | ||
// } | ||
KamelImage( | ||
modifier = modifier, | ||
resource = asyncPainterResource(data = url), | ||
contentDescription = contentDescription, | ||
contentScale = contentScale, | ||
onLoading = onLoading, | ||
onFailure = onFailure | ||
) | ||
} |
29 changes: 29 additions & 0 deletions
29
core/ui/src/commonMain/kotlin/com/stslex/core/ui/base/image/NativeNetworkImage.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 @@ | ||
package com.stslex.core.ui.base.image | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.layout.ContentScale | ||
import io.ktor.client.HttpClient | ||
import io.ktor.client.engine.cio.CIO | ||
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation | ||
import io.ktor.serialization.kotlinx.json.json | ||
import io.ktor.util.InternalAPI | ||
import kotlinx.serialization.json.Json | ||
|
||
@OptIn(InternalAPI::class) | ||
@Composable | ||
fun NativeNetworkImage( | ||
url: String, | ||
contentDescription: String?, | ||
contentScale: ContentScale, | ||
modifier: Modifier = Modifier, | ||
) { | ||
|
||
} | ||
|
||
val client = HttpClient(CIO) { | ||
install(ContentNegotiation) { | ||
json(Json { isLenient = true; ignoreUnknownKeys = true }) | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
core/ui/src/commonMain/kotlin/com/stslex/core/ui/base/image/NetworkImage.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 com.stslex.core.ui.base.image | ||
|
||
import androidx.compose.foundation.layout.BoxScope | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.layout.ContentScale | ||
|
||
@Composable | ||
fun NetworkImage( | ||
url: String, | ||
modifier: Modifier = Modifier, | ||
imageType: ImageType = ImageType.KAMEL, | ||
contentDescription: String? = null, | ||
contentScale: ContentScale = ContentScale.Fit, | ||
onLoading: @Composable (BoxScope.(Float) -> Unit)? = null, | ||
onFailure: @Composable (BoxScope.(Throwable) -> Unit)? = null, | ||
) { | ||
when (imageType) { | ||
ImageType.NATIVE -> NativeNetworkImage( | ||
modifier = modifier, | ||
url = url, | ||
contentDescription = contentDescription, | ||
contentScale = contentScale | ||
) | ||
|
||
ImageType.KAMEL -> KamelNetworkImage( | ||
modifier = modifier, | ||
url = url, | ||
contentDescription = contentDescription, | ||
contentScale = contentScale, | ||
onLoading = onLoading, | ||
onFailure = onFailure | ||
) | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
core/ui/src/commonMain/kotlin/com/stslex/core/ui/theme/AppDimension.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,10 @@ | ||
package com.stslex.core.ui.theme | ||
|
||
import androidx.compose.ui.unit.dp | ||
|
||
object AppDimension { | ||
|
||
val small = 4.dp | ||
val medium = 8.dp | ||
val large = 16.dp | ||
} |
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
Oops, something went wrong.