Skip to content

Commit

Permalink
Improved the sample app navigation (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
adnanjelic committed Oct 27, 2023
1 parent cd86117 commit ede14e2
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ internal class PaymentCardInputScopeImpl(
@Composable
override fun CardImage(modifier: Modifier) {
Icon(
painter = painterResource(id = cardImageResource), contentDescription = "",
painter = painterResource(id = cardImageResource),
contentDescription = "",
modifier = modifier,
tint = Color.Unspecified
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,22 @@
package com.evervault.sampleapplication

import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.navigation.NavController
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.evervault.sampleapplication.navigation.NavigationGraph
import com.evervault.sampleapplication.ui.theme.EvervaultandroidTheme
import com.evervault.sdk.CustomConfig
import com.evervault.sdk.Evervault
import com.evervault.sdk.input.ui.PaymentCardInput

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -36,8 +26,8 @@ class MainActivity : ComponentActivity() {
customConfig = CustomConfig(isDebugMode = true)
)
super.onCreate(savedInstanceState)
setContent {

setContent {
var encrypted: String? by remember { mutableStateOf(null) }

val navController = rememberNavController()
Expand All @@ -48,8 +38,10 @@ class MainActivity : ComponentActivity() {

EvervaultandroidTheme {
// A surface container using the 'background' color from the theme
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {

Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
NavigationGraph(navController = navController)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.evervault.sampleapplication
package com.evervault.sampleapplication.navigation

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.shape.RoundedCornerShape
Expand All @@ -14,8 +14,10 @@ import androidx.navigation.compose.composable
import com.evervault.sampleapplication.sample.PaymentCardCustomLayoutWithNewComponents
import com.evervault.sampleapplication.sample.PaymentCardCustomLayoutWithNewComponentsWithoutLabels
import com.evervault.sampleapplication.ui.views.BasicEncryptionView
import com.evervault.sampleapplication.ui.views.CageView
import com.evervault.sampleapplication.ui.views.CreditCardInputView
import com.evervault.sampleapplication.ui.views.FileEncryptionView
import com.evervault.sampleapplication.ui.views.MainScreen
import com.evervault.sampleapplication.ui.views.PaymentCardView
import com.evervault.sampleapplication.ui.views.component.CustomTheme
import com.evervault.sampleapplication.ui.views.component.customPlaceholderTexts
Expand All @@ -27,33 +29,32 @@ import com.evervault.sdk.input.ui.card.RowsPaymentCard
import com.evervault.sdk.input.ui.inlinePaymentCardInputLayout
import com.evervault.sdk.input.ui.rowsPaymentCardInputLayout

// TODO: Extract navigation routes into an object and implement it in [ContentView]
@Composable
fun NavigationGraph(navController: NavHostController) {
NavHost(
navController,
startDestination = "home",
startDestination = Route.Home.route,
modifier = Modifier.fillMaxSize(),
) {
composable("home") {
ContentView(navController = navController)
composable(Route.Home.route) {
MainScreen(navController = navController)
}

composable("BasicEncryptionView") {
composable(Route.BasicEncryption.route) {
BasicEncryptionView()
}

composable("FileEncryptionView") {
composable(Route.FileEncryption.route) {
FileEncryptionView()
}

composable("CreditCardInputView") {
composable(Route.CreditCardInput.route) {
CreditCardInputView {
PaymentCardInput(onDataChange = it)
}
}

composable("CreditCardInputViewWithPlaceholders") {
composable(Route.CreditCardInputWithPlaceholders.route) {
CreditCardInputView {
PaymentCardInput(
layout = inlinePaymentCardInputLayout(
Expand All @@ -64,7 +65,7 @@ fun NavigationGraph(navController: NavHostController) {
}
}

composable("CreditCardInputViewCustom") {
composable(Route.CreditCardInputCustom.route) {
CreditCardInputView {
CustomTheme {
PaymentCardInput(
Expand All @@ -80,7 +81,7 @@ fun NavigationGraph(navController: NavHostController) {
}
}

composable("CreditCardInputViewRows") {
composable(Route.CreditCardInputRows.route) {
CreditCardInputView {
PaymentCardInput(
layout = rowsPaymentCardInputLayout(),
Expand All @@ -89,7 +90,7 @@ fun NavigationGraph(navController: NavHostController) {
}
}

composable("CreditCardInputViewRowsWithPlaceholders") {
composable(Route.CreditCardInputRowsWithPlaceholders.route) {
CreditCardInputView {
PaymentCardInput(
layout = rowsPaymentCardInputLayout(placeholderTexts = customPlaceholderTexts()),
Expand All @@ -98,7 +99,7 @@ fun NavigationGraph(navController: NavHostController) {
}
}

composable("CreditCardInputViewCustomStyle") {
composable(Route.CreditCardInputCustomStyle.route) {
CreditCardInputView {
PaymentCardInput(
layout = customPaymentCardInputLayout(),
Expand All @@ -107,43 +108,43 @@ fun NavigationGraph(navController: NavHostController) {
}
}

composable("InlinePaymentCardView") {
composable(Route.InlinePaymentCard.route) {
PaymentCardView { onDataChange ->
InlinePaymentCard(onDataChange = onDataChange)
}
}

composable("InlinePaymentCardCustomView") {
composable(Route.InlinePaymentCardCustomStyle.route) {
PaymentCardView { onDataChange ->
CustomTheme {
InlinePaymentCard(onDataChange = onDataChange)
}
}
}

composable("RowsPaymentCardView") {
composable(Route.RowsPaymentCard.route) {
PaymentCardView { onDataChange ->
RowsPaymentCard(onDataChange = onDataChange)
}
}

composable("CreditCardInputViewCustomComposables") {
composable(Route.CreditCardInputCustomComposables.route) {
PaymentCardView { onDataChange ->
PaymentCard(onDataChange = onDataChange) { modifier ->
PaymentCardCustomLayoutWithNewComponents(modifier)
}
}
}

composable("CreditCardInputViewCustomComposablesWithoutLabels") {
composable(Route.CreditCardInputCustomComposablesWithoutLabels.route) {
PaymentCardView { onDataChange ->
PaymentCard(onDataChange = onDataChange) { modifier ->
PaymentCardCustomLayoutWithNewComponentsWithoutLabels(modifier)
}
}
}

composable("CageView") {
composable(Route.Cage.route) {
CageView()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.evervault.sampleapplication.navigation

sealed class Route(val route: String) {

object Home : Route("home")

object BasicEncryption : Route("BasicEncryption")

object FileEncryption : Route("FileEncryption")

object CreditCardInput : Route("CreditCardInput")

object CreditCardInputWithPlaceholders : Route("CreditCardInputWithPlaceholders")

object CreditCardInputCustom : Route("CreditCardInputCustom")

object CreditCardInputRows : Route("CreditCardInputRows")

object CreditCardInputRowsWithPlaceholders : Route("CreditCardInputRowsWithPlaceholders")

object CreditCardInputCustomStyle : Route("CreditCardInputCustomStyle")

object InlinePaymentCard : Route("InlinePaymentCard")

object InlinePaymentCardCustomStyle : Route("InlinePaymentCardCustomStyle")

object RowsPaymentCard : Route("RowsPaymentCard")

object CreditCardInputCustomComposables : Route("CreditCardInputCustomComposables")

object CreditCardInputCustomComposablesWithoutLabels :
Route("CreditCardInputCustomComposablesWithoutLabels")

object Cage : Route("Cage")
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.evervault.sampleapplication
package com.evervault.sampleapplication.ui.views

import AttestationDocCache
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand All @@ -14,7 +13,6 @@ import androidx.compose.ui.unit.dp
import com.evervault.sdk.cages.AttestationData
import com.evervault.sdk.cages.PCRs
import com.evervault.sdk.cages.cagesTrustManager
import com.evervault.sdk.cages.trustManager
import com.google.gson.Gson
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
Expand All @@ -25,8 +23,8 @@ import java.io.IOException
@Composable
fun CageView() {

val cageName = "hello-cage"
val appId = "app-000000000000"
val cageName = "hello-cage"
val appId = "app-000000000000"

var responseText: String? by remember { mutableStateOf(null) }

Expand All @@ -35,15 +33,17 @@ fun CageView() {
val url = "https://$cageName.$appId.cage.evervault.com/hello"

val client = OkHttpClient.Builder()
.cagesTrustManager(AttestationData(
cageName = cageName,
// Replace with legitimate PCR strings when not in debug mode
PCRs(
pcr0 = "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
pcr1 = "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
pcr2 = "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
pcr8 = "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
)),
.cagesTrustManager(
AttestationData(
cageName = cageName,
// Replace with legitimate PCR strings when not in debug mode
PCRs(
pcr0 = "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
pcr1 = "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
pcr2 = "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
pcr8 = "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
)
),
appId
)
.build()
Expand Down
Loading

0 comments on commit ede14e2

Please sign in to comment.