Skip to content

Commit

Permalink
build,refactor: drop koin dependency injection framework
Browse files Browse the repository at this point in the history
Currently we cannot utilize it correctly, and since it contributes to a batch of bugs, it may be better to drop it for now.
  • Loading branch information
WhiredPlanck committed Mar 4, 2024
1 parent 003f625 commit afe4dcf
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 60 deletions.
1 change: 0 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ dependencies {
implementation(libs.androidx.viewpager2)
implementation(libs.flexbox)
implementation(libs.kaml)
implementation(libs.koin.android)
implementation(libs.timber)
implementation(libs.utilcode)
implementation(libs.xxpermissions)
Expand Down
7 changes: 0 additions & 7 deletions app/src/main/java/com/osfans/trime/TrimeApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import com.osfans.trime.data.db.ClipboardHelper
import com.osfans.trime.data.db.CollectionHelper
import com.osfans.trime.data.db.DraftHelper
import com.osfans.trime.ui.main.LogActivity
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.core.context.startKoin
import timber.log.Timber
import kotlin.system.exitProcess

Expand Down Expand Up @@ -107,10 +104,6 @@ class TrimeApplication : Application() {
lastPid = this
Timber.d("Last pid is $lastPid. Set it to current pid: $currentPid")
}
startKoin {
androidLogger()
androidContext(this@TrimeApplication)
}
appPrefs.internal.pid = currentPid
ClipboardHelper.init(applicationContext)
CollectionHelper.init(applicationContext)
Expand Down
7 changes: 1 addition & 6 deletions app/src/main/java/com/osfans/trime/ime/bar/QuickBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,11 @@ import com.osfans.trime.databinding.CandidateBarBinding
import com.osfans.trime.databinding.TabBarBinding
import com.osfans.trime.ime.core.TrimeInputMethodService
import com.osfans.trime.ime.enums.SymbolKeyboardType
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import splitties.views.dsl.core.add
import splitties.views.dsl.core.lParams
import splitties.views.dsl.core.matchParent

class QuickBar : KoinComponent {
private val context: Context by inject()
private val service: TrimeInputMethodService by inject()

class QuickBar(context: Context, service: TrimeInputMethodService) {
val oldCandidateBar by lazy {
CandidateBarBinding.inflate(LayoutInflater.from(context)).apply {
with(root) {
Expand Down
36 changes: 4 additions & 32 deletions app/src/main/java/com/osfans/trime/ime/core/InputView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.app.Dialog
import android.content.res.Configuration
import android.graphics.Color
import android.os.Build
import android.view.ContextThemeWrapper
import android.view.View
import android.view.View.OnClickListener
import android.view.WindowManager
Expand All @@ -20,7 +19,6 @@ import androidx.lifecycle.lifecycleScope
import com.osfans.trime.core.Rime
import com.osfans.trime.core.RimeNotification
import com.osfans.trime.data.theme.ColorManager
import com.osfans.trime.data.theme.Theme
import com.osfans.trime.data.theme.ThemeManager
import com.osfans.trime.ime.bar.QuickBar
import com.osfans.trime.ime.keyboard.KeyboardWindow
Expand All @@ -29,11 +27,6 @@ import com.osfans.trime.util.ColorUtils
import com.osfans.trime.util.styledFloat
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import org.koin.core.context.loadKoinModules
import org.koin.core.context.unloadKoinModules
import org.koin.dsl.module
import splitties.dimensions.dp
import splitties.views.dsl.constraintlayout.above
import splitties.views.dsl.constraintlayout.below
Expand Down Expand Up @@ -62,7 +55,7 @@ import splitties.views.imageDrawable
class InputView(
val service: TrimeInputMethodService,
val rime: Rime,
) : ConstraintLayout(service), KoinComponent {
) : ConstraintLayout(service) {
private val theme get() = ThemeManager.activeTheme
private var shouldUpdateNavbarForeground = false
private var shouldUpdateNavbarBackground = false
Expand Down Expand Up @@ -91,26 +84,9 @@ class InputView(
private val notificationHandlerJob: Job

private val themedContext = context.withTheme(android.R.style.Theme_DeviceDefault_Settings)
val quickBar: QuickBar by inject()
val keyboardWindow: KeyboardWindow by inject()
val liquidKeyboard: LiquidKeyboard by inject()

private val module =
module {
// the basic dependencies for the components to be injected
// provided by InputView (including itself)
single<InputView> { this@InputView }
single<Theme> { theme }
single<ContextThemeWrapper> { themedContext }
single<TrimeInputMethodService> { service }
// the components need to be injected
// Note: these components can be injected into other components,
// but you must construct them there, otherwise Koin cannot
// inject them automatically.
single { KeyboardWindow() }
single { LiquidKeyboard() }
single { QuickBar() }
}
val quickBar = QuickBar(themedContext, service)
val keyboardWindow = KeyboardWindow(themedContext, service)
val liquidKeyboard = LiquidKeyboard(themedContext, service, theme)

private val keyboardSidePadding = theme.style.getInt("keyboard_padding")
private val keyboardSidePaddingLandscape = theme.style.getInt("keyboard_padding_land")
Expand Down Expand Up @@ -140,9 +116,6 @@ class InputView(
val keyboardView: View

init {
// MUST call before any other operations
loadKoinModules(module)

notificationHandlerJob =
service.lifecycleScope.launch {
rime.notificationFlow.collect {
Expand Down Expand Up @@ -360,7 +333,6 @@ class InputView(
// cancel the notification job and unload the Koin module,
// implies that InputView should not be attached again after detached.
notificationHandlerJob.cancel()
unloadKoinModules(module)
super.onDetachedFromWindow()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,11 @@ import com.osfans.trime.core.Rime
import com.osfans.trime.databinding.MainInputLayoutBinding
import com.osfans.trime.databinding.SymbolInputLayoutBinding
import com.osfans.trime.ime.core.TrimeInputMethodService
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import splitties.views.dsl.core.add
import splitties.views.dsl.core.lParams
import splitties.views.dsl.core.matchParent

class KeyboardWindow : KoinComponent {
private val context: Context by inject()
private val service: TrimeInputMethodService by inject()

class KeyboardWindow(context: Context, service: TrimeInputMethodService) {
val oldMainInputView by lazy {
MainInputLayoutBinding.inflate(LayoutInflater.from(context)).apply {
with(mainKeyboardView) {
Expand Down
12 changes: 5 additions & 7 deletions app/src/main/java/com/osfans/trime/ime/symbol/LiquidKeyboard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,14 @@ import com.osfans.trime.ime.enums.SymbolKeyboardType
import com.osfans.trime.ime.text.TextInputManager
import com.osfans.trime.ui.main.LiquidKeyboardEditActivity
import kotlinx.coroutines.launch
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import splitties.dimensions.dp
import timber.log.Timber

class LiquidKeyboard : KoinComponent, ClipboardHelper.OnClipboardUpdateListener {
private val context: Context by inject()
private val service: TrimeInputMethodService by inject()
private val theme: Theme by inject()

class LiquidKeyboard(
private val context: Context,
private val service: TrimeInputMethodService,
private val theme: Theme,
) : ClipboardHelper.OnClipboardUpdateListener {
private lateinit var keyboardView: RecyclerView
private val symbolHistory = SymbolHistory(180)
private var adapterType: AdapterType = AdapterType.INIT
Expand Down
1 change: 0 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ androidx-room-ktx = { module = "androidx.room:room-ktx", version.ref = "room" }
androidx-viewpager2 = { module = "androidx.viewpager2:viewpager2", version = "1.1.0-beta02" }
flexbox = { module = "com.google.android.flexbox:flexbox", version = "3.0.0" }
kaml = { module = "com.charleskorn.kaml:kaml", version = "0.56.0" }
koin-android = { module = "io.insert-koin:koin-android", version = "3.5.3" }
timber = { module = "com.jakewharton.timber:timber", version = "5.0.1" }
utilcode = { module = "com.blankj:utilcodex", version = "1.31.1" }
xxpermissions = { module = "com.github.getActivity:XXPermissions", version = "18.5" }
Expand Down

0 comments on commit afe4dcf

Please sign in to comment.