diff --git a/dataconnect/app/src/main/java/com/google/firebase/example/dataconnect/ui/components/ReviewCard.kt b/dataconnect/app/src/main/java/com/google/firebase/example/dataconnect/ui/components/ReviewCard.kt index bd0a8f9393..15676631d8 100644 --- a/dataconnect/app/src/main/java/com/google/firebase/example/dataconnect/ui/components/ReviewCard.kt +++ b/dataconnect/app/src/main/java/com/google/firebase/example/dataconnect/ui/components/ReviewCard.kt @@ -1,5 +1,6 @@ package com.google.firebase.example.dataconnect.ui.components +import android.os.Build import android.widget.Space import androidx.compose.foundation.background import androidx.compose.foundation.layout.Column @@ -17,17 +18,17 @@ import androidx.compose.ui.semantics.text import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp +import com.google.firebase.dataconnect.LocalDate +import com.google.firebase.dataconnect.toJavaLocalDate import java.text.SimpleDateFormat -import java.time.LocalDate -import java.time.LocalDateTime -import java.util.Date +import java.time.format.DateTimeFormatter import java.util.Locale @Composable fun ReviewCard( userName: String, - date: Date, + date: LocalDate, rating: Double, text: String, movieName: String? = null @@ -55,10 +56,23 @@ fun ReviewCard( modifier = Modifier.padding(bottom = 8.dp) ) { Text( - text = SimpleDateFormat( - "dd MMM, yyyy", - Locale.getDefault() - ).format(date), + text = + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + val dateFormatter = DateTimeFormatter.ofPattern("dd MMM, yyyy", Locale.getDefault()) + date.toJavaLocalDate().format(dateFormatter) + } else { + val parseableDateString = date.run { + val year = "$year".padStart(4, '0') + val month = "$month".padStart(2, '0') + val day = "$day".padStart(2, '0') + "$year-$month-$day" + } + val dateParser = SimpleDateFormat("y-M-d", Locale.US) + val parsedDate = dateParser.parse(parseableDateString) ?: + throw Exception("INTERNAL ERROR: unparseable date string: $parseableDateString") + val dateFormatter = SimpleDateFormat("dd MMM, yyyy", Locale.getDefault()) + dateFormatter.format(parsedDate) + }, style = MaterialTheme.typography.titleMedium ) Spacer(modifier = Modifier.width(8.dp)) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 00284342f5..ef6ed05e45 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,7 +2,7 @@ agp = "8.7.2" coilCompose = "2.7.0" firebaseAuth = "23.1.0" -firebaseDataConnect = "16.0.0-beta02" +firebaseDataConnect = "16.0.0-beta03" kotlin = "2.0.21" coreKtx = "1.13.1" junit = "4.13.2"