This repository was archived by the owner on Mar 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Android] Refactor credential management (#108)
This updates the way we implement the credential displayer and includes some status lists changes.
- Loading branch information
1 parent
1d92bed
commit bf841b1
Showing
17 changed files
with
1,000 additions
and
1,203 deletions.
There are no files selected for viewing
493 changes: 0 additions & 493 deletions
493
example/src/main/java/com/spruceid/mobilesdkexample/credentials/AchievementCredentialItem.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
example/src/main/java/com/spruceid/mobilesdkexample/credentials/CredentialDetailsView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package com.spruceid.mobilesdkexample.credentials | ||
|
||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.HorizontalDivider | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.rotate | ||
import androidx.compose.ui.draw.scale | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import androidx.navigation.NavController | ||
import com.spruceid.mobile.sdk.CredentialPack | ||
import com.spruceid.mobile.sdk.CredentialStatusList | ||
import com.spruceid.mobilesdkexample.R | ||
import com.spruceid.mobilesdkexample.navigation.Screen | ||
import com.spruceid.mobilesdkexample.utils.credentialDisplaySelector | ||
import com.spruceid.mobilesdkexample.viewmodels.CredentialPacksViewModel | ||
import com.spruceid.mobilesdkexample.viewmodels.StatusListViewModel | ||
import java.util.UUID | ||
|
||
@Composable | ||
fun CredentialDetailsView( | ||
navController: NavController, | ||
credentialPacksViewModel: CredentialPacksViewModel, | ||
statusListViewModel: StatusListViewModel, | ||
credentialPackId: String | ||
) { | ||
var credentialItem by remember { mutableStateOf<ICredentialView?>(null) } | ||
var credentialPack by remember { mutableStateOf<CredentialPack?>(null) } | ||
val statusList by statusListViewModel.observeStatusForId(UUID.fromString(credentialPackId)) | ||
.collectAsState() | ||
|
||
LaunchedEffect(Unit) { | ||
credentialPack = credentialPacksViewModel.getById(credentialPackId) ?: CredentialPack() | ||
credentialItem = credentialDisplaySelector( | ||
credentialPack!!, | ||
statusListViewModel, | ||
null, | ||
null, | ||
null | ||
) | ||
statusListViewModel.fetchAndUpdateStatus(credentialPack!!) | ||
} | ||
|
||
fun back() { | ||
navController.navigate(Screen.HomeScreen.route) { | ||
popUpTo(0) | ||
} | ||
} | ||
|
||
credentialItem?.let { | ||
Column( | ||
Modifier | ||
.padding(all = 20.dp) | ||
.padding(top = 20.dp) | ||
) { | ||
Row(verticalAlignment = Alignment.CenterVertically) { | ||
Image( | ||
painter = painterResource(id = R.drawable.chevron), | ||
contentDescription = stringResource(id = R.string.chevron), | ||
modifier = Modifier | ||
.scale(0.75f) | ||
.rotate(180f) | ||
.padding(start = 10.dp) | ||
.clickable { | ||
back() | ||
} | ||
) | ||
it.credentialListItem() | ||
} | ||
HorizontalDivider(modifier = Modifier.padding(vertical = 16.dp)) | ||
if (statusList != CredentialStatusList.REVOKED) { | ||
credentialItem!!.credentialDetails() | ||
} else { | ||
credentialItem!!.credentialRevokedInfo({ | ||
back() | ||
}) | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.