commit 72b03085060d58d028a2e90972db72b84559587a parent 102e2df4e78c2fbde21cf33f533be2281c75abeb Author: rhunk <101876869+rhunk@users.noreply.github.com> Date: Sun, 8 Oct 2023 20:17:22 +0200 refactor: enum values() deprecation Diffstat:
19 files changed, 31 insertions(+), 31 deletions(-)
diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/bridge/BridgeService.kt b/app/src/main/kotlin/me/rhunk/snapenhance/bridge/BridgeService.kt @@ -75,7 +75,7 @@ class BridgeService : Service() { override fun fileOperation(action: Int, fileType: Int, content: ByteArray?): ByteArray { val resolvedFile = BridgeFileType.fromValue(fileType)?.resolve(this@BridgeService) - return when (FileActionType.values()[action]) { + return when (FileActionType.entries[action]) { FileActionType.CREATE_AND_READ -> { resolvedFile?.let { if (!it.exists()) { diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/MainActivity.kt b/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/MainActivity.kt @@ -46,7 +46,7 @@ class MainActivity : ComponentActivity() { checkForRequirements() } - sections = EnumSection.values().toList().associateWith { + sections = EnumSection.entries.associateWith { it.section.java.constructors.first().newInstance() as Section }.onEach { (section, instance) -> with(instance) { diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/Section.kt b/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/Section.kt @@ -54,7 +54,7 @@ enum class EnumSection( companion object { fun fromRoute(route: String): EnumSection { - return values().first { it.route == route } + return entries.first { it.route == route } } } } diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/sections/downloads/DownloadsSection.kt b/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/sections/downloads/DownloadsSection.kt @@ -85,7 +85,7 @@ class DownloadsSection : Section() { } DropdownMenu(expanded = showMenu, onDismissRequest = { showMenu = false }) { - MediaDownloadSource.values().toList().forEach { filter -> + MediaDownloadSource.entries.forEach { filter -> DropdownMenuItem( text = { Row( diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/sections/home/SettingsSection.kt b/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/sections/home/SettingsSection.kt @@ -95,14 +95,14 @@ class SettingsSection : Section() { .verticalScroll(ScrollState(0)) ) { RowTitle(title = "Actions") - EnumAction.values().forEach { enumAction -> + EnumAction.entries.forEach { enumAction -> RowAction(title = context.translation["actions.${enumAction.key}"]) { launchActionIntent(enumAction) } } RowTitle(title = "Clear Files") - BridgeFileType.values().forEach { fileType -> + BridgeFileType.entries.forEach { fileType -> RowAction(title = fileType.displayName, requireConfirmation = true) { runCatching { fileType.resolve(context.androidContext).delete() diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/sections/social/ScopeContent.kt b/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/sections/social/ScopeContent.kt @@ -72,7 +72,7 @@ class ScopeContent( ContentCard { //manager anti features etc - MessagingRuleType.values().forEach { ruleType -> + MessagingRuleType.entries.forEach { ruleType -> var ruleEnabled by remember { mutableStateOf(rules.any { it.key == ruleType.key }) } diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/sections/social/SocialSection.kt b/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/sections/social/SocialSection.kt @@ -66,7 +66,7 @@ class SocialSection : Section() { Content() } - SocialScope.values().forEach { scope -> + SocialScope.entries.forEach { scope -> composable(scope.tabRoute) { val id = it.arguments?.getString("id") ?: return@composable remember { diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/action/impl/ExportChatMessages.kt b/core/src/main/kotlin/me/rhunk/snapenhance/action/impl/ExportChatMessages.kt @@ -69,8 +69,8 @@ class ExportChatMessages : AbstractAction() { context.runOnUiThread { ViewAppearanceHelper.newAlertDialogBuilder(context.mainActivity) .setTitle(context.translation["chat_export.select_export_format"]) - .setItems(ExportFormat.values().map { it.name }.toTypedArray()) { _, which -> - cont.resumeWith(Result.success(ExportFormat.values()[which])) + .setItems(ExportFormat.entries.map { it.name }.toTypedArray()) { _, which -> + cont.resumeWith(Result.success(ExportFormat.entries[which])) } .setOnCancelListener { cont.resumeWith(Result.success(null)) diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/bridge/types/BridgeFileType.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/bridge/types/BridgeFileType.kt @@ -18,7 +18,7 @@ enum class BridgeFileType(val value: Int, val fileName: String, val displayName: companion object { fun fromValue(value: Int): BridgeFileType? { - return values().firstOrNull { it.value == value } + return entries.firstOrNull { it.value == value } } } } \ No newline at end of file diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/config/ConfigObjects.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/config/ConfigObjects.kt @@ -39,8 +39,8 @@ class ConfigParams( var customTranslationPath: String? = null, var customOptionTranslationPath: String? = null ) { - val notices get() = _notices?.let { FeatureNotice.values().filter { flag -> it and flag.id != 0 } } ?: emptyList() - val flags get() = _flags?.let { ConfigFlag.values().filter { flag -> it and flag.id != 0 } } ?: emptyList() + val notices get() = _notices?.let { FeatureNotice.entries.filter { flag -> it and flag.id != 0 } } ?: emptyList() + val flags get() = _flags?.let { ConfigFlag.entries.filter { flag -> it and flag.id != 0 } } ?: emptyList() fun addNotices(vararg values: FeatureNotice) { this._notices = (this._notices ?: 0) or values.fold(0) { acc, featureNotice -> acc or featureNotice.id } diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/config/impl/Rules.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/config/impl/Rules.kt @@ -14,7 +14,7 @@ class Rules : ConfigContainer() { } init { - MessagingRuleType.values().toList().filter { it.listMode }.forEach { ruleType -> + MessagingRuleType.entries.filter { it.listMode }.forEach { ruleType -> rules[ruleType] = unique(ruleType.key,"whitelist", "blacklist") { customTranslationPath = "rules.properties.${ruleType.key}" customOptionTranslationPath = "rules.modes" diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/download/data/MediaDownloadSource.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/download/data/MediaDownloadSource.kt @@ -22,7 +22,7 @@ enum class MediaDownloadSource( companion object { fun fromKey(key: String?): MediaDownloadSource { if (key == null) return NONE - return values().find { it.key == key } ?: NONE + return entries.find { it.key == key } ?: NONE } } } \ No newline at end of file diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/logger/LogChannel.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/logger/LogChannel.kt @@ -11,7 +11,7 @@ enum class LogChannel( companion object { fun fromChannel(channel: String): LogChannel? { - return values().find { it.channel == channel } + return entries.find { it.channel == channel } } } } \ No newline at end of file diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/logger/LogLevel.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/logger/LogLevel.kt @@ -16,15 +16,15 @@ enum class LogLevel( companion object { fun fromLetter(letter: String): LogLevel? { - return values().find { it.letter == letter } + return entries.find { it.letter == letter } } fun fromShortName(shortName: String): LogLevel? { - return values().find { it.shortName == shortName } + return entries.find { it.shortName == shortName } } fun fromPriority(priority: Int): LogLevel? { - return values().find { it.priority == priority } + return entries.find { it.priority == priority } } } } \ No newline at end of file diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/messaging/MessagingCoreObjects.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/messaging/MessagingCoreObjects.kt @@ -10,7 +10,7 @@ enum class RuleState( WHITELIST("whitelist"); companion object { - fun getByName(name: String) = values().first { it.key == name } + fun getByName(name: String) = entries.first { it.key == name } } } @@ -22,7 +22,7 @@ enum class SocialScope( GROUP("group", "group_info/{id}"); companion object { - fun getByName(name: String) = values().first { it.key == name } + fun getByName(name: String) = entries.first { it.key == name } } } @@ -43,7 +43,7 @@ enum class MessagingRuleType( } companion object { - fun getByName(name: String) = values().firstOrNull { it.key == name } + fun getByName(name: String) = entries.firstOrNull { it.key == name } } } diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/util/protobuf/WireType.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/util/protobuf/WireType.kt @@ -9,6 +9,6 @@ enum class WireType(val value: Int) { FIXED32(5); companion object { - fun fromValue(value: Int) = values().firstOrNull { it.value == value } + fun fromValue(value: Int) = entries.firstOrNull { it.value == value } } } diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/data/FileType.kt b/core/src/main/kotlin/me/rhunk/snapenhance/data/FileType.kt @@ -38,7 +38,7 @@ enum class FileType( ) fun fromString(string: String?): FileType { - return values().firstOrNull { it.fileExtension.equals(string, ignoreCase = true) } ?: UNKNOWN + return entries.firstOrNull { it.fileExtension.equals(string, ignoreCase = true) } ?: UNKNOWN } private fun bytesToHex(bytes: ByteArray): String { diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/data/SnapEnums.kt b/core/src/main/kotlin/me/rhunk/snapenhance/data/SnapEnums.kt @@ -26,15 +26,15 @@ enum class NotificationType ( companion object { fun getIncomingValues(): List<NotificationType> { - return values().filter { it.isIncoming }.toList() + return entries.filter { it.isIncoming }.toList() } fun getOutgoingValues(): List<NotificationType> { - return values().filter { it.associatedOutgoingContentType != null }.toList() + return entries.filter { it.associatedOutgoingContentType != null }.toList() } fun fromContentType(contentType: ContentType): NotificationType? { - return values().firstOrNull { it.associatedOutgoingContentType == contentType } + return entries.firstOrNull { it.associatedOutgoingContentType == contentType } } } } @@ -63,7 +63,7 @@ enum class ContentType(val id: Int) { companion object { fun fromId(i: Int): ContentType { - return values().firstOrNull { it.id == i } ?: UNKNOWN + return entries.firstOrNull { it.id == i } ?: UNKNOWN } fun fromMessageContainer(protoReader: ProtoReader?): ContentType? { @@ -165,7 +165,7 @@ enum class FriendLinkType(val value: Int, val shortName: String) { companion object { fun fromValue(value: Int): FriendLinkType { - return values().firstOrNull { it.value == value } ?: MUTUAL + return entries.firstOrNull { it.value == value } ?: MUTUAL } } } \ No newline at end of file diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/manager/impl/ActionManager.kt b/core/src/main/kotlin/me/rhunk/snapenhance/manager/impl/ActionManager.kt @@ -15,7 +15,7 @@ class ActionManager( private val actions = mutableMapOf<String, AbstractAction>() override fun init() { - EnumAction.values().forEach { enumAction -> + EnumAction.entries.forEach { enumAction -> actions[enumAction.key] = enumAction.clazz.java.getConstructor().newInstance().apply { this.context = modContext } @@ -24,7 +24,7 @@ class ActionManager( fun onNewIntent(intent: Intent?) { val action = intent?.getStringExtra(ACTION_PARAMETER) ?: return - execute(EnumAction.values().find { it.key == action } ?: return) + execute(EnumAction.entries.find { it.key == action } ?: return) intent.removeExtra(ACTION_PARAMETER) }