Skip to content

Commit

Permalink
Merge pull request #154 from Semper-Viventem/update-target
Browse files Browse the repository at this point in the history
Update SDK target and make it possible to change JDK from env variables
  • Loading branch information
Semper-Viventem authored Aug 20, 2024
2 parents 42993e2 + 9b30f68 commit 9a7ef8e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 18 deletions.
43 changes: 35 additions & 8 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ apply {
}

android {
compileSdk = 34
compileSdk = 35
namespace = "f.cking.software"
val javaConfig: JavaConfig = JavaConfig.getByString(getEnvJavaConfigVersion())

defaultConfig {
applicationId = "f.cking.software"
minSdk = 29
targetSdk = 34
targetSdk = 35

versionCode = 1708536357
versionName = "0.26.1-beta"
versionCode = 1708536358
versionName = "0.26.2-beta"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

Expand Down Expand Up @@ -108,16 +109,16 @@ android {
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_22
targetCompatibility = JavaVersion.VERSION_22
sourceCompatibility = javaConfig.javaVersion
targetCompatibility = javaConfig.javaVersion
}

kotlin {
jvmToolchain(22)
jvmToolchain(javaConfig.jdkVersion)
}

kotlinOptions {
jvmTarget = "22"
jvmTarget = javaConfig.jvmTarget
}

buildFeatures.apply {
Expand Down Expand Up @@ -195,4 +196,30 @@ dependencies {
// tests
testImplementation(libs.junit)
androidTestImplementation(libs.ktx.testing)
}

private fun getEnvJavaConfigVersion(): String {
val version = gradleLocalProperties(rootDir, providers).getProperty("JAVA_CONFIG_VERSION", System.getenv("JAVA_CONFIG_VERSION") ?: "UNSPECIFIED")
println("Environment JDK version selected is ${version}. To override it define JAVA_CONFIG_VERSION environment variable or local properties.")
return version
}

enum class JavaConfig(val jvmTarget: String, val jdkVersion: Int, val javaVersion: JavaVersion) {
JAVA_21("21", 21, JavaVersion.VERSION_21),
JAVA_22("22", 22, JavaVersion.VERSION_22);

companion object {
fun getByString(versionStr: String?): JavaConfig {
return when (versionStr) {
"21" -> JAVA_21
"22" -> JAVA_22
else -> {
println("Java version ${versionStr} is not recognized. The default one will be used instead for this project: ${DEFAULT.jvmTarget}")
DEFAULT
}
}
}

private val DEFAULT = JAVA_22
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,20 @@ object DeviceListScreen {
}
}

viewModel.devicesViewState.mapIndexed { index, deviceData ->
item(contentType = ListContentType.DEVICE, key = "device_${deviceData.address}") {
val devices = viewModel.devicesViewState

items(devices.size, key = { "device_${devices[it]}" }, contentType = { ListContentType.DEVICE}) { index ->
val deviceData = devices[index]
DeviceListItem(
modifier = Modifier.animateItemPlacement(),
device = deviceData,
onClick = { viewModel.onDeviceClick(deviceData) },
onTagSelected = { viewModel.onTagSelected(it) },
)

}
val showDivider = viewModel.devicesViewState.getOrNull(index + 1)?.lastDetectTimeMs != deviceData.lastDetectTimeMs
if (showDivider) {
item(contentType = ListContentType.DIVIDER, key = "${deviceData.lastDetectTimeMs}") { Divider(Modifier.animateItemPlacement()) }
Divider(Modifier.animateItemPlacement())
}
}

Expand All @@ -193,7 +194,7 @@ object DeviceListScreen {
}

enum class ListContentType {
ENJOY_THE_APP, CURRENT_BATCH, DEVICE, DIVIDER, PAGINATION_PROGRESS, BOTTOM_SPACER,
ENJOY_THE_APP, CURRENT_BATCH, DEVICE, PAGINATION_PROGRESS, BOTTOM_SPACER,
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,14 @@ class DeviceListViewModel(
val anyFilterApplyed = isSearchMode || appliedFilter.isNotEmpty()

scannerObservingJob?.cancel()
if (isScannerEnabled || anyFilterApplyed) {
disablePagination()
} else {
enablePagination()
}
disablePagination()

// TODO fix realtime items observing before enabling pagination
// if (isScannerEnabled || anyFilterApplyed) {
// disablePagination()
// } else {
// enablePagination()
// }

if (invalidateCurrentBatch) {
lastBatchJob?.cancel()
Expand Down

0 comments on commit 9a7ef8e

Please sign in to comment.