Skip to content

Commit d6c6335

Browse files
wip create auto screen
Co-Authored-By: Boban Sijuk <49131853+Boki91@users.noreply.github.com>
1 parent f9dd01a commit d6c6335

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/AutoConnectCarousel.kt

+20-11
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ fun PreviewAutoConnectCarousel() {
4646
AppTheme { AutoConnectCarousel() }
4747
}
4848

49+
private const val CAROUSEL_PAGE_SIZE = 3
50+
4951
@OptIn(ExperimentalFoundationApi::class)
5052
@Composable
5153
fun AutoConnectCarousel() {
52-
val pagerState = rememberPagerState(pageCount = { 3 })
54+
val pagerState = rememberPagerState(pageCount = { CAROUSEL_PAGE_SIZE })
5355
HorizontalPager(state = pagerState, modifier = Modifier.fillMaxSize()) { page ->
5456
val scope = rememberCoroutineScope()
5557
ConstraintLayout(
@@ -70,14 +72,16 @@ fun AutoConnectCarousel() {
7072
end.linkTo(parent.end)
7173
bottom.linkTo(imageRef.top)
7274
},
75+
style = MaterialTheme.typography.labelMedium,
76+
color = MaterialTheme.colorScheme.onSecondary,
7377
text =
7478
HtmlCompat.fromHtml(
7579
stringResource(
7680
id =
7781
when (page) {
78-
0 -> R.string.carousel_slide_1_text_1
79-
1 -> R.string.carousel_slide_2_text_1
80-
else -> R.string.carousel_slide_3_text_1
82+
0 -> R.string.auto_connect_carousel_first_slide_top_text
83+
1 -> R.string.auto_connect_carousel_second_slide_top_text
84+
else -> R.string.auto_connect_carousel_third_slide_top_text
8185
}
8286
),
8387
HtmlCompat.FROM_HTML_MODE_COMPACT
@@ -86,7 +90,7 @@ fun AutoConnectCarousel() {
8690
boldSpanStyle =
8791
SpanStyle(
8892
fontWeight = FontWeight.ExtraBold,
89-
color = MaterialTheme.colorScheme.onSecondary
93+
color = MaterialTheme.colorScheme.onPrimary
9094
)
9195
)
9296
)
@@ -129,7 +133,7 @@ fun AutoConnectCarousel() {
129133
contentDescription = null,
130134
)
131135

132-
if (page != 2) {
136+
if (page < CAROUSEL_PAGE_SIZE) {
133137
IconButton(
134138
modifier =
135139
Modifier.constrainAs(nextButtonRef) {
@@ -156,14 +160,17 @@ fun AutoConnectCarousel() {
156160
end.linkTo(parent.end)
157161
start.linkTo(parent.start)
158162
},
163+
style = MaterialTheme.typography.labelMedium,
164+
color = MaterialTheme.colorScheme.onSecondary,
159165
text =
160166
HtmlCompat.fromHtml(
161167
stringResource(
162168
id =
163169
when (page) {
164-
0 -> R.string.carousel_slide_1_text_2
165-
1 -> R.string.carousel_slide_2_text_2
166-
else -> R.string.carousel_slide_3_text_2
170+
0 -> R.string.auto_connect_carousel_first_slide_bottom_text
171+
1 -> R.string.auto_connect_carousel_second_slide_bottom_text
172+
else ->
173+
R.string.auto_connect_carousel_third_slide_bottom_text
167174
}
168175
),
169176
HtmlCompat.FROM_HTML_MODE_COMPACT
@@ -172,7 +179,7 @@ fun AutoConnectCarousel() {
172179
boldSpanStyle =
173180
SpanStyle(
174181
fontWeight = FontWeight.ExtraBold,
175-
color = MaterialTheme.colorScheme.onSecondary
182+
color = MaterialTheme.colorScheme.onPrimary
176183
)
177184
)
178185
)
@@ -183,6 +190,7 @@ fun AutoConnectCarousel() {
183190
.padding(top = Dimens.topPadding)
184191
.constrainAs(pageIndicatorRef) {
185192
top.linkTo(lowerTextRef.bottom)
193+
186194
end.linkTo(parent.end)
187195
start.linkTo(parent.start)
188196
},
@@ -191,7 +199,8 @@ fun AutoConnectCarousel() {
191199
) {
192200
repeat(pagerState.pageCount) { iteration ->
193201
val color =
194-
if (pagerState.currentPage == iteration) Color.LightGray else Color.DarkGray
202+
if (pagerState.currentPage == iteration) MaterialTheme.colorScheme.onPrimary
203+
else MaterialTheme.colorScheme.primary
195204
Box(
196205
modifier =
197206
Modifier.padding(Dimens.indicatorPadding)

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/AutoConnectAndLockdownModeScreen.kt

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package net.mullvad.mullvadvpn.compose.screen
22

3-
import android.content.ActivityNotFoundException
4-
import android.widget.Toast
53
import androidx.compose.runtime.Composable
64
import androidx.compose.ui.platform.LocalContext
75
import androidx.compose.ui.res.stringResource
@@ -33,13 +31,7 @@ fun AutoConnectAndLockdownModeScreen(
3331
appBarTitle = stringResource(id = R.string.auto_connect_and_lockdown_mode_two_lines),
3432
navigationIcon = { NavigateBackIconButton(onBackClick) },
3533
buttonTitle = stringResource(id = R.string.go_to_vpn_settings),
36-
onButtonClick = {
37-
try {
38-
context.openVpnSettings()
39-
} catch (e: ActivityNotFoundException) {
40-
Toast.makeText(context, R.string.settings_vpn, Toast.LENGTH_SHORT).show()
41-
}
42-
},
34+
onButtonClick = { context.openVpnSettings() },
4335
content = { modifier -> AutoConnectCarousel() }
4436
)
4537
}

android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/ContextExtensions.kt

+3
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,6 @@ fun Context.openVpnSettings() {
4646
val intent = Intent("android.settings.VPN_SETTINGS")
4747
startActivity(intent)
4848
}
49+
50+
fun Context.vpnSettingsAvailable(): Boolean =
51+
Intent("android.net.vpn.SETTINGS").resolveActivity(packageManager) != null

0 commit comments

Comments
 (0)