Skip to content

Commit b7f6cc3

Browse files
fix: resolve ktlint formatting violations
1 parent 40e912c commit b7f6cc3

4 files changed

Lines changed: 80 additions & 61 deletions

File tree

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* ktlint-disable */
21
package com.roxybasicneedbot.kdownloader.core.clipboard
32

43
import android.content.ClipboardManager
@@ -10,31 +9,33 @@ import kotlinx.coroutines.flow.callbackFlow
109
import java.util.regex.Pattern
1110

1211
actual class PlatformClipboardMonitor actual constructor() {
13-
private val clipboardManager = AndroidContext.appContext.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
12+
private val clipboardManager =
13+
AndroidContext.appContext.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
1414

1515
private val urlPattern = Pattern.compile(
16-
"https?://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]"
16+
"https?://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]",
1717
)
1818

19-
actual fun observeUrls(): Flow<String> = callbackFlow {
20-
val listener = ClipboardManager.OnPrimaryClipChangedListener {
21-
val text = getClipboardText()
22-
if (text != null && isUrl(text)) {
23-
trySend(text)
19+
actual fun observeUrls(): Flow<String> =
20+
callbackFlow {
21+
val listener =
22+
ClipboardManager.OnPrimaryClipChangedListener {
23+
val text = getClipboardText()
24+
if (text != null && isUrl(text)) {
25+
trySend(text)
26+
}
27+
}
28+
clipboardManager.addPrimaryClipChangedListener(listener)
29+
30+
val initialText = getClipboardText()
31+
if (initialText != null && isUrl(initialText)) {
32+
trySend(initialText)
2433
}
25-
}
26-
clipboardManager.addPrimaryClipChangedListener(listener)
27-
28-
// Emit initial value if any
29-
val initialText = getClipboardText()
30-
if (initialText != null && isUrl(initialText)) {
31-
trySend(initialText)
32-
}
3334

34-
awaitClose {
35-
clipboardManager.removePrimaryClipChangedListener(listener)
35+
awaitClose {
36+
clipboardManager.removePrimaryClipChangedListener(listener)
37+
}
3638
}
37-
}
3839

3940
actual fun getClipboardText(): String? {
4041
val clip = clipboardManager.primaryClip ?: return null
@@ -45,7 +46,5 @@ actual class PlatformClipboardMonitor actual constructor() {
4546
return null
4647
}
4748

48-
private fun isUrl(text: String): Boolean {
49-
return urlPattern.matcher(text).find()
50-
}
49+
private fun isUrl(text: String): Boolean = urlPattern.matcher(text).find()
5150
}

kdownloader-core/src/androidMain/kotlin/com/roxybasicneedbot/kdownloader/core/network/PlatformNetworkMonitor.kt

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* ktlint-disable */
21
package com.roxybasicneedbot.kdownloader.core.network
32

43
import android.content.Context
@@ -12,33 +11,40 @@ import kotlinx.coroutines.flow.Flow
1211
import kotlinx.coroutines.flow.callbackFlow
1312

1413
actual class PlatformNetworkMonitor {
15-
private val cm = AndroidContext.appContext.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
14+
private val cm =
15+
AndroidContext.appContext.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
1616

17-
actual fun observeConnectivity(): Flow<NetworkState> = callbackFlow {
18-
val callback = object : ConnectivityManager.NetworkCallback() {
19-
override fun onAvailable(network: Network) {
20-
trySend(getCurrentState())
21-
}
17+
actual fun observeConnectivity(): Flow<NetworkState> =
18+
callbackFlow {
19+
val callback =
20+
object : ConnectivityManager.NetworkCallback() {
21+
override fun onAvailable(network: Network) {
22+
trySend(getCurrentState())
23+
}
2224

23-
override fun onLost(network: Network) {
24-
trySend(NetworkState.DISCONNECTED)
25-
}
25+
override fun onLost(network: Network) {
26+
trySend(NetworkState.DISCONNECTED)
27+
}
2628

27-
override fun onCapabilitiesChanged(network: Network, capabilities: NetworkCapabilities) {
28-
trySend(getCurrentState())
29-
}
30-
}
29+
override fun onCapabilitiesChanged(
30+
network: Network,
31+
capabilities: NetworkCapabilities,
32+
) {
33+
trySend(getCurrentState())
34+
}
35+
}
3136

32-
val request = NetworkRequest.Builder()
33-
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
34-
.build()
35-
cm.registerNetworkCallback(request, callback)
36-
trySend(getCurrentState())
37+
val request =
38+
NetworkRequest.Builder()
39+
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
40+
.build()
41+
cm.registerNetworkCallback(request, callback)
42+
trySend(getCurrentState())
3743

38-
awaitClose {
39-
cm.unregisterNetworkCallback(callback)
44+
awaitClose {
45+
cm.unregisterNetworkCallback(callback)
46+
}
4047
}
41-
}
4248

4349
actual fun isConnected(): Boolean {
4450
val capabilities = cm.getNetworkCapabilities(cm.activeNetwork) ?: return false
@@ -51,8 +57,11 @@ actual class PlatformNetworkMonitor {
5157
}
5258

5359
private fun getCurrentState(): NetworkState {
54-
val capabilities = cm.getNetworkCapabilities(cm.activeNetwork) ?: return NetworkState.DISCONNECTED
55-
if (!capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)) return NetworkState.DISCONNECTED
60+
val capabilities =
61+
cm.getNetworkCapabilities(cm.activeNetwork) ?: return NetworkState.DISCONNECTED
62+
if (!capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)) {
63+
return NetworkState.DISCONNECTED
64+
}
5665
return if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
5766
NetworkState.CONNECTED_WIFI
5867
} else {

kdownloader-core/src/androidMain/kotlin/com/roxybasicneedbot/kdownloader/core/storage/PlatformFileStorage.kt

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* ktlint-disable */
21
package com.roxybasicneedbot.kdownloader.core.storage
32

43
import java.io.File
@@ -7,7 +6,11 @@ import java.io.RandomAccessFile
76
actual class PlatformFileStorage {
87
actual constructor()
98

10-
actual suspend fun write(path: String, offset: Long, data: ByteArray) {
9+
actual suspend fun write(
10+
path: String,
11+
offset: Long,
12+
data: ByteArray,
13+
) {
1114
val file = File(path)
1215
file.parentFile?.mkdirs()
1316
RandomAccessFile(file, "rw").use { raf ->
@@ -16,7 +19,11 @@ actual class PlatformFileStorage {
1619
}
1720
}
1821

19-
actual suspend fun read(path: String, offset: Long, length: Int): ByteArray {
22+
actual suspend fun read(
23+
path: String,
24+
offset: Long,
25+
length: Int,
26+
): ByteArray {
2027
val file = File(path)
2128
if (!file.exists()) return ByteArray(0)
2229
RandomAccessFile(file, "r").use { raf ->
@@ -31,20 +38,22 @@ actual class PlatformFileStorage {
3138
File(path).delete()
3239
}
3340

34-
actual suspend fun exists(path: String): Boolean {
35-
return File(path).exists()
36-
}
41+
actual suspend fun exists(path: String): Boolean = File(path).exists()
3742

38-
actual suspend fun size(path: String): Long {
39-
return File(path).length()
40-
}
43+
actual suspend fun size(path: String): Long = File(path).length()
4144

42-
actual suspend fun createTempFile(prefix: String, suffix: String): String {
45+
actual suspend fun createTempFile(
46+
prefix: String,
47+
suffix: String,
48+
): String {
4349
val temp = File.createTempFile(prefix, suffix)
4450
return temp.absolutePath
4551
}
4652

47-
actual suspend fun mergeFiles(sourcePaths: List<String>, destPath: String) {
53+
actual suspend fun mergeFiles(
54+
sourcePaths: List<String>,
55+
destPath: String,
56+
) {
4857
val destFile = File(destPath)
4958
destFile.parentFile?.mkdirs()
5059
destFile.outputStream().use { output ->

kdownloader-core/src/androidMain/kotlin/com/roxybasicneedbot/kdownloader/core/util/HashVerifier.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
/* ktlint-disable */
21
package com.roxybasicneedbot.kdownloader.core.util
32

43
import java.io.File
54
import java.security.MessageDigest
65

76
actual object HashVerifier {
8-
actual suspend fun verify(filePath: String, expectedHash: String, algorithm: String): Boolean {
9-
return try {
7+
actual suspend fun verify(
8+
filePath: String,
9+
expectedHash: String,
10+
algorithm: String,
11+
): Boolean =
12+
try {
1013
val file = File(filePath)
1114
if (!file.exists()) return false
1215
val digest = MessageDigest.getInstance(algorithm)
@@ -24,5 +27,4 @@ actual object HashVerifier {
2427
} catch (e: Exception) {
2528
false
2629
}
27-
}
2830
}

0 commit comments

Comments
 (0)