Migrating Lint to 1.3.1

This commit is contained in:
Vitor Pamplona
2024-07-03 11:06:02 -04:00
parent 692f7c4270
commit 8d88efd27b
201 changed files with 1858 additions and 1814 deletions

View File

@@ -29,9 +29,7 @@ object Constants {
setOf(FeedType.FOLLOWS, FeedType.PUBLIC_CHATS, FeedType.PRIVATE_DMS, FeedType.GLOBAL)
val activeTypesSearch = setOf(FeedType.SEARCH)
fun convertDefaultRelays(): Array<Relay> {
return defaultRelays.map { Relay(it.url, it.read, it.write, it.feedTypes) }.toTypedArray()
}
fun convertDefaultRelays(): Array<Relay> = defaultRelays.map { Relay(it.url, it.read, it.write, it.feedTypes) }.toTypedArray()
val defaultRelays =
arrayOf(

View File

@@ -20,8 +20,8 @@
*/
package com.vitorpamplona.ammolite.relays
class EOSETime(var time: Long) {
override fun toString(): String {
return time.toString()
}
class EOSETime(
var time: Long,
) {
override fun toString(): String = time.toString()
}

View File

@@ -34,12 +34,18 @@ import kotlinx.coroutines.launch
import java.util.UUID
import java.util.concurrent.atomic.AtomicBoolean
abstract class NostrDataSource(val debugName: String) {
abstract class NostrDataSource(
val debugName: String,
) {
private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
private var subscriptions = mapOf<String, Subscription>()
data class Counter(val subscriptionId: String, val eventKind: Int, var counter: Int)
data class Counter(
val subscriptionId: String,
val eventKind: Int,
var counter: Int,
)
private var eventCounter = mapOf<Int, Counter>()
var changingFilters = AtomicBoolean()
@@ -58,9 +64,7 @@ abstract class NostrDataSource(val debugName: String) {
fun hashCodeFields(
str1: String,
str2: Int,
): Int {
return 31 * str1.hashCode() + str2.hashCode()
}
): Int = 31 * str1.hashCode() + str2.hashCode()
private val clientListener =
object : Client.Listener() {

View File

@@ -47,21 +47,13 @@ object RelayPool : Relay.Listener {
MutableSharedFlow<RelayPoolStatus>(1, 1, onBufferOverflow = BufferOverflow.DROP_OLDEST)
val statusFlow: SharedFlow<RelayPoolStatus> = _statusFlow.asSharedFlow()
fun availableRelays(): Int {
return relays.size
}
fun availableRelays(): Int = relays.size
fun connectedRelays(): Int {
return relays.count { it.isConnected() }
}
fun connectedRelays(): Int = relays.count { it.isConnected() }
fun getRelay(url: String): Relay? {
return relays.firstOrNull { it.url == url }
}
fun getRelay(url: String): Relay? = relays.firstOrNull { it.url == url }
fun getRelays(url: String): List<Relay> {
return relays.filter { it.url == url }
}
fun getRelays(url: String): List<Relay> = relays.filter { it.url == url }
fun getAll() = relays

View File

@@ -26,9 +26,7 @@ import com.vitorpamplona.quartz.utils.TimeUtils
object RelayStats {
private val innerCache = mutableMapOf<String, RelayStat>()
fun get(url: String): RelayStat {
return innerCache.getOrPut(url) { RelayStat() }
}
fun get(url: String): RelayStat = innerCache.getOrPut(url) { RelayStat() }
fun addBytesReceived(
url: String,

View File

@@ -59,9 +59,7 @@ object HttpClientManager {
}
}
fun getDefaultProxy(): Proxy? {
return this.internalProxy
}
fun getDefaultProxy(): Proxy? = this.internalProxy
fun setDefaultTimeout(timeout: Duration) {
Log.d("HttpClient", "Changing timeout to: $timeout")
@@ -87,7 +85,8 @@ object HttpClientManager {
): OkHttpClient {
val seconds = if (proxy != null) timeout.seconds * 3 else timeout.seconds
val duration = Duration.ofSeconds(seconds)
return OkHttpClient.Builder()
return OkHttpClient
.Builder()
.proxy(proxy)
.readTimeout(duration)
.connectTimeout(duration)
@@ -123,8 +122,8 @@ object HttpClientManager {
}
}
fun getHttpClient(useProxy: Boolean = true): OkHttpClient {
return if (useProxy) {
fun getHttpClient(useProxy: Boolean = true): OkHttpClient =
if (useProxy) {
if (this.defaultHttpClient == null) {
this.defaultHttpClient = buildHttpClient(internalProxy, defaultTimeout)
}
@@ -135,13 +134,10 @@ object HttpClientManager {
}
defaultHttpClientWithoutProxy!!
}
}
fun initProxy(
useProxy: Boolean,
hostname: String,
port: Int,
): Proxy? {
return if (useProxy) Proxy(Proxy.Type.SOCKS, InetSocketAddress(hostname, port)) else null
}
): Proxy? = if (useProxy) Proxy(Proxy.Type.SOCKS, InetSocketAddress(hostname, port)) else null
}

View File

@@ -31,4 +31,6 @@ fun checkNotInMainThread() {
fun isMainThread() = Looper.myLooper() == Looper.getMainLooper()
class OnMainThreadException(str: String) : RuntimeException(str)
class OnMainThreadException(
str: String,
) : RuntimeException(str)