Skip to content

Commit

Permalink
refactor: fix compile error due to dependency update
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiredPlanck committed Dec 12, 2023
1 parent 6157d6a commit 774bffd
Showing 1 changed file with 3 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,41 +1,27 @@
package com.osfans.trime.ime.lifecycle

import android.inputmethodservice.InputMethodService
import android.view.View
import androidx.annotation.CallSuper
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LifecycleRegistry
import androidx.lifecycle.ViewTreeLifecycleOwner
import androidx.lifecycle.coroutineScope
import kotlinx.coroutines.CoroutineScope
import androidx.lifecycle.setViewTreeLifecycleOwner

open class LifecycleInputMethodService :
InputMethodService(),
LifecycleOwner {
private val lifecycleRegistry by lazy { LifecycleRegistry(this) }

val uiScope: CoroutineScope
get() = lifecycle.coroutineScope

final override fun getLifecycle(): Lifecycle {
return lifecycleRegistry
}
override val lifecycle = lifecycleRegistry

@CallSuper
override fun onCreate() {
super.onCreate()
window.window!!.decorView.setViewTreeLifecycleOwner(this)
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE)
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START)
}

@CallSuper
override fun onCreateInputView(): View? {
val decorView = window!!.window!!.decorView
ViewTreeLifecycleOwner.set(decorView, this)
return null
}

@CallSuper
override fun onDestroy() {
super.onDestroy()
Expand Down

0 comments on commit 774bffd

Please sign in to comment.