Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Retain Search Filter After Deleting or Renaming Note Type in ManageNotetypes #17103

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
30 changes: 21 additions & 9 deletions AnkiDroid/src/main/java/com/ichi2/anki/notetype/ManageNotetypes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class ManageNotetypes : AnkiActivity() {

private var currentNotetypes: List<ManageNoteTypeUiModel> = emptyList()

// Store search query
private var searchQuery: String = ""

private val notetypesAdapter: NotetypesAdapter by lazy {
NotetypesAdapter(
this@ManageNotetypes,
Expand Down Expand Up @@ -115,20 +118,29 @@ class ManageNotetypes : AnkiActivity() {
}

override fun onQueryTextChange(newText: String?): Boolean {
val filteredList = if (newText.isNullOrEmpty()) {
currentNotetypes
} else {
currentNotetypes.filter {
it.name.lowercase().contains(newText.lowercase())
}
}
notetypesAdapter.submitList(filteredList)
// Update the search query
searchQuery = newText.orEmpty()
filterNoteTypes(searchQuery)
return true
}
})
return true
}

/**
* Filters and updates the note types list based on the query
*/
private fun filterNoteTypes(query: String) {
val filteredList = if (query.isEmpty()) {
currentNotetypes
} else {
currentNotetypes.filter {
it.name.lowercase().contains(query.lowercase())
}
}
notetypesAdapter.submitList(filteredList)
}

@SuppressLint("CheckResult")
private fun renameNotetype(manageNoteTypeUiModel: ManageNoteTypeUiModel) {
launchCatchingTask {
Expand Down Expand Up @@ -215,7 +227,7 @@ class ManageNotetypes : AnkiActivity() {

currentNotetypes = updatedNotetypes

notetypesAdapter.submitList(updatedNotetypes)
filterNoteTypes(searchQuery)
actionBar.subtitle = resources.getQuantityString(
R.plurals.model_browser_types_available,
updatedNotetypes.size,
Expand Down