mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-26 12:44:38 +00:00
Add proper payment method type to BackupTypeSettings screen.
This commit is contained in:
committed by
Greyson Parrelli
parent
45239c2264
commit
c0da0bd272
@@ -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
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user