Add proper payment method type to BackupTypeSettings screen.

This commit is contained in:
Alex Hart 2024-06-21 14:41:17 -03:00 committed by Greyson Parrelli
parent 45239c2264
commit c0da0bd272
3 changed files with 25 additions and 9 deletions

View file

@ -11,6 +11,7 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
@ -54,7 +55,7 @@ class BackupsTypeSettingsFragment : ComposeFragment() {
Callbacks()
}
val state by viewModel.state
val state by viewModel.state.collectAsState()
BackupsTypeSettingsContent(
state = state,
@ -127,7 +128,7 @@ private fun BackupsTypeSettingsContent(
item {
Rows.TextRow(
text = "Payment history", // TODO [message-backups] final copy
text = stringResource(id = R.string.BackupsTypeSettingsFragment__payment_history),
onClick = contentCallbacks::onPaymentHistoryClick
)
}

View file

@ -5,18 +5,24 @@
package org.thoughtcrime.securesms.components.settings.app.chats.backups.type
import androidx.compose.runtime.State
import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.thoughtcrime.securesms.backup.v2.BackupRepository
import org.thoughtcrime.securesms.components.settings.app.subscription.InAppPaymentsRepository
import org.thoughtcrime.securesms.components.settings.app.subscription.InAppPaymentsRepository.toPaymentSourceType
import org.thoughtcrime.securesms.database.model.InAppPaymentSubscriberRecord
import org.thoughtcrime.securesms.keyvalue.SignalStore
class BackupsTypeSettingsViewModel : ViewModel() {
private val internalState = mutableStateOf(BackupsTypeSettingsState())
private val internalState = MutableStateFlow(BackupsTypeSettingsState())
val state: State<BackupsTypeSettingsState> = internalState
val state: StateFlow<BackupsTypeSettingsState> = internalState
init {
refresh()
@ -25,9 +31,16 @@ class BackupsTypeSettingsViewModel : ViewModel() {
fun refresh() {
viewModelScope.launch {
val tier = SignalStore.backup.backupTier
internalState.value = state.value.copy(
messageBackupsType = if (tier != null) BackupRepository.getBackupsType(tier) else null
)
val paymentMethod = withContext(Dispatchers.IO) {
InAppPaymentsRepository.getLatestPaymentMethodType(InAppPaymentSubscriberRecord.Type.BACKUP)
}
internalState.update {
it.copy(
messageBackupsType = if (tier != null) BackupRepository.getBackupsType(tier) else null,
paymentSourceType = paymentMethod.toPaymentSourceType()
)
}
}
}
}

View file

@ -7021,6 +7021,8 @@
<string name="BackupsTypeSettingsFragment__paypal">PayPal</string>
<!-- Displayed as the user\'s payment method as a label in a preference row -->
<string name="BackupsTypeSettingsFragment__unknown">Unknown</string>
<!-- Row title for entering payment history -->
<string name="BackupsTypeSettingsFragment__payment_history">Payment history</string>
<!-- RemoteRestoreActivity -->
<!-- Displayed at restore time to tell the user when their last backup was made. %$1s is replaced with the date (e.g. March 5, 2024) and %$2s is replaced with the time (e.g. 9:00am) -->