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

@@ -165,7 +165,7 @@ class ContactSelectionListAdapter(
FIND_BY_PHONE_NUMBER("find-by-phone-number");
companion object {
fun fromCode(code: String) = values().first { it.code == code }
fun fromCode(code: String) = entries.first { it.code == code }
}
}

View File

@@ -23,14 +23,14 @@ object AttachmentCreator : Parcelable.Creator<Attachment> {
@JvmStatic
fun writeSubclass(dest: Parcel, instance: Attachment) {
val subclass = Subclass.values().firstOrNull { it.clazz == instance::class.java } ?: error("Unexpected subtype ${instance::class.java.simpleName}")
val subclass = Subclass.entries.firstOrNull { it.clazz == instance::class.java } ?: error("Unexpected subtype ${instance::class.java.simpleName}")
dest.writeString(subclass.code)
}
override fun createFromParcel(source: Parcel): Attachment {
val rawCode = source.readString()!!
return when (Subclass.values().first { rawCode == it.code }) {
return when (Subclass.entries.first { rawCode == it.code }) {
Subclass.DATABASE -> DatabaseAttachment(source)
Subclass.POINTER -> PointerAttachment(source)
Subclass.TOMBSTONE -> TombstoneAttachment(source)

View File

@@ -37,7 +37,7 @@ enum class Cdn(private val value: Int) {
}
override fun deserialize(data: Int): Cdn {
return values().first { it.value == data }
return entries.first { it.value == data }
}
fun fromCdnNumber(cdnNumber: Int): Cdn {

View File

@@ -30,7 +30,7 @@ object Avatars {
A210("A210", 0xFF5C5C5C.toInt());
fun deserialize(code: String): ForegroundColor {
return values().find { it.code == code } ?: throw IllegalArgumentException()
return entries.find { it.code == code } ?: throw IllegalArgumentException()
}
fun serialize(): String = code
@@ -39,7 +39,7 @@ object Avatars {
/**
* Mapping which associates color codes to ColorPair objects containing background and foreground colors.
*/
val colorMap: Map<String, ColorPair> = ForegroundColor.values().map {
val colorMap: Map<String, ColorPair> = ForegroundColor.entries.map {
ColorPair(AvatarColor.deserialize(it.serialize()), it)
}.associateBy {
it.code
@@ -134,7 +134,7 @@ object Avatars {
@JvmStatic
fun getForegroundColor(avatarColor: AvatarColor): ForegroundColor {
return ForegroundColor.values().firstOrNull { it.serialize() == avatarColor.serialize() } ?: ForegroundColor.A210
return ForegroundColor.entries.firstOrNull { it.serialize() == avatarColor.serialize() } ?: ForegroundColor.A210
}
data class DefaultAvatar(

View File

@@ -190,7 +190,7 @@ class BadgeSpriteTransformation(
private val TAG = Log.tag(BadgeSpriteTransformation::class.java)
private fun getDensity(density: String): Density {
return Density.values().first { it.density == density }
return Density.entries.first { it.density == density }
}
private fun getFrame(size: Size, density: Density, isDarkTheme: Boolean): Frame {

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 }
}
}

View File

@@ -197,7 +197,7 @@ class ConversationListSearchAdapter(
companion object {
fun fromCode(code: String): ChatFilterOptions {
return values().firstOrNull { it.code == code } ?: WITHOUT_TIP
return entries.firstOrNull { it.code == code } ?: WITHOUT_TIP
}
}
}

View File

@@ -2793,7 +2793,7 @@ class AttachmentTable(
companion object {
fun deserialize(value: Int): ThumbnailRestoreState {
return values().firstOrNull { it.value == value } ?: NONE
return entries.firstOrNull { it.value == value } ?: NONE
}
}
}
@@ -2833,7 +2833,7 @@ class AttachmentTable(
companion object {
fun deserialize(value: Int): ArchiveTransferState {
return values().firstOrNull { it.value == value } ?: NONE
return entries.firstOrNull { it.value == value } ?: NONE
}
}
}

View File

@@ -1631,7 +1631,7 @@ class CallTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTabl
}
override fun deserialize(data: Int): ReadState {
return ReadState.values().first { it.code == data }
return entries.first { it.code == data }
}
}
}
@@ -1716,7 +1716,7 @@ class CallTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTabl
override fun serialize(data: Event): Int = data.code
override fun deserialize(data: Int): Event {
return values().firstOrNull {
return entries.firstOrNull {
it.code == data
} ?: throw IllegalArgumentException("Unknown event $data")
}

View File

@@ -162,6 +162,6 @@ class InAppPaymentSubscriberTable(
object TypeSerializer : Serializer<InAppPaymentSubscriberRecord.Type, Int> {
override fun serialize(data: InAppPaymentSubscriberRecord.Type): Int = data.code
override fun deserialize(input: Int): InAppPaymentSubscriberRecord.Type = InAppPaymentSubscriberRecord.Type.values().first { it.code == input }
override fun deserialize(input: Int): InAppPaymentSubscriberRecord.Type = InAppPaymentSubscriberRecord.Type.entries.first { it.code == input }
}
}

View File

@@ -414,7 +414,7 @@ class InAppPaymentTable(context: Context, databaseHelper: SignalDatabase) : Data
companion object : Serializer<State, Int> {
override fun serialize(data: State): Int = data.code
override fun deserialize(input: Int): State = State.values().first { it.code == input }
override fun deserialize(input: Int): State = entries.first { it.code == input }
}
}
}

View File

@@ -4714,7 +4714,7 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
companion object {
fun fromId(id: Int): VibrateState {
return values()[id]
return entries[id]
}
fun fromBoolean(enabled: Boolean): VibrateState {
@@ -4730,7 +4730,7 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
companion object {
fun fromId(id: Int): RegisteredState {
return values()[id]
return entries[id]
}
}
}
@@ -4743,7 +4743,7 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
companion object {
fun fromMode(mode: Int): SealedSenderAccessMode {
return values()[mode]
return entries[mode]
}
}
}
@@ -4759,7 +4759,7 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
companion object {
fun fromId(id: Int): InsightsBannerTier {
return values()[id]
return entries[id]
}
}
}
@@ -4774,7 +4774,7 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
companion object {
fun fromId(id: Int): RecipientType {
return values()[id]
return entries[id]
}
}
}
@@ -4785,7 +4785,7 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
companion object {
fun fromId(id: Int): MentionSetting {
return values()[id]
return entries[id]
}
}
}
@@ -4800,7 +4800,7 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
companion object {
fun fromId(id: Int): PhoneNumberSharingState {
return values()[id]
return entries[id]
}
}
}
@@ -4812,7 +4812,7 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
companion object {
fun fromId(id: Int): PhoneNumberDiscoverableState {
return PhoneNumberDiscoverableState.values()[id]
return entries[id]
}
}
}

View File

@@ -2352,7 +2352,7 @@ class ThreadTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTa
companion object {
fun deserialize(value: Int): ReadStatus {
for (status in values()) {
for (status in entries) {
if (status.value == value) {
return status
}

View File

@@ -55,7 +55,7 @@ data class RemoteMegaphoneRecord(
companion object {
fun from(id: String?): ActionId? {
return values().firstOrNull { it.id == id }
return entries.firstOrNull { it.id == id }
}
}
}

View File

@@ -25,7 +25,7 @@ enum class EmojiCategory(val priority: Int, val key: String, @AttrRes val icon:
companion object {
@JvmStatic
fun forKey(key: String) = values().first { it.key == key }
fun forKey(key: String) = entries.first { it.key == key }
@JvmStatic
@StringRes

View File

@@ -25,7 +25,7 @@ object TextToScript {
)
fun guessScript(text: CharSequence): SupportedScript {
val scriptCounts: MutableMap<SupportedScript, Int> = SupportedScript.values().associate { it to 0 }.toMutableMap()
val scriptCounts: MutableMap<SupportedScript, Int> = SupportedScript.entries.associate { it to 0 }.toMutableMap()
val input = text.toString()
for (i in 0 until input.codePointCount(0, input.length)) {

View File

@@ -21,7 +21,7 @@ object TypefaceCache {
*/
fun warm(context: Context, script: SupportedScript) {
val appContext = context.applicationContext
TextFont.values().forEach {
TextFont.entries.forEach {
get(appContext, it, script).subscribe()
}
}

View File

@@ -33,7 +33,7 @@ class PushProcessMessageJobMigration : JobMigration(10) {
private fun migrateJob(jobData: JobData): JobData {
val data = JsonJobData.deserialize(jobData.data)
return if (data.hasInt("message_state")) {
val state = MessageState.values()[data.getInt("message_state")]
val state = MessageState.entries[data.getInt("message_state")]
return when (state) {
MessageState.NOOP -> jobData.withFactoryKey(FailingJob.KEY)

View File

@@ -42,7 +42,7 @@ class FontDownloaderJob private constructor(parameters: Parameters) : BaseJob(pa
override fun onRun() {
val script = Fonts.getSupportedScript(LocaleUtil.getLocaleDefaults(), SupportedScript.UNKNOWN)
val asyncResults = TextFont.values()
val asyncResults = TextFont.entries
.map { Fonts.resolveFont(context, it, script) }
.filterIsInstance(Fonts.FontResult.Async::class.java)

View File

@@ -320,7 +320,7 @@ class InAppPaymentKeepAliveJob private constructor(
override fun create(parameters: Parameters, serializedData: ByteArray?): InAppPaymentKeepAliveJob {
return InAppPaymentKeepAliveJob(
parameters,
InAppPaymentSubscriberRecord.Type.values().first { it.code == JsonJobData.deserialize(serializedData).getInt(DATA_TYPE) }
InAppPaymentSubscriberRecord.Type.entries.first { it.code == JsonJobData.deserialize(serializedData).getInt(DATA_TYPE) }
)
}
}

View File

@@ -66,7 +66,7 @@ class PushProcessMessageErrorJob private constructor(
override fun create(parameters: Parameters, serializedData: ByteArray?): PushProcessMessageErrorJob {
val data = JsonJobData.deserialize(serializedData)
val state = MessageState.values()[data.getInt(KEY_MESSAGE_STATE)]
val state = MessageState.entries[data.getInt(KEY_MESSAGE_STATE)]
check(state != MessageState.DECRYPTED_OK && state != MessageState.NOOP)
val exceptionMetadata = ExceptionMetadata(

View File

@@ -13,6 +13,6 @@ enum class GifQuickSearchOption(private val rank: Int, val image: Int, val query
ANGRY(7, R.drawable.ic_gif_angry_24, "angry");
companion object {
val ranked: List<GifQuickSearchOption> by lazy { values().sortedBy { it.rank } }
val ranked: List<GifQuickSearchOption> by lazy { entries.sortedBy { it.rank } }
}
}

View File

@@ -565,7 +565,7 @@ class AccountValues internal constructor(store: KeyValueStore, context: Context)
companion object {
fun deserialize(value: Long): UsernameSyncState {
return values().firstOrNull { it.value == value } ?: throw IllegalArgumentException("Invalid value: $value")
return entries.firstOrNull { it.value == value } ?: throw IllegalArgumentException("Invalid value: $value")
}
}
}

View File

@@ -31,7 +31,7 @@ class QuoteModel(
companion object {
@JvmStatic
fun fromCode(code: Int): Type {
for (value in values()) {
for (value in entries) {
if (value.code == code) {
return value
}
@@ -41,7 +41,7 @@ class QuoteModel(
@JvmStatic
fun fromDataMessageType(dataMessageType: SignalServiceDataMessage.Quote.Type): Type {
for (value in values()) {
for (value in entries) {
if (value.dataMessageType === dataMessageType) {
return value
}

View File

@@ -48,6 +48,6 @@ object WelcomePermissions {
@JvmStatic
fun getWelcomePermissions(isUserBackupSelectionRequired: Boolean): Array<String> {
return Permissions.values().map { it.getPermissions(isUserBackupSelectionRequired) }.flatten().toTypedArray()
return Permissions.entries.map { it.getPermissions(isUserBackupSelectionRequired) }.flatten().toTypedArray()
}
}

View File

@@ -65,7 +65,7 @@ class RestoreActivity : BaseActivity() {
companion object {
fun deserialize(value: Int): NavTarget {
return values().firstOrNull { it.value == value } ?: NONE
return entries.firstOrNull { it.value == value } ?: NONE
}
}
}

View File

@@ -210,13 +210,13 @@ class AnalogClockStickerDrawable(val context: Context) : Drawable(), Animatable
GREEN(3);
fun next(): Style {
val values = Style.values()
val values = entries.toTypedArray()
return values[(values.indexOf(this) + 1) % values.size]
}
companion object {
fun fromType(type: Int) = Style.values().first { it.type == type }
fun fromType(type: Int) = entries.first { it.type == type }
}
}
}

View File

@@ -250,13 +250,13 @@ class DigitalClockStickerDrawable(
DARK_WITH_RED_TEXT(4);
fun next(): Style {
val values = Style.values()
val values = entries.toTypedArray()
return values[(values.indexOf(this) + 1) % values.size]
}
companion object {
fun fromType(type: Int) = Style.values().first { it.type == type }
fun fromType(type: Int) = entries.first { it.type == type }
}
}
}

View File

@@ -9,6 +9,6 @@ enum class FeatureSticker(val type: String) {
companion object {
@JvmStatic
fun fromType(type: String) = FeatureSticker.values().first { it.type == type }
fun fromType(type: String) = entries.first { it.type == type }
}
}

View File

@@ -163,7 +163,7 @@ class StorySlateView @JvmOverloads constructor(
companion object {
fun fromCode(code: Int): State {
return values().firstOrNull {
return entries.firstOrNull {
it.code == code
} ?: HIDDEN
}

View File

@@ -21,7 +21,7 @@ object AudioDeviceMapping {
@JvmStatic
fun fromPlatformType(type: Int): SignalAudioManager.AudioDevice {
for (kind in SignalAudioManager.AudioDevice.values()) {
for (kind in SignalAudioManager.AudioDevice.entries) {
if (getEquivalentPlatformTypes(kind).contains(type)) return kind
}
return SignalAudioManager.AudioDevice.NONE

View File

@@ -384,7 +384,7 @@ class FullSignalAudioManager(context: Context, eventListener: EventListener?) :
if (isId) {
throw IllegalArgumentException("Passing audio device address $device to legacy audio manager")
}
val mappedDevice = AudioDevice.values()[device]
val mappedDevice = AudioDevice.entries[device]
val actualDevice: AudioDevice = if (mappedDevice == AudioDevice.EARPIECE && audioDevices.contains(AudioDevice.WIRED_HEADSET)) AudioDevice.WIRED_HEADSET else mappedDevice
Log.d(TAG, "selectAudioDevice(): device: $device actualDevice: $actualDevice")

View File

@@ -111,7 +111,7 @@ class NotificationProfileScheduleTest {
@Test
fun `when enabled schedule 12am to 12am for all days then return true`() {
val schedule = NotificationProfileSchedule(id = 1L, enabled = true, start = 0, end = 2400, daysEnabled = DayOfWeek.values().toSet())
val schedule = NotificationProfileSchedule(id = 1L, enabled = true, start = 0, end = 2400, daysEnabled = DayOfWeek.entries.toSet())
assertTrue(schedule.isCurrentlyActive(sunday0am.toMillis(ZoneOffset.UTC)))
assertTrue(schedule.isCurrentlyActive(sunday1am.toMillis(ZoneOffset.UTC)))
@@ -128,7 +128,7 @@ class NotificationProfileScheduleTest {
@Test
fun `when disabled schedule 12am to 12am for all days then return false`() {
val schedule = NotificationProfileSchedule(id = 1L, enabled = false, start = 0, end = 2400, daysEnabled = DayOfWeek.values().toSet())
val schedule = NotificationProfileSchedule(id = 1L, enabled = false, start = 0, end = 2400, daysEnabled = DayOfWeek.entries.toSet())
assertFalse(schedule.isCurrentlyActive(sunday0am.toMillis(ZoneOffset.UTC)))
assertFalse(schedule.isCurrentlyActive(sunday1am.toMillis(ZoneOffset.UTC)))
@@ -145,7 +145,7 @@ class NotificationProfileScheduleTest {
@Test
fun `when end time is midnight return midnight of next day from now`() {
val schedule = NotificationProfileSchedule(id = 1L, enabled = false, start = 0, end = 2400, daysEnabled = DayOfWeek.values().toSet())
val schedule = NotificationProfileSchedule(id = 1L, enabled = false, start = 0, end = 2400, daysEnabled = DayOfWeek.entries.toSet())
assertThat(schedule.endDateTime(sunday930am), `is`(monday0am))
}
}

View File

@@ -184,7 +184,7 @@ class NotificationProfilesTest {
every { notificationProfileValues.manuallyEnabledUntil } returns 0
every { notificationProfileValues.manuallyDisabledAt } returns sunday830am.toMillis(ZoneOffset.UTC)
val schedule = NotificationProfileSchedule(id = 3L, enabled = true, start = 2200, end = 1000, daysEnabled = DayOfWeek.values().toSet())
val schedule = NotificationProfileSchedule(id = 3L, enabled = true, start = 2200, end = 1000, daysEnabled = DayOfWeek.entries.toSet())
val profiles = listOf(first.copy(schedule = schedule))
assertThat("active profile is null", NotificationProfiles.getActiveProfile(profiles, sunday9am.toMillis(ZoneOffset.UTC), utc), nullValue())
}

View File

@@ -58,7 +58,7 @@ sealed class PaymentSourceType {
companion object {
fun fromCode(code: String?): PaymentSourceType {
return when (Codes.values().firstOrNull { it.code == code } ?: Codes.UNKNOWN) {
return when (Codes.entries.firstOrNull { it.code == code } ?: Codes.UNKNOWN) {
Codes.UNKNOWN -> Unknown
Codes.PAY_PAL -> PayPal
Codes.CREDIT_CARD -> Stripe.CreditCard

View File

@@ -58,7 +58,7 @@ sealed class StripeDeclineCode(val rawCode: String) {
return Unknown("null")
}
val typedCode: Code? = Code.values().firstOrNull { it.code == code }
val typedCode: Code? = Code.entries.firstOrNull { it.code == code }
return typedCode?.let { Known(typedCode) } ?: Unknown(code)
}
}

View File

@@ -36,7 +36,7 @@ sealed class StripeFailureCode(val rawCode: String) {
return Unknown("null")
}
val typedCode: Code? = Code.values().firstOrNull { it.code == code }
val typedCode: Code? = Code.entries.firstOrNull { it.code == code }
return typedCode?.let { Known(typedCode) } ?: Unknown(code)
}
}

View File

@@ -22,6 +22,6 @@ enum class StripeIntentStatus(private val code: String) {
companion object {
@JvmStatic
@JsonCreator
fun fromCode(code: String): StripeIntentStatus = StripeIntentStatus.values().first { it.code == code }
fun fromCode(code: String): StripeIntentStatus = entries.first { it.code == code }
}
}

View File

@@ -23,7 +23,7 @@ class ArchiveMediaResponse(
companion object {
fun from(code: Int): StatusCodes {
return values().firstOrNull { it.code == code } ?: Unknown
return entries.firstOrNull { it.code == code } ?: Unknown
}
}
}

View File

@@ -19,7 +19,7 @@ enum class ArchiveMediaUploadFormStatusCodes(val code: Int) {
companion object {
fun from(code: Int): ArchiveMediaUploadFormStatusCodes {
return values().firstOrNull { it.code == code } ?: Unknown
return entries.firstOrNull { it.code == code } ?: Unknown
}
}
}

View File

@@ -269,7 +269,7 @@ class SignalServiceDataMessage private constructor(
companion object {
@JvmStatic
fun fromProto(protoType: QuoteProto.Type): Type {
return values().firstOrNull { it.protoType == protoType } ?: NORMAL
return entries.firstOrNull { it.protoType == protoType } ?: NORMAL
}
}
}