Skip to content

Commit

Permalink
[Android] Display ISO8601 dates with local timestamp (#66)
Browse files Browse the repository at this point in the history
This updates the CredentialDate component to display ISO8601 dates with local timestamps and also disables app rotation for Android.
  • Loading branch information
Juliano1612 authored Dec 17, 2024
1 parent 69eacc7 commit 69567de
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.spruceid.mobilesdkexample

import android.annotation.SuppressLint
import android.app.Application
import android.content.Intent
import android.content.pm.ActivityInfo
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
Expand Down Expand Up @@ -58,9 +60,12 @@ class MainActivity : ComponentActivity() {
}
}

@SuppressLint("SourceLockedOrientationActivity")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT

enableEdgeToEdge()
setContent {
MobileSdkTheme {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import com.spruceid.mobilesdkexample.utils.splitCamelCase
import kotlinx.coroutines.launch
import org.json.JSONObject
import java.time.OffsetDateTime
import java.time.ZoneId
import java.time.format.DateTimeFormatter

class AchievementCredentialItem : ICredentialView {
Expand Down Expand Up @@ -386,6 +387,8 @@ class AchievementCredentialItem : ICredentialView {
val ISO8601DateFormat =
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss[.SSS]Z")
val parsedDate = OffsetDateTime.parse(awardedDate, ISO8601DateFormat)
val localZoneParsedDate =
parsedDate.atZoneSameInstant(ZoneId.systemDefault())
val dateTimeFormatter =
DateTimeFormatter.ofPattern("MMM dd, yyyy 'at' h:mm a")

Expand All @@ -396,7 +399,10 @@ class AchievementCredentialItem : ICredentialView {
Pair(obj["identityType"].toString(), obj["identityHash"].toString())
}
}
details?.add(0, Pair("awardedDate", parsedDate.format(dateTimeFormatter)))
details?.add(
0,
Pair("awardedDate", localZoneParsedDate.format(dateTimeFormatter))
)

Row(
Modifier.padding(horizontal = 12.dp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp
import com.spruceid.mobilesdkexample.ui.theme.ColorStone500
import com.spruceid.mobilesdkexample.ui.theme.ColorStone950
import com.spruceid.mobilesdkexample.ui.theme.Inter
import java.time.OffsetDateTime
import java.time.ZoneId
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter

Expand All @@ -25,8 +25,9 @@ fun CredentialDate(dateString: String) {
try {
val ISO8601DateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss[.SSS]Z")
val parsedDate = OffsetDateTime.parse(dateString, ISO8601DateFormat)
val localZoneParsedDate = parsedDate.atZoneSameInstant(ZoneId.systemDefault())
val dateTimeFormatter = DateTimeFormatter.ofPattern("MMM dd, yyyy 'at' h:mm a")
date = parsedDate.format(dateTimeFormatter)
date = localZoneParsedDate.format(dateTimeFormatter)
return@LaunchedEffect
} catch (_: Exception) {
}
Expand Down

0 comments on commit 69567de

Please sign in to comment.