Skip to content

Commit

Permalink
refactor: move LiquidKeyboard to InputView
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiredPlanck committed Feb 2, 2024
1 parent e56142d commit c3ffaea
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
5 changes: 5 additions & 0 deletions app/src/main/java/com/osfans/trime/ime/core/InputView.kt
Expand Up @@ -11,6 +11,7 @@ import androidx.core.view.updateLayoutParams
import com.osfans.trime.data.theme.Theme
import com.osfans.trime.ime.bar.QuickBar
import com.osfans.trime.ime.keyboard.KeyboardWindow
import com.osfans.trime.ime.symbol.LiquidKeyboard
import com.osfans.trime.util.styledFloat
import org.koin.core.context.loadKoinModules
import org.koin.core.context.unloadKoinModules
Expand Down Expand Up @@ -61,6 +62,7 @@ class InputView(
private val themedContext = context.withTheme(android.R.style.Theme_DeviceDefault_Settings)
val quickBar = QuickBar()
val keyboardWindow = KeyboardWindow()
val liquidKeyboard = LiquidKeyboard()

private val module =
module {
Expand All @@ -69,6 +71,7 @@ class InputView(
single { themedContext }
single { service }
single { keyboardWindow }
single { liquidKeyboard }
single { quickBar }
}

Expand Down Expand Up @@ -103,6 +106,8 @@ class InputView(
// MUST call before any other operations
loadKoinModules(module)

liquidKeyboard.setKeyboardView(keyboardWindow.oldSymbolInputView.liquidKeyboardView)

keyboardView =
constraintLayout {
isMotionEventSplittingEnabled = true
Expand Down
8 changes: 1 addition & 7 deletions app/src/main/java/com/osfans/trime/ime/core/Trime.kt
Expand Up @@ -61,7 +61,6 @@ import com.osfans.trime.ime.keyboard.KeyboardView
import com.osfans.trime.ime.keyboard.KeyboardWindow
import com.osfans.trime.ime.landscapeinput.LandscapeInputUIMode
import com.osfans.trime.ime.lifecycle.LifecycleInputMethodService
import com.osfans.trime.ime.symbol.LiquidKeyboard
import com.osfans.trime.ime.symbol.TabManager
import com.osfans.trime.ime.symbol.TabView
import com.osfans.trime.ime.text.Candidate
Expand All @@ -84,7 +83,6 @@ import java.util.Objects

@Suppress("ktlint:standard:property-naming")
open class Trime : LifecycleInputMethodService() {
private var liquidKeyboard: LiquidKeyboard? = null
private var normalTextEditor = false
private val prefs: AppPrefs
get() = AppPrefs.defaultInstance()
Expand Down Expand Up @@ -235,7 +233,6 @@ open class Trime : LifecycleInputMethodService() {
textInputManager = TextInputManager.getInstance()
activeEditorInstance = EditorInstance(context)
inputFeedbackManager = InputFeedbackManager(context)
liquidKeyboard = LiquidKeyboard(context)
mCompositionPopupWindow = CompositionPopupWindow()
restartSystemStartTimingSync()
try {
Expand Down Expand Up @@ -268,7 +265,7 @@ open class Trime : LifecycleInputMethodService() {
if (inputView == null) return
if (tabIndex >= 0) {
inputView!!.switchUiByState(KeyboardWindow.State.Symbol)
symbolKeyboardType = liquidKeyboard!!.select(tabIndex)
symbolKeyboardType = inputView!!.liquidKeyboard.select(tabIndex)
tabView!!.updateTabWidth()
mTabRoot!!.move(tabView!!.hightlightLeft, tabView!!.hightlightRight)
showLiquidKeyboardToolbar()
Expand Down Expand Up @@ -516,9 +513,6 @@ open class Trime : LifecycleInputMethodService() {
mCompositionPopupWindow!!.init(compositionRootBinding!!.compositionRoot, mCandidateRoot!!)
mTabRoot = inputView!!.quickBar.oldTabBar.root

liquidKeyboard!!.setKeyboardView(
inputView!!.keyboardWindow.oldSymbolInputView.liquidKeyboardView,
)
tabView = inputView!!.quickBar.oldTabBar.tabs
for (listener in eventListeners) {
listener.onInitializeInputUi(inputView!!)
Expand Down
25 changes: 13 additions & 12 deletions app/src/main/java/com/osfans/trime/ime/symbol/LiquidKeyboard.kt
Expand Up @@ -22,19 +22,22 @@ import com.osfans.trime.data.db.CollectionHelper
import com.osfans.trime.data.db.DatabaseBean
import com.osfans.trime.data.db.DraftHelper
import com.osfans.trime.data.theme.Theme
import com.osfans.trime.data.theme.ThemeManager
import com.osfans.trime.ime.core.Trime
import com.osfans.trime.ime.enums.KeyCommandType
import com.osfans.trime.ime.enums.SymbolKeyboardType
import com.osfans.trime.ime.text.TextInputManager
import com.osfans.trime.ui.main.LiquidKeyboardEditActivity
import com.osfans.trime.util.dp2px
import kotlinx.coroutines.launch
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import timber.log.Timber

class LiquidKeyboard(private val context: Context) : ClipboardHelper.OnClipboardUpdateListener {
private lateinit var theme: Theme
private val service: Trime = Trime.getService()
class LiquidKeyboard : KoinComponent, ClipboardHelper.OnClipboardUpdateListener {
private val context: Context by inject()
private val service: Trime by inject()
private val theme: Theme by inject()

private lateinit var keyboardView: RecyclerView
private val symbolHistory = SymbolHistory(180)
private var adapterType: AdapterType = AdapterType.INIT
Expand Down Expand Up @@ -69,14 +72,12 @@ class LiquidKeyboard(private val context: Context) : ClipboardHelper.OnClipboard
}

fun setKeyboardView(view: RecyclerView) {
keyboardView = view
keyboardView.apply {
val space = dp2px(3)
addItemDecoration(SpacesItemDecoration(space))
setPadding(space)
}
theme = ThemeManager.activeTheme
adapterType = AdapterType.INIT
keyboardView =
view.apply {
val space = dp2px(3)
addItemDecoration(SpacesItemDecoration(space))
setPadding(space)
}
}

// 及时更新layoutManager, 以防在旋转屏幕后打开液体键盘crash
Expand Down

0 comments on commit c3ffaea

Please sign in to comment.