Skip to content

Commit

Permalink
Update screen updates
Browse files Browse the repository at this point in the history
  • Loading branch information
kp-iva-nedeleva committed Oct 16, 2024
1 parent b194551 commit 6c82d40
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 41 deletions.
3 changes: 2 additions & 1 deletion capabilities/ui/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@
<string name="geo_servers">Show Geo-located Regions</string>

<string name="update_required_title">Upgrade Your Experience</string>
<string name="update_required_message">You\'re using an older version of PIA. Update your app now to enjoy an enhanced experience with all the latest features.</string>
<string name="update_required_message">Your app is outdated. Please update to continue using the app.</string>
<string name="update_required_action">Update Now</string>
<string name="update_required_info">Tapping \"Update Now\" will disconnect the VPN.</string>
</resources>
1 change: 1 addition & 0 deletions features/splash/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ dependencies {
implementation(project(":core:router"))
implementation(project(":core:regions"))
implementation(project(":core:httpclient"))
implementation(project(":core:vpnconnect"))
implementation(project(":capabilities:ui"))
implementation(project(":capabilities:notifications"))
implementation(project(":capabilities:featureflags"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import org.koin.core.qualifier.named
import org.koin.dsl.module

val splashModule = module {
viewModel { SplashViewModel(get(), get(), get(), get(), get(named("update-url"))) }
viewModel { SplashViewModel(get(), get(), get(), get(), get(named("update-url")), get()) }
}
98 changes: 59 additions & 39 deletions features/splash/src/main/java/com/kape/splash/ui/UpdateScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import android.net.Uri
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
Expand All @@ -26,6 +28,7 @@ import com.kape.splash.ui.vm.SplashViewModel
import com.kape.ui.R
import com.kape.ui.mobile.elements.PrimaryButton
import com.kape.ui.mobile.elements.Screen
import com.kape.ui.mobile.text.OnboardingDescriptionPaymentText
import com.kape.ui.mobile.text.OnboardingDescriptionText
import com.kape.ui.mobile.text.OnboardingTitleText
import com.kape.ui.utils.LocalColors
Expand All @@ -41,53 +44,70 @@ fun UpdateScreen(viewModel: SplashViewModel = koinViewModel()) = Screen {
.padding(top = 64.dp)
.background(LocalColors.current.background),
verticalArrangement = Arrangement.SpaceBetween,
horizontalAlignment = Alignment.CenterHorizontally,
) {
Column(modifier = Modifier.widthIn(max = 520.dp)) {
Image(
painter = painterResource(id = R.drawable.shield),
contentDescription = null,
modifier = Modifier
.padding(40.dp)
.height(140.dp)
.fillMaxWidth(),
)
Column(modifier = Modifier.semantics(mergeDescendants = true) { }) {
OnboardingTitleText(
content = stringResource(id = R.string.update_required_title),
Box(
modifier = Modifier
.widthIn(max = 520.dp)
.fillMaxHeight()
.weight(1f, true),
) {
Column(
verticalArrangement = Arrangement.SpaceBetween,
) {
Image(
painter = painterResource(id = R.drawable.shield),
contentDescription = null,
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
.padding(40.dp)
.height(200.dp)
.fillMaxWidth(),
)
Column(modifier = Modifier.semantics(mergeDescendants = true) { }) {
OnboardingTitleText(
content = stringResource(id = R.string.update_required_title),
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
)

OnboardingDescriptionText(
content = stringResource(id = R.string.update_required_message),
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
)
}
}

OnboardingDescriptionText(
content = stringResource(id = R.string.update_required_message),
Column(modifier = Modifier.align(Alignment.BottomCenter)) {
PrimaryButton(
text = stringResource(id = R.string.update_required_action),
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
)
}
.padding(start = 16.dp, top = 4.dp, bottom = 36.dp, end = 16.dp)
.align(Alignment.CenterHorizontally),
) {
viewModel.onUpdateClicked(
launchUpdate = { url ->
val launchIntent = Intent(Intent.ACTION_VIEW)
launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
launchIntent.data = Uri.parse(url)
// Silently fail if Google Play Store isn't installed.
if (launchIntent.resolveActivity(context.packageManager) != null) {
context.startActivity(launchIntent)
}
},
)
}

Spacer(modifier = Modifier.weight(1f))
if (viewModel.isConnected()) {
OnboardingDescriptionPaymentText(
stringResource(R.string.update_required_info),
Modifier.align(Alignment.CenterHorizontally),
)

PrimaryButton(
text = stringResource(id = R.string.update_required_action),
modifier = Modifier
.fillMaxWidth()
.padding(start = 16.dp, top = 4.dp, bottom = 36.dp, end = 16.dp)
.align(Alignment.CenterHorizontally),
) {
viewModel.onUpdateClicked(
launchUpdate = { url ->
val launchIntent = Intent(Intent.ACTION_VIEW)
launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
launchIntent.data = Uri.parse(url)
// Silently fail if Google Play Store isn't installed.
if (launchIntent.resolveActivity(context.packageManager) != null) {
context.startActivity(launchIntent)
}
},
)
Spacer(modifier = Modifier.padding(bottom = 40.dp))
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.kape.httpclient.domain.GetWebsiteDownloadLink
import com.kape.router.EnterFlow
import com.kape.router.ExitFlow
import com.kape.router.Router
import com.kape.vpnconnect.domain.ConnectionUseCase
import com.kape.vpnregions.utils.RegionListProvider
import kotlinx.coroutines.launch
import org.koin.core.component.KoinComponent
Expand All @@ -17,6 +18,7 @@ class SplashViewModel(
private val forceUpdateUseCase: ForceUpdateUseCase,
private val getWebsiteDownloadLink: GetWebsiteDownloadLink,
private val appUpdateUrl: String,
private val connectionUseCase: ConnectionUseCase,
) : ViewModel(), KoinComponent {

private var updateUrl: String = ""
Expand Down Expand Up @@ -46,6 +48,11 @@ class SplashViewModel(
}

fun onUpdateClicked(launchUpdate: (updateUrl: String) -> Unit) {
viewModelScope.launch {
connectionUseCase.stopConnection().collect {}
}
launchUpdate(appUpdateUrl.ifEmpty { updateUrl })
}

fun isConnected(): Boolean = connectionUseCase.isConnected()
}

0 comments on commit 6c82d40

Please sign in to comment.