@@ -53,79 +53,77 @@ class MainActivity : ComponentActivity() {
5353 override fun onCreate (savedInstanceState : Bundle ? ) {
5454 super .onCreate(savedInstanceState)
5555 setContent {
56- Cert4Android .theme {
57- val snackBarHostState = remember { SnackbarHostState () }
58- val certificateDetails = model.certificateDetailsFlow.collectAsStateWithLifecycle().value
59-
60- Box (Modifier .fillMaxSize()) {
61- Column (
62- Modifier
63- .padding(8 .dp)
64- .verticalScroll(rememberScrollState())
65- ) {
66- Button (onClick = {
67- model.testAccess(" https://www.github.com" )
68- }, modifier = Modifier .padding(top = 16 .dp)) {
69- Text (" Access normal URL with trusted system certs" )
70- }
56+ val snackBarHostState = remember { SnackbarHostState () }
57+ val certificateDetails = model.certificateDetailsFlow.collectAsStateWithLifecycle().value
58+
59+ Box (Modifier .fillMaxSize()) {
60+ Column (
61+ Modifier
62+ .padding(8 .dp)
63+ .verticalScroll(rememberScrollState())
64+ ) {
65+ Button (onClick = {
66+ model.testAccess(" https://www.github.com" )
67+ }, modifier = Modifier .padding(top = 16 .dp)) {
68+ Text (" Access normal URL with trusted system certs" )
69+ }
7170
72- Button (onClick = {
73- model.testAccess(" https://www.github.com" , trustSystemCerts = false )
74- }, modifier = Modifier .padding(top = 16 .dp)) {
75- Text (" Access normal URL with distrusted system certs" )
76- }
71+ Button (onClick = {
72+ model.testAccess(" https://www.github.com" , trustSystemCerts = false )
73+ }, modifier = Modifier .padding(top = 16 .dp)) {
74+ Text (" Access normal URL with distrusted system certs" )
75+ }
7776
78- Button (onClick = {
79- model.testAccess(" https://expired.badssl.com/" )
80- }, modifier = Modifier .padding(top = 16 .dp)) {
81- Text (" Access URL with expired certificate" )
82- }
77+ Button (onClick = {
78+ model.testAccess(" https://expired.badssl.com/" )
79+ }, modifier = Modifier .padding(top = 16 .dp)) {
80+ Text (" Access URL with expired certificate" )
81+ }
8382
84- Button (onClick = {
85- model.testAccess(" https://self-signed.badssl.com/" )
86- }, modifier = Modifier .padding(top = 16 .dp)) {
87- Text (" Access URL with self-signed certificate" )
88- }
83+ Button (onClick = {
84+ model.testAccess(" https://self-signed.badssl.com/" )
85+ }, modifier = Modifier .padding(top = 16 .dp)) {
86+ Text (" Access URL with self-signed certificate" )
87+ }
8988
90- Button (onClick = {
91- model.testAccess(" https://wrong.host.badssl.com/" )
92- }, modifier = Modifier .padding(top = 16 .dp)) {
93- Text (" Access URL with certificate for wrong host name" )
94- }
89+ Button (onClick = {
90+ model.testAccess(" https://wrong.host.badssl.com/" )
91+ }, modifier = Modifier .padding(top = 16 .dp)) {
92+ Text (" Access URL with certificate for wrong host name" )
93+ }
9594
96- Button (onClick = {
97- model.testAccess(
98- " https://wrong.host.badssl.com/" ,
99- trustSystemCerts = false
100- )
101- }, modifier = Modifier .padding(top = 16 .dp)) {
102- Text (" Access URL with certificate for wrong host name with distrusted system certs" )
103- }
95+ Button (onClick = {
96+ model.testAccess(
97+ " https://wrong.host.badssl.com/" ,
98+ trustSystemCerts = false
99+ )
100+ }, modifier = Modifier .padding(top = 16 .dp)) {
101+ Text (" Access URL with certificate for wrong host name with distrusted system certs" )
102+ }
104103
105- Button (onClick = {
106- model.reset()
107- }, modifier = Modifier .padding(top = 16 .dp)) {
108- Text (" Clear trusted certs" )
109- }
104+ Button (onClick = {
105+ model.reset()
106+ }, modifier = Modifier .padding(top = 16 .dp)) {
107+ Text (" Clear trusted certs" )
108+ }
110109
111- val result = model.resultMessage.observeAsState()
112- result.value?.let { msg ->
113- if (msg.isNotEmpty())
114- LaunchedEffect (snackBarHostState) {
115- snackBarHostState.showSnackbar(msg)
116- model.resultMessage.value = null
117- }
118- }
110+ val result = model.resultMessage.observeAsState()
111+ result.value?.let { msg ->
112+ if (msg.isNotEmpty())
113+ LaunchedEffect (snackBarHostState) {
114+ snackBarHostState.showSnackbar(msg)
115+ model.resultMessage.value = null
116+ }
119117 }
118+ }
120119
121- if (certificateDetails != null )
122- TrustCertificateDialog (certificateDetails, model::registerUserDecision)
120+ if (certificateDetails != null )
121+ TrustCertificateDialog (certificateDetails, model::registerUserDecision)
123122
124- SnackbarHost (
125- snackBarHostState,
126- modifier = Modifier .align(Alignment .BottomCenter )
127- )
128- }
123+ SnackbarHost (
124+ snackBarHostState,
125+ modifier = Modifier .align(Alignment .BottomCenter )
126+ )
129127 }
130128 }
131129 }
0 commit comments