Skip to content

Commit 13787eb

Browse files
committed
chore: format with ktlint 1.3.1
1 parent ded5388 commit 13787eb

109 files changed

Lines changed: 1036 additions & 858 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/src/main/java/com/osfans/trime/TrimeApplication.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,8 @@ class TrimeApplication : Application() {
7272
if (BuildConfig.DEBUG) {
7373
Timber.plant(
7474
object : Timber.DebugTree() {
75-
override fun createStackElementTag(element: StackTraceElement): String {
76-
return "${super.createStackElementTag(element)}|${element.fileName}:${element.lineNumber}"
77-
}
75+
override fun createStackElementTag(element: StackTraceElement): String =
76+
"${super.createStackElementTag(element)}|${element.fileName}:${element.lineNumber}"
7877

7978
override fun log(
8079
priority: Int,

app/src/main/java/com/osfans/trime/core/Rime.kt

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ import kotlin.system.measureTimeMillis
2222
*
2323
* @see [librime](https://github.com/rime/librime)
2424
*/
25-
class Rime : RimeApi, RimeLifecycleOwner {
25+
class Rime :
26+
RimeApi,
27+
RimeLifecycleOwner {
2628
private val lifecycleImpl = RimeLifecycleImpl()
2729
override val lifecycle get() = lifecycleImpl
2830

@@ -236,19 +238,13 @@ class Rime : RimeApi, RimeLifecycleOwner {
236238
val currentSchemaName get() = mStatus?.schemaName ?: ""
237239

238240
@JvmStatic
239-
fun hasMenu(): Boolean {
240-
return !inputContext?.menu?.candidates.isNullOrEmpty()
241-
}
241+
fun hasMenu(): Boolean = !inputContext?.menu?.candidates.isNullOrEmpty()
242242

243243
@JvmStatic
244-
fun hasLeft(): Boolean {
245-
return hasMenu() && inputContext?.menu?.pageNumber != 0
246-
}
244+
fun hasLeft(): Boolean = hasMenu() && inputContext?.menu?.pageNumber != 0
247245

248246
@JvmStatic
249-
fun showAsciiPunch(): Boolean {
250-
return mStatus?.isAsciiPunch == true || mStatus?.isAsciiMode == true
251-
}
247+
fun showAsciiPunch(): Boolean = mStatus?.isAsciiPunch == true || mStatus?.isAsciiMode == true
252248

253249
@JvmStatic
254250
val composingText: String
@@ -297,9 +293,7 @@ class Rime : RimeApi, RimeLifecycleOwner {
297293
}
298294

299295
@JvmStatic
300-
fun getOption(option: String): Boolean {
301-
return getRimeOption(option)
302-
}
296+
fun getOption(option: String): Boolean = getRimeOption(option)
303297

304298
fun toggleOption(option: String) {
305299
setOption(option, !getOption(option))

app/src/main/java/com/osfans/trime/core/RimeDispatcher.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,19 @@ import kotlin.coroutines.CoroutineContext
2727
*
2828
* Adapted from [fcitx5-android/FcitxDispatcher.kt](https://github.com/fcitx5-android/fcitx5-android/blob/364afb44dcf0d9e3db3d43a21a32601b2190cbdf/app/src/main/java/org/fcitx/fcitx5/android/core/FcitxDispatcher.kt).
2929
*/
30-
class RimeDispatcher(private val looper: RimeLooper) : CoroutineDispatcher() {
30+
class RimeDispatcher(
31+
private val looper: RimeLooper,
32+
) : CoroutineDispatcher() {
3133
interface RimeLooper {
3234
fun nativeStartup(fullCheck: Boolean)
3335

3436
fun nativeFinalize()
3537
}
3638

37-
class WrappedRunnable(private val runnable: Runnable, private val name: String? = null) :
38-
Runnable by runnable {
39+
class WrappedRunnable(
40+
private val runnable: Runnable,
41+
private val name: String? = null,
42+
) : Runnable by runnable {
3943
private val time = System.currentTimeMillis()
4044
var started = false
4145
private set
@@ -59,9 +63,10 @@ class RimeDispatcher(private val looper: RimeLooper) : CoroutineDispatcher() {
5963
}
6064

6165
private val internalDispatcher =
62-
Executors.newSingleThreadExecutor {
63-
Thread(it, "rime-main")
64-
}.asCoroutineDispatcher()
66+
Executors
67+
.newSingleThreadExecutor {
68+
Thread(it, "rime-main")
69+
}.asCoroutineDispatcher()
6570

6671
private val internalScope = CoroutineScope(internalDispatcher)
6772

app/src/main/java/com/osfans/trime/core/RimeLifecycle.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,20 @@ class RimeLifecycleScope(
8686
suspend fun <T> RimeLifecycle.whenAtState(
8787
state: RimeLifecycle.State,
8888
block: suspend CoroutineScope.() -> T,
89-
): T {
90-
return if (currentStateFlow.value == state) {
89+
): T =
90+
if (currentStateFlow.value == state) {
9191
block(lifecycleScope)
9292
} else {
9393
StateDelegate(this, state).run(block)
9494
}
95-
}
9695

9796
suspend inline fun <T> RimeLifecycle.whenReady(noinline block: suspend CoroutineScope.() -> T) =
9897
whenAtState(RimeLifecycle.State.READY, block)
9998

100-
private class StateDelegate(val lifecycle: RimeLifecycle, val state: RimeLifecycle.State) {
99+
private class StateDelegate(
100+
val lifecycle: RimeLifecycle,
101+
val state: RimeLifecycle.State,
102+
) {
101103
private var job: Job? = null
102104

103105
init {

app/src/main/java/com/osfans/trime/core/RimeNotification.kt

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,46 @@
44

55
package com.osfans.trime.core
66

7-
sealed class RimeNotification<T>(open val value: T) {
7+
sealed class RimeNotification<T>(
8+
open val value: T,
9+
) {
810
abstract val messageType: MessageType
911

10-
data class SchemaNotification(override val value: SchemaItem) :
11-
RimeNotification<SchemaItem>(value) {
12+
data class SchemaNotification(
13+
override val value: SchemaItem,
14+
) : RimeNotification<SchemaItem>(value) {
1215
override val messageType: MessageType
1316
get() = MessageType.Schema
1417

1518
override fun toString() = "SchemaEvent(schemaId=${value.id}, schemaName=${value.name})"
1619
}
1720

18-
data class OptionNotification(override val value: Value) :
19-
RimeNotification<OptionNotification.Value>(value) {
21+
data class OptionNotification(
22+
override val value: Value,
23+
) : RimeNotification<OptionNotification.Value>(value) {
2024
override val messageType: MessageType
2125
get() = MessageType.Option
2226

23-
data class Value(val option: String, val value: Boolean)
27+
data class Value(
28+
val option: String,
29+
val value: Boolean,
30+
)
2431

2532
override fun toString() = "OptionNotification(option=${value.option}, value=${value.value})"
2633
}
2734

28-
data class DeployNotification(override val value: String) :
29-
RimeNotification<String>(value) {
35+
data class DeployNotification(
36+
override val value: String,
37+
) : RimeNotification<String>(value) {
3038
override val messageType: MessageType
3139
get() = MessageType.Deploy
3240

3341
override fun toString() = "DeployNotification(state=$value)"
3442
}
3543

36-
data class UnknownNotification(override val value: String) :
37-
RimeNotification<String>(value) {
44+
data class UnknownNotification(
45+
override val value: String,
46+
) : RimeNotification<String>(value) {
3847
override val messageType: MessageType
3948
get() = MessageType.Unknown
4049
}

app/src/main/java/com/osfans/trime/core/RimeProto.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@
55
package com.osfans.trime.core
66

77
class RimeProto {
8-
data class Commit(val text: String?)
8+
data class Commit(
9+
val text: String?,
10+
)
911

10-
data class Candidate(val text: String, val comment: String?, val label: String)
12+
data class Candidate(
13+
val text: String,
14+
val comment: String?,
15+
val label: String,
16+
)
1117

1218
data class Context(
1319
val composition: Composition,

app/src/main/java/com/osfans/trime/daemon/RimeDaemon.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,16 @@ object RimeDaemon {
128128
fun restartRime(fullCheck: Boolean = false) =
129129
lock.withLock {
130130
val id = restartId++
131-
NotificationCompat.Builder(appContext, CHANNEL_ID)
131+
NotificationCompat
132+
.Builder(appContext, CHANNEL_ID)
132133
.setSmallIcon(R.drawable.ic_baseline_sync_24)
133134
.setContentTitle(appContext.getString(R.string.rime_daemon))
134135
.setContentText(appContext.getString(R.string.restarting_rime))
135136
.setOngoing(true)
136137
.setProgress(100, 0, true)
137138
.setPriority(NotificationCompat.PRIORITY_HIGH)
138-
.build().let { notificationManager.notify(id, it) }
139+
.build()
140+
.let { notificationManager.notify(id, it) }
139141
realRime.finalize()
140142
realRime.startup(fullCheck)
141143
TrimeApplication.getInstance().coroutineScope.launch {

app/src/main/java/com/osfans/trime/data/base/DataDiff.kt

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,30 @@ sealed interface DataDiff {
99

1010
val ordinal: Int
1111

12-
data class CreateFile(override val path: String) : DataDiff {
12+
data class CreateFile(
13+
override val path: String,
14+
) : DataDiff {
1315
override val ordinal: Int
1416
get() = 3
1517
}
1618

17-
data class UpdateFile(override val path: String) : DataDiff {
19+
data class UpdateFile(
20+
override val path: String,
21+
) : DataDiff {
1822
override val ordinal: Int
1923
get() = 2
2024
}
2125

22-
data class DeleteDir(override val path: String) : DataDiff {
26+
data class DeleteDir(
27+
override val path: String,
28+
) : DataDiff {
2329
override val ordinal: Int
2430
get() = 1
2531
}
2632

27-
data class DeleteFile(override val path: String) : DataDiff {
33+
data class DeleteFile(
34+
override val path: String,
35+
) : DataDiff {
2836
override val ordinal: Int
2937
get() = 0
3038
}
@@ -35,21 +43,24 @@ sealed interface DataDiff {
3543
new: DataChecksums,
3644
): List<DataDiff> {
3745
if (old.sha256 == new.sha256) return emptyList()
38-
return new.files.mapNotNull { (path, sha256) ->
39-
when {
40-
path !in old.files && sha256.isNotBlank() -> CreateFile(path)
41-
old.files[path] != sha256 ->
42-
if (sha256.isNotBlank()) UpdateFile(path) else null
43-
else -> null
46+
return new.files
47+
.mapNotNull { (path, sha256) ->
48+
when {
49+
path !in old.files && sha256.isNotBlank() -> CreateFile(path)
50+
old.files[path] != sha256 ->
51+
if (sha256.isNotBlank()) UpdateFile(path) else null
52+
else -> null
53+
}
54+
}.toMutableList()
55+
.apply {
56+
addAll(
57+
old.files
58+
.filterKeys { it !in new.files }
59+
.map { (path, sha256) ->
60+
if (sha256.isNotBlank()) DeleteFile(path) else DeleteDir(path)
61+
},
62+
)
4463
}
45-
}.toMutableList().apply {
46-
addAll(
47-
old.files.filterKeys { it !in new.files }
48-
.map { (path, sha256) ->
49-
if (sha256.isNotBlank()) DeleteFile(path) else DeleteDir(path)
50-
},
51-
)
52-
}
5364
}
5465
}
5566
}

app/src/main/java/com/osfans/trime/data/base/DataManager.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ object DataManager {
2727

2828
private val json by lazy { Json }
2929

30-
private fun deserializeDataChecksums(raw: String): DataChecksums {
31-
return json.decodeFromString<DataChecksums>(raw)
32-
}
30+
private fun deserializeDataChecksums(raw: String): DataChecksums = json.decodeFromString<DataChecksums>(raw)
3331

3432
// If Android version supports direct boot, we put the hierarchy in device encrypted storage
3533
// instead of credential encrypted storage so that data can be accessed before user unlock
@@ -41,12 +39,11 @@ object DataManager {
4139
File(appContext.applicationInfo.dataDir)
4240
}
4341

44-
private fun AssetManager.dataChecksums(): DataChecksums {
45-
return open(DATA_CHECKSUMS_NAME)
42+
private fun AssetManager.dataChecksums(): DataChecksums =
43+
open(DATA_CHECKSUMS_NAME)
4644
.bufferedReader()
4745
.use { it.readText() }
4846
.let { deserializeDataChecksums(it) }
49-
}
5047

5148
private val prefs get() = AppPrefs.defaultInstance()
5249

app/src/main/java/com/osfans/trime/data/db/ClipboardHelper.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,16 @@ object ClipboardHelper :
6161

6262
private val limit get() = AppPrefs.defaultInstance().clipboard.clipboardLimit
6363
private val compare get() =
64-
AppPrefs.defaultInstance().clipboard.clipboardCompareRules
64+
AppPrefs
65+
.defaultInstance()
66+
.clipboard.clipboardCompareRules
6567
.split('\n')
6668
.map { Regex(it.trim()) }
6769
.toHashSet()
6870
private val output get() =
69-
AppPrefs.defaultInstance().clipboard.clipboardOutputRules
71+
AppPrefs
72+
.defaultInstance()
73+
.clipboard.clipboardOutputRules
7074
.split('\n')
7175
.map { Regex(it) }
7276
.toHashSet()
@@ -123,8 +127,7 @@ object ClipboardHelper :
123127
?.takeIf {
124128
it.text!!.isNotBlank() &&
125129
!it.text.matchesAny(output)
126-
}
127-
?.let { b ->
130+
}?.let { b ->
128131
if (b.text?.removeRegexSet(compare)?.isEmpty() == true) return
129132
Timber.d("Accept clipboard $b")
130133
launch {
@@ -160,8 +163,7 @@ object ClipboardHelper :
160163
} else {
161164
it
162165
}
163-
}
164-
.sortedBy { it.id }
166+
}.sortedBy { it.id }
165167
.subList(0, all.size - limit)
166168
clbDao.delete(outdated)
167169
}

0 commit comments

Comments
 (0)