11package com.example.sw0b_001.ui.views.tabs
22
33import androidx.compose.foundation.background
4- import androidx.compose.foundation.clickable
54import androidx.compose.foundation.layout.Arrangement
65import androidx.compose.foundation.layout.Box
76import androidx.compose.foundation.layout.Column
87import androidx.compose.foundation.layout.ExperimentalLayoutApi
9- import androidx.compose.foundation.layout.FlowRow
108import androidx.compose.foundation.layout.Row
119import androidx.compose.foundation.layout.Spacer
1210import androidx.compose.foundation.layout.fillMaxSize
@@ -21,12 +19,15 @@ import androidx.compose.foundation.shape.RoundedCornerShape
2119import androidx.compose.foundation.verticalScroll
2220import androidx.compose.material.icons.Icons
2321import androidx.compose.material.icons.filled.ChatBubbleOutline
22+ import androidx.compose.material.icons.filled.Close
23+ import androidx.compose.material3.Button
2424import androidx.compose.material3.ButtonDefaults
2525import androidx.compose.material3.Card
2626import androidx.compose.material3.CardDefaults
2727import androidx.compose.material3.ExperimentalMaterial3Api
2828import androidx.compose.material3.HorizontalDivider
2929import androidx.compose.material3.Icon
30+ import androidx.compose.material3.IconButton
3031import androidx.compose.material3.LinearProgressIndicator
3132import androidx.compose.material3.MaterialTheme
3233import androidx.compose.material3.OutlinedButton
@@ -94,15 +95,19 @@ fun SupportedPlatformsView(
9495 LaunchedEffect (Unit ) {
9596 supportedPlatformsViewModel.fetch()
9697 }
98+ var showDefaultSmsCard by remember {
99+ mutableStateOf(true )
100+ }
97101
98102 val inPreviewMode = LocalInspectionMode .current
99103
100- var isDefault by remember{
101- mutableStateOf(inPreviewMode || context.isDefault()) }
104+ var isDefault by remember {
105+ mutableStateOf(inPreviewMode || context.isDefault())
106+ }
102107
103108 val getDefaultPermission = getSetDefaultBehaviour(context) {
104109 isDefault = context.isDefault()
105- if (isDefault) {
110+ if (isDefault) {
106111 navController.navigate(HomeScreenNav ()) {
107112 popUpTo(HomeScreenNav ()) {
108113 inclusive = true
@@ -112,68 +117,86 @@ fun SupportedPlatformsView(
112117 }
113118 }
114119
115- Column (
116- modifier = Modifier
117- .fillMaxSize()
118- .padding(start = 16 .dp, end = 16 .dp, top = 16 .dp)
119- .verticalScroll(rememberScrollState()),
120- horizontalAlignment = Alignment .CenterHorizontally
120+ Box (
121+ modifier = Modifier .fillMaxSize()
121122 ) {
122- Text (
123- text = if (isCompose) stringResource(R .string.send_new_message)
124- else stringResource(R .string.supported_platforms),
125- style = MaterialTheme .typography.titleMedium,
126- fontWeight = FontWeight .SemiBold ,
127- textAlign = TextAlign .Center ,
128- modifier = Modifier .padding(bottom = 16 .dp),
129- )
130-
131- if (inPreviewMode || (isCompose && ! isDefault && ! isOnboarding)) {
132- Column (
133- modifier = Modifier
134- .fillMaxWidth()
135- .padding(16 .dp),
136- horizontalAlignment = Alignment .CenterHorizontally ,
137- verticalArrangement = Arrangement .Center
138- ) {
139- OutlinedButton (onClick = {
140- getDefaultPermission.launch(makeDefault(context))
141- }) {
142- Row (
143- horizontalArrangement = Arrangement .Center ,
144- verticalAlignment = Alignment .CenterVertically ,
145- modifier = Modifier
146- .fillMaxWidth()
147- .padding(8 .dp),
148- ) {
149- Icon (
150- imageVector = Icons .Default .ChatBubbleOutline ,
151- contentDescription = stringResource(R .string.compose),
152- )
153-
154- Spacer (Modifier .size(ButtonDefaults .IconSpacing ))
123+ Column (
124+ modifier = Modifier
125+ .fillMaxSize()
126+ .padding(horizontal = 16 .dp, vertical = 16 .dp)
127+ .padding(bottom = 170 .dp)
128+ .verticalScroll(rememberScrollState()),
129+ horizontalAlignment = Alignment .CenterHorizontally
130+ ) {
131+ Text (
132+ text = if (isCompose) stringResource(R .string.send_new_message)
133+ else stringResource(R .string.supported_platforms),
134+ style = MaterialTheme .typography.titleMedium,
135+ fontWeight = FontWeight .SemiBold ,
136+ textAlign = TextAlign .Center ,
137+ modifier = Modifier .padding(bottom = 16 .dp),
138+ )
155139
156- Text (
157- stringResource(R .string.set_as_default_sms_app),
158- fontWeight = FontWeight .SemiBold ,
159- )
140+ if (inPreviewMode || (isCompose && ! isDefault && ! isOnboarding)) {
141+ Column (
142+ modifier = Modifier
143+ .fillMaxWidth()
144+ .padding(16 .dp),
145+ horizontalAlignment = Alignment .CenterHorizontally ,
146+ verticalArrangement = Arrangement .Center
147+ ) {
148+ OutlinedButton (onClick = {
149+ getDefaultPermission.launch(makeDefault(context))
150+ }) {
151+ Row (
152+ horizontalArrangement = Arrangement .Center ,
153+ verticalAlignment = Alignment .CenterVertically ,
154+ modifier = Modifier
155+ .fillMaxWidth()
156+ .padding(8 .dp),
157+ ) {
158+ Icon (
159+ imageVector = Icons .Default .ChatBubbleOutline ,
160+ contentDescription = stringResource(R .string.compose),
161+ )
162+
163+ Spacer (Modifier .size(ButtonDefaults .IconSpacing ))
164+
165+ Text (
166+ stringResource(R .string.set_as_default_sms_app),
167+ fontWeight = FontWeight .SemiBold ,
168+ )
169+ }
160170 }
161171 }
172+ HorizontalDivider ()
162173 }
163174
164- HorizontalDivider ()
175+ PlatformListContent (
176+ isCompose = isCompose,
177+ supportedPlatformsViewModel = supportedPlatformsViewModel,
178+ tokensViewModel = tokensViewModel,
179+ isOnboarding = isOnboarding,
180+ navController = navController,
181+ )
165182 }
166183
167- PlatformListContent (
168- isCompose = isCompose,
169- supportedPlatformsViewModel = supportedPlatformsViewModel,
170- tokensViewModel = tokensViewModel,
171- isOnboarding = isOnboarding,
172- navController = navController,
173- )
184+ if (! isDefault && showDefaultSmsCard) {
185+ DefaultSmsCard (
186+ modifier = Modifier
187+ .align(Alignment .BottomCenter )
188+ .padding(16 .dp),
189+ onDismiss = {
190+ showDefaultSmsCard = false
191+ },
192+ onSetDefault = {
193+ getDefaultPermission.launch(makeDefault(context))
194+ }
195+ )
196+ }
197+ }
174198 }
175199
176- }
177200
178201@OptIn(ExperimentalLayoutApi ::class )
179202@Composable
@@ -500,3 +523,75 @@ fun PlatformListRow(
500523 }
501524}
502525
526+
527+ @Composable
528+ fun DefaultSmsCard (
529+ modifier : Modifier = Modifier ,
530+ onDismiss : () -> Unit ,
531+ onSetDefault : () -> Unit
532+ ) {
533+ Card (
534+ modifier = modifier.fillMaxWidth(),
535+ shape = RoundedCornerShape (15 .dp),
536+ colors = CardDefaults .cardColors(
537+ containerColor = MaterialTheme .colorScheme.surfaceContainer
538+ )
539+ ) {
540+ Column (
541+ modifier = Modifier
542+ .fillMaxWidth()
543+ .padding(16 .dp)
544+ ) {
545+ Row (
546+ modifier = Modifier .fillMaxWidth(),
547+ horizontalArrangement = Arrangement .End
548+ ) {
549+ IconButton (
550+ onClick = {
551+ onDismiss()
552+ },
553+ modifier = Modifier .size(28 .dp)
554+ ) {
555+ Icon (
556+ imageVector = Icons .Default .Close ,
557+ contentDescription = " Dismiss" ,
558+ tint = MaterialTheme .colorScheme.onSurfaceVariant
559+ )
560+ }
561+ }
562+
563+ Spacer (modifier = Modifier .height(8 .dp))
564+
565+ Text (
566+ text = " To send attachments and enjoy the full RelaySMS experience, make RelaySMS your default SMS app." ,
567+ style = MaterialTheme .typography.bodyMedium,
568+ textAlign = TextAlign .Center ,
569+ color = MaterialTheme .colorScheme.onSurfaceVariant,
570+ modifier = Modifier .fillMaxWidth()
571+ )
572+
573+ Spacer (modifier = Modifier .height(24 .dp))
574+
575+ Button (
576+ onClick = onSetDefault,
577+ modifier = Modifier
578+ .align(Alignment .CenterHorizontally )
579+ .height(44 .dp)
580+ .width(170 .dp),
581+ shape = RoundedCornerShape (14 .dp),
582+ elevation = ButtonDefaults .buttonElevation(
583+ defaultElevation = 1 .dp
584+ ),
585+ colors = ButtonDefaults .buttonColors(
586+ containerColor = MaterialTheme .colorScheme.primary
587+ )
588+ ) {
589+ Text (
590+ text = " Set Default SMS App" ,
591+ style = MaterialTheme .typography.titleSmall,
592+ fontWeight = FontWeight .SemiBold
593+ )
594+ }
595+ }
596+ }
597+ }
0 commit comments