{"id":13644282,"url":"https://github.com/mirrajabi/search-dialog","last_synced_at":"2025-04-21T07:30:40.980Z","repository":{"id":166073537,"uuid":"91489764","full_name":"mirrajabi/search-dialog","owner":"mirrajabi","description":"An easy to use, yet very customizable search dialog","archived":false,"fork":false,"pushed_at":"2020-10-01T19:14:57.000Z","size":204,"stargazers_count":513,"open_issues_count":4,"forks_count":91,"subscribers_count":14,"default_branch":"master","last_synced_at":"2024-11-09T16:44:13.284Z","etag":null,"topics":["android","dialog","popup","search","search-interface"],"latest_commit_sha":null,"homepage":"http://mirrajabi.nl","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/mirrajabi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-05-16T18:11:06.000Z","updated_at":"2024-11-02T04:39:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"ba6cecf6-745b-41cd-a4ed-5fa6094f478c","html_url":"https://github.com/mirrajabi/search-dialog","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/mirrajabi%2Fsearch-dialog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mirrajabi%2Fsearch-dialog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mirrajabi%2Fsearch-dialog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mirrajabi%2Fsearch-dialog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mirrajabi","download_url":"https://codeload.github.com/mirrajabi/search-dialog/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250014559,"owners_count":21360972,"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","dialog","popup","search","search-interface"],"created_at":"2024-08-02T01:02:00.564Z","updated_at":"2025-04-21T07:30:40.410Z","avatar_url":"https://github.com/mirrajabi.png","language":"Java","funding_links":[],"categories":["SearchView"],"sub_categories":[],"readme":"# search-dialog\n[![](https://jitpack.io/v/mirrajabi/search-dialog.svg)](https://jitpack.io/#mirrajabi/search-dialog)\n\nAn awesome and customizable search dialog with built-in search options.\n\n![search_dialog](https://cloud.githubusercontent.com/assets/8886687/26755439/869f9e6c-48a2-11e7-9e6c-829b573e7730.jpg)\n\n### Usage\n\nFirst add jitpack to your projects build.gradle file\n\n```gradle\nallprojects {\n    repositories {\n        ...\n        maven { url \"https://jitpack.io\" }\n   \t}\n}\n```\n\nThen add the dependency in modules build.gradle file\n\n```gradle\ndependencies {\n    implementation 'com.github.mirrajabi:search-dialog:1.2.4'\n}\n```\n\n## Simple usage\n\nif you just want to use the simple search dialog first you need to provide searchable items.\nto achieve this you should implement [Searchable](https://github.com/mirrajabi/search-dialog/blob/master/library/src/main/java/ir/mirrajabi/searchdialog/core/Searchable.java) in your model.\n\nyou can see the [SampleSearchModel](https://github.com/mirrajabi/search-dialog/blob/master/app/src/main/java/ir/mirrajabi/searchdialog/sample/models/SampleSearchModel.java) for example :\n\n```java\npublic class SampleSearchModel implements Searchable {\n    private String mTitle;\n\n    public SampleSearchModel(String title) {\n        mTitle = title;\n    }\n\n    @Override\n    public String getTitle() {\n        return mTitle;\n    }\n\n    public SampleSearchModel setTitle(String title) {\n        mTitle = title;\n        return this;\n    }\n}\n```\n\nnow generate some search options in your activity :\n\n```java\n    private ArrayList\u003cSampleSearchModel\u003e createSampleData(){\n        ArrayList\u003cSampleSearchModel\u003e items = new ArrayList\u003c\u003e();\n        items.add(new SampleSearchModel(\"First item\"));\n        items.add(new SampleSearchModel(\"Second item\"));\n        items.add(new SampleSearchModel(\"Third item\"));\n        items.add(new SampleSearchModel(\"The ultimate item\"));\n        items.add(new SampleSearchModel(\"Last item\"));\n        items.add(new SampleSearchModel(\"Lorem ipsum\"));\n        items.add(new SampleSearchModel(\"Dolor sit\"));\n        items.add(new SampleSearchModel(\"Some random word\"));\n        items.add(new SampleSearchModel(\"guess who's back\"));\n        return items;\n    }\n```\n\nthen you just need to add the below lines where you want to show the dialog :\n\n```java\nnew SimpleSearchDialogCompat(MainActivity.this, \"Search...\",\n                        \"What are you looking for...?\", null, createSampleData(),\n                        new SearchResultListener\u003cSampleSearchModel\u003e() {\n                            @Override\n                            public void onSelected(BaseSearchDialogCompat dialog,\n                                                   SampleSearchModel item, int position) {\n                                // If filtering is enabled, [position] is the index of the item in the filtered result, not in the unfiltered source\n                                Toast.makeText(MainActivity.this, item.getTitle(),\n                                        Toast.LENGTH_SHORT).show();\n                                dialog.dismiss();\n                            }\n                        }).show();\n```\n\nThe constructor parameters are\n```java\nSimpleSearchDialogCompat(Context context, String title, String searchHint,\n                                    @Nullable Filter filter, ArrayList\u003cT\u003e items,\n                                    SearchResultListener\u003cT\u003e searchResultListener)\n```\n\n### Loading view(added to [SimpleSearchDialogCompat](https://github.com/mirrajabi/search-dialog/blob/master/library/src/main/java/ir/mirrajabi/searchdialog/SimpleSearchDialogCompat.java) in [v1.1](https://github.com/mirrajabi/search-dialog/releases/tag/1.1))\n\nJust use `setLoading(true)` for showing and `setLoading(false)` for hiding it on an instance of [SimpleSearchDialogCompat](https://github.com/mirrajabi/search-dialog/blob/master/library/src/main/java/ir/mirrajabi/searchdialog/SimpleSearchDialogCompat.java)\n\n### Changing default adapters text colors(added in [v1.2.1](https://github.com/mirrajabi/search-dialog/releases/tag/1.2.1))\n\nIf you want to change the default colors just override these colors in your `colors.xml` or wherever you want [like this](https://github.com/mirrajabi/search-dialog/blob/master/app/src/main/res/values/colors.xml#L6).\n\n```xml\n    \u003ccolor name=\"searchDialogResultColor\"/\u003e\n    \u003ccolor name=\"searchDialogResultHighlightColor\"/\u003e\n```\n\n## Advanced usage\n\n### The layout\n\nI used [this layout](https://github.com/mirrajabi/search-dialog/blob/master/library/src/main/res/layout/search_dialog_compat.xml) for simple search dialog but you can use anything else.\nOf course your layout should have thse two views :\n- An EditText to use as search key input\n- A RecyclerView for showing the results in it\n\n### The search dialog\n\nYou can use your custom layouts, adapters and search options by creating a class inheriting the [BaseSearchDialogCompat](https://github.com/mirrajabi/search-dialog/blob/master/library/src/main/java/ir/mirrajabi/searchdialog/core/BaseSearchDialogCompat.java)\ntake a look at [SimpleSearchDialogCompat](https://github.com/mirrajabi/search-dialog/blob/master/library/src/main/java/ir/mirrajabi/searchdialog/SimpleSearchDialogCompat.java) to see an example of how it can be done\nYou should implement the BaseSearchDialogCompat methods : \n\n```java\n    // handle your view with this one\n    protected abstract void getView(View view);\n    // Id of your custom layout\n    @LayoutRes protected abstract int getLayoutResId();\n    // Id of the search edittext you used in your custom layout\n    @IdRes protected abstract int getSearchBoxId();\n    // Id of the recyclerview you used in your custom layout\n    @IdRes protected abstract int getRecyclerViewId();\n\n```\n### The search filter\n\nYou can use your custom filters for text searching. The one used in [SimpleSearchDialogCompat](https://github.com/mirrajabi/search-dialog/blob/master/library/src/main/java/ir/mirrajabi/searchdialog/SimpleSearchDialogCompat.java) is [SimpleSearchFilter](https://github.com/mirrajabi/search-dialog/blob/master/library/src/main/java/ir/mirrajabi/searchdialog/SimpleSearchFilter.java).\nIt checks the search key and if an item and the key had partially exact same letters it will add that item to results and also if the CheckLCS was set to true, it will check if the amount of matching letters was bigger than the given AccuracyPercentage the item will be added to results\n\n\n### The [adapter](https://github.com/mirrajabi/search-dialog/blob/master/library/src/main/java/ir/mirrajabi/searchdialog/adapters/SearchDialogAdapter.java)\n\nthe one used in SimpleSearchDialogCompat is so simple despite its too long. the main functionality is in [initializeViews](https://github.com/mirrajabi/search-dialog/blob/master/library/src/main/java/ir/mirrajabi/searchdialog/adapters/SearchDialogAdapter.java#L94) method.\nyou can create your custom adapters and use it instead of this one\n\n### The [StringsHelper](https://github.com/mirrajabi/search-dialog/blob/master/library/src/main/java/ir/mirrajabi/searchdialog/StringsHelper.java)\n\nit has two methods which you can use for highlighting the results.\n\n```java\n/*\n * Returns a SpannableString with \n * highlighted LCS(Longest Common Subsequence)\n * of two strings with the givven color\n */\nSpannableStringBuilder highlightLCS(String text1, String text2, int highlightColor);\n\n// Returns the LCS(Longest Common Subsequence) of two strings\nString lcs(String text1, String text2) \n```\n\n\n#### See the [sample app](https://github.com/mirrajabi/search-dialog/tree/master/app) to get a better understanding of the advanced usage\n\n### Used in sample app\n\n- [Okhttp](https://github.com/square/okhttp)\n- [OkhttpJsonMock](https://github.com/mirrajabi/okhttp-json-mock)\n- [Retrofit](http://github.com/square/retrofit)\n- [ButterKnife](https://github.com/JakeWharton/butterknife)\n- [Glide](https://github.com/bumptech/glide)\n- [Circle-ImageView](https://github.com/hdodenhof/CircleImageView)\n- [RandomUser](https://randomuser.me)'s fake api for sample images \n\n### Changelog\n\n1.2.4 - `Added an option to SimpleSearchDialogCompat so that the dialog cancellation on touching outside the dialog can be customized.`\n\n1.2.3 - `Changed minSdkVersion to 14. Added getter for the title textview of simple search dialog. Improved results sorting.`\n\n1.2.2 - `Gradle tools version and dependencies were updated.`\n\n1.2.1 - `Added an option for changing text color and highlight color of default adapter.`\n\n1.2 - `Added getter for views in simple search dialog and an option to turn off the auto filtering on search edittext.`\n\n1.1.1 - `Fixes drawable overriding issue.`\n\n1.1 - `Added loading feature.`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmirrajabi%2Fsearch-dialog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmirrajabi%2Fsearch-dialog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmirrajabi%2Fsearch-dialog/lists"}