Move from enum.values() to enum.entries.

Resolves #13767
This commit is contained in:
Grzegorz Bobryk
2024-11-03 16:18:10 +01:00
committed by Greyson Parrelli
parent be92b3cf0a
commit cafbf48783
60 changed files with 95 additions and 95 deletions

View File

@@ -246,7 +246,7 @@ class AppSettingsActivity : DSLSettingsActivity(), InAppPaymentComponent {
companion object {
fun fromCode(code: Int?): StartLocation {
return values().find { code == it.code } ?: HOME
return entries.find { code == it.code } ?: HOME
}
}
}

View File

@@ -1091,7 +1091,7 @@ private fun BackupFrequencyDialog(
modifier = Modifier.padding(24.dp)
)
BackupFrequency.values().forEach {
BackupFrequency.entries.forEach {
Rows.RadioRow(
selected = selected == it,
text = getTextForFrequency(backupsFrequency = it),

View File

@@ -93,8 +93,8 @@ class DataAndStorageSettingsFragment : DSLSettingsFragment(R.string.preferences_
radioListPref(
title = DSLSettingsText.from(R.string.DataAndStorageSettingsFragment__sent_media_quality),
listItems = sentMediaQualityLabels,
selected = SentMediaQuality.values().indexOf(state.sentMediaQuality),
onSelected = { viewModel.setSentMediaQuality(SentMediaQuality.values()[it]) }
selected = SentMediaQuality.entries.indexOf(state.sentMediaQuality),
onSelected = { viewModel.setSentMediaQuality(SentMediaQuality.entries[it]) }
)
textPref(

View File

@@ -140,7 +140,7 @@ private fun Content(
expanded = expanded,
onDismissRequest = { expanded = false }
) {
PendingOneTimeDonation.PaymentMethodType.values().forEach { item ->
PendingOneTimeDonation.PaymentMethodType.entries.forEach { item ->
DropdownMenuItem(
text = { Text(text = item.name) },
onClick = {

View File

@@ -516,19 +516,19 @@ class InternalSettingsFragment : DSLSettingsFragment(R.string.preferences__inter
radioListPref(
title = DSLSettingsText.from("Audio processing method"),
listItems = CallManager.AudioProcessingMethod.values().map { it.name }.toTypedArray(),
selected = CallManager.AudioProcessingMethod.values().indexOf(state.callingAudioProcessingMethod),
listItems = CallManager.AudioProcessingMethod.entries.map { it.name }.toTypedArray(),
selected = CallManager.AudioProcessingMethod.entries.indexOf(state.callingAudioProcessingMethod),
onSelected = {
viewModel.setInternalCallingAudioProcessingMethod(CallManager.AudioProcessingMethod.values()[it])
viewModel.setInternalCallingAudioProcessingMethod(CallManager.AudioProcessingMethod.entries[it])
}
)
radioListPref(
title = DSLSettingsText.from("Bandwidth mode"),
listItems = CallManager.DataMode.values().map { it.name }.toTypedArray(),
selected = CallManager.DataMode.values().indexOf(state.callingDataMode),
listItems = CallManager.DataMode.entries.map { it.name }.toTypedArray(),
selected = CallManager.DataMode.entries.indexOf(state.callingDataMode),
onSelected = {
viewModel.setInternalCallingDataMode(CallManager.DataMode.values()[it])
viewModel.setInternalCallingDataMode(CallManager.DataMode.entries[it])
}
)

View File

@@ -55,7 +55,7 @@ fun DonationErrorValueTypeSelector(
expanded = expanded,
onDismissRequest = { expanded = false }
) {
DonationErrorValue.Type.values().filterNot {
DonationErrorValue.Type.entries.filterNot {
selectedPaymentMethodType == PendingOneTimeDonation.PaymentMethodType.PAYPAL && it == DonationErrorValue.Type.FAILURE_CODE
}.forEach { item ->
DropdownMenuItem(
@@ -149,8 +149,8 @@ private fun DeclineCodeErrorsDropdown(
) {
val values = remember(paymentMethodType) {
when (paymentMethodType) {
PendingOneTimeDonation.PaymentMethodType.PAYPAL -> PayPalDeclineCode.KnownCode.values()
else -> StripeDeclineCode.Code.values()
PendingOneTimeDonation.PaymentMethodType.PAYPAL -> PayPalDeclineCode.KnownCode.entries.toTypedArray()
else -> StripeDeclineCode.Code.entries.toTypedArray()
}.map { it.name }.toTypedArray()
}
@@ -162,7 +162,7 @@ private fun FailureCodeErrorsDropdown(
onErrorCodeSelected: (String) -> Unit
) {
val values = remember {
StripeFailureCode.Code.values().map { it.name }.toTypedArray()
StripeFailureCode.Code.entries.map { it.name }.toTypedArray()
}
ValuesDropdown(values = values, onErrorCodeSelected = onErrorCodeSelected)

View File

@@ -33,16 +33,16 @@ class InternalDonorErrorConfigurationFragment : DSLSettingsFragment() {
radioListPref(
title = DSLSettingsText.from("Cancellation Reason"),
selected = UnexpectedSubscriptionCancellation.values().indexOf(state.selectedUnexpectedSubscriptionCancellation),
listItems = UnexpectedSubscriptionCancellation.values().map { it.status }.toTypedArray(),
selected = UnexpectedSubscriptionCancellation.entries.indexOf(state.selectedUnexpectedSubscriptionCancellation),
listItems = UnexpectedSubscriptionCancellation.entries.map { it.status }.toTypedArray(),
onSelected = { viewModel.setSelectedUnexpectedSubscriptionCancellation(it) },
isEnabled = state.selectedBadge == null || state.selectedBadge.isSubscription()
)
radioListPref(
title = DSLSettingsText.from("Charge Failure"),
selected = StripeDeclineCode.Code.values().indexOf(state.selectedStripeDeclineCode),
listItems = StripeDeclineCode.Code.values().map { it.code }.toTypedArray(),
selected = StripeDeclineCode.Code.entries.indexOf(state.selectedStripeDeclineCode),
listItems = StripeDeclineCode.Code.entries.map { it.code }.toTypedArray(),
onSelected = { viewModel.setStripeDeclineCode(it) },
isEnabled = state.selectedBadge == null || state.selectedBadge.isSubscription()
)

View File

@@ -77,8 +77,8 @@ class InternalDonorErrorConfigurationViewModel : ViewModel() {
fun setSelectedUnexpectedSubscriptionCancellation(unexpectedSubscriptionCancellationIndex: Int) {
store.update {
it.copy(
selectedUnexpectedSubscriptionCancellation = if (unexpectedSubscriptionCancellationIndex in UnexpectedSubscriptionCancellation.values().indices) {
UnexpectedSubscriptionCancellation.values()[unexpectedSubscriptionCancellationIndex]
selectedUnexpectedSubscriptionCancellation = if (unexpectedSubscriptionCancellationIndex in UnexpectedSubscriptionCancellation.entries.toTypedArray().indices) {
UnexpectedSubscriptionCancellation.entries[unexpectedSubscriptionCancellationIndex]
} else {
null
}
@@ -89,8 +89,8 @@ class InternalDonorErrorConfigurationViewModel : ViewModel() {
fun setStripeDeclineCode(stripeDeclineCodeIndex: Int) {
store.update {
it.copy(
selectedStripeDeclineCode = if (stripeDeclineCodeIndex in StripeDeclineCode.Code.values().indices) {
StripeDeclineCode.Code.values()[stripeDeclineCodeIndex]
selectedStripeDeclineCode = if (stripeDeclineCodeIndex in StripeDeclineCode.Code.entries.toTypedArray().indices) {
StripeDeclineCode.Code.entries[stripeDeclineCodeIndex]
} else {
null
}

View File

@@ -45,11 +45,11 @@ class CustomExpireTimerSelectorView @JvmOverloads constructor(
return
}
TimerUnit.values()
TimerUnit.entries
.find { (timer / it.valueMultiplier) < it.maxValue }
?.let { timerUnit ->
valuePicker.value = (timer / timerUnit.valueMultiplier).toInt()
unitPicker.value = TimerUnit.values().indexOf(timerUnit)
unitPicker.value = TimerUnit.entries.indexOf(timerUnit)
unitChange(unitPicker.value)
}
}
@@ -59,7 +59,7 @@ class CustomExpireTimerSelectorView @JvmOverloads constructor(
}
private fun unitChange(newValue: Int) {
val timerUnit: TimerUnit = TimerUnit.values()[newValue]
val timerUnit: TimerUnit = TimerUnit.entries[newValue]
valuePicker.minValue = timerUnit.minValue
valuePicker.maxValue = timerUnit.maxValue
@@ -79,7 +79,7 @@ class CustomExpireTimerSelectorView @JvmOverloads constructor(
WEEKS(1, 4, TimeUnit.DAYS.toSeconds(7));
companion object {
fun get(value: Int) = values()[value]
fun get(value: Int) = entries[value]
}
}
}

View File

@@ -388,7 +388,7 @@ private fun SetKeepMessagesScreen(
.verticalScroll(rememberScrollState())
) {
KeepMessagesDuration
.values()
.entries
.forEach {
Rows.RadioRow(
text = stringResource(id = it.stringResource),

View File

@@ -97,7 +97,7 @@ enum class IdealBank(
}
fun fromCode(code: String): IdealBank {
return values().first { it.code == code }
return entries.first { it.code == code }
}
}

View File

@@ -85,7 +85,7 @@ private fun BankSelectionContent(
navigationIconPainter = painterResource(id = R.drawable.symbol_x_24)
) { paddingValues ->
LazyColumn(modifier = Modifier.padding(paddingValues)) {
items(IdealBank.values()) {
items(IdealBank.entries.toTypedArray()) {
val uiValues = it.getUIValues()
Row(

View File

@@ -131,7 +131,7 @@ sealed class DonationError(val source: DonationErrorSource, cause: Throwable) :
private val TAG = Log.tag(DonationError::class.java)
private val donationErrorSubjectSourceMap: Map<DonationErrorSource, Subject<DonationError>> = DonationErrorSource.values().associate { source ->
private val donationErrorSubjectSourceMap: Map<DonationErrorSource, Subject<DonationError>> = DonationErrorSource.entries.associate { source ->
source to PublishSubject.create()
}

View File

@@ -43,7 +43,7 @@ enum class DonationErrorSource(private val code: String) {
companion object {
@JvmStatic
fun deserialize(code: String): DonationErrorSource {
return values().firstOrNull { it.code == code } ?: UNKNOWN
return entries.firstOrNull { it.code == code } ?: UNKNOWN
}
}
}

View File

@@ -122,7 +122,7 @@ data class PayPalDeclineCode(
PROCESSOR_NETWORK_UNAVAILABLE_TRY_AGAIN(3000);
companion object {
fun fromCode(code: Int): KnownCode? = values().firstOrNull { it.code == code }
fun fromCode(code: Int): KnownCode? = entries.firstOrNull { it.code == code }
}
}
}

View File

@@ -16,7 +16,7 @@ enum class UnexpectedSubscriptionCancellation(val status: String) {
companion object {
@JvmStatic
fun fromStatus(status: String?): UnexpectedSubscriptionCancellation? {
return values().firstOrNull { it.status == status }
return entries.firstOrNull { it.status == status }
}
}
}

View File

@@ -74,7 +74,7 @@ enum class UsernameQrCodeColorScheme(
*/
@JvmStatic
fun deserialize(serialized: String?): UsernameQrCodeColorScheme {
return values().firstOrNull { it.key == serialized } ?: Blue
return entries.firstOrNull { it.key == serialized } ?: Blue
}
}
}

View File

@@ -183,7 +183,7 @@ class UsernameLinkQrColorPickerFragment : ComposeFragment() {
SignalTheme(isDarkMode = false) {
Surface {
ColorPicker(
colors = UsernameQrCodeColorScheme.values().toList().toImmutableList(),
colors = UsernameQrCodeColorScheme.entries.toImmutableList(),
selected = UsernameQrCodeColorScheme.Blue,
onSelectionChanged = {}
)

View File

@@ -25,7 +25,7 @@ class UsernameLinkQrColorPickerViewModel : ViewModel() {
UsernameLinkQrColorPickerState(
username = SignalStore.account.username!!,
qrCodeData = QrCodeState.Loading,
colorSchemes = UsernameQrCodeColorScheme.values().asList().toImmutableList(),
colorSchemes = UsernameQrCodeColorScheme.entries.toImmutableList(),
selectedColorScheme = SignalStore.misc.usernameQrCodeColorScheme
)
)

View File

@@ -64,7 +64,7 @@ class PendingParticipantsBottomSheet : ComposeBottomSheetDialogFragment() {
@JvmStatic
fun getAction(bundle: Bundle): Action {
val code = bundle.getInt(ACTION, 0)
return Action.values().first { it.code == code }
return Action.entries.first { it.code == code }
}
}