Skip to content

Commit

Permalink
Feature/add search bar to manage note types (#15789)
Browse files Browse the repository at this point in the history
* Add search functionality to ManageNotetypes section

This commit introduces a search bar to the ManageNotetypes section, enabling users to search for specific note types. The search bar enhances usability and improves the overall user experience.

* Add search functionality to ManageNotetypes section

This commit introduces a search bar to the ManageNotetypes section, enabling users to search for specific note types. The search bar enhances usability and improves the overall user experience.

* Add search functionality to ManageNotetypes section

This commit introduces a search bar to the ManageNotetypes section in the appbar, enabling users to search for specific note types. The search bar enhances usability and improves the overall user experience.

* Add search functionality to ManageNotetypes section

This commit introduces a search bar to the ManageNotetypes section in the appbar, enabling users to search for specific note types. The search bar enhances usability and improves the overall user experience.

* Update AnkiDroid/src/main/java/com/ichi2/anki/notetype/ManageNotetypes.kt

Co-authored-by: David Allison <[email protected]>

* Delete AnkiDroid/src/main/res/layout/manage_notes_type_toolbar.xml

* Delete AnkiDroid/src/main/res/menu/manage_notes_type_menu.xml

* Delete AnkiDroid/src/main/res/values/strings.xml

* Add search functionality to ManageNotetypes section

This commit introduces a search bar to the ManageNotetypes section in the appbar, enabling users to search for specific note types. The search bar enhances usability and improves the overall user experience.

*Additional Fixes have been made from previous commit such as The manage_notes_type_menu.xml & manage_notes_type_toolbar.xml is removed and standard toolbar and locale_dialog_action_search is used instead , The FirstRun  is been removed*

* Add search functionality to ManageNotetypes section

This commit introduces a search bar to the ManageNotetypes section in the appbar, enabling users to search for specific note types. The search bar enhances usability and improves the overall user experience.

*Additional Fixes have been made from previous commit such as The manage_notes_type_menu.xml & manage_notes_type_toolbar.xml is removed and standard toolbar and locale_dialog_action_search is used instead , The FirstRun  is been removed*

* Add search functionality to ManageNotetypes section

This commit introduces a search bar to the ManageNotetypes section in the appbar, enabling users to search for specific note types. The search bar enhances usability and improves the overall user experience.

*Additional Fixes have been made from previous commit such as The manage_notes_type_menu.xml & manage_notes_type_toolbar.xml is removed and standard toolbar and locale_dialog_action_search is used instead , The FirstRun  is been removed*

* Add search functionality to ManageNotetypes section

This commit introduces a search bar to the ManageNotetypes section in the appbar, enabling users to search for specific note types. The search bar enhances usability and improves the overall user experience.

*Additional Fixes have been made from previous commit such as The manage_notes_type_menu.xml & manage_notes_type_toolbar.xml is removed and standard toolbar and locale_dialog_action_search is used instead , The FirstRun  is been removed*

* *Additional Fixes have been made from previous commit such as background thread using Dispatcher.IO added  ,  null safety checks (?.) added , comments removed  *

* *Additional Fixes have been made from previous commit such as comments are been removed  *

* *Additional Fixes have been made from previous commit such as comments are been removed  *

* *Changes reverted   *

* *Changes reverted   *

* *Changes reverted as follows : toolbar.xml file reverted , additional space in 02-strings.xml removed , space added in NotetypeAdapter.kt *

* *Changes reverted as follows : space added between the methods , searchview?.maxWidth = Integer.MAX_VALUE added , the string name changed to cd_manage_notetypes_add**

* changes made

* error in unit test fixed

---------

Co-authored-by: David Allison <[email protected]>
  • Loading branch information
AffanShaikhsurab and david-allison authored Mar 28, 2024
1 parent bb0c4a8 commit 33ec7ae
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
40 changes: 40 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/notetype/ManageNotetypes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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<NoteTypeUiModel> = emptyList()

private val notetypesAdapter: NotetypesAdapter by lazy {
NotetypesAdapter(
this@ManageNotetypes,
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion AnkiDroid/src/main/res/layout/activity_manage_note_types.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@

<include layout="@layout/toolbar" />

<!-- RecyclerView for displaying note types -->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/note_types_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:clipToPadding="false"
android:paddingBottom="104dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/item_manage_note_type" />
</LinearLayout>

<!-- Floating Action Button for adding new note types -->
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/note_type_add"
android:layout_width="wrap_content"
Expand All @@ -33,6 +36,7 @@
android:layout_marginEnd="32dp"
app:fabSize="normal"
app:srcCompat="@drawable/ic_add_white"
android:contentDescription="@string/cd_manage_notetypes_add"
app:backgroundTint="?attr/fab_normal"
tools:ignore="HardcodedText" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
1 change: 1 addition & 0 deletions AnkiDroid/src/main/res/values/02-strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@

<!-- Manage note types -->
<string name="field_editor_model_not_available">Failed to access collection. Please try again!</string>
<string name="cd_manage_notetypes_add">Add a new note type</string>

<!-- App Intro -->
<string name="intro_ankidroid_tagline_one">Study less</string>
Expand Down

0 comments on commit 33ec7ae

Please sign in to comment.