0
0
mirror of https://github.com/thunderbird/thunderbird-android.git synced 2024-09-20 12:12:15 +02:00

Merge pull request #7387 from thunderbird/change-use-of-enum-values-by-entries

Change use of Enum.values() to Enum.entries
This commit is contained in:
Wolf-Martell Montwé 2023-11-28 16:26:40 +00:00 committed by GitHub
commit e0957e2278
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 47 additions and 22 deletions

View File

@ -19,6 +19,6 @@ enum class CatalogAtomPage(
}
companion object {
fun all() = values().toList().toImmutableList()
fun all() = entries.toImmutableList()
}
}

View File

@ -14,6 +14,6 @@ enum class CatalogMoleculePage(
}
companion object {
fun all() = values().toList().toImmutableList()
fun all() = entries.toImmutableList()
}
}

View File

@ -13,6 +13,6 @@ enum class CatalogOrganismPage(
}
companion object {
fun all() = values().toList().toImmutableList()
fun all() = entries.toImmutableList()
}
}

View File

@ -670,7 +670,7 @@ class Account(override val uuid: String) : BaseAccount {
companion object {
fun fromInt(initialSetting: Int): DeletePolicy {
return values().find { it.setting == initialSetting } ?: error("DeletePolicy $initialSetting unknown")
return entries.find { it.setting == initialSetting } ?: error("DeletePolicy $initialSetting unknown")
}
}
}

View File

@ -9,7 +9,7 @@ enum class SendState(val databaseName: String) {
companion object {
@JvmStatic
fun fromDatabaseName(databaseName: String): SendState {
return SendState.values().firstOrNull { it.databaseName == databaseName }
return entries.firstOrNull { it.databaseName == databaseName }
?: throw IllegalArgumentException("Unknown value: $databaseName")
}
}

View File

@ -14,7 +14,7 @@ class NotificationVibrationDecoder {
val systemPatternArray = systemPattern.toLongArray()
val repeatCount = systemPattern.size / 2
val pattern = VibratePattern.values()
val pattern = VibratePattern.entries
.firstOrNull { vibratePattern ->
val testPattern = NotificationVibration.getSystemPattern(vibratePattern, repeatCount)

View File

@ -679,7 +679,7 @@ class MessageListFragment :
}
fun onCycleSort() {
val sortTypes = SortType.values()
val sortTypes = SortType.entries
val currentIndex = sortTypes.indexOf(sortType)
val newIndex = if (currentIndex == sortTypes.lastIndex) 0 else currentIndex + 1
val nextSortType = sortTypes[newIndex]
@ -763,6 +763,7 @@ class MessageListFragment :
val cancelText = getString(R.string.dialog_confirm_spam_cancel_button)
ConfirmationDialogFragment.newInstance(dialogId, title, message, confirmText, cancelText)
}
R.id.dialog_confirm_delete -> {
val title = getString(R.string.dialog_confirm_delete_title)
val selectionSize = activeMessages!!.size
@ -775,6 +776,7 @@ class MessageListFragment :
val cancelText = getString(R.string.dialog_confirm_delete_cancel_button)
ConfirmationDialogFragment.newInstance(dialogId, title, message, confirmText, cancelText)
}
R.id.dialog_confirm_mark_all_as_read -> {
val title = getString(R.string.dialog_confirm_mark_all_as_read_title)
val message = getString(R.string.dialog_confirm_mark_all_as_read_message)
@ -782,6 +784,7 @@ class MessageListFragment :
val cancelText = getString(R.string.dialog_confirm_mark_all_as_read_cancel_button)
ConfirmationDialogFragment.newInstance(dialogId, title, message, confirmText, cancelText)
}
R.id.dialog_confirm_empty_trash -> {
val title = getString(R.string.dialog_confirm_empty_trash_title)
val message = getString(R.string.dialog_confirm_empty_trash_message)
@ -789,6 +792,7 @@ class MessageListFragment :
val cancelText = getString(R.string.dialog_confirm_delete_cancel_button)
ConfirmationDialogFragment.newInstance(dialogId, title, message, confirmText, cancelText)
}
else -> {
throw RuntimeException("Called showDialog(int) with unknown dialog id.")
}
@ -1210,14 +1214,17 @@ class MessageListFragment :
onSpamConfirmed(activeMessages!!)
activeMessages = null
}
R.id.dialog_confirm_delete -> {
onDeleteConfirmed(activeMessages!!)
activeMessage = null
adapter.activeMessage = null
}
R.id.dialog_confirm_mark_all_as_read -> {
markAllAsRead()
}
R.id.dialog_confirm_empty_trash -> {
messagingController.emptyTrash(account, null)
}
@ -1628,21 +1635,27 @@ class MessageListFragment :
SwipeAction.ToggleSelection -> {
toggleMessageSelect(item)
}
SwipeAction.ToggleRead -> {
setFlag(item, Flag.SEEN, !item.isRead)
}
SwipeAction.ToggleStar -> {
setFlag(item, Flag.FLAGGED, !item.isStarred)
}
SwipeAction.Archive -> {
onArchive(item.messageReference)
}
SwipeAction.Delete -> {
onDelete(listOf(item.messageReference))
}
SwipeAction.Spam -> {
onSpam(listOf(item.messageReference))
}
SwipeAction.Move -> {
val messageReference = item.messageReference
resetSwipedView(messageReference)
@ -1672,6 +1685,7 @@ class MessageListFragment :
SwipeAction.Archive -> {
!isOutbox && item.account.hasArchiveFolder() && item.folderId != item.account.archiveFolderId
}
SwipeAction.Delete -> true
SwipeAction.Move -> !isOutbox && messagingController.isMoveCapable(item.account)
SwipeAction.Spam -> !isOutbox && item.account.hasSpamFolder() && item.folderId != item.account.spamFolderId
@ -1967,48 +1981,59 @@ class MessageListFragment :
onDelete(selectedMessages)
true
}
R.id.mark_as_read -> {
setFlagForSelected(Flag.SEEN, true)
false
}
R.id.mark_as_unread -> {
setFlagForSelected(Flag.SEEN, false)
false
}
R.id.flag -> {
setFlagForSelected(Flag.FLAGGED, true)
false
}
R.id.unflag -> {
setFlagForSelected(Flag.FLAGGED, false)
false
}
R.id.select_all -> {
selectAll()
false
}
R.id.archive -> {
onArchive(selectedMessages)
// TODO: Only finish action mode if all messages have been moved.
true
}
R.id.spam -> {
onSpam(selectedMessages)
// TODO: Only finish action mode if all messages have been moved.
true
}
R.id.move -> {
onMove(selectedMessages)
true
}
R.id.move_to_drafts -> {
onMoveToDraftsFolder(selectedMessages)
true
}
R.id.copy -> {
onCopy(selectedMessages)
true
}
else -> return false
}

View File

@ -31,7 +31,7 @@ enum class AuthenticationType(
companion object {
val DEFAULT = PasswordCleartext
fun all() = values().toList().toImmutableList()
fun all() = entries.toImmutableList()
fun outgoing() = all()
}

View File

@ -13,7 +13,7 @@ enum class ConnectionSecurity {
companion object {
val DEFAULT = TLS
fun all() = values().toList().toImmutableList()
fun all() = entries.toImmutableList()
}
}

View File

@ -13,10 +13,10 @@ enum class IncomingProtocolType(
companion object {
val DEFAULT = IMAP
fun all() = values().toList().toImmutableList()
fun all() = entries.toImmutableList()
fun fromName(name: String): IncomingProtocolType {
return values().find { it.defaultName == name } ?: throw IllegalArgumentException("Unknown protocol: $name")
return entries.find { it.defaultName == name } ?: throw IllegalArgumentException("Unknown protocol: $name")
}
}
}

View File

@ -12,7 +12,7 @@ enum class OutgoingProtocolType(
companion object {
val DEFAULT = SMTP
fun all() = values().toList().toImmutableList()
fun all() = entries.toImmutableList()
}
}

View File

@ -9,7 +9,7 @@ class AuthenticationTypeTest {
@Test
fun `should map all AuthenticationType to AuthTypes`() {
val types = AuthenticationType.values()
val types = AuthenticationType.entries
for (type in types) {
val authType = type.toAuthType()
@ -28,7 +28,7 @@ class AuthenticationTypeTest {
@Test
fun `should map all AuthTypes to AuthenticationTypes`() {
val types = AuthType.values()
val types = AuthType.entries
for (type in types) {
val authenticationType = type.toAuthenticationType()

View File

@ -59,7 +59,7 @@ class ConnectionSecurityTest {
@Test
fun `should map all MailConnectionSecurities to ConnectionSecurities`() {
val securities = MailConnectionSecurity.values()
val securities = MailConnectionSecurity.entries
for (security in securities) {
val connectionSecurity = security.toConnectionSecurity()
@ -76,7 +76,7 @@ class ConnectionSecurityTest {
@Test
fun `should map to all ConnectionSecurities to MailConnectionSecurities`() {
val connectionSecurities = ConnectionSecurity.values()
val connectionSecurities = ConnectionSecurity.entries
for (security in connectionSecurities) {
val mailConnectionSecurity = security.toMailConnectionSecurity()

View File

@ -12,7 +12,7 @@ class IncomingProtocolTypeTest {
val protocolTypes = IncomingProtocolType.all()
assertThat(protocolTypes).isEqualTo(
IncomingProtocolType.values().toList(),
IncomingProtocolType.entries,
)
}

View File

@ -11,7 +11,7 @@ class OutgoingProtocolTypeTest {
val protocolTypes = OutgoingProtocolType.all()
assertThat(protocolTypes).isEqualTo(
OutgoingProtocolType.values().toList(),
OutgoingProtocolType.entries,
)
}

View File

@ -19,7 +19,7 @@ enum class EmailCheckFrequency(
companion object {
val DEFAULT = EVERY_HOUR
fun all() = values().toList().toImmutableList()
fun all() = entries.toImmutableList()
fun fromMinutes(minutes: Int): EmailCheckFrequency {
return all().find { it.minutes == minutes } ?: DEFAULT

View File

@ -17,7 +17,7 @@ enum class EmailDisplayCount(
companion object {
val DEFAULT = MESSAGES_25
fun all() = values().toList().toImmutableList()
fun all() = entries.toImmutableList()
fun fromCount(count: Int): EmailDisplayCount {
return all().find { it.count == count } ?: DEFAULT

View File

@ -9,7 +9,7 @@ class AutoDiscoveryAuthenticationTypeKtTest {
@Test
fun `should map all AutoDiscoveryAuthenticationTypes`() {
val types = AutoDiscoveryAuthenticationType.values()
val types = AutoDiscoveryAuthenticationType.entries
for (type in types) {
val authenticationType = type.toAuthenticationType()

View File

@ -9,7 +9,7 @@ class AutoDiscoveryConnectionSecurityKtTest {
@Test
fun `should map all AutoDiscoveryConnectionSecurities`() {
val securities = AutoDiscoveryConnectionSecurity.values()
val securities = AutoDiscoveryConnectionSecurity.entries
for (security in securities) {
val connectionSecurity = security.toConnectionSecurity()