Skip to content

Commit e236272

Browse files
committed
chore: format code with ktlint 1.0.1
1 parent e66cd6f commit e236272

Some content is hidden

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

73 files changed

+2372
-1660
lines changed

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

+42-27
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ class TrimeApplication : Application() {
2424
private var instance: TrimeApplication? = null
2525
private var lastPid: Int? = null
2626

27-
fun getInstance() =
28-
instance ?: throw IllegalStateException("Trime application is not created!")
27+
fun getInstance() = instance ?: throw IllegalStateException("Trime application is not created!")
2928

3029
fun getLastPid() = lastPid
30+
3131
private const val MAX_STACKTRACE_SIZE = 128000
3232
}
3333

@@ -40,13 +40,14 @@ class TrimeApplication : Application() {
4040
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
4141
putExtra(LogActivity.FROM_CRASH, true)
4242
// avoid transaction overflow
43-
val truncated = e.stackTraceToString().let {
44-
if (it.length > MAX_STACKTRACE_SIZE) {
45-
it.take(MAX_STACKTRACE_SIZE) + "<truncated>"
46-
} else {
47-
it
43+
val truncated =
44+
e.stackTraceToString().let {
45+
if (it.length > MAX_STACKTRACE_SIZE) {
46+
it.take(MAX_STACKTRACE_SIZE) + "<truncated>"
47+
} else {
48+
it
49+
}
4850
}
49-
}
5051
putExtra(LogActivity.CRASH_STACK_TRACE, truncated)
5152
},
5253
)
@@ -60,27 +61,41 @@ class TrimeApplication : Application() {
6061
initDefaultPreferences()
6162
}
6263
if (BuildConfig.DEBUG) {
63-
Timber.plant(object : Timber.DebugTree() {
64-
override fun createStackElementTag(element: StackTraceElement): String {
65-
return "${super.createStackElementTag(element)}|${element.fileName}:${element.lineNumber}"
66-
}
64+
Timber.plant(
65+
object : Timber.DebugTree() {
66+
override fun createStackElementTag(element: StackTraceElement): String {
67+
return "${super.createStackElementTag(element)}|${element.fileName}:${element.lineNumber}"
68+
}
6769

68-
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
69-
super.log(
70-
priority,
71-
"[${Thread.currentThread().name}] ${tag?.substringBefore('|')}",
72-
"${tag?.substringAfter('|')}] $message",
73-
t,
74-
)
75-
}
76-
})
70+
override fun log(
71+
priority: Int,
72+
tag: String?,
73+
message: String,
74+
t: Throwable?,
75+
) {
76+
super.log(
77+
priority,
78+
"[${Thread.currentThread().name}] ${tag?.substringBefore('|')}",
79+
"${tag?.substringAfter('|')}] $message",
80+
t,
81+
)
82+
}
83+
},
84+
)
7785
} else {
78-
Timber.plant(object : Timber.Tree() {
79-
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
80-
if (priority < Log.INFO) return
81-
Log.println(priority, "[${Thread.currentThread().name}]", message)
82-
}
83-
})
86+
Timber.plant(
87+
object : Timber.Tree() {
88+
override fun log(
89+
priority: Int,
90+
tag: String?,
91+
message: String,
92+
t: Throwable?,
93+
) {
94+
if (priority < Log.INFO) return
95+
Log.println(priority, "[${Thread.currentThread().name}]", message)
96+
}
97+
},
98+
)
8499
}
85100
// record last pid for crash logs
86101
val appPrefs = AppPrefs.defaultInstance()

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

+27-11
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ class Rime(fullCheck: Boolean) {
5151
private var mContext: RimeContext? = null
5252
private var mStatus: RimeStatus? = null
5353
private var isHandlingRimeNotification = false
54-
private val notificationFlow_ = MutableSharedFlow<RimeNotification>(
55-
extraBufferCapacity = 15,
56-
onBufferOverflow = BufferOverflow.DROP_OLDEST,
57-
)
54+
private val notificationFlow_ =
55+
MutableSharedFlow<RimeNotification>(
56+
extraBufferCapacity = 15,
57+
onBufferOverflow = BufferOverflow.DROP_OLDEST,
58+
)
5859

5960
init {
6061
System.loadLibrary("rime_jni")
@@ -175,13 +176,16 @@ class Rime(fullCheck: Boolean) {
175176

176177
@JvmStatic
177178
fun isVoidKeycode(keycode: Int): Boolean {
178-
val XK_VoidSymbol = 0xffffff
179-
return keycode <= 0 || keycode == XK_VoidSymbol
179+
val voidSymbol = 0xffffff
180+
return keycode <= 0 || keycode == voidSymbol
180181
}
181182

182183
// KeyProcess 调用JNI方法发送keycode和mask
183184
@JvmStatic
184-
fun processKey(keycode: Int, mask: Int): Boolean {
185+
fun processKey(
186+
keycode: Int,
187+
mask: Int,
188+
): Boolean {
185189
if (isVoidKeycode(keycode)) return false
186190
Timber.d("processKey: keyCode=$keycode, mask=$mask")
187191
return processRimeKey(keycode, mask).also {
@@ -250,7 +254,10 @@ class Rime(fullCheck: Boolean) {
250254
}
251255

252256
@JvmStatic
253-
fun setOption(option: String, value: Boolean) {
257+
fun setOption(
258+
option: String,
259+
value: Boolean,
260+
) {
254261
if (isHandlingRimeNotification) return
255262
setRimeOption(option, value)
256263
}
@@ -306,7 +313,10 @@ class Rime(fullCheck: Boolean) {
306313

307314
// input
308315
@JvmStatic
309-
external fun processRimeKey(keycode: Int, mask: Int): Boolean
316+
external fun processRimeKey(
317+
keycode: Int,
318+
mask: Int,
319+
): Boolean
310320

311321
@JvmStatic
312322
external fun commitRimeComposition(): Boolean
@@ -326,7 +336,10 @@ class Rime(fullCheck: Boolean) {
326336

327337
// runtime options
328338
@JvmStatic
329-
external fun setRimeOption(option: String, value: Boolean)
339+
external fun setRimeOption(
340+
option: String,
341+
value: Boolean,
342+
)
330343

331344
@JvmStatic
332345
external fun getRimeOption(option: String): Boolean
@@ -407,7 +420,10 @@ class Rime(fullCheck: Boolean) {
407420
external fun selectRimeSchemas(schemaIds: Array<String>): Boolean
408421

409422
@JvmStatic
410-
external fun getRimeStateLabel(optionName: String, state: Boolean): String?
423+
external fun getRimeStateLabel(
424+
optionName: String,
425+
state: Boolean,
426+
): String?
411427

412428
/** call from rime_jni */
413429
@JvmStatic

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

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.osfans.trime.core
22

33
sealed class RimeNotification {
4-
54
abstract val messageType: MessageType
65

76
data class SchemaNotification(val messageValue: String) :
@@ -51,12 +50,14 @@ sealed class RimeNotification {
5150

5251
companion object RimeNotificationHandler {
5352
@JvmStatic
54-
fun create(type: String, value: String) =
55-
when (type) {
56-
"schema" -> SchemaNotification(value)
57-
"option" -> OptionNotification(value)
58-
"deploy" -> DeployNotification(value)
59-
else -> UnknownNotification(value)
60-
}
53+
fun create(
54+
type: String,
55+
value: String,
56+
) = when (type) {
57+
"schema" -> SchemaNotification(value)
58+
"option" -> OptionNotification(value)
59+
"deploy" -> DeployNotification(value)
60+
else -> UnknownNotification(value)
61+
}
6162
}
6263
}

app/src/main/java/com/osfans/trime/data/AppPrefs.kt

+14-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ class AppPrefs(
3131
* The type is automatically derived from the given [default] value.
3232
* @return The value for [key] or [default].
3333
*/
34-
private inline fun <reified T> getPref(key: String, default: T): T {
34+
private inline fun <reified T> getPref(
35+
key: String,
36+
default: T,
37+
): T {
3538
return when {
3639
false is T -> {
3740
shared.getBoolean(key, default as Boolean) as T
@@ -53,7 +56,10 @@ class AppPrefs(
5356
* Sets the [value] for [key] in the shared preferences, puts the value into the corresponding
5457
* cache and returns it.
5558
*/
56-
private inline fun <reified T> setPref(key: String, value: T) {
59+
private inline fun <reified T> setPref(
60+
key: String,
61+
value: T,
62+
) {
5763
when {
5864
false is T -> {
5965
shared.edit().putBoolean(key, value as Boolean).apply()
@@ -114,6 +120,7 @@ class AppPrefs(
114120
const val PID = "general__pid"
115121
const val LAST_BUILD_GIT_HASH = "general__last_build_git_hash"
116122
}
123+
117124
var lastVersionName: String
118125
get() = prefs.getPref(LAST_VERSION_NAME, "")
119126
set(v) = prefs.setPref(LAST_VERSION_NAME, v)
@@ -173,6 +180,7 @@ class AppPrefs(
173180
const val DELETE_CANDIDATE_TIMEOUT = "keyboard__key_delete_candidate_timeout"
174181
const val SHOULD_LONG_CLICK_DELETE_CANDIDATE = "keyboard__long_click_delete_candidate"
175182
}
183+
176184
var inlinePreedit: InlineModeType
177185
get() = InlineModeType.fromString(prefs.getPref(INLINE_PREEDIT_MODE, "preview"))
178186
set(v) = prefs.setPref(INLINE_PREEDIT_MODE, v)
@@ -298,6 +306,7 @@ class AppPrefs(
298306
const val AUTO_DARK = "theme_auto_dark"
299307
const val USE_MINI_KEYBOARD = "theme_use_mini_keyboard"
300308
}
309+
301310
var selectedTheme: String
302311
get() = prefs.getPref(SELECTED_THEME, "trime")
303312
set(v) = prefs.setPref(SELECTED_THEME, v)
@@ -326,6 +335,7 @@ class AppPrefs(
326335
const val LAST_BACKGROUND_SYNC = "profile_last_background_sync"
327336
val EXTERNAL_PATH_PREFIX: String = PathUtils.getExternalStoragePath()
328337
}
338+
329339
var sharedDataDir: String
330340
get() = prefs.getPref(SHARED_DATA_DIR, "$EXTERNAL_PATH_PREFIX/rime")
331341
set(v) = prefs.setPref(SHARED_DATA_DIR, v)
@@ -358,6 +368,7 @@ class AppPrefs(
358368
const val DRAFT_LIMIT = "clipboard_draft_limit"
359369
const val CLIPBOARD_LIMIT = "clipboard_clipboard_limit"
360370
}
371+
361372
var clipboardCompareRules: List<String>
362373
get() = prefs.getPref(CLIPBOARD_COMPARE_RULES, "").trim().split('\n')
363374
set(v) = prefs.setPref(CLIPBOARD_COMPARE_RULES, v.joinToString("\n"))
@@ -388,6 +399,7 @@ class AppPrefs(
388399
const val SHOW_STATUS_BAR_ICON = "other__show_status_bar_icon"
389400
const val DESTROY_ON_QUIT = "other__destroy_on_quit"
390401
}
402+
391403
var uiMode: String
392404
get() = prefs.getPref(UI_MODE, "auto")
393405
set(v) = prefs.setPref(UI_MODE, v)

app/src/main/java/com/osfans/trime/data/DataDirectoryChangeListener.kt

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package com.osfans.trime.data
44
* Do something when data directory change.
55
*/
66
object DataDirectoryChangeListener {
7-
87
// listener list
98
val directoryChangeListeners = mutableListOf<DataDirectoryChangeListener.Listener>()
109

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

+16-9
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ object DataManager : DataDirectoryChangeListener.Listener {
2727

2828
sealed class Diff {
2929
object New : Diff()
30+
3031
object Update : Diff()
32+
3133
object Keep : Diff()
3234
}
3335

@@ -48,7 +50,10 @@ object DataManager : DataDirectoryChangeListener.Listener {
4850
return defaultPath.absolutePath
4951
}
5052

51-
private fun diff(old: String, new: String): Diff {
53+
private fun diff(
54+
old: String,
55+
new: String,
56+
): Diff {
5257
return when {
5358
old.isBlank() -> Diff.New
5459
!new.contentEquals(old) -> Diff.Update
@@ -64,14 +69,16 @@ object DataManager : DataDirectoryChangeListener.Listener {
6469
diff(oldHash, newHash).run {
6570
Timber.d("Diff: $this")
6671
when (this) {
67-
is Diff.New -> ResourceUtils.copyFileFromAssets(
68-
"rime",
69-
sharedDataDir.absolutePath,
70-
)
71-
is Diff.Update -> ResourceUtils.copyFileFromAssets(
72-
"rime",
73-
sharedDataDir.absolutePath,
74-
)
72+
is Diff.New ->
73+
ResourceUtils.copyFileFromAssets(
74+
"rime",
75+
sharedDataDir.absolutePath,
76+
)
77+
is Diff.Update ->
78+
ResourceUtils.copyFileFromAssets(
79+
"rime",
80+
sharedDataDir.absolutePath,
81+
)
7582
is Diff.Keep -> {}
7683
}
7784
}

app/src/main/java/com/osfans/trime/data/SymbolHistory.kt

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import com.osfans.trime.util.appContext
55
class SymbolHistory(
66
val capacity: Int,
77
) : LinkedHashMap<String, String>(0, .75f, true) {
8-
98
companion object {
109
const val FILE_NAME = "symbol_history"
1110
}
@@ -25,8 +24,7 @@ class SymbolHistory(
2524
file.writeText(values.joinToString("\n"))
2625
}
2726

28-
override fun removeEldestEntry(eldest: MutableMap.MutableEntry<String, String>?) =
29-
size > capacity
27+
override fun removeEldestEntry(eldest: MutableMap.MutableEntry<String, String>?) = size > capacity
3028

3129
fun insert(s: String) = put(s, s)
3230

0 commit comments

Comments
 (0)