Skip to content

Commit afe4dcf

Browse files
committed
build,refactor: drop koin dependency injection framework
Currently we cannot utilize it correctly, and since it contributes to a batch of bugs, it may be better to drop it for now.
1 parent 003f625 commit afe4dcf

File tree

7 files changed

+11
-60
lines changed

7 files changed

+11
-60
lines changed

app/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ dependencies {
126126
implementation(libs.androidx.viewpager2)
127127
implementation(libs.flexbox)
128128
implementation(libs.kaml)
129-
implementation(libs.koin.android)
130129
implementation(libs.timber)
131130
implementation(libs.utilcode)
132131
implementation(libs.xxpermissions)

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ import com.osfans.trime.data.db.ClipboardHelper
1010
import com.osfans.trime.data.db.CollectionHelper
1111
import com.osfans.trime.data.db.DraftHelper
1212
import com.osfans.trime.ui.main.LogActivity
13-
import org.koin.android.ext.koin.androidContext
14-
import org.koin.android.ext.koin.androidLogger
15-
import org.koin.core.context.startKoin
1613
import timber.log.Timber
1714
import kotlin.system.exitProcess
1815

@@ -107,10 +104,6 @@ class TrimeApplication : Application() {
107104
lastPid = this
108105
Timber.d("Last pid is $lastPid. Set it to current pid: $currentPid")
109106
}
110-
startKoin {
111-
androidLogger()
112-
androidContext(this@TrimeApplication)
113-
}
114107
appPrefs.internal.pid = currentPid
115108
ClipboardHelper.init(applicationContext)
116109
CollectionHelper.init(applicationContext)

app/src/main/java/com/osfans/trime/ime/bar/QuickBar.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,11 @@ import com.osfans.trime.databinding.CandidateBarBinding
1111
import com.osfans.trime.databinding.TabBarBinding
1212
import com.osfans.trime.ime.core.TrimeInputMethodService
1313
import com.osfans.trime.ime.enums.SymbolKeyboardType
14-
import org.koin.core.component.KoinComponent
15-
import org.koin.core.component.inject
1614
import splitties.views.dsl.core.add
1715
import splitties.views.dsl.core.lParams
1816
import splitties.views.dsl.core.matchParent
1917

20-
class QuickBar : KoinComponent {
21-
private val context: Context by inject()
22-
private val service: TrimeInputMethodService by inject()
23-
18+
class QuickBar(context: Context, service: TrimeInputMethodService) {
2419
val oldCandidateBar by lazy {
2520
CandidateBarBinding.inflate(LayoutInflater.from(context)).apply {
2621
with(root) {

app/src/main/java/com/osfans/trime/ime/core/InputView.kt

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import android.app.Dialog
55
import android.content.res.Configuration
66
import android.graphics.Color
77
import android.os.Build
8-
import android.view.ContextThemeWrapper
98
import android.view.View
109
import android.view.View.OnClickListener
1110
import android.view.WindowManager
@@ -20,7 +19,6 @@ import androidx.lifecycle.lifecycleScope
2019
import com.osfans.trime.core.Rime
2120
import com.osfans.trime.core.RimeNotification
2221
import com.osfans.trime.data.theme.ColorManager
23-
import com.osfans.trime.data.theme.Theme
2422
import com.osfans.trime.data.theme.ThemeManager
2523
import com.osfans.trime.ime.bar.QuickBar
2624
import com.osfans.trime.ime.keyboard.KeyboardWindow
@@ -29,11 +27,6 @@ import com.osfans.trime.util.ColorUtils
2927
import com.osfans.trime.util.styledFloat
3028
import kotlinx.coroutines.Job
3129
import kotlinx.coroutines.launch
32-
import org.koin.core.component.KoinComponent
33-
import org.koin.core.component.inject
34-
import org.koin.core.context.loadKoinModules
35-
import org.koin.core.context.unloadKoinModules
36-
import org.koin.dsl.module
3730
import splitties.dimensions.dp
3831
import splitties.views.dsl.constraintlayout.above
3932
import splitties.views.dsl.constraintlayout.below
@@ -62,7 +55,7 @@ import splitties.views.imageDrawable
6255
class InputView(
6356
val service: TrimeInputMethodService,
6457
val rime: Rime,
65-
) : ConstraintLayout(service), KoinComponent {
58+
) : ConstraintLayout(service) {
6659
private val theme get() = ThemeManager.activeTheme
6760
private var shouldUpdateNavbarForeground = false
6861
private var shouldUpdateNavbarBackground = false
@@ -91,26 +84,9 @@ class InputView(
9184
private val notificationHandlerJob: Job
9285

9386
private val themedContext = context.withTheme(android.R.style.Theme_DeviceDefault_Settings)
94-
val quickBar: QuickBar by inject()
95-
val keyboardWindow: KeyboardWindow by inject()
96-
val liquidKeyboard: LiquidKeyboard by inject()
97-
98-
private val module =
99-
module {
100-
// the basic dependencies for the components to be injected
101-
// provided by InputView (including itself)
102-
single<InputView> { this@InputView }
103-
single<Theme> { theme }
104-
single<ContextThemeWrapper> { themedContext }
105-
single<TrimeInputMethodService> { service }
106-
// the components need to be injected
107-
// Note: these components can be injected into other components,
108-
// but you must construct them there, otherwise Koin cannot
109-
// inject them automatically.
110-
single { KeyboardWindow() }
111-
single { LiquidKeyboard() }
112-
single { QuickBar() }
113-
}
87+
val quickBar = QuickBar(themedContext, service)
88+
val keyboardWindow = KeyboardWindow(themedContext, service)
89+
val liquidKeyboard = LiquidKeyboard(themedContext, service, theme)
11490

11591
private val keyboardSidePadding = theme.style.getInt("keyboard_padding")
11692
private val keyboardSidePaddingLandscape = theme.style.getInt("keyboard_padding_land")
@@ -140,9 +116,6 @@ class InputView(
140116
val keyboardView: View
141117

142118
init {
143-
// MUST call before any other operations
144-
loadKoinModules(module)
145-
146119
notificationHandlerJob =
147120
service.lifecycleScope.launch {
148121
rime.notificationFlow.collect {
@@ -360,7 +333,6 @@ class InputView(
360333
// cancel the notification job and unload the Koin module,
361334
// implies that InputView should not be attached again after detached.
362335
notificationHandlerJob.cancel()
363-
unloadKoinModules(module)
364336
super.onDetachedFromWindow()
365337
}
366338
}

app/src/main/java/com/osfans/trime/ime/keyboard/KeyboardWindow.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,11 @@ import com.osfans.trime.core.Rime
77
import com.osfans.trime.databinding.MainInputLayoutBinding
88
import com.osfans.trime.databinding.SymbolInputLayoutBinding
99
import com.osfans.trime.ime.core.TrimeInputMethodService
10-
import org.koin.core.component.KoinComponent
11-
import org.koin.core.component.inject
1210
import splitties.views.dsl.core.add
1311
import splitties.views.dsl.core.lParams
1412
import splitties.views.dsl.core.matchParent
1513

16-
class KeyboardWindow : KoinComponent {
17-
private val context: Context by inject()
18-
private val service: TrimeInputMethodService by inject()
19-
14+
class KeyboardWindow(context: Context, service: TrimeInputMethodService) {
2015
val oldMainInputView by lazy {
2116
MainInputLayoutBinding.inflate(LayoutInflater.from(context)).apply {
2217
with(mainKeyboardView) {

app/src/main/java/com/osfans/trime/ime/symbol/LiquidKeyboard.kt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,14 @@ import com.osfans.trime.ime.enums.SymbolKeyboardType
2828
import com.osfans.trime.ime.text.TextInputManager
2929
import com.osfans.trime.ui.main.LiquidKeyboardEditActivity
3030
import kotlinx.coroutines.launch
31-
import org.koin.core.component.KoinComponent
32-
import org.koin.core.component.inject
3331
import splitties.dimensions.dp
3432
import timber.log.Timber
3533

36-
class LiquidKeyboard : KoinComponent, ClipboardHelper.OnClipboardUpdateListener {
37-
private val context: Context by inject()
38-
private val service: TrimeInputMethodService by inject()
39-
private val theme: Theme by inject()
40-
34+
class LiquidKeyboard(
35+
private val context: Context,
36+
private val service: TrimeInputMethodService,
37+
private val theme: Theme,
38+
) : ClipboardHelper.OnClipboardUpdateListener {
4139
private lateinit var keyboardView: RecyclerView
4240
private val symbolHistory = SymbolHistory(180)
4341
private var adapterType: AdapterType = AdapterType.INIT

gradle/libs.versions.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ androidx-room-ktx = { module = "androidx.room:room-ktx", version.ref = "room" }
2727
androidx-viewpager2 = { module = "androidx.viewpager2:viewpager2", version = "1.1.0-beta02" }
2828
flexbox = { module = "com.google.android.flexbox:flexbox", version = "3.0.0" }
2929
kaml = { module = "com.charleskorn.kaml:kaml", version = "0.56.0" }
30-
koin-android = { module = "io.insert-koin:koin-android", version = "3.5.3" }
3130
timber = { module = "com.jakewharton.timber:timber", version = "5.0.1" }
3231
utilcode = { module = "com.blankj:utilcodex", version = "1.31.1" }
3332
xxpermissions = { module = "com.github.getActivity:XXPermissions", version = "18.5" }

0 commit comments

Comments
 (0)