Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.reline:realm-searchadapter:1.0'
}
dependencies {
implementation("com.github.reline:realm-searchadapter:1.0")
}
<dependency>
<groupId>com.github.reline</groupId>
<artifactId>realm-searchadapter</artifactId>
<version>1.0</version>
</dependency>
libraryDependencies += "com.github.reline" % "realm-searchadapter" % "1.0"
:dependencies [[com.github.reline/realm-searchadapter "1.0"]]
Built on Realm's RealmRecyclerViewAdapter
Adapted from Thorben Primke's realm-searchview
###How to include it
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
dependencies {
compile 'com.github.Reline:realm-searchadapter:1.0'
}
##RealmSearchAdapter
The following list of parameters are available to customize the filtering.
filterKey
: The filterKey is required as it is the columnName that the results are filtered by.
useContains
: If true, uses contains
, otherwise uses beginsWith
.
useCaseSensitive
: If true, ensures that the filter is respecting casing. If false, ignores any casing.
sortAscending
: If true, ascending, otherwise descending.
sortKey
: The columnName by which the results should be sorted.
basePredicate
: The basePredicate is used to filter the results whenever the searchBar is empty.
The RealmSearchAdapter
has two constructors. One that only takes the filterKey
parameter and one that takes all parameters.
In addition, the adapter has to be provided with an OrderedRealmCollection of the objects to be filtered. It is used throughout the life of view to requery the results.
###Example
OrderedRealmCollection<Person> people = realm.where(Person.class).greaterThan("age", 21).findAll();
MyRealmSearchAdapter adapter = new MyRealmSearchAdapter(context, people, "name");
myRecyclerView.setAdapter(adapter);
The adapter is now ready to be filtered
adapter.filter("Nathan");
or with a SearchView
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
adapter.filter(newText);
return true;
}
});