mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-06-05 06:10:14 +00:00
small cleanup in ClipbardHistoryView
This commit is contained in:
parent
180bd179c5
commit
8284adb32c
1 changed files with 10 additions and 15 deletions
|
@ -30,7 +30,6 @@ import helium314.keyboard.latin.common.Constants
|
||||||
import helium314.keyboard.latin.settings.Settings
|
import helium314.keyboard.latin.settings.Settings
|
||||||
import helium314.keyboard.latin.utils.ResourceUtils
|
import helium314.keyboard.latin.utils.ResourceUtils
|
||||||
import helium314.keyboard.latin.utils.ToolbarKey
|
import helium314.keyboard.latin.utils.ToolbarKey
|
||||||
import helium314.keyboard.latin.utils.ToolbarMode
|
|
||||||
import helium314.keyboard.latin.utils.createToolbarKey
|
import helium314.keyboard.latin.utils.createToolbarKey
|
||||||
import helium314.keyboard.latin.utils.getCodeForToolbarKey
|
import helium314.keyboard.latin.utils.getCodeForToolbarKey
|
||||||
import helium314.keyboard.latin.utils.getCodeForToolbarKeyLongClick
|
import helium314.keyboard.latin.utils.getCodeForToolbarKeyLongClick
|
||||||
|
@ -50,15 +49,14 @@ class ClipboardHistoryView @JvmOverloads constructor(
|
||||||
private val clipboardLayoutParams = ClipboardLayoutParams(context)
|
private val clipboardLayoutParams = ClipboardLayoutParams(context)
|
||||||
private val pinIconId: Int
|
private val pinIconId: Int
|
||||||
private val keyBackgroundId: Int
|
private val keyBackgroundId: Int
|
||||||
private var initialized = false
|
|
||||||
|
|
||||||
private lateinit var clipboardRecyclerView: ClipboardHistoryRecyclerView
|
private lateinit var clipboardRecyclerView: ClipboardHistoryRecyclerView
|
||||||
private lateinit var placeholderView: TextView
|
private lateinit var placeholderView: TextView
|
||||||
private val toolbarKeys = mutableListOf<ImageButton>()
|
private val toolbarKeys = mutableListOf<ImageButton>()
|
||||||
private lateinit var clipboardAdapter: ClipboardAdapter
|
private lateinit var clipboardAdapter: ClipboardAdapter
|
||||||
|
|
||||||
var keyboardActionListener: KeyboardActionListener? = null
|
lateinit var keyboardActionListener: KeyboardActionListener
|
||||||
var clipboardHistoryManager: ClipboardHistoryManager? = null
|
private var clipboardHistoryManager: ClipboardHistoryManager? = null
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val clipboardViewAttr = context.obtainStyledAttributes(attrs,
|
val clipboardViewAttr = context.obtainStyledAttributes(attrs,
|
||||||
|
@ -68,12 +66,10 @@ class ClipboardHistoryView @JvmOverloads constructor(
|
||||||
val keyboardViewAttr = context.obtainStyledAttributes(attrs, R.styleable.KeyboardView, defStyle, R.style.KeyboardView)
|
val keyboardViewAttr = context.obtainStyledAttributes(attrs, R.styleable.KeyboardView, defStyle, R.style.KeyboardView)
|
||||||
keyBackgroundId = keyboardViewAttr.getResourceId(R.styleable.KeyboardView_keyBackground, 0)
|
keyBackgroundId = keyboardViewAttr.getResourceId(R.styleable.KeyboardView_keyBackground, 0)
|
||||||
keyboardViewAttr.recycle()
|
keyboardViewAttr.recycle()
|
||||||
val keyboardAttr = context.obtainStyledAttributes(attrs, R.styleable.Keyboard, defStyle, R.style.SuggestionStripView)
|
|
||||||
if (Settings.getValues().mSecondaryStripVisible) {
|
if (Settings.getValues().mSecondaryStripVisible) {
|
||||||
getEnabledClipboardToolbarKeys(context.prefs())
|
getEnabledClipboardToolbarKeys(context.prefs())
|
||||||
.forEach { toolbarKeys.add(createToolbarKey(context, KeyboardIconsSet.instance, it)) }
|
.forEach { toolbarKeys.add(createToolbarKey(context, KeyboardIconsSet.instance, it)) }
|
||||||
}
|
}
|
||||||
keyboardAttr.recycle()
|
|
||||||
fitsSystemWindows = true
|
fitsSystemWindows = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +84,7 @@ class ClipboardHistoryView @JvmOverloads constructor(
|
||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
private fun initialize() { // needs to be delayed for access to ClipboardStrip, which is not a child of this view
|
private fun initialize() { // needs to be delayed for access to ClipboardStrip, which is not a child of this view
|
||||||
if (initialized) return
|
if (this::clipboardAdapter.isInitialized) return
|
||||||
val colors = Settings.getValues().mColors
|
val colors = Settings.getValues().mColors
|
||||||
clipboardAdapter = ClipboardAdapter(clipboardLayoutParams, this).apply {
|
clipboardAdapter = ClipboardAdapter(clipboardLayoutParams, this).apply {
|
||||||
itemBackgroundId = keyBackgroundId
|
itemBackgroundId = keyBackgroundId
|
||||||
|
@ -111,7 +107,6 @@ class ClipboardHistoryView @JvmOverloads constructor(
|
||||||
colors.setColor(it, ColorType.TOOL_BAR_KEY)
|
colors.setColor(it, ColorType.TOOL_BAR_KEY)
|
||||||
colors.setBackground(it, ColorType.STRIP_BACKGROUND)
|
colors.setBackground(it, ColorType.STRIP_BACKGROUND)
|
||||||
}
|
}
|
||||||
initialized = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupClipKey(params: KeyDrawParams) {
|
private fun setupClipKey(params: KeyDrawParams) {
|
||||||
|
@ -192,7 +187,7 @@ class ClipboardHistoryView @JvmOverloads constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
fun stopClipboardHistory() {
|
fun stopClipboardHistory() {
|
||||||
if (!initialized) return
|
if (!this::clipboardAdapter.isInitialized) return
|
||||||
clipboardRecyclerView.adapter = null
|
clipboardRecyclerView.adapter = null
|
||||||
clipboardHistoryManager?.setHistoryChangeListener(null)
|
clipboardHistoryManager?.setHistoryChangeListener(null)
|
||||||
clipboardHistoryManager = null
|
clipboardHistoryManager = null
|
||||||
|
@ -204,7 +199,7 @@ class ClipboardHistoryView @JvmOverloads constructor(
|
||||||
if (tag is ToolbarKey) {
|
if (tag is ToolbarKey) {
|
||||||
val code = getCodeForToolbarKey(tag)
|
val code = getCodeForToolbarKey(tag)
|
||||||
if (code != KeyCode.UNSPECIFIED) {
|
if (code != KeyCode.UNSPECIFIED) {
|
||||||
keyboardActionListener?.onCodeInput(code, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, false)
|
keyboardActionListener.onCodeInput(code, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -215,7 +210,7 @@ class ClipboardHistoryView @JvmOverloads constructor(
|
||||||
if (tag is ToolbarKey) {
|
if (tag is ToolbarKey) {
|
||||||
val longClickCode = getCodeForToolbarKeyLongClick(tag)
|
val longClickCode = getCodeForToolbarKeyLongClick(tag)
|
||||||
if (longClickCode != KeyCode.UNSPECIFIED) {
|
if (longClickCode != KeyCode.UNSPECIFIED) {
|
||||||
keyboardActionListener?.onCodeInput(
|
keyboardActionListener.onCodeInput(
|
||||||
longClickCode,
|
longClickCode,
|
||||||
Constants.NOT_A_COORDINATE,
|
Constants.NOT_A_COORDINATE,
|
||||||
Constants.NOT_A_COORDINATE,
|
Constants.NOT_A_COORDINATE,
|
||||||
|
@ -228,15 +223,15 @@ class ClipboardHistoryView @JvmOverloads constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onKeyDown(clipId: Long) {
|
override fun onKeyDown(clipId: Long) {
|
||||||
keyboardActionListener?.onPressKey(KeyCode.NOT_SPECIFIED, 0, true)
|
keyboardActionListener.onPressKey(KeyCode.NOT_SPECIFIED, 0, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onKeyUp(clipId: Long) {
|
override fun onKeyUp(clipId: Long) {
|
||||||
val clipContent = clipboardHistoryManager?.getHistoryEntryContent(clipId)
|
val clipContent = clipboardHistoryManager?.getHistoryEntryContent(clipId)
|
||||||
keyboardActionListener?.onTextInput(clipContent?.content.toString())
|
keyboardActionListener.onTextInput(clipContent?.content.toString())
|
||||||
keyboardActionListener?.onReleaseKey(KeyCode.NOT_SPECIFIED, false)
|
keyboardActionListener.onReleaseKey(KeyCode.NOT_SPECIFIED, false)
|
||||||
if (Settings.getValues().mAlphaAfterClipHistoryEntry)
|
if (Settings.getValues().mAlphaAfterClipHistoryEntry)
|
||||||
keyboardActionListener?.onCodeInput(KeyCode.ALPHA, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, false)
|
keyboardActionListener.onCodeInput(KeyCode.ALPHA, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onClipboardHistoryEntryAdded(at: Int) {
|
override fun onClipboardHistoryEntryAdded(at: Int) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue