@@ -6,185 +6,61 @@ import android.content.Context.ROLE_SERVICE
66import android.content.Intent
77import android.os.Build
88import android.provider.Telephony
9+ import androidx.compose.foundation.Image
910import androidx.compose.foundation.layout.Arrangement
1011import androidx.compose.foundation.layout.Column
11- import androidx.compose.foundation.layout.Row
12- import androidx.compose.foundation.layout.Spacer
1312import androidx.compose.foundation.layout.fillMaxSize
1413import androidx.compose.foundation.layout.fillMaxWidth
1514import androidx.compose.foundation.layout.padding
16- import androidx.compose.foundation.layout.size
17- import androidx.compose.foundation.rememberScrollState
18- import androidx.compose.foundation.verticalScroll
19- import androidx.compose.material.icons.Icons
20- import androidx.compose.material.icons.filled.ChatBubbleOutline
21- import androidx.compose.material.icons.filled.Create
22- import androidx.compose.material3.Button
23- import androidx.compose.material3.ButtonDefaults
24- import androidx.compose.material3.Card
25- import androidx.compose.material3.CardDefaults
26- import androidx.compose.material3.ExperimentalMaterial3Api
27- import androidx.compose.material3.Icon
2815import androidx.compose.material3.MaterialTheme
29- import androidx.compose.material3.OutlinedButton
3016import androidx.compose.material3.Text
3117import androidx.compose.runtime.Composable
32- import androidx.compose.runtime.getValue
33- import androidx.compose.runtime.mutableStateOf
34- import androidx.compose.runtime.remember
35- import androidx.compose.runtime.setValue
3618import androidx.compose.ui.Alignment
3719import androidx.compose.ui.Modifier
38- import androidx.compose.ui.platform.LocalContext
39- import androidx.compose.ui.platform.LocalInspectionMode
40- import androidx.compose.ui.res.stringResource
41- import androidx.compose.ui.text.SpanStyle
42- import androidx.compose.ui.text.buildAnnotatedString
20+ import androidx.compose.ui.res.painterResource
4321import androidx.compose.ui.text.font.FontWeight
4422import androidx.compose.ui.text.style.TextAlign
45- import androidx.compose.ui.text.withStyle
4623import androidx.compose.ui.tooling.preview.Preview
4724import androidx.compose.ui.unit.dp
4825import androidx.navigation.NavController
49- import com.afkanerd.smswithoutborders_libsmsmms.extensions.context.isDefault
50- import com.afkanerd.smswithoutborders_libsmsmms.ui.getSetDefaultBehaviour
51- import com.afkanerd.smswithoutborders_libsmsmms.ui.navigation.HomeScreenNav
5226import com.example.sw0b_001.R
5327import com.example.sw0b_001.ui.theme.AppTheme
28+ import androidx.compose.foundation.layout.Box
29+ import androidx.compose.foundation.layout.size
5430
55- @OptIn(ExperimentalMaterial3Api ::class )
5631@Composable
57- fun GetStartedView (navController : NavController ) {
58- val context = LocalContext .current
59- val previewMode = LocalInspectionMode .current
60-
61- var isDefault by remember{
62- mutableStateOf(previewMode || context.isDefault()) }
63-
64- val getDefaultPermission = getSetDefaultBehaviour(context) {
65- isDefault = context.isDefault()
66- if (isDefault) {
67- navController.navigate(HomeScreenNav ()) {
68- popUpTo(HomeScreenNav ()) {
69- inclusive = true
70- }
71- launchSingleTop = true
72- }
73- }
74- }
75-
32+ fun GetStartedView (navController : NavController ) {
7633 Column (
7734 modifier = Modifier
78- .verticalScroll(rememberScrollState())
7935 .fillMaxSize()
80- .padding(8 .dp),
36+ .padding(24 .dp),
8137 horizontalAlignment = Alignment .CenterHorizontally ,
38+ verticalArrangement = Arrangement .Center
8239 ) {
83- Card (
84- elevation = CardDefaults .cardElevation(4 .dp),
85- colors = CardDefaults .cardColors(MaterialTheme .colorScheme.background),
86- modifier = Modifier
87- .fillMaxWidth()
40+ Box (
41+ modifier = Modifier .fillMaxWidth(),
42+ contentAlignment = Alignment .Center
8843 ) {
89- Column (
90- modifier = Modifier
91- .fillMaxWidth()
92- .padding(16 .dp),
93- horizontalAlignment = Alignment .CenterHorizontally ,
94- verticalArrangement = Arrangement .Center
95- ) {
96- Button (
97- onClick = { TODO () },
98- colors = ButtonDefaults
99- .buttonColors(MaterialTheme .colorScheme.primary),
100- modifier = Modifier .fillMaxWidth(),
101- elevation = ButtonDefaults .buttonElevation(4 .dp)
102- ) {
103- Row (
104- horizontalArrangement = Arrangement .Center ,
105- verticalAlignment = Alignment .CenterVertically ,
106- modifier = Modifier .padding(8 .dp)
107- ) {
108- Icon (
109- imageVector = Icons .Filled .Create ,
110- contentDescription = stringResource(R .string.compose),
111- tint = MaterialTheme .colorScheme.onPrimary,
112- )
113-
114- Spacer (Modifier .size(ButtonDefaults .IconSpacing ))
115-
116- Text (
117- stringResource(R .string.compose_message),
118- color = MaterialTheme .colorScheme.onPrimary,
119- fontWeight = FontWeight .SemiBold
120- )
121- }
122- }
123-
124- Text (text = buildAnnotatedString {
125- withStyle(style = SpanStyle (color = MaterialTheme .colorScheme.onBackground)) {
126- append(stringResource(R .string.use_your_phone_number_to_send_an_email_with_the_alias))
127- }
128- withStyle(style = SpanStyle (
129- color = MaterialTheme .colorScheme.tertiary,
130- fontWeight = FontWeight .Bold )
131- ) { append(" your_phonenumber@relaysms.me" ) } },
132- style = MaterialTheme .typography.bodySmall,
133- modifier = Modifier
134- .fillMaxWidth()
135- .padding(
136- top = 16 .dp,
137- start = 20 .dp,
138- end = 20 .dp
139- ),
140- color = MaterialTheme .colorScheme.onBackground,
141- textAlign = TextAlign .Center
142- )
143- }
44+ Image (
45+ painter = painterResource(R .drawable.home_image),
46+ contentDescription = null ,
47+ modifier = Modifier .size(180 .dp)
48+ )
14449 }
14550
146- if (LocalInspectionMode .current || ! isDefault) {
147- Spacer (Modifier .weight(1f ))
148-
149- Column (
150- modifier = Modifier
151- .fillMaxWidth()
152- .padding(16 .dp),
153- horizontalAlignment = Alignment .CenterHorizontally ,
154- verticalArrangement = Arrangement .Center
155- ) {
156- OutlinedButton (onClick = {
157- getDefaultPermission.launch(makeDefault(context))
158- }) {
159- Row (
160- horizontalArrangement = Arrangement .Center ,
161- verticalAlignment = Alignment .CenterVertically ,
162- modifier = Modifier
163- .fillMaxWidth()
164- .padding(8 .dp),
165- ) {
166- Icon (
167- imageVector = Icons .Default .ChatBubbleOutline ,
168- contentDescription = stringResource(R .string.compose),
169- )
170-
171- Spacer (Modifier .size(ButtonDefaults .IconSpacing ))
172-
173- Text (
174- stringResource(R .string.set_as_default_sms_app),
175- fontWeight = FontWeight .SemiBold ,
176- )
177- }
178- }
179- }
180- }
51+ Text (
52+ text = " Compose your first message." ,
53+ style = MaterialTheme .typography.titleMedium,
54+ fontWeight = FontWeight .Medium ,
55+ color = MaterialTheme .colorScheme.onSurfaceVariant,
56+ textAlign = TextAlign .Center ,
57+ modifier = Modifier .padding(top = 8 .dp)
58+ )
18159 }
18260}
18361
184-
18562fun makeDefault (context : Context ): Intent {
186- // TODO: replace this with checking other permissions - since this gives null in level 35
187- return if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .Q ) {
63+ return if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .Q ) {
18864 val roleManager = context.getSystemService(ROLE_SERVICE ) as RoleManager
18965 roleManager.createRequestRoleIntent(RoleManager .ROLE_SMS ).apply {
19066 putExtra(Telephony .Sms .Intents .EXTRA_PACKAGE_NAME , context.packageName)
@@ -199,7 +75,7 @@ fun makeDefault(context: Context): Intent {
19975@Preview(showBackground = true )
20076@Composable
20177fun GetStartedPreviewLoggedIn () {
202- AppTheme (darkTheme = false ) {
203- GetStartedView ( navController = NavController (LocalContext .current))
78+ AppTheme (darkTheme = false ) {
79+ GetStartedView (navController = NavController (androidx.compose.ui.platform. LocalContext .current))
20480 }
20581}
0 commit comments