This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Subscription queryDogsByInput() { | |
return RxTextView.textChanges(editText) | |
.switchMap(charSequence -> realm.where(Dog.class) | |
.contains(DogFields.NAME, charSequence.toString()) | |
.findAllSortedAsync(DogFields.NAME) | |
.asObservable() | |
).filter(RealmResults::isLoaded) // filter async results while not loaded | |
.subscribe(dogs -> adapter.updateData(dogs)); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
catService.getCats() | |
.subscribeOn(Schedulers.io()) | |
.retry() | |
.subscribe(catsBO -> { | |
try(Realm realm = Realm.getDefaultInstance()) { | |
Cat defaultCat = new Cat(); | |
long rank; | |
if(realm.where(Cat.class).count() > 0) { | |
rank = realm.where(Cat.class).max(CatFields.RANK).longValue(); | |
} else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SAY NO TO THIS | |
Realm realm = Realm.getDefaultInstance(); | |
realm.beginTransaction(); // NO | |
realm.copyToRealm(dog) | |
realm.commitTransaction(); // NO NO NO NO NO | |
// CLOSE THE REALM OH MY GOD WHY | |
// ---------------------- | |
// SAY YES TO THIS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
adapter = new RealmRecyclerViewAdapter<Dog, DogViewHolder>(getContext(), | |
realm.where(Dog.class).contains(currentName).findAllAsync(), true) { // query definition + true == automatic updates | |
@Override | |
public DogViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | |
return new DogViewHolder(LayoutInflater.from(parent.getContext()) | |
.inflate(R.layout.view_dog_item, parent, false)); | |
} | |
@Override | |
public void onBindViewHolder(DogViewHolder holder, int position) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try(Realm realm = Realm.getDefaultInstance()) { | |
final RealmResults<Dog> dogs = realm.where(Dog.class).findAll(); // NO | |
realm.executeTransaction(inRealm -> { // NO | |
for(Dog dog : dogs) { // NO | |
//... | |
} | |
}); | |
} | |
//////////////////// |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Top-level build file where you can add configuration options common to all sub-projects/modules. | |
buildscript { | |
repositories { | |
jcenter() | |
mavenCentral() | |
maven {url "https://clojars.org/repo/"} | |
maven { url "https://jitpack.io" } | |
} | |
dependencies { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'com.android.application' | |
//apply plugin: 'com.neenbedankt.android-apt' | |
//apply plugin: 'me.tatarka.retrolambda' | |
apply plugin: 'realm-android' // <-- added this line |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'com.android.application' | |
//apply plugin: 'com.neenbedankt.android-apt' | |
//apply plugin: 'me.tatarka.retrolambda' | |
apply plugin: 'realm-android' | |
android { | |
compileSdkVersion 24 | |
buildToolsVersion "24.0.2" | |
//compileOptions { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#realm | |
-keepnames public class * extends io.realm.RealmObject | |
-keep @io.realm.annotations.RealmModule class * | |
-keep class io.realm.** { *; } | |
-dontwarn javax.** | |
-dontwarn io.realm.** | |
#realm 0.84.1+ | |
-keep class io.realm.annotations.RealmModule | |
-keep @io.realm.annotations.RealmModule class * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NewsActivity extends AppCompatActivity { | |
// ... | |
private RealmChangeListener<RealmResults<NewsPost>> realmChangeListener; | |
private RealmResults<NewsPost> listenerSet; | |
private long postId; | |
private Realm realm; | |
@Override | |
protected void onCreate(Bundle bundle) { |
OlderNewer