add close history view toolbar button (#649)

This commit is contained in:
codokie 2024-04-06 19:11:28 +03:00 committed by GitHub
parent dcddcccf09
commit 38126d2840
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 33 additions and 3 deletions

View file

@ -69,7 +69,7 @@ class ClipboardHistoryView @JvmOverloads constructor(
// even when state is activated, the not activated color is set // even when state is activated, the not activated color is set
// in suggestionStripView the same thing works correctly, wtf? // in suggestionStripView the same thing works correctly, wtf?
// need to properly fix it (and maybe undo the inverted isActivated) when adding a toggle key // need to properly fix it (and maybe undo the inverted isActivated) when adding a toggle key
listOf(ToolbarKey.LEFT, ToolbarKey.RIGHT, ToolbarKey.COPY, ToolbarKey.CLEAR_CLIPBOARD, ToolbarKey.SELECT_WORD, ToolbarKey.SELECT_ALL) listOf(ToolbarKey.LEFT, ToolbarKey.RIGHT, ToolbarKey.COPY, ToolbarKey.CLEAR_CLIPBOARD, ToolbarKey.SELECT_WORD, ToolbarKey.SELECT_ALL, ToolbarKey.CLOSE_HISTORY)
.forEach { toolbarKeys.add(createToolbarKey(context, keyboardAttr, it)) } .forEach { toolbarKeys.add(createToolbarKey(context, keyboardAttr, it)) }
keyboardAttr.recycle() keyboardAttr.recycle()
} }

View file

@ -56,6 +56,7 @@ fun getCodeForToolbarKey(key: ToolbarKey) = when (key) {
FULL_RIGHT -> KeyCode.MOVE_END_OF_LINE FULL_RIGHT -> KeyCode.MOVE_END_OF_LINE
SELECT_WORD -> KeyCode.CLIPBOARD_SELECT_WORD SELECT_WORD -> KeyCode.CLIPBOARD_SELECT_WORD
CLEAR_CLIPBOARD -> null // not managed via code input CLEAR_CLIPBOARD -> null // not managed via code input
CLOSE_HISTORY -> KeyCode.ALPHA
} }
private fun getStyleableIconId(key: ToolbarKey) = when (key) { private fun getStyleableIconId(key: ToolbarKey) = when (key) {
@ -77,6 +78,7 @@ private fun getStyleableIconId(key: ToolbarKey) = when (key) {
FULL_LEFT -> R.styleable.Keyboard_iconFullLeft FULL_LEFT -> R.styleable.Keyboard_iconFullLeft
FULL_RIGHT -> R.styleable.Keyboard_iconFullRight FULL_RIGHT -> R.styleable.Keyboard_iconFullRight
SELECT_WORD -> R.styleable.Keyboard_iconSelectWord SELECT_WORD -> R.styleable.Keyboard_iconSelectWord
CLOSE_HISTORY -> R.styleable.Keyboard_iconCloseView
} }
fun getToolbarIconByName(name: String, context: Context): Drawable? { fun getToolbarIconByName(name: String, context: Context): Drawable? {
@ -91,12 +93,12 @@ fun getToolbarIconByName(name: String, context: Context): Drawable? {
// names need to be aligned with resources strings (using lowercase of key.name) // names need to be aligned with resources strings (using lowercase of key.name)
enum class ToolbarKey { enum class ToolbarKey {
VOICE, CLIPBOARD, UNDO, REDO, SETTINGS, SELECT_ALL, SELECT_WORD, COPY, ONE_HANDED, LEFT, RIGHT, UP, DOWN, VOICE, CLIPBOARD, UNDO, REDO, SETTINGS, SELECT_ALL, SELECT_WORD, COPY, ONE_HANDED, LEFT, RIGHT, UP, DOWN,
FULL_LEFT, FULL_RIGHT, INCOGNITO, AUTOCORRECT, CLEAR_CLIPBOARD FULL_LEFT, FULL_RIGHT, INCOGNITO, AUTOCORRECT, CLEAR_CLIPBOARD, CLOSE_HISTORY
} }
fun toToolbarKeyString(keys: Collection<ToolbarKey>) = keys.joinToString(";") { it.name } fun toToolbarKeyString(keys: Collection<ToolbarKey>) = keys.joinToString(";") { it.name }
val defaultToolbarPref = entries.filterNot { it == CLEAR_CLIPBOARD }.joinToString(";") { val defaultToolbarPref = entries.filterNot { it == CLEAR_CLIPBOARD || it == CLOSE_HISTORY }.joinToString(";") {
when (it) { when (it) {
INCOGNITO, AUTOCORRECT, UP, DOWN, ONE_HANDED, FULL_LEFT, FULL_RIGHT -> "${it.name},false" INCOGNITO, AUTOCORRECT, UP, DOWN, ONE_HANDED, FULL_LEFT, FULL_RIGHT -> "${it.name},false"
else -> "${it.name},true" else -> "${it.name},true"

View file

@ -0,0 +1,12 @@
<!--
icon available in Android Studio
SPDX-License-Identifier: Apache-2.0
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportHeight="24"
android:viewportWidth="24" >
<path android:fillColor="#FFF"
android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
</vector>

View file

@ -0,0 +1,12 @@
<!--
icon available in Android Studio
SPDX-License-Identifier: Apache-2.0
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportHeight="960"
android:viewportWidth="960" >
<path android:fillColor="#FFF"
android:pathData="m256,760 l-56,-56 224,-224 -224,-224 56,-56 224,224 224,-224 56,56 -224,224 224,224 -56,56 -224,-224 -224,224Z"/>
</vector>

View file

@ -278,6 +278,7 @@
<attr name="iconBin" format="reference" /> <attr name="iconBin" format="reference" />
<attr name="iconUndo" format="reference" /> <attr name="iconUndo" format="reference" />
<attr name="iconRedo" format="reference" /> <attr name="iconRedo" format="reference" />
<attr name="iconCloseView" format="reference" />
</declare-styleable> </declare-styleable>
<declare-styleable name="Keyboard_Key"> <declare-styleable name="Keyboard_Key">

View file

@ -47,5 +47,6 @@
<item name="iconFullLeft">@drawable/ic_to_start</item> <item name="iconFullLeft">@drawable/ic_to_start</item>
<item name="iconFullRight">@drawable/ic_to_end</item> <item name="iconFullRight">@drawable/ic_to_end</item>
<item name="iconSelectWord">@drawable/ic_select</item> <item name="iconSelectWord">@drawable/ic_select</item>
<item name="iconCloseView">@drawable/ic_close_view</item>
</style> </style>
</resources> </resources>

View file

@ -52,5 +52,6 @@
<item name="iconFullLeft">@drawable/ic_to_start</item> <item name="iconFullLeft">@drawable/ic_to_start</item>
<item name="iconFullRight">@drawable/ic_to_end</item> <item name="iconFullRight">@drawable/ic_to_end</item>
<item name="iconSelectWord">@drawable/ic_select</item> <item name="iconSelectWord">@drawable/ic_select</item>
<item name="iconCloseView">@drawable/ic_close_view</item>
</style> </style>
</resources> </resources>

View file

@ -51,5 +51,6 @@
<item name="iconFullLeft">@drawable/ic_to_start_rounded</item> <item name="iconFullLeft">@drawable/ic_to_start_rounded</item>
<item name="iconFullRight">@drawable/ic_to_end_rounded</item> <item name="iconFullRight">@drawable/ic_to_end_rounded</item>
<item name="iconSelectWord">@drawable/ic_select_rounded</item> <item name="iconSelectWord">@drawable/ic_select_rounded</item>
<item name="iconCloseView">@drawable/ic_close_view_rounded</item>
</style> </style>
</resources> </resources>