Skip to content

Commit

Permalink
Merge pull request #47 from stslex/dev
Browse files Browse the repository at this point in the history
update all libs and refactor imnage loading
  • Loading branch information
stslex authored Nov 12, 2024
2 parents 29f32e8 + d8e5339 commit 51dc9aa
Show file tree
Hide file tree
Showing 25 changed files with 104 additions and 202 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ fun Project.configureKMPCompose(
implementation(libs.findLibrary("kotlinx-collections-immutable").get())
implementation(libs.findLibrary("koin-compose").get())
implementation(libs.findLibrary("lifecycle-viewmodel").get())
implementation(libs.findLibrary("kamel").get())
}
}
}
4 changes: 3 additions & 1 deletion commonApp/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
#-renamesourcefileattribute SourceFile

-keep class io.ktor.** { *; }
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ fun InitialApp(
val authScreen = Screen.Auth::class.simpleName.orEmpty()
if (
isAuth.not() &&
currentScreen?.route?.contains(authScreen) == true
currentScreen != null &&
currentScreen.route?.contains(authScreen) == true
) {
navHostController.navigate(Screen.Auth)
}
Expand All @@ -75,12 +76,10 @@ fun InitialApp(
}
}
) { _ ->
Box(
modifier = Modifier.fillMaxSize()
) {
Box(modifier = Modifier.fillMaxSize()) {
AppNavigationHost(
navHostController = navHostController,
startScreen = if (userStore.isAuth) Screen.Auth else Screen.FilmFeed
startScreen = if (userStore.isAuth) Screen.FilmFeed else Screen.Auth
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.stslex.wizard.core.network.api.server.model
package com.stslex.wizard.core.core.error

/**
* Error refresh token response
Expand Down
2 changes: 1 addition & 1 deletion core/network/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ kotlin {
implementation(project(":core:database"))
implementation(libs.bundles.ktor)
implementation(libs.slf4j.simple)
implementation(libs.kamel)
implementation(libs.kotlinx.datetime)
}
buildConfig {
setLocalProperty(project.rootProject)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.stslex.wizard.core.network.api.server.error_handler

import com.stslex.wizard.core.network.api.server.model.ErrorRefresh
import com.stslex.wizard.core.core.error.ErrorRefresh
import io.ktor.client.HttpClient
import io.ktor.client.plugins.CallRequestExceptionHandler
import io.ktor.client.plugins.HttpResponseValidator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import com.stslex.wizard.core.network.clients.match.model.response.MatchResponse
import com.stslex.wizard.core.network.clients.match.model.response.MatchStatusResponse
import com.stslex.wizard.core.network.clients.match.model.response.MatchUserResponse
import com.stslex.wizard.core.network.model.PagingRequest
import com.stslex.wizard.core.network.utils.currentTimeMs
import kotlinx.coroutines.delay
import kotlinx.datetime.Clock

class MockMatchClientImpl : MatchClient {

Expand Down Expand Up @@ -62,7 +62,7 @@ class MockMatchClientImpl : MatchClient {
}

private fun createMatch(index: Int): MatchDetailResponse {
val created = currentTimeMs
val created = Clock.System.now().epochSeconds
val updated = created + 1000 * 60 * 60
val expires = created + 1000 * 60 * 60 * 24
return MatchDetailResponse(
Expand Down

This file was deleted.

This file was deleted.

13 changes: 8 additions & 5 deletions core/ui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ kotlin {
commonMain.dependencies {
implementation(project(":core:core"))
implementation(project(":core:network"))
}
androidMain.dependencies {
api(libs.coil.compose)
implementation(libs.kotlinx.datetime)
implementation(libs.bundles.coil)
implementation(libs.bundles.ktor)
implementation(libs.slf4j.simple)
}
iosMain.dependencies {
// TODO research TLS PROBLEM
implementation(libs.ktor.client.darwin)
api(libs.ktor.client.darwin)
}
androidMain.dependencies {
api(libs.ktor.client.android)
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.stslex.wizard.core.ui.base

import androidx.compose.runtime.Stable
import com.stslex.wizard.core.network.api.server.model.ErrorRefresh
import com.stslex.wizard.core.core.error.ErrorRefresh

@Stable
sealed class AppError(open val message: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package com.stslex.wizard.core.ui.base
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import com.stslex.wizard.core.network.utils.currentTimeMs
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.datetime.Clock

private class Clicker(
private val throttle: Long = 500
Expand All @@ -14,7 +14,7 @@ private class Clicker(
private var lastClickTime = 0L

fun click(onClick: () -> Unit) {
val currentTime = currentTimeMs
val currentTime = Clock.System.now().epochSeconds
if (currentTime - lastClickTime < throttle) {
return
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.stslex.wizard.core.ui.base.image

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import coil3.ImageLoader
import coil3.compose.LocalPlatformContext
import coil3.compose.rememberAsyncImagePainter
import coil3.network.ktor3.KtorNetworkFetcherFactory
import io.ktor.client.HttpClient
import io.ktor.client.engine.cio.CIO

// todo refactor
private var imageLoader: ImageLoader? = null

@Composable
internal fun rememberImageLoader(): ImageLoader {
val platformContext = LocalPlatformContext.current
return remember {
imageLoader ?: ImageLoader
.Builder(platformContext)
.components { add(KtorNetworkFetcherFactory(HttpClient(CIO))) }
.build()
}
}

@Composable
fun AppImage(
url: String,
modifier: Modifier = Modifier,
contentDescription: String? = null,
contentScale: ContentScale = ContentScale.Fit,
onLoading: @Composable (BoxScope.(Float) -> Unit)? = null,
onFailure: @Composable (BoxScope.(Throwable) -> Unit)? = null,
) {
val imageLoader = rememberImageLoader()
val painter = rememberAsyncImagePainter(
model = url,
imageLoader = imageLoader,
)
// todo add states
Image(
modifier = modifier,
painter = painter,
contentDescription = contentDescription,
contentScale = contentScale
)
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import com.stslex.wizard.core.ui.base.SwipeScrollConnection
import com.stslex.wizard.core.ui.base.SwipeState
import com.stslex.wizard.core.ui.base.image.NetworkImage
import com.stslex.wizard.core.ui.base.image.AppImage
import com.stslex.wizard.core.ui.base.onClick
import com.stslex.wizard.core.ui.base.onClickDelay
import com.stslex.wizard.core.ui.theme.AppDimension
Expand Down Expand Up @@ -408,7 +408,7 @@ internal fun FilmHeader(
title: String,
modifier: Modifier = Modifier,
) {
NetworkImage(
AppImage(
modifier = modifier
.fillMaxWidth(),
url = url,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.stslex.wizard.feature.film_feed.ui

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
Expand All @@ -19,7 +20,9 @@ internal fun FeedScreen(
sendAction: (Action) -> Unit,
) {
Box(
modifier = modifier.fillMaxSize()
modifier = modifier
.fillMaxSize()
.statusBarsPadding()
) {
when (val screenState = state.screen) {
is ScreenState.Content -> FeedScreenContent(
Expand Down
Loading

0 comments on commit 51dc9aa

Please sign in to comment.