Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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("MMM d, 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("MMM d, yyyy", Locale.getDefault())
dateFormatter.format(parsedDate)
},
style = MaterialTheme.typography.titleMedium
)
Spacer(modifier = Modifier.width(8.dp))
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down