Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment.Companion.Center
import androidx.compose.ui.Alignment.Companion.CenterHorizontally
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextAlign
Expand All @@ -50,6 +51,7 @@ import org.thoughtcrime.securesms.ui.components.BackAppBar
import org.thoughtcrime.securesms.ui.components.DangerFillButtonRect
import org.thoughtcrime.securesms.ui.components.annotatedStringResource
import org.thoughtcrime.securesms.ui.components.inlineContentMap
import org.thoughtcrime.securesms.ui.sessionDropShadow
import org.thoughtcrime.securesms.ui.theme.LocalColors
import org.thoughtcrime.securesms.ui.theme.LocalDimensions
import org.thoughtcrime.securesms.ui.theme.LocalType
Expand Down Expand Up @@ -309,9 +311,15 @@ fun NonOriginatingLinkCell(
) {
// icon
Box(modifier = Modifier
.then(
if (LocalColors.current.isLight)
Modifier.sessionDropShadow()
else Modifier
)
.clip(MaterialTheme.shapes.small)
.background(color = LocalColors.current.backgroundSecondary)
.background(
color = LocalColors.current.accent.copy(alpha = 0.2f),
shape = MaterialTheme.shapes.small
)
.padding(10.dp)
){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ fun CancelPlanNonOriginating(
.put(APP_PRO_KEY, NonTranslatableStringConstants.APP_PRO)
.put(PLATFORM_ACCOUNT_KEY, providerData.platformAccount)
.format(),
linkCellsInfo = stringResource(R.string.proCancellationOptions),
linkCellsInfo =
Phrase.from(context.getText(R.string.proCancellationOptions))
.put(PRO_KEY, NonTranslatableStringConstants.PRO)
.format().toString(),
linkCells = listOf(
NonOriginatingLinkCellData(
title = Phrase.from(context.getText(R.string.onDevice))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ fun CancelPlan(
BaseCellButtonProSettingsScreen(
disabled = true,
onBack = onBack,
buttonText = Phrase.from(context.getText(R.string.cancelProPlan))
buttonText = Phrase.from(context.getText(R.string.cancelAccess))
.put(PRO_KEY, NonTranslatableStringConstants.PRO)
.format().toString(),
dangerButton = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@ fun PlanConfirmationScreen(
onBack: () -> Unit,
) {
val proData by viewModel.proSettingsUIState.collectAsState()
val previousState by viewModel.choosePlanState.collectAsState()

PlanConfirmation(
proData = proData,
previousProState = (previousState as? State.Success<ProSettingsViewModel.ChoosePlanState>)
?.value?.proStatus ?: ProStatus.NeverSubscribed,
sendCommand = viewModel::onCommand,
onBack = onBack,
)
Expand All @@ -73,6 +76,7 @@ fun PlanConfirmationScreen(
@Composable
fun PlanConfirmation(
proData: ProSettingsViewModel.ProSettingsState,
previousProState: ProStatus,
sendCommand: (ProSettingsViewModel.Commands) -> Unit,
onBack: () -> Unit,
) {
Expand Down Expand Up @@ -113,7 +117,7 @@ fun PlanConfirmation(

Spacer(Modifier.height(LocalDimensions.current.xsSpacing))

val description = when (proData.proDataState.type) {
val description = when (previousProState) {
is ProStatus.Active -> {
Phrase.from(context.getText(R.string.proAllSetDescription))
.put(APP_PRO_KEY, NonTranslatableStringConstants.APP_PRO)
Expand Down Expand Up @@ -148,7 +152,7 @@ fun PlanConfirmation(

Spacer(Modifier.height(LocalDimensions.current.spacing))

val buttonLabel = when (proData.proDataState.type) {
val buttonLabel = when (previousProState) {
is ProStatus.Active -> stringResource(R.string.theReturn)

else -> {
Expand Down Expand Up @@ -189,6 +193,7 @@ private fun PreviewPlanConfirmationActive(
showProBadge = false,
),
),
previousProState = previewAutoRenewingApple,
sendCommand = {},
onBack = {},
)
Expand All @@ -209,6 +214,7 @@ private fun PreviewPlanConfirmationExpired(
showProBadge = true,
),
),
previousProState = previewExpiredApple,
sendCommand = {},
onBack = {},
)
Expand All @@ -229,6 +235,7 @@ private fun PreviewPlanConfirmationNeverSub(
showProBadge = true,
),
),
previousProState = ProStatus.NeverSubscribed,
sendCommand = {},
onBack = {},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ fun ProManage(
title = Phrase.from(LocalContext.current, R.string.managePro)
.put(PRO_KEY, NonTranslatableStringConstants.PRO)
.format().toString(),
dropShadow = LocalColors.current.isLight && data is ProStatus.Expired
) {
// Cell content
Column(
Expand Down Expand Up @@ -896,7 +897,7 @@ fun ProManage(

is State.Success<*> -> Triple<CharSequence?, Color, @Composable BoxScope.() -> Unit>(
null,
LocalColors.current.text, renewIcon(LocalColors.current.accent)
LocalColors.current.text, renewIcon(LocalColors.current.accentText)
)
}

Expand All @@ -906,7 +907,7 @@ fun ProManage(
.put(PRO_KEY, NonTranslatableStringConstants.PRO)
.format().toString()
),
titleColor = if(subscriptionRefreshState is State.Success ) LocalColors.current.accent
titleColor = if(subscriptionRefreshState is State.Success ) LocalColors.current.accentText
else LocalColors.current.text,
subtitle = if(subtitle == null) null else annotatedStringResource(subtitle),
subtitleColor = subColor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import org.thoughtcrime.securesms.debugmenu.DebugLogGroup
import org.thoughtcrime.securesms.dependencies.ManagerScope
import org.thoughtcrime.securesms.pro.api.ProDetails
import org.thoughtcrime.securesms.pro.db.ProDatabase
import org.thoughtcrime.securesms.util.NetworkConnectivity
import java.time.Instant
import javax.inject.Inject
import javax.inject.Singleton
Expand All @@ -31,6 +32,7 @@ class ProDetailsRepository @Inject constructor(
@ManagerScope scope: CoroutineScope,
loginStateRepository: LoginStateRepository,
private val prefs: TextSecurePreferences,
private val networkConnectivity: NetworkConnectivity,
) {
sealed interface LoadState {
val lastUpdated: Pair<ProDetails, Instant>?
Expand All @@ -56,12 +58,14 @@ class ProDetailsRepository @Inject constructor(
.map { it.state }
.distinctUntilChanged(),

networkConnectivity.networkAvailable,

db.proDetailsChangeNotification
.onStart { emit(Unit) }
.map { db.getProDetailsAndLastUpdated() }
) { state, last ->
) { state, isOnline, last ->
when (state) {
WorkInfo.State.ENQUEUED, WorkInfo.State.BLOCKED -> LoadState.Loading(last, waitingForNetwork = true)
WorkInfo.State.ENQUEUED, WorkInfo.State.BLOCKED -> LoadState.Loading(last, waitingForNetwork = !isOnline)
WorkInfo.State.RUNNING -> LoadState.Loading(last, waitingForNetwork = false)
WorkInfo.State.SUCCEEDED -> {
if (last != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,18 @@ class ProStatusManager @Inject constructor(
(TextSecurePreferences.events.filter { it == TextSecurePreferences.SET_FORCE_CURRENT_USER_PRO } as Flow<*>)
.onStart { emit(Unit) }
.map { prefs.forceCurrentUserAsPro() },
){ shouldShowProBadge, proDetailsState, debugSubscription, debugProPlanStatus, forceCurrentUserAsPro ->
){ shouldShowProBadge, proDetailsState,
debugSubscription, debugProPlanStatus, forceCurrentUserAsPro ->
val proDataRefreshState = when(debugProPlanStatus){
DebugMenuViewModel.DebugProPlanStatus.LOADING -> State.Loading
DebugMenuViewModel.DebugProPlanStatus.ERROR -> State.Error(Exception())
else -> {
// calculate the real refresh state here
when(proDetailsState){
is ProDetailsRepository.LoadState.Loading -> State.Loading
is ProDetailsRepository.LoadState.Loading -> {
if(proDetailsState.waitingForNetwork) State.Error(Exception())
else State.Loading
}
is ProDetailsRepository.LoadState.Error -> State.Error(Exception())
else -> State.Success(Unit)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ fun SessionNetworkInfoSection(modifier: Modifier = Modifier) {

// 2.) Session network description
val sessionNetworkDetailsAnnotatedString = annotatedStringResource(
highlightColor = LocalColors.current.accentText,
text = Phrase.from(context.getText(R.string.sessionNetworkDescription))
.put(NETWORK_NAME_KEY, NETWORK_NAME)
.put(TOKEN_NAME_LONG_KEY, TOKEN_NAME_LONG)
Expand Down Expand Up @@ -342,14 +341,12 @@ fun NodeDetailsBox(
val appName = context.getString(R.string.app_name)

val nodesInSwarmAS = annotatedStringResource(
highlightColor = LocalColors.current.accentText,
text = Phrase.from(context, R.string.sessionNetworkNodesSwarm)
.put(APP_NAME_KEY, appName)
.format()
)

val nodesSecuringMessagesAS = annotatedStringResource(
highlightColor = LocalColors.current.accentText,
text = Phrase.from(context, R.string.sessionNetworkNodesSecuring)
.put(APP_NAME_KEY, appName)
.format()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private fun resources(): Resources {
@Composable
fun annotatedStringResource(
@StringRes id: Int,
highlightColor: Color = LocalColors.current.accent
highlightColor: Color = LocalColors.current.accentText
): AnnotatedString {
val resources = resources()
val density = LocalDensity.current
Expand All @@ -74,7 +74,7 @@ fun annotatedStringResource(
@Composable
fun annotatedStringResource(
text: CharSequence,
highlightColor: Color = LocalColors.current.accent
highlightColor: Color = LocalColors.current.accentText
): AnnotatedString {
val density = LocalDensity.current
return remember(text.hashCode()) {
Expand Down