Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ class KeyboardListFragment : Fragment(R.layout.fragment_keyboard_list) {

override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
return when (menuItem.itemId) {
R.id.action_select_keyboard_layouts -> {
findNavController().navigate(R.id.action_select_keyboard_layouts)
true
}

R.id.action_export_layouts -> {
launchExportPicker()
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ object SettingSearchIndex {
private const val SINGLE_CHARACTER_RESULT_LIMIT = 20
private const val MULTI_CHARACTER_RESULT_LIMIT = 50
private val extraKeywordsByKey = mapOf(
"keyboard_selection_preference" to listOf(
"choose",
"select",
"apply",
"layout",
"keyboard layout",
"キーボードを選ぶ",
"キーボードを適用",
"レイアウト",
"レイアウトを選ぶ",
"選択",
"適用",
),
"shortcut_toolbar_size_setting_fragment_preference" to listOf(
"shortcut",
"toolbar",
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/res/menu/keyboard_list_menu.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
android:id="@+id/action_select_keyboard_layouts"
android:icon="@drawable/keyboard_24px"
android:title="@string/keyboard_selection_preference_title"
app:showAsAction="ifRoom" />

<item
android:id="@+id/action_export_layouts"
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/navigation/mobile_navigation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@
android:id="@+id/keyboardListFragment"
android:name="com.kazumaproject.markdownhelperkeyboard.custom_keyboard.ui.KeyboardListFragment"
android:label="@string/custom_layout_fragment_title">
<action
android:id="@+id/action_select_keyboard_layouts"
app:destination="@id/keyboardSelectionFragment" />
<action
android:id="@+id/action_keyboardListFragment_to_keyboardEditorFragment"
app:destination="@id/keyboardEditorFragment" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package com.kazumaproject.markdownhelperkeyboard.setting_activity.ui.setting

import android.content.Context
import android.view.MenuItem
import androidx.test.core.app.ApplicationProvider
import com.kazumaproject.markdownhelperkeyboard.R
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import org.xmlpull.v1.XmlPullParser

@RunWith(RobolectricTestRunner::class)
@Config(sdk = [35])
class KeyboardSelectionEntryPointTest {

private val context: Context = ApplicationProvider.getApplicationContext()

@Test
fun keyboardSelectionCanBeFoundByCommonAliasesInNewAndLegacySearch() {
val aliases = listOf(
"choose layout",
"select keyboard layout",
"キーボードを適用",
"レイアウトを選ぶ",
)

SettingSearchScope.entries.forEach { scope ->
val destinations = SettingSearchIndex.searchable(context, scope)

aliases.forEach { alias ->
val resultKeys = SettingSearchIndex.search(context, destinations, alias)
.map { it.key }

assertTrue(
"Missing keyboard selection for '$alias' in $scope",
"keyboard_selection_preference" in resultKeys,
)
}
}
}

@Test
fun customKeyboardHeaderLinksToKeyboardSelectionWithAnIfRoomAction() {
val actionId = context.resources.getIdentifier(
"action_select_keyboard_layouts",
"id",
context.packageName,
)
assertTrue("Missing custom-keyboard header action", actionId != 0)

val menuItem = xmlElements(R.menu.keyboard_list_menu, "item")
.firstOrNull { it.androidId == actionId }
?: error("Missing action_select_keyboard_layouts from keyboard_list_menu")

assertEquals(R.string.keyboard_selection_preference_title, menuItem.androidTitle)
assertEquals(
context.resources.getIdentifier("keyboard_24px", "drawable", context.packageName),
menuItem.androidIcon,
)
assertEquals(MenuItem.SHOW_AS_ACTION_IF_ROOM, menuItem.showAsAction)

val navAction = xmlElements(R.navigation.mobile_navigation, "action")
.firstOrNull { it.androidId == actionId }
?: error("Missing action_select_keyboard_layouts from mobile_navigation")

assertEquals(R.id.keyboardSelectionFragment, navAction.destination)
}

private fun xmlElements(xmlRes: Int, tagName: String): List<XmlElement> {
val parser = context.resources.getXml(xmlRes)
return parser.use {
buildList {
while (parser.eventType != XmlPullParser.END_DOCUMENT) {
if (parser.eventType == XmlPullParser.START_TAG && parser.name == tagName) {
add(
XmlElement(
androidId = parser.getAttributeResourceValue(ANDROID_NS, "id", 0),
androidTitle = parser.getAttributeResourceValue(ANDROID_NS, "title", 0),
androidIcon = parser.getAttributeResourceValue(ANDROID_NS, "icon", 0),
showAsAction = parser.getAttributeIntValue(APP_NS, "showAsAction", 0),
destination = parser.getAttributeResourceValue(APP_NS, "destination", 0),
)
)
}
parser.next()
}
}
}
}

private data class XmlElement(
val androidId: Int,
val androidTitle: Int,
val androidIcon: Int,
val showAsAction: Int,
val destination: Int,
)

private companion object {
private const val ANDROID_NS = "http://schemas.android.com/apk/res/android"
private const val APP_NS = "http://schemas.android.com/apk/res-auto"
}
}
Loading