Skip to content

Commit

Permalink
Update Supporting Pane to Kotlin 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Orgiu committed Sep 3, 2024
1 parent 90f5cf9 commit 46417e2
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 29 deletions.
18 changes: 9 additions & 9 deletions CanonicalLayouts/supporting-pane-views/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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'
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ val data = mapOf(
"backend" to listOf("kotlin", "java"),
"java" to listOf("backend", "android", "desktop"),
"flutter" to listOf("android", "desktop")
)
)

data class State(val key: String = data.keys.first(), val items: List<String> = data.values.first())
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions CanonicalLayouts/supporting-pane-views/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion CanonicalLayouts/supporting-pane-views/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
android.nonTransitiveRClass=true
android.nonFinalResIds=false
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 46417e2

Please sign in to comment.