From 46417e265882e716a31df55d67fa8e22d3ba6487 Mon Sep 17 00:00:00 2001 From: Rob Orgiu Date: Tue, 3 Sep 2024 17:12:16 +0200 Subject: [PATCH] Update Supporting Pane to Kotlin 2.0 --- .../supporting-pane-views/app/build.gradle | 18 +++++++++--------- .../supporting/pane/views/ContentViewModel.kt | 7 +++---- .../com/google/supporting/pane/views/Data.kt | 4 +++- .../supporting/pane/views/MainActivity.kt | 15 ++++++--------- .../app/src/main/res/layout/item_support.xml | 1 + .../supporting-pane-views/build.gradle | 8 ++++---- .../supporting-pane-views/gradle.properties | 3 ++- .../gradle/wrapper/gradle-wrapper.properties | 2 +- 8 files changed, 29 insertions(+), 29 deletions(-) diff --git a/CanonicalLayouts/supporting-pane-views/app/build.gradle b/CanonicalLayouts/supporting-pane-views/app/build.gradle index fa29a56f8..8ad26701b 100644 --- a/CanonicalLayouts/supporting-pane-views/app/build.gradle +++ b/CanonicalLayouts/supporting-pane-views/app/build.gradle @@ -21,12 +21,12 @@ plugins { android { namespace 'com.google.supporting.pane.views' - compileSdk 33 + compileSdk 35 defaultConfig { applicationId "com.google.supporting.pane.views" minSdk 21 - targetSdk 33 + targetSdk 35 versionCode 1 versionName "1.0" @@ -54,13 +54,13 @@ android { dependencies { - implementation 'androidx.core:core-ktx:1.9.0' - implementation 'androidx.appcompat:appcompat:1.5.1' - implementation 'com.google.android.material:material:1.6.1' + implementation 'androidx.core:core-ktx:1.13.1' + implementation 'androidx.appcompat:appcompat:1.7.0' + implementation 'com.google.android.material:material:1.12.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.3' - implementation 'androidx.fragment:fragment-ktx:1.5.2' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3' + implementation 'androidx.fragment:fragment-ktx:1.8.2' testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test.ext:junit:1.1.3' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + androidTestImplementation 'androidx.test.ext:junit:1.2.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1' } \ No newline at end of file diff --git a/CanonicalLayouts/supporting-pane-views/app/src/main/java/com/google/supporting/pane/views/ContentViewModel.kt b/CanonicalLayouts/supporting-pane-views/app/src/main/java/com/google/supporting/pane/views/ContentViewModel.kt index 0f684cb9a..9723f49ed 100644 --- a/CanonicalLayouts/supporting-pane-views/app/src/main/java/com/google/supporting/pane/views/ContentViewModel.kt +++ b/CanonicalLayouts/supporting-pane-views/app/src/main/java/com/google/supporting/pane/views/ContentViewModel.kt @@ -21,11 +21,10 @@ import kotlinx.coroutines.flow.MutableStateFlow class ContentViewModel : ViewModel() { - val state = MutableStateFlow(data.keys.first()) - val supportingState = MutableStateFlow(data[state.value].orEmpty()) + val state = MutableStateFlow(State()) fun selectFromSupportingPane(key: String) { - state.value = key - supportingState.value = data[key].orEmpty() + val newState = State(key = key, items = data[key].orEmpty()) + state.value = newState } } \ No newline at end of file diff --git a/CanonicalLayouts/supporting-pane-views/app/src/main/java/com/google/supporting/pane/views/Data.kt b/CanonicalLayouts/supporting-pane-views/app/src/main/java/com/google/supporting/pane/views/Data.kt index 330ffa7d6..f46fc15ca 100644 --- a/CanonicalLayouts/supporting-pane-views/app/src/main/java/com/google/supporting/pane/views/Data.kt +++ b/CanonicalLayouts/supporting-pane-views/app/src/main/java/com/google/supporting/pane/views/Data.kt @@ -23,4 +23,6 @@ val data = mapOf( "backend" to listOf("kotlin", "java"), "java" to listOf("backend", "android", "desktop"), "flutter" to listOf("android", "desktop") -) \ No newline at end of file +) + +data class State(val key: String = data.keys.first(), val items: List = data.values.first()) diff --git a/CanonicalLayouts/supporting-pane-views/app/src/main/java/com/google/supporting/pane/views/MainActivity.kt b/CanonicalLayouts/supporting-pane-views/app/src/main/java/com/google/supporting/pane/views/MainActivity.kt index 9f9ec688e..411aa5e0a 100644 --- a/CanonicalLayouts/supporting-pane-views/app/src/main/java/com/google/supporting/pane/views/MainActivity.kt +++ b/CanonicalLayouts/supporting-pane-views/app/src/main/java/com/google/supporting/pane/views/MainActivity.kt @@ -16,8 +16,8 @@ package com.google.supporting.pane.views -import androidx.appcompat.app.AppCompatActivity import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope import androidx.lifecycle.repeatOnLifecycle @@ -28,7 +28,7 @@ import kotlinx.coroutines.launch class MainActivity : AppCompatActivity() { private val viewModel = ContentViewModel() - private var binding : ActivityMainBinding? = null + private var binding: ActivityMainBinding? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -41,13 +41,10 @@ class MainActivity : AppCompatActivity() { lifecycleScope.launch { repeatOnLifecycle(Lifecycle.State.STARTED) { - viewModel.state.collect { label -> - binding?.mainView?.setText(label) - } - } - repeatOnLifecycle(Lifecycle.State.STARTED) { - viewModel.supportingState.collect { items -> - binding?.supportingView?.updateItems(items) + viewModel.state.collect { state -> + println("Add main content") + binding?.mainView?.setText(state.key) + binding?.supportingView?.updateItems(state.items) } } } diff --git a/CanonicalLayouts/supporting-pane-views/app/src/main/res/layout/item_support.xml b/CanonicalLayouts/supporting-pane-views/app/src/main/res/layout/item_support.xml index a5ef20f50..3c3d515a8 100644 --- a/CanonicalLayouts/supporting-pane-views/app/src/main/res/layout/item_support.xml +++ b/CanonicalLayouts/supporting-pane-views/app/src/main/res/layout/item_support.xml @@ -29,6 +29,7 @@ android:layout_marginTop="8dp" android:layout_marginEnd="8dp" android:layout_marginBottom="8dp" + android:textColor="@color/design_default_color_primary" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" diff --git a/CanonicalLayouts/supporting-pane-views/build.gradle b/CanonicalLayouts/supporting-pane-views/build.gradle index acbb3c0b2..44313117b 100644 --- a/CanonicalLayouts/supporting-pane-views/build.gradle +++ b/CanonicalLayouts/supporting-pane-views/build.gradle @@ -15,10 +15,10 @@ */ plugins { - id 'com.android.application' version '7.3.0' apply false - id 'com.android.library' version '7.3.0' apply false - id 'org.jetbrains.kotlin.android' version '1.7.10' apply false - id 'com.diffplug.spotless' version '5.7.0' apply true + id 'com.android.application' version '8.6.0' apply false + id 'com.android.library' version '8.6.0' apply false + id 'org.jetbrains.kotlin.android' version '2.0.0' apply false + id 'com.diffplug.spotless' version '6.9.0' apply true } subprojects { diff --git a/CanonicalLayouts/supporting-pane-views/gradle.properties b/CanonicalLayouts/supporting-pane-views/gradle.properties index 3c5031eb7..f19c7b9b2 100644 --- a/CanonicalLayouts/supporting-pane-views/gradle.properties +++ b/CanonicalLayouts/supporting-pane-views/gradle.properties @@ -20,4 +20,5 @@ kotlin.code.style=official # Enables namespacing of each library's R class so that its R class includes only the # resources declared in the library itself and none from the library's dependencies, # thereby reducing the size of the R class for that library -android.nonTransitiveRClass=true \ No newline at end of file +android.nonTransitiveRClass=true +android.nonFinalResIds=false \ No newline at end of file diff --git a/CanonicalLayouts/supporting-pane-views/gradle/wrapper/gradle-wrapper.properties b/CanonicalLayouts/supporting-pane-views/gradle/wrapper/gradle-wrapper.properties index 2fdb4357e..1e6879269 100644 --- a/CanonicalLayouts/supporting-pane-views/gradle/wrapper/gradle-wrapper.properties +++ b/CanonicalLayouts/supporting-pane-views/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Wed Aug 17 15:01:41 CEST 2022 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME