Skip to content

Commit 79a70cd

Browse files
authored
Merge update/gradle-9 into main
* Gradle 9 update and minor enhancements. * Updated Detekt configuration to v2.0.0 * Updated Detekt configuration to v2.0.0 * Minor cleanup in app/build.gradle.kts
1 parent 4cc086c commit 79a70cd

9 files changed

Lines changed: 239 additions & 204 deletions

File tree

app/build.gradle.kts

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1+
import dev.detekt.gradle.Detekt
12
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
23

34
plugins {
45
alias(libs.plugins.android.application)
56
alias(libs.plugins.detekt)
67
alias(libs.plugins.junit5)
7-
alias(libs.plugins.kotlin.android)
88
alias(libs.plugins.kotlin.compose)
99
alias(libs.plugins.kotlin.serialization)
1010
alias(libs.plugins.ksp)
1111
alias(libs.plugins.room)
1212
}
1313

1414
android {
15-
namespace = libs.versions.project.application.id.get()
16-
compileSdk = libs.versions.project.compile.sdk.version.get().toInt()
17-
1815
buildFeatures {
1916
buildConfig = true
2017
compose = true
@@ -48,6 +45,11 @@ android {
4845
sourceCompatibility = JavaVersion.VERSION_17
4946
targetCompatibility = JavaVersion.VERSION_17
5047
}
48+
compileSdk {
49+
version = release(libs.versions.project.compile.sdk.version.get().toInt()) {
50+
minorApiLevel = 1
51+
}
52+
}
5153
defaultConfig {
5254
applicationId = libs.versions.project.application.id.get()
5355
minSdk = libs.versions.project.min.sdk.version.get().toInt()
@@ -57,36 +59,36 @@ android {
5759

5860
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
5961
}
60-
detekt {
61-
toolVersion = libs.versions.detekt.get()
62-
config.setFrom(file("../config/detekt/detekt.yml"))
63-
buildUponDefaultConfig = true
64-
autoCorrect = true
65-
}
66-
kotlin {
67-
compilerOptions {
68-
optIn.add("kotlin.RequiresOptIn")
69-
jvmTarget.set(JvmTarget.JVM_17)
70-
}
71-
}
72-
room {
73-
schemaDirectory(path = "$projectDir/schemas")
74-
}
75-
tasks.withType<Test> {
76-
useJUnitPlatform()
62+
namespace = libs.versions.project.application.id.get()
63+
}
64+
detekt {
65+
toolVersion = libs.versions.detekt.get()
66+
config.setFrom(file("../config/detekt/detekt.yml"))
67+
buildUponDefaultConfig = true
68+
autoCorrect = true
69+
}
70+
kotlin {
71+
compilerOptions {
72+
optIn.add("kotlin.RequiresOptIn")
73+
jvmTarget.set(JvmTarget.JVM_17)
7774
}
7875
}
76+
room {
77+
schemaDirectory(path = "$projectDir/schemas")
78+
}
7979

8080
dependencies {
8181
//region AndroidX Libraries
82-
implementation(libs.annotation)
83-
implementation(libs.appcompat)
82+
implementation(libs.androidx.concurrent.futures)
83+
implementation(libs.androidx.concurrent.futures.ktx)
8484
implementation(libs.androidx.core.ktx)
8585
implementation(libs.androidx.core.splashscreen)
8686
implementation(libs.androidx.lifecycle.runtime.ktx)
8787
implementation(libs.androidx.navigation.compose)
8888
implementation(libs.androidx.security.crypto.ktx)
8989
implementation(libs.androidx.work)
90+
implementation(libs.annotation)
91+
implementation(libs.appcompat)
9092
implementation(libs.bundles.glance)
9193
implementation(libs.material)
9294
implementation(libs.room.runtime)
@@ -102,7 +104,6 @@ dependencies {
102104

103105
//region 3rd Party Libraries
104106
coreLibraryDesugaring(libs.desugar.jdk.libs)
105-
detektPlugins(libs.detekt.compose)
106107
implementation(libs.coil.compose)
107108
implementation(libs.bundles.koin)
108109
implementation(libs.bundles.koin.compose)
@@ -144,4 +145,17 @@ dependencies {
144145
androidTestImplementation(libs.mockk.android)
145146
androidTestImplementation(libs.turbine)
146147
//endregion
148+
}
149+
150+
tasks.withType<Test> {
151+
useJUnitPlatform()
152+
}
153+
154+
tasks.withType<Detekt>().configureEach {
155+
reports {
156+
checkstyle.required.set(true)
157+
html.required.set(true)
158+
sarif.required.set(true)
159+
markdown.required.set(true)
160+
}
147161
}

app/src/main/java/com/codermp/composeandroidtemplate/core/presentation/designsystem/theme/Color.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@file:Suppress("MagicNumber")
2+
13
package com.codermp.composeandroidtemplate.core.presentation.designsystem.theme
24

35
import androidx.compose.ui.graphics.Color

app/src/main/java/com/codermp/composeandroidtemplate/core/presentation/ui/DeviceConfiguration.kt

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
1+
@file:Suppress("MaxLineLength")
2+
13
package com.codermp.composeandroidtemplate.core.presentation.ui
24

3-
import androidx.window.core.layout.WindowHeightSizeClass
5+
import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
6+
import androidx.compose.runtime.Composable
47
import androidx.window.core.layout.WindowSizeClass
5-
import androidx.window.core.layout.WindowWidthSizeClass
8+
import androidx.window.core.layout.WindowSizeClass.Companion.HEIGHT_DP_EXPANDED_LOWER_BOUND
9+
import androidx.window.core.layout.WindowSizeClass.Companion.HEIGHT_DP_MEDIUM_LOWER_BOUND
10+
import androidx.window.core.layout.WindowSizeClass.Companion.WIDTH_DP_EXPANDED_LOWER_BOUND
11+
import androidx.window.core.layout.WindowSizeClass.Companion.WIDTH_DP_MEDIUM_LOWER_BOUND
12+
13+
/**
14+
* Composable function that returns the current device configuration.
15+
*/
16+
@Composable
17+
fun currentDeviceConfiguration(): DeviceConfiguration {
18+
val windowSizeClass = currentWindowAdaptiveInfo().windowSizeClass
19+
return DeviceConfiguration.fromWindowSizeClass(windowSizeClass = windowSizeClass)
20+
}
621

722
/**
823
* Represents the configuration of the device based on the window size class.
@@ -17,28 +32,31 @@ enum class DeviceConfiguration {
1732
TABLET_LANDSCAPE,
1833
DESKTOP;
1934

35+
val isMobile: Boolean
36+
get() = this in listOf(MOBILE_PORTRAIT, MOBILE_LANDSCAPE)
37+
38+
val isWideScreen: Boolean
39+
get() = this in listOf(TABLET_LANDSCAPE, DESKTOP)
40+
2041
companion object {
2142
/**
2243
* Function that returns the appropriate [DeviceConfiguration] based on the provided [windowSizeClass].
2344
* @param windowSizeClass The [WindowSizeClass] of the device.
2445
* @return The corresponding [DeviceConfiguration] based on the window size class.
2546
*/
2647
fun fromWindowSizeClass(windowSizeClass: WindowSizeClass): DeviceConfiguration {
27-
val widthClass = windowSizeClass.windowWidthSizeClass
28-
val heightClass = windowSizeClass.windowHeightSizeClass
29-
30-
return when {
31-
widthClass == WindowWidthSizeClass.COMPACT &&
32-
heightClass == WindowHeightSizeClass.MEDIUM -> MOBILE_PORTRAIT
33-
widthClass == WindowWidthSizeClass.COMPACT &&
34-
heightClass == WindowHeightSizeClass.EXPANDED -> MOBILE_PORTRAIT
35-
widthClass == WindowWidthSizeClass.EXPANDED &&
36-
heightClass == WindowHeightSizeClass.COMPACT -> MOBILE_LANDSCAPE
37-
widthClass == WindowWidthSizeClass.MEDIUM &&
38-
heightClass == WindowHeightSizeClass.EXPANDED -> TABLET_PORTRAIT
39-
widthClass == WindowWidthSizeClass.EXPANDED &&
40-
heightClass == WindowHeightSizeClass.MEDIUM -> TABLET_LANDSCAPE
41-
else -> DESKTOP
48+
return with(receiver = windowSizeClass) {
49+
when {
50+
minWidthDp < WIDTH_DP_MEDIUM_LOWER_BOUND &&
51+
minHeightDp >= HEIGHT_DP_MEDIUM_LOWER_BOUND -> MOBILE_PORTRAIT
52+
minWidthDp >= WIDTH_DP_MEDIUM_LOWER_BOUND &&
53+
minHeightDp < HEIGHT_DP_MEDIUM_LOWER_BOUND -> MOBILE_LANDSCAPE
54+
minWidthDp in WIDTH_DP_MEDIUM_LOWER_BOUND..WIDTH_DP_EXPANDED_LOWER_BOUND &&
55+
minHeightDp >= HEIGHT_DP_MEDIUM_LOWER_BOUND -> TABLET_PORTRAIT
56+
minWidthDp >= WIDTH_DP_EXPANDED_LOWER_BOUND &&
57+
minHeightDp in HEIGHT_DP_MEDIUM_LOWER_BOUND..HEIGHT_DP_EXPANDED_LOWER_BOUND -> TABLET_LANDSCAPE
58+
else -> DESKTOP
59+
}
4260
}
4361
}
4462
}

app/src/main/java/com/codermp/composeandroidtemplate/core/presentation/ui/ObserveAsEvents.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ import kotlinx.coroutines.withContext
1414
* @param flow The [Flow] to observe.
1515
* @param key1 The first key to use for the [LaunchedEffect].
1616
* @param key2 The second key to use for the [LaunchedEffect].
17-
* @param onEvent The function to call when a new event is emitted.
17+
* @param onEvent The suspend function to call when a new event is emitted.
1818
*/
1919
@Composable
2020
fun <T> ObserveAsEvents(
2121
flow: Flow<T>,
2222
key1: Any? = null,
2323
key2: Any? = null,
24-
onEvent: (T) -> Unit
24+
onEvent: suspend (T) -> Unit
2525
) {
2626
val lifecycleOwner = LocalLifecycleOwner.current
2727

0 commit comments

Comments
 (0)