diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 913d316..fc6f42c 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -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" @@ -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 { @@ -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 + } } \ No newline at end of file diff --git a/app/src/main/java/f/cking/software/ui/devicelist/DeviceListScreen.kt b/app/src/main/java/f/cking/software/ui/devicelist/DeviceListScreen.kt index b4cbd49..7fc27fa 100644 --- a/app/src/main/java/f/cking/software/ui/devicelist/DeviceListScreen.kt +++ b/app/src/main/java/f/cking/software/ui/devicelist/DeviceListScreen.kt @@ -158,8 +158,10 @@ 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, @@ -167,10 +169,9 @@ object DeviceListScreen { 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()) } } @@ -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 diff --git a/app/src/main/java/f/cking/software/ui/devicelist/DeviceListViewModel.kt b/app/src/main/java/f/cking/software/ui/devicelist/DeviceListViewModel.kt index 24bc70c..4f08e60 100644 --- a/app/src/main/java/f/cking/software/ui/devicelist/DeviceListViewModel.kt +++ b/app/src/main/java/f/cking/software/ui/devicelist/DeviceListViewModel.kt @@ -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()