diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/notetype/ManageNotetypes.kt b/AnkiDroid/src/main/java/com/ichi2/anki/notetype/ManageNotetypes.kt index 0f8506e0e090..af6d537f9feb 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/notetype/ManageNotetypes.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/notetype/ManageNotetypes.kt @@ -16,8 +16,11 @@ package com.ichi2.anki.notetype import android.annotation.SuppressLint +import android.app.SearchManager +import android.content.Context import android.content.Intent import android.os.Bundle +import android.view.Menu import android.view.View import android.widget.AdapterView import android.widget.ArrayAdapter @@ -27,6 +30,7 @@ import androidx.activity.result.ActivityResult import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.ActionBar import androidx.appcompat.app.AlertDialog +import androidx.appcompat.widget.SearchView import androidx.core.widget.addTextChangedListener import androidx.recyclerview.widget.RecyclerView import anki.notetypes.StockNotetype @@ -51,6 +55,9 @@ import com.ichi2.utils.* class ManageNotetypes : AnkiActivity() { private lateinit var actionBar: ActionBar private lateinit var noteTypesList: RecyclerView + + private var currentNotetypes: List = emptyList() + private val notetypesAdapter: NotetypesAdapter by lazy { NotetypesAdapter( this@ManageNotetypes, @@ -78,6 +85,7 @@ class ManageNotetypes : AnkiActivity() { if (showedActivityFailedScreen(savedInstanceState)) { return } + super.onCreate(savedInstanceState) setTitle(R.string.model_browser_label) setContentView(R.layout.activity_manage_note_types) @@ -91,6 +99,35 @@ class ManageNotetypes : AnkiActivity() { launchCatchingTask { runAndRefreshAfter() } // shows the initial note types list } + override fun onCreateOptionsMenu(menu: Menu): Boolean { + menuInflater.inflate(R.menu.locale_dialog_search_bar, menu) + + val searchItem = menu.findItem(R.id.locale_dialog_action_search) + val searchManager = getSystemService(Context.SEARCH_SERVICE) as SearchManager + val searchView = searchItem?.actionView as? SearchView + searchView?.maxWidth = Integer.MAX_VALUE + searchView?.setSearchableInfo(searchManager.getSearchableInfo(componentName)) + + searchView?.setOnQueryTextListener(object : SearchView.OnQueryTextListener { + override fun onQueryTextSubmit(query: String): Boolean { + return true + } + + override fun onQueryTextChange(newText: String?): Boolean { + val filteredList = if (newText.isNullOrEmpty()) { + currentNotetypes + } else { + currentNotetypes.filter { + it.name.lowercase().contains(newText.lowercase()) + } + } + notetypesAdapter.submitList(filteredList) + return true + } + }) + return true + } + @SuppressLint("CheckResult") private fun renameNotetype(noteTypeUiModel: NoteTypeUiModel) { launchCatchingTask { @@ -274,6 +311,9 @@ class ManageNotetypes : AnkiActivity() { getNotetypeNameIdUseCount().map { it.toUiModel() } } } + + currentNotetypes = updatedNotetypes + notetypesAdapter.submitList(updatedNotetypes) actionBar.subtitle = resources.getQuantityString( R.plurals.model_browser_types_available, diff --git a/AnkiDroid/src/main/res/layout/activity_manage_note_types.xml b/AnkiDroid/src/main/res/layout/activity_manage_note_types.xml index 051946b998d3..d9c0356b5b19 100644 --- a/AnkiDroid/src/main/res/layout/activity_manage_note_types.xml +++ b/AnkiDroid/src/main/res/layout/activity_manage_note_types.xml @@ -14,16 +14,19 @@ + + diff --git a/AnkiDroid/src/main/res/values/02-strings.xml b/AnkiDroid/src/main/res/values/02-strings.xml index 3b49d3843b79..afdbd407821d 100644 --- a/AnkiDroid/src/main/res/values/02-strings.xml +++ b/AnkiDroid/src/main/res/values/02-strings.xml @@ -340,6 +340,7 @@ Failed to access collection. Please try again! + Add a new note type Study less