Skip to content

Commit

Permalink
move detail to different module
Browse files Browse the repository at this point in the history
  • Loading branch information
Tewelde, Fethi (F.) committed Dec 8, 2024
1 parent 9c24ca2 commit 48ccc1c
Show file tree
Hide file tree
Showing 39 changed files with 481 additions and 424 deletions.
8 changes: 6 additions & 2 deletions composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.compose.compiler.gradle.ComposeFeatureFlag
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
Expand Down Expand Up @@ -60,8 +61,8 @@ kotlin {
}

commonMain.dependencies {
implementation(projects.core.designsystem)
implementation(projects.feature.arts)
implementation(projects.feature.detail)

implementation(compose.material3)
implementation(compose.components.resources)
Expand Down Expand Up @@ -92,7 +93,10 @@ kotlin {
}

composeCompiler {
enableStrongSkippingMode = true
featureFlags = setOf(
ComposeFeatureFlag.StrongSkipping,
ComposeFeatureFlag.OptimizeNonSkippingGroups
)
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,19 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import coil3.ImageLoader
import coil3.PlatformContext
import coil3.annotation.ExperimentalCoilApi
import coil3.compose.setSingletonImageLoaderFactory
import coil3.disk.DiskCache
import coil3.memory.MemoryCache
import coil3.network.ktor3.KtorNetworkFetcherFactory
import coil3.request.CachePolicy
import coil3.request.crossfade
import coil3.util.DebugLogger
import com.tewelde.rijksmuseum.core.designsystem.theme.RijksmuseumTheme
import com.tewelde.rijksmuseum.navigation.RijksmuseumNavGraph
import com.tewelde.rijksmuseum.theme.RijksmuseumTheme
import okio.FileSystem
import org.jetbrains.compose.ui.tooling.preview.Preview
import org.koin.compose.KoinContext

@OptIn(ExperimentalCoilApi::class)
@Composable
@Preview
fun App(disableDiskCache: Boolean = false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import coil3.network.CacheStrategy
import coil3.network.NetworkFetcher
import coil3.network.ktor3.asNetworkClient
import com.tewelde.rijksmuseum.feature.arts.di.artsModule
import com.tewelde.rijksmuseum.feature.detail.di.detailModule
import io.ktor.client.HttpClient
import org.koin.dsl.module

@OptIn(ExperimentalCoilApi::class)
val appModule = module {
includes(artsModule)
includes(artsModule, detailModule)
single {
NetworkFetcher.Factory(
networkClient = { get<HttpClient>().asNetworkClient() },
cacheStrategy = { CacheStrategy() },
cacheStrategy = { CacheStrategy.DEFAULT },
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.SnackbarResult
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.tewelde.rijksmuseum.core.designsystem.RijksmuseumDestination
import com.tewelde.rijksmuseum.feature.arts.detail.DetailScreenRoute
import com.tewelde.rijksmuseum.feature.arts.detail.DetailViewModel
import com.tewelde.rijksmuseum.feature.arts.navigation.Gallery
import com.tewelde.rijksmuseum.feature.arts.navigation.galleryGraph
import org.koin.compose.currentKoinScope
import com.tewelde.rijksmuseum.feature.detail.navigation.detailScreen
import com.tewelde.rijksmuseum.feature.detail.navigation.navigateToDetail

/**
* Main navigation graph for the Art Gallery Viewer app.
Expand All @@ -26,43 +22,29 @@ import org.koin.compose.currentKoinScope
fun RijksmuseumNavGraph(
modifier: Modifier = Modifier,
snackbarHostState: SnackbarHostState,
startDestination: RijksmuseumDestination = RijksmuseumDestination.Gallery,
startDestination: Any = Gallery,
navController: NavHostController = rememberNavController(),
) {
NavHost(
modifier = modifier,
startDestination = startDestination.route,
startDestination = startDestination,
navController = navController,
) {
galleryGraph(navController)
composable(RijksmuseumDestination.DetailScreen.route) { entry ->
val id = entry.arguments
?.getString("id")
?.let(::requireNotNull)
.orEmpty()
val viewModel = koinViewModel<DetailViewModel>()

DetailScreenRoute(
objectId = id,
viewModel = viewModel,
onBackClick = navController::navigateUp,
snackbarHostState = snackbarHostState,
onShowSnackbar = { message, action, duration ->
snackbarHostState.showSnackbar(
message = message,
actionLabel = action,
duration = duration,
) == SnackbarResult.ActionPerformed
}
)
}
}
}

@Composable
inline fun <reified T : ViewModel> koinViewModel(): T {
val scope = currentKoinScope()
return viewModel {
scope.get<T>()
galleryGraph(
navController = navController,
onBackClick = navController::navigateUp,
onArtClick = { id -> navController.navigateToDetail(id) }
)
detailScreen(
onBackClick = navController::navigateUp,
snackbarHostState = snackbarHostState,
onShowSnackbar = { message, action, duration ->
snackbarHostState.showSnackbar(
message = message,
actionLabel = action,
duration = duration,
) == SnackbarResult.ActionPerformed
}
)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.tewelde.rijksmuseum.core.designsystem.theme
package com.tewelde.rijksmuseum.theme

import androidx.compose.ui.graphics.Color

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.tewelde.rijksmuseum.core.designsystem.theme
package com.tewelde.rijksmuseum.theme


import androidx.compose.foundation.isSystemInDarkTheme
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.tewelde.rijksmuseum.core.designsystem.theme
package com.tewelde.rijksmuseum.theme

import androidx.compose.material3.Typography
import androidx.compose.ui.text.TextStyle
Expand Down

This file was deleted.

5 changes: 0 additions & 5 deletions feature/arts/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,15 @@ kotlin {
commonMain.dependencies {
api(projects.core.common)
implementation(projects.core.model)
implementation(projects.core.permissions)
api(projects.core.domain)
implementation(projects.core.permissions)
implementation(projects.core.designsystem)

implementation(libs.koin.compose)
implementation(libs.koin.composeVM)

implementation(libs.navigation.compose)
implementation(libs.androidx.lifecycle.viewmodel)
implementation(libs.androidx.lifecycle.runtimeCompose)

implementation(libs.filekit.core)

implementation(libs.coil.compose)
}
}
Expand Down
76 changes: 1 addition & 75 deletions feature/arts/src/androidMain/kotlin/Utils.android.kt
Original file line number Diff line number Diff line change
@@ -1,81 +1,7 @@
import android.content.ContentValues
import android.content.Context
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.os.Build
import android.os.Environment
import android.provider.MediaStore
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalView
import com.tewelde.rijksmuseum.core.model.Art
import com.tewelde.rijksmuseum.resources.Res
import com.tewelde.rijksmuseum.resources.permission_denied
import io.github.vinceglb.filekit.core.FileKitPlatformSettings
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import okio.FileSystem
import org.jetbrains.compose.resources.StringResource
import kotlin.coroutines.coroutineContext

@Composable
actual fun screenHeight(): Int = LocalView.current.resources.displayMetrics.heightPixels

@Composable
actual fun screenWidth(): Int = LocalView.current.resources.displayMetrics.widthPixels


actual class FileUtil(private val context: Context) {
actual fun filesystem(): FileSystem? = FileSystem.SYSTEM

actual suspend fun saveFile(
bytes: ByteArray,
baseName: String,
extension: String,
initialDirectory: String?,
platformSettings: FileKitPlatformSettings?,
onFailure: (Throwable) -> Unit,
onSuccess: () -> Unit
) {
CoroutineScope(coroutineContext).launch(Dispatchers.IO) {
runCatching {
val imageBitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.size)
val mContentValues =
ContentValues().apply {
put(MediaStore.Images.Media.DATE_ADDED, System.currentTimeMillis())
put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg")
put(MediaStore.Images.Media.RELATIVE_PATH, Environment.DIRECTORY_PICTURES)
put(MediaStore.Images.Media.DISPLAY_NAME, baseName)
}

context.contentResolver
.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, mContentValues)
.apply {
this?.let {
context.contentResolver.openOutputStream(it)?.let { outStream ->
imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, outStream)
}
}
onSuccess()
}
}.onFailure {
it.printStackTrace()
onFailure(it)
}
}
}

actual suspend fun shouldAskStorageRuntimePermission(): Boolean =
Build.VERSION.SDK_INT < Build.VERSION_CODES.Q
}

actual val Art.artUrl: String
get() = this.webImage.url

actual val minGridSize: Int
get() = 175

actual val permissionDeniedMessage: StringResource = Res.string.permission_denied

actual val web: Boolean
get() = false
get() = 175
31 changes: 1 addition & 30 deletions feature/arts/src/commonMain/kotlin/Utils.kt
Original file line number Diff line number Diff line change
@@ -1,33 +1,4 @@
import androidx.compose.runtime.Composable
import com.tewelde.rijksmuseum.core.model.Art
import io.github.vinceglb.filekit.core.FileKitPlatformSettings
import okio.FileSystem
import org.jetbrains.compose.resources.StringResource

@Composable
expect fun screenHeight(): Int

@Composable
expect fun screenWidth(): Int

expect val web: Boolean

expect val Art.artUrl: String

expect val permissionDeniedMessage: StringResource

expect val minGridSize: Int

expect class FileUtil {
fun filesystem(): FileSystem?
suspend fun saveFile(
bytes: ByteArray,
baseName: String = "file",
extension: String,
initialDirectory: String? = null,
platformSettings: FileKitPlatformSettings? = null,
onFailure: (Throwable) -> Unit,
onSuccess: () -> Unit
)
suspend fun shouldAskStorageRuntimePermission(): Boolean
}
expect val Art.artUrl: String
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
package com.tewelde.rijksmuseum.feature.arts.di

import com.tewelde.rijksmuseum.core.domain.di.domainModule
import com.tewelde.rijksmuseum.core.permissions.permissionsModule
import com.tewelde.rijksmuseum.feature.arts.detail.DetailViewModel
import com.tewelde.rijksmuseum.feature.arts.gallery.GalleryViewModel
import org.koin.compose.viewmodel.dsl.viewModelOf
import org.koin.core.module.Module
import org.koin.core.module.dsl.viewModelOf
import org.koin.dsl.module

val artsModule = module {
includes(domainModule, platformModule, permissionsModule)
includes(domainModule)
viewModelOf(::GalleryViewModel)
viewModelOf(::DetailViewModel)
}


expect val platformModule: Module
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ fun ArtsScreenRoute(
viewModel: GalleryViewModel,
onNavigateToCollection: () -> Unit
) {
val uiState by viewModel.uiState.collectAsStateWithLifecycle(
lifecycleOwner = androidx.compose.ui.platform.LocalLifecycleOwner.current
)
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
ArtsScreen(
uiState = uiState,
onNavigateToCollection = onNavigateToCollection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ fun CollectionScreenRoute(
onBackClick: () -> Unit,
onArtClick: (String) -> Unit,
) {
val uiState by viewModel.uiState.collectAsStateWithLifecycle(
lifecycleOwner = androidx.compose.ui.platform.LocalLifecycleOwner.current
)
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
CollectionScreen(
uiState = uiState,
onBackClick = onBackClick,
Expand Down
Loading

0 comments on commit 48ccc1c

Please sign in to comment.