{"id":18995839,"url":"https://github.com/mars885/persistent-search-view","last_synced_at":"2025-04-08T00:36:25.132Z","repository":{"id":42180117,"uuid":"144021364","full_name":"mars885/persistent-search-view","owner":"mars885","description":"An Android library designed to simplify the process of implementing search-related functionality.","archived":false,"fork":false,"pushed_at":"2025-02-20T19:21:14.000Z","size":761,"stargazers_count":415,"open_issues_count":5,"forks_count":42,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-31T23:33:48.600Z","etag":null,"topics":["android","android-library","android-searchview","search","searchview"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mars885.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-08T13:57:40.000Z","updated_at":"2025-03-03T02:28:54.000Z","dependencies_parsed_at":"2025-03-17T21:45:34.051Z","dependency_job_id":null,"html_url":"https://github.com/mars885/persistent-search-view","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mars885%2Fpersistent-search-view","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mars885%2Fpersistent-search-view/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mars885%2Fpersistent-search-view/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mars885%2Fpersistent-search-view/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mars885","download_url":"https://codeload.github.com/mars885/persistent-search-view/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247755560,"owners_count":20990620,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","android-library","android-searchview","search","searchview"],"created_at":"2024-11-08T17:33:02.813Z","updated_at":"2025-04-08T00:36:25.108Z","avatar_url":"https://github.com/mars885.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PersistentSearchView\nAn android library designed to simplify the process of implementing search-related functionality.\n\n![](https://img.shields.io/badge/API-21%2B-orange.svg?style=flat)\n[![Platform](https://img.shields.io/badge/platform-Android-green.svg)](http://developer.android.com/index.html)\n[![Download](https://img.shields.io/maven-central/v/com.paulrybitskyi.persistentsearchview/persistentsearchview.svg?label=Download)](https://search.maven.org/search?q=com.paulrybitskyi.persistentsearchview)\n[![Build](https://github.com/mars885/persistent-search-view/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/mars885/persistent-search-view/actions)\n[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-PersistentSearchView-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/7102)\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n\n## Contents\n\n* [Demo](#demo-youtube)\n* [Getting Started](#getting-started)\n* [Basic Implementation](#basic-implementation)\n* [Basic Recent Suggestions Implementation](#basic-recent-suggestions-implementation)\n* [Basic Regular Suggestions Implementation](#basic-regular-suggestions-implementation)\n* [Advanced Use](#advanced-use)\n* [Difference between recent and regular suggestions](#difference-between-recent-and-regular-suggestions)\n* [Contribution](#contribution)\n* [Hall of Fame](#hall-of-fame)\n* [License](#license)\n\n## Demo (YouTube)\n\n\u003ca href=\"https://www.youtube.com/watch?v=t6AgY0hYJHU\"\u003e\n\u003cimg src=\"/media/video_thumbnail.jpg\" width=\"200\" height=\"356\"/\u003e\n\u003c/a\u003e\n\n## Getting Started\n\n1. Make sure that you've added the `mavenCentral()` repository to your top-level `build.gradle` file.\n\n````groovy\nbuildscript {\n    //...\n    repositories {\n        //...\n        mavenCentral()\n    }\n    //...\n}\n````\n\n2. Add the library dependency to your module-level `build.gradle` file. \n\n````groovy\ndependencies {\n    implementation \"com.paulrybitskyi.persistentsearchview:persistentsearchview:1.1.5\"\n}\n````\n\n3. If your `targetSdk` is **30** and you want to use the voice search feature, add these lines to your app's `AndroidManifest.xml`:\n\n````xml\n\u003cmanifest ...\u003e\n\n    //...\n    \u003cqueries\u003e\n        \u003cintent\u003e\n            \u003caction android:name=\"android.speech.RecognitionService\"/\u003e\n        \u003c/intent\u003e\n    \u003c/queries\u003e\n    //...\n\n\u003c/manifest\u003e\n````\n4. Proceed with the implementation of your own search view.\n\n## Basic Implementation\n\nImplementation of a PersistentSearchView with basic functionality involves 2 main steps - declaring a widget inside the XML file of your choice and configuring it in one of the Java/Kotlin classes.\n\nLet's implement a PersistentSearchView with basic functionality by following the steps listed above:\n\n1. Declaring a widget inside the XML file.\n\n    \u003cdetails\u003e\u003csummary\u003e\u003cb\u003eXML (click to expand)\u003c/b\u003e\u003c/summary\u003e\n    \u003cp\u003e\n\n    ````xml\n    \u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n    \u003cRelativeLayout\n        xmlns:android=\"http://schemas.android.com/apk/res/android\"\n        xmlns:app=\"http://schemas.android.com/apk/res-auto\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"match_parent\"\u003e\n\n        \u003c!-- Other widgets here --\u003e\n\n        \u003ccom.paulrybitskyi.persistentsearchview.PersistentSearchView\n            android:id=\"@+id/persistentSearchView\"\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"wrap_content\"\n            android:paddingTop=\"4dp\"\n            android:paddingLeft=\"4dp\"\n            android:paddingStart=\"4dp\"\n            android:paddingRight=\"4dp\"\n            android:paddingEnd=\"4dp\"/\u003e\n\n    \u003c/RelativeLayout\u003e\n    ````\n    \u003c/p\u003e\u003c/details\u003e\n\n2. Configuring the widget in one of the Java/Kotlin classes.\n\n    \u003cdetails\u003e\u003csummary\u003e\u003cb\u003eKotlin (click to expand)\u003c/b\u003e\u003c/summary\u003e\n    \u003cp\u003e\n\n    ````kotlin\n    override fun onCreate(savedInstanceState: Bundle?) {\n        super.onCreate(savedInstanceState)\n        setContentView(R.layout.demo_activity_layout)\n\n        //...\n\n        with(persistentSearchView) {\n            setOnLeftBtnClickListener {\n                // Handle the left button click\n            }\n            setOnClearInputBtnClickListener {\n                // Handle the clear input button click\n            }\n\n            // Setting a delegate for the voice recognition input\n            setVoiceRecognitionDelegate(VoiceRecognitionDelegate(this@DemoActivity))\n\n            setOnSearchConfirmedListener { searchView, query -\u003e\n                // Handle a search confirmation. This is the place where you'd\n                // want to perform a search against your data provider.\n            }\n\n            // Disabling the suggestions since they are unused in\n            // the simple implementation\n            setSuggestionsDisabled(true)\n        }\n    }\n\n\n    //...\n\n\n    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {\n        super.onActivityResult(requestCode, resultCode, data)\n\n        // Calling the voice recognition delegate to properly handle voice input results\n        VoiceRecognitionDelegate.handleResult(persistentSearchView, requestCode, resultCode, data)\n    }\n    ````\n\n    \u003c/p\u003e\u003c/details\u003e\n\n    \u003cdetails\u003e\u003csummary\u003e\u003cb\u003eJava (click to expand)\u003c/b\u003e\u003c/summary\u003e\n    \u003cp\u003e\n\n    ````java\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.demo_activity_layout);\n\n        //...\n\n        persistentSearchView.setOnLeftBtnClickListener(new OnClickListener() {\n\n            @Override\n            public void onClick(View view) {\n                // Handle the left button click\n            }\n\n        });\n\n        persistentSearchView.setOnClearInputBtnClickListener(new OnClickListener() {\n\n            @Override\n            public void onClick(View view) {\n                // Handle the clear input button click\n            }\n\n        });\n\n        // Setting a delegate for the voice recognition input\n        persistentSearchView.setVoiceRecognitionDelegate(new VoiceRecognitionDelegate(this));\n\n        persistentSearchView.setOnSearchConfirmedListener(new OnSearchConfirmedListener() {\n\n            @Override\n            public void onSearchConfirmed(PersistentSearchView searchView, String query) {\n                // Handle a search confirmation. This is the place where you'd\n                // want to perform a search against your data provider.\n            }\n\n        });\n\n        // Disabling the suggestions since they are unused in\n        // the simple implementation\n        persistentSearchView.setSuggestionsDisabled();\n    }\n\n\n    //...\n\n\n    @Override\n    protected fun onActivityResult(int requestCode, int resultCode, Intent data) {\n        super.onActivityResult(requestCode, resultCode, data);\n\n        // Calling the voice recognition delegate to properly handle voice input results\n        VoiceRecognitionDelegate.handleResult(persistentSearchView, requestCode, resultCode, data);\n    }\n    ````\n\n    \u003c/p\u003e\u003c/details\u003e\n\n## Basic Recent Suggestions Implementation\n\nImplementation of a PersistentSearchView with recent suggestions is pretty much the same as [Basic Implementation](#basic-implementation) with one exception: the view configuration.\n\nIn this implementation you'll need to provide a bit more configuration for the widget in order to show recent suggestions to the user, such as providing implementation for a couple of listeners as well as fetching suggestions from your data provider and setting them to the search view.\n\nFor example, here is the configuration of the widget with recent suggestions functionality:\n\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eJava (click to expand)\u003c/b\u003e\u003c/summary\u003e\n\u003cp\u003e\n\n````java\n@Override\nprotected void onCreate(Bundle savedInstanceState) {\n    super.onCreate(savedInstanceState);\n    setContentView(R.layout.demo_activity_layout);\n\n    //...\n\n    persistentSearchView.setOnLeftBtnClickListener(new OnClickListener() {\n        \n        @Override\n        public void onClick(View view) {\n            // Handle the left button click\n        }\n\n    });\n\n    persistentSearchView.setOnClearInputBtnClickListener(new OnClickListener() {\n        \n        @Override\n        public void onClick(View view) {\n            // Handle the clear input button click\n        }\n\n    });\n\n    // Setting a delegate for the voice recognition input\n    persistentSearchView.setVoiceRecognitionDelegate(new VoiceRecognitionDelegate(this));\n\n    persistentSearchView.setOnSearchConfirmedListener(new OnSearchConfirmedListener() {\n\n        @Override\n        public void onSearchConfirmed(PersistentSearchView searchView, String query) {\n            // Handle a search confirmation. This is the place where you'd\n            // want to save a new query and perform a search against your\n            // data provider.\n        }\n\n    });\n\n    persistentSearchView.setOnSearchQueryChangeListener(new OnSearchQueryChangeListener() {\n        \n        @Override\n        public void onSearchQueryChanged(PersistentSearchView searchView, String oldQuery, String newQuery) {\n            // Handle a search query change. This is the place where you'd\n            // want load new suggestions based on the newQuery parameter.\n        }\n\n    });\n\n    persistentSearchView.setOnSuggestionChangeListener(new OnSuggestionChangeListener() {\n\n        @Override\n        public void onSuggestionPicked(SuggestionItem suggestion) {\n            // Handle a suggestion pick event. This is the place where you'd\n            // want to perform a search against your data provider.\n        }\n\n        @Override\n        public void onSuggestionRemoved(SuggestionItem suggestion) {\n            // Handle a suggestion remove event. This is the place where\n            // you'd want to remove the suggestion from your data provider.\n        }\n\n    });\n}\n\t\n\n//...\n\n\n@Override\npublic void onResume() {\n    super.onResume();\n\n    List\u003cString\u003e searchQueries = null;\n\n    // Fetching the search queries from the data provider\n    if(persistentSearchView.isInputQueryEmpty) {\n        searchQueries = mDataProvider.getInitialSearchQueries();\n    } else {\n        searchQueries = mDataProvider.getSuggestionsForQuery(persistentSearchView.inputQuery);\n    }\n\n    // Converting them to recent suggestions and setting them to the widget\n    persistentSearchView.setSuggestions(SuggestionCreationUtil.asRecentSearchSuggestions(searchQueries), false);\n}\n\n\t\n//...\n\n\n@Override\nprotected fun onActivityResult(int requestCode, int resultCode, Intent data) {\n    super.onActivityResult(requestCode, resultCode, data);\n\n    // Calling the voice recognition delegate to properly handle voice input results\n    VoiceRecognitionDelegate.handleResult(persistentSearchView, requestCode, resultCode, data);\n}\n````\n\n\u003c/p\u003e\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eKotlin (click to expand)\u003c/b\u003e\u003c/summary\u003e\n\u003cp\u003e\n\n````kotlin\noverride fun onCreate(savedInstanceState: Bundle?) {\n    super.onCreate(savedInstanceState)\n    setContentView(R.layout.demo_activity_layout)\n\n    //...\n\n    with(persistentSearchView) {\n        setOnLeftBtnClickListener {\n            // Handle the left button click\n        }\n        setOnClearInputBtnClickListener {\n            // Handle the clear input button click\n        }\n\n        // Setting a delegate for the voice recognition input\n        setVoiceRecognitionDelegate(VoiceRecognitionDelegate(this@DemoActivity))\n\n        setOnSearchConfirmedListener { searchView, query -\u003e\n            // Handle a search confirmation. This is the place where you'd\n            // want to save a new query and perform a search against your\n            // data provider.\n        }\n\n        setOnSearchQueryChangeListener { searchView, oldQuery, newQuery -\u003e\n            // Handle a search query change. This is the place where you'd\n            // want load new suggestions based on the newQuery parameter.\n        }\n\n        setOnSuggestionChangeListener(object : OnSuggestionChangeListener {\n\n            override fun onSuggestionPicked(suggestion: SuggestionItem) {\n                // Handle a suggestion pick event. This is the place where you'd\n                // want to perform a search against your data provider.\n            }\n\n            override fun onSuggestionRemoved(suggestion: SuggestionItem) {\n                // Handle a suggestion remove event. This is the place where\n                // you'd want to remove the suggestion from your data provider.\n            }\n\n        })\n    }\n}\n\n\n//...\n\n\noverride fun onResume() {\n    super.onResume()\n\n    // Fetching the search queries from the data provider\n    val searchQueries = if(persistentSearchView.isInputQueryEmpty) {\n        mDataProvider.getInitialSearchQueries()\n    } else {\n        mDataProvider.getSuggestionsForQuery(persistentSearchView.inputQuery)\n    }\n\n    // Converting them to recent suggestions and setting them to the widget\n    persistentSearchView.setSuggestions(SuggestionCreationUtil.asRecentSearchSuggestions(searchQueries), false)\n}\n\n\n//...\n\n\noverride fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {\n    super.onActivityResult(requestCode, resultCode, data)\n\n    // Calling the voice recognition delegate to properly handle voice input results\n    VoiceRecognitionDelegate.handleResult(persistentSearchView, requestCode, resultCode, data)\n}\n````\n\n\u003c/p\u003e\u003c/details\u003e\n\n## Basic Regular Suggestions Implementation\n\nImplementation of a PersistentSearchView with regular suggestions is identical to the [Basic Recent Suggestions Implementation](#basic-recent-suggestions-implementation) with one exception: suggestions creation method [asRecentSearchSuggestions(searchQueries)](https://github.com/mars885/persistentsearchview/blob/master/persistentsearchview/src/main/java/com/paulrybitskyi/persistentsearchview/utils/SuggestionCreationUtil.java#L47) should be replaced with [asRegularSearchSuggestions(searchQueries)](https://github.com/mars885/persistentsearchview/blob/master/persistentsearchview/src/main/java/com/paulrybitskyi/persistentsearchview/utils/SuggestionCreationUtil.java#L62).\n\n## Advanced Use\n\nSee the [Sample app](https://github.com/mars885/persistentsearchview/tree/master/sample).\n\n## Difference between recent and regular suggestions\n\nThe difference between recent and regular suggestions is that a user can remove recent suggestions from the list while regular suggestions cannot be removed (there is no remove button on the regular suggestions).\n\nFor example, here are screenshots of recent suggestions compared to regular:\n\n\u003ctable\u003e\n\t\u003ctbody\u003e\n\t\t\u003ctr\u003e\n\t\t\t\u003ctd align=\"center\"\u003eRecent\u003c/td\u003e\n\t\t\t\u003ctd align=\"center\"\u003eRegular\u003c/td\u003e\n\t\t\u003c/tr\u003e\n\t\t\u003ctr\u003e\n\t\t\t\u003ctd align=\"center\"\u003e\n\t\t\t\t\u003cimg src=\"/media/recent_suggestions.jpg\" width=\"341\" height=\"326\"/\u003e\n\t\t\t\u003c/td\u003e\n\t\t\t\u003ctd align=\"center\"\u003e\n\t\t\t\t\u003cimg src=\"/media/regular_suggestions.jpg\" width=\"341\" height=\"326\"/\u003e\n\t\t\t\u003c/td\u003e\n\t\t\u003c/tr\u003e\n\t\u003c/tbody\u003e\n\u003c/table\u003e\n\n## Contribution\n\nSee the [CONTRIBUTING.md](CONTRIBUTING.md) file.\n\n## Hall of Fame\n\n\u003ctable\u003e\n    \u003ctbody\u003e\n        \u003ctr\u003e\n            \u003ctd align=\"center\"\u003e\n                \u003ca href=\"https://play.google.com/store/apps/details?id=com.arthurivanets.owly\"\u003e\n\t                \u003cimg src=\"https://lh3.googleusercontent.com/FHaz_qNghV02MpQBEnR4K3yVGsbS_0qcUsEHidzfujI3V01zyLp6yo7oK0-ymILdRk9k=s360\" width=\"70\" height=\"70\"/\u003e\n                \u003c/a\u003e\n            \u003c/td\u003e\n            \u003ctd align=\"center\"\u003e\u003cb\u003eOwly\u003c/b\u003e\u003c/td\u003e\n        \u003c/tr\u003e\n    \u003c/tbody\u003e\n\u003c/table\u003e\n\n\u003e Using PersistentSearchView in your app and want it to get listed here? Email me at github@paulrybitskyi.com!\n\n## License\n\nPersistentSearchView is licensed under the [Apache 2.0 License](LICENSE).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmars885%2Fpersistent-search-view","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmars885%2Fpersistent-search-view","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmars885%2Fpersistent-search-view/lists"}