srctree

Robin Linden parent faacdab5 0ec87b03
Replace Enum.values() w/ Enum.entries

atox/src/main/kotlin/settings/Settings.kt added: 48, removed: 48, total 0
@@ -1,4 +1,5 @@
// SPDX-FileCopyrightText: 2020-2022 aTox contributors
// SPDX-FileCopyrightText: 2020-2024 Robin Lindén <dev@robinlinden.eu>
// SPDX-FileCopyrightText: 2022 aTox contributors
//
// SPDX-License-Identifier: GPL-3.0-only
 
@@ -66,7 +67,7 @@ class Settings @Inject constructor(private val ctx: Context) {
set(seconds) = preferences.edit().putLong("auto_away_seconds", seconds).apply()
 
var proxyType: ProxyType
get() = ProxyType.values()[preferences.getInt("proxy_type", 0)]
get() = ProxyType.entries[preferences.getInt("proxy_type", 0)]
set(type) = preferences.edit { putInt("proxy_type", type.ordinal) }
 
var proxyAddress: String
@@ -78,11 +79,11 @@ class Settings @Inject constructor(private val ctx: Context) {
set(port) = preferences.edit { putInt("proxy_port", port) }
 
var ftAutoAccept: FtAutoAccept
get() = FtAutoAccept.values()[preferences.getInt("ft_auto_accept", 0)]
get() = FtAutoAccept.entries[preferences.getInt("ft_auto_accept", 0)]
set(autoAccept) = preferences.edit { putInt("ft_auto_accept", autoAccept.ordinal) }
 
var bootstrapNodeSource: BootstrapNodeSource
get() = BootstrapNodeSource.values()[preferences.getInt("bootstrap_node_source", 0)]
get() = BootstrapNodeSource.entries[preferences.getInt("bootstrap_node_source", 0)]
set(source) = preferences.edit { putInt("bootstrap_node_source", source.ordinal) }
 
var disableScreenshots: Boolean
 
atox/src/main/kotlin/ui/chat/ChatAdapter.kt added: 48, removed: 48, total 0
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2020-2021 aTox contributors
// SPDX-FileCopyrightText: 2019-2024 Robin Lindén <dev@robinlinden.eu>
//
// SPDX-License-Identifier: GPL-3.0-only
 
@@ -64,7 +64,6 @@ private enum class ChatItemType {
SentFileTransfer,
}
 
private val types = ChatItemType.values()
private val timeFormatter = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT)
 
private class MessageViewHolder(row: View) {
@@ -98,7 +97,7 @@ class ChatAdapter(
override fun getCount(): Int = messages.size
override fun getItem(position: Int): Any = messages[position]
override fun getItemId(position: Int): Long = position.toLong()
override fun getViewTypeCount(): Int = types.size
override fun getViewTypeCount(): Int = ChatItemType.entries.size
override fun getItemViewType(position: Int): Int = with(messages[position]) {
when (type) {
MessageType.Normal -> when (sender) {
@@ -117,7 +116,7 @@ class ChatAdapter(
}
 
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View =
when (val type = types[getItemViewType(position)]) {
when (val type = ChatItemType.entries[getItemViewType(position)]) {
ChatItemType.ReceivedMessage, ChatItemType.SentMessage,
ChatItemType.ReceivedAction, ChatItemType.SentAction,
-> {
 
atox/src/main/kotlin/ui/contactlist/ContactAdapter.kt added: 48, removed: 48, total 0
@@ -1,4 +1,5 @@
// SPDX-FileCopyrightText: 2020-2021 aTox contributors
// SPDX-FileCopyrightText: 2019-2024 Robin Lindén <dev@robinlinden.eu>
// SPDX-FileCopyrightText: 2021-2022 aTox contributors
//
// SPDX-License-Identifier: GPL-3.0-only
 
@@ -25,8 +26,6 @@ enum class ContactListItemType {
Contact,
}
 
private val types = ContactListItemType.values()
 
class ContactAdapter(
private val inflater: LayoutInflater,
private val context: Context,
@@ -48,7 +47,7 @@ class ContactAdapter(
}
 
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View =
when (types[getItemViewType(position)]) {
when (ContactListItemType.entries[getItemViewType(position)]) {
ContactListItemType.FriendRequest -> {
val view: View
val vh: FriendRequestViewHolder
 
atox/src/main/kotlin/ui/settings/SettingsFragment.kt added: 48, removed: 48, total 0
@@ -1,4 +1,5 @@
// SPDX-FileCopyrightText: 2019-2022 aTox contributors
// SPDX-FileCopyrightText: 2019-2024 Robin Lindén <dev@robinlinden.eu>
// SPDX-FileCopyrightText: 2021-2022 aTox contributors
//
// SPDX-License-Identifier: GPL-3.0-only
 
@@ -144,7 +145,7 @@ class SettingsFragment : BaseFragment<FragmentSettingsBinding>(FragmentSettingsB
settingFtAutoAccept.setSelection(vm.getFtAutoAccept().ordinal)
 
settingFtAutoAccept.onItemSelectedListener {
vm.setFtAutoAccept(FtAutoAccept.values()[it])
vm.setFtAutoAccept(FtAutoAccept.entries[it])
}
 
settingConfirmQuitting.isChecked = vm.getConfirmQuitting()
@@ -170,7 +171,7 @@ class SettingsFragment : BaseFragment<FragmentSettingsBinding>(FragmentSettingsB
proxyType.setSelection(vm.getProxyType().ordinal)
 
proxyType.onItemSelectedListener {
val selected = ProxyType.values()[it]
val selected = ProxyType.entries[it]
vm.setProxyType(selected)
 
// Disable UDP if a proxy is selected to ensure all traffic goes through the proxy.
@@ -272,7 +273,7 @@ class SettingsFragment : BaseFragment<FragmentSettingsBinding>(FragmentSettingsB
settingBootstrapNodes.setSelection(vm.getBootstrapNodeSource().ordinal)
 
settingBootstrapNodes.onItemSelectedListener {
val source = BootstrapNodeSource.values()[it]
val source = BootstrapNodeSource.entries[it]
 
// Hack to avoid triggering the document chooser again if the user has set it to UserProvided.
if (source == vm.getBootstrapNodeSource()) return@onItemSelectedListener
 
core/src/main/kotlin/db/Converters.kt added: 48, removed: 48, total 0
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2019-2020 aTox contributors
// SPDX-FileCopyrightText: 2019-2024 Robin Lindén <dev@robinlinden.eu>
//
// SPDX-License-Identifier: GPL-3.0-only
 
@@ -14,7 +14,7 @@ class Converters private constructor() {
companion object {
@TypeConverter
@JvmStatic
fun toStatus(status: Int): UserStatus = UserStatus.values()[status]
fun toStatus(status: Int): UserStatus = UserStatus.entries[status]
 
@TypeConverter
@JvmStatic
@@ -22,7 +22,7 @@ class Converters private constructor() {
 
@TypeConverter
@JvmStatic
fun toConnection(connection: Int): ConnectionStatus = ConnectionStatus.values()[connection]
fun toConnection(connection: Int): ConnectionStatus = ConnectionStatus.entries[connection]
 
@TypeConverter
@JvmStatic
@@ -30,7 +30,7 @@ class Converters private constructor() {
 
@TypeConverter
@JvmStatic
fun toSender(sender: Int): Sender = Sender.values()[sender]
fun toSender(sender: Int): Sender = Sender.entries[sender]
 
@TypeConverter
@JvmStatic
@@ -38,7 +38,7 @@ class Converters private constructor() {
 
@TypeConverter
@JvmStatic
fun toMessageType(type: Int): MessageType = MessageType.values()[type]
fun toMessageType(type: Int): MessageType = MessageType.entries[type]
 
@TypeConverter
@JvmStatic
 
core/src/test/kotlin/db/ConvertersTest.kt added: 48, removed: 48, total 0
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2020 aTox contributors
// SPDX-FileCopyrightText: 2020-2024 Robin Lindén <dev@robinlinden.eu>
//
// SPDX-License-Identifier: GPL-3.0-only
 
@@ -14,7 +14,7 @@ import ltd.evilcorp.core.vo.UserStatus
class ConvertersTest {
@Test
fun `user status can be converted`() {
UserStatus.values().forEach {
UserStatus.entries.forEach {
assertEquals(it.ordinal, Converters.fromStatus(it))
assertEquals(it, Converters.toStatus(it.ordinal))
}
@@ -22,7 +22,7 @@ class ConvertersTest {
 
@Test
fun `connection status can be converted`() {
ConnectionStatus.values().forEach {
ConnectionStatus.entries.forEach {
assertEquals(it.ordinal, Converters.fromConnection(it))
assertEquals(it, Converters.toConnection(it.ordinal))
}
@@ -30,7 +30,7 @@ class ConvertersTest {
 
@Test
fun `sender can be converted`() {
Sender.values().forEach {
Sender.entries.forEach {
assertEquals(it.ordinal, Converters.fromSender(it))
assertEquals(it, Converters.toSender(it.ordinal))
}
@@ -38,7 +38,7 @@ class ConvertersTest {
 
@Test
fun `message type can be converted`() {
MessageType.values().forEach {
MessageType.entries.forEach {
assertEquals(it.ordinal, Converters.fromMessageType(it))
assertEquals(it, Converters.toMessageType(it.ordinal))
}
 
domain/src/main/kotlin/tox/ToxUtil.kt added: 48, removed: 48, total 0
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2019-2021 aTox contributors
// SPDX-FileCopyrightText: 2019-2024 Robin Lindén <dev@robinlinden.eu>
//
// SPDX-License-Identifier: GPL-3.0-only
 
@@ -18,9 +18,9 @@ import ltd.evilcorp.core.vo.UserStatus
 
fun String.hexToBytes(): ByteArray = chunked(2).map { it.uppercase().toInt(radix = 16).toByte() }.toByteArray()
fun ByteArray.bytesToHex(): String = this.joinToString("") { "%02X".format(it) }
fun ToxUserStatus.toUserStatus(): UserStatus = UserStatus.values()[this.ordinal]
fun ToxConnection.toConnectionStatus(): ConnectionStatus = ConnectionStatus.values()[this.ordinal]
fun ToxMessageType.toMessageType(): MessageType = MessageType.values()[this.ordinal]
fun ToxUserStatus.toUserStatus(): UserStatus = UserStatus.entries[this.ordinal]
fun ToxConnection.toConnectionStatus(): ConnectionStatus = ConnectionStatus.entries[this.ordinal]
fun ToxMessageType.toMessageType(): MessageType = MessageType.entries[this.ordinal]
fun SaveOptions.toToxOptions(): ToxOptions = ToxOptions(
true,
udpEnabled,
 
domain/src/test/kotlin/tox/ToxUtilTest.kt added: 48, removed: 48, total 0
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2020-2022 Robin Lindén <dev@robinlinden.eu>
// SPDX-FileCopyrightText: 2020-2024 Robin Lindén <dev@robinlinden.eu>
//
// SPDX-License-Identifier: GPL-3.0-only
 
@@ -22,10 +22,10 @@ private fun byteArrayOf(vararg bytes: Int) = ByteArray(bytes.size) { bytes[it].t
class ToxUtilTest {
@Test
fun `connection enums can be converted`() {
assert(ToxConnection.values().size == ConnectionStatus.values().size)
assert(ConnectionStatus.values().size == 3)
assert(ToxConnection.entries.size == ConnectionStatus.entries.size)
assert(ConnectionStatus.entries.size == 3)
 
ToxConnection.values().forEach {
ToxConnection.entries.forEach {
assertEquals(it.ordinal, it.toConnectionStatus().ordinal)
}
 
@@ -36,9 +36,9 @@ class ToxUtilTest {
 
@Test
fun `message type enums can be converted`() {
assertEquals(2, ToxMessageType.values().size)
assertEquals(2, ToxMessageType.entries.size)
 
ToxMessageType.values().forEach { type ->
ToxMessageType.entries.forEach { type ->
assertEquals(type.ordinal, type.toMessageType().ordinal)
assertEquals(type, type.toMessageType().toToxType())
}
@@ -49,14 +49,14 @@ class ToxUtilTest {
 
@Test
fun `status enums can be converted`() {
assert(ToxUserStatus.values().size == UserStatus.values().size)
assert(UserStatus.values().size == 3)
assert(ToxUserStatus.entries.size == UserStatus.entries.size)
assert(UserStatus.entries.size == 3)
 
ToxUserStatus.values().forEach {
ToxUserStatus.entries.forEach {
assertEquals(it.ordinal, it.toUserStatus().ordinal)
}
 
UserStatus.values().forEach { type ->
UserStatus.entries.forEach { type ->
assertEquals(type, type.toToxType().toUserStatus())
}