Commit a2a23c21 authored by Tiago Cunha's avatar Tiago Cunha

New format on stuff, fixes

parent 0040eb30
...@@ -33,6 +33,14 @@ public class Migration implements RealmMigration { ...@@ -33,6 +33,14 @@ public class Migration implements RealmMigration {
.addField(RealmSpotlightRoom.Columns.ID, String.class, FieldAttribute.PRIMARY_KEY) .addField(RealmSpotlightRoom.Columns.ID, String.class, FieldAttribute.PRIMARY_KEY)
.addField(RealmSpotlightRoom.Columns.NAME, String.class) .addField(RealmSpotlightRoom.Columns.NAME, String.class)
.addField(RealmSpotlightRoom.Columns.TYPE, String.class); .addField(RealmSpotlightRoom.Columns.TYPE, String.class);
oldVersion++;
}
if (oldVersion == 2) {
RealmObjectSchema roomSchema = schema.get("RealmSpotlightUser");
roomSchema.addField(RealmSpotlightUser.Columns.NAME, String.class);
} }
} }
} }
...@@ -14,7 +14,9 @@ public class RealmStore { ...@@ -14,7 +14,9 @@ public class RealmStore {
return new RealmConfiguration.Builder() return new RealmConfiguration.Builder()
.name(name + ".realm") .name(name + ".realm")
.modules(new RocketChatLibraryModule()) .modules(new RocketChatLibraryModule())
.deleteRealmIfMigrationNeeded().build(); .migration(new Migration())
.schemaVersion(3)
.build();
} }
public static void put(String name) { public static void put(String name) {
......
...@@ -15,7 +15,7 @@ public class RocketChatPersistenceRealm { ...@@ -15,7 +15,7 @@ public class RocketChatPersistenceRealm {
new RealmConfiguration.Builder() new RealmConfiguration.Builder()
.name("rocket.chat.persistence.realm") .name("rocket.chat.persistence.realm")
.modules(new RocketChatLibraryModule()) .modules(new RocketChatLibraryModule())
.schemaVersion(2) .schemaVersion(3)
.migration(new Migration()) .migration(new Migration())
.build()); .build());
} }
......
...@@ -10,11 +10,13 @@ public class RealmSpotlightUser extends RealmObject { ...@@ -10,11 +10,13 @@ public class RealmSpotlightUser extends RealmObject {
public interface Columns { public interface Columns {
String ID = "_id"; String ID = "_id";
String USERNAME = "username"; String USERNAME = "username";
String NAME = "name";
String STATUS = "status"; String STATUS = "status";
} }
@PrimaryKey private String _id; @PrimaryKey private String _id;
private String username; private String username;
private String name;
private String status; private String status;
public String getId() { public String getId() {
...@@ -33,6 +35,14 @@ public class RealmSpotlightUser extends RealmObject { ...@@ -33,6 +35,14 @@ public class RealmSpotlightUser extends RealmObject {
this.username = username; this.username = username;
} }
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getStatus() { public String getStatus() {
return status; return status;
} }
...@@ -45,6 +55,7 @@ public class RealmSpotlightUser extends RealmObject { ...@@ -45,6 +55,7 @@ public class RealmSpotlightUser extends RealmObject {
return SpotlightUser.builder() return SpotlightUser.builder()
.setId(_id) .setId(_id)
.setUsername(username) .setUsername(username)
.setName(name)
.setStatus(status) .setStatus(status)
.build(); .build();
} }
......
...@@ -6,6 +6,7 @@ import com.fernandocejas.arrow.optional.Optional; ...@@ -6,6 +6,7 @@ import com.fernandocejas.arrow.optional.Optional;
import io.reactivex.Flowable; import io.reactivex.Flowable;
import io.reactivex.Single; import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.realm.Case;
import io.realm.Realm; import io.realm.Realm;
import io.realm.RealmResults; import io.realm.RealmResults;
import io.realm.Sort; import io.realm.Sort;
...@@ -149,7 +150,7 @@ public class RealmRoomRepository extends RealmRepository implements RoomReposito ...@@ -149,7 +150,7 @@ public class RealmRoomRepository extends RealmRepository implements RoomReposito
() -> new Pair<>(RealmStore.getRealm(hostname), Looper.myLooper()), () -> new Pair<>(RealmStore.getRealm(hostname), Looper.myLooper()),
pair -> RxJavaInterop.toV2Flowable( pair -> RxJavaInterop.toV2Flowable(
pair.first.where(RealmRoom.class) pair.first.where(RealmRoom.class)
.like(RealmRoom.NAME, "*" + name + "*") .like(RealmRoom.NAME, "*" + name + "*", Case.INSENSITIVE)
.beginGroup() .beginGroup()
.equalTo(RealmRoom.TYPE, RealmRoom.TYPE_CHANNEL) .equalTo(RealmRoom.TYPE, RealmRoom.TYPE_CHANNEL)
.or() .or()
......
...@@ -4,6 +4,7 @@ import android.os.Looper; ...@@ -4,6 +4,7 @@ import android.os.Looper;
import android.support.v4.util.Pair; import android.support.v4.util.Pair;
import io.reactivex.Flowable; import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.realm.Case;
import io.realm.Sort; import io.realm.Sort;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -32,7 +33,7 @@ public class RealmSpotlightRoomRepository extends RealmRepository ...@@ -32,7 +33,7 @@ public class RealmSpotlightRoomRepository extends RealmRepository
() -> new Pair<>(RealmStore.getRealm(hostname), Looper.myLooper()), () -> new Pair<>(RealmStore.getRealm(hostname), Looper.myLooper()),
pair -> RxJavaInterop.toV2Flowable( pair -> RxJavaInterop.toV2Flowable(
pair.first.where(RealmSpotlightRoom.class) pair.first.where(RealmSpotlightRoom.class)
.like(RealmSpotlightRoom.Columns.NAME, "*" + name + "*") .like(RealmSpotlightRoom.Columns.NAME, "*" + name + "*", Case.INSENSITIVE)
.beginGroup() .beginGroup()
.equalTo(RealmSpotlightRoom.Columns.TYPE, RealmRoom.TYPE_CHANNEL) .equalTo(RealmSpotlightRoom.Columns.TYPE, RealmRoom.TYPE_CHANNEL)
.or() .or()
......
...@@ -4,6 +4,7 @@ import android.os.Looper; ...@@ -4,6 +4,7 @@ import android.os.Looper;
import android.support.v4.util.Pair; import android.support.v4.util.Pair;
import io.reactivex.Flowable; import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.realm.Case;
import io.realm.Sort; import io.realm.Sort;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -31,7 +32,15 @@ public class RealmSpotlightUserRepository extends RealmRepository ...@@ -31,7 +32,15 @@ public class RealmSpotlightUserRepository extends RealmRepository
() -> new Pair<>(RealmStore.getRealm(hostname), Looper.myLooper()), () -> new Pair<>(RealmStore.getRealm(hostname), Looper.myLooper()),
pair -> RxJavaInterop.toV2Flowable( pair -> RxJavaInterop.toV2Flowable(
pair.first.where(RealmSpotlightUser.class) pair.first.where(RealmSpotlightUser.class)
.like(RealmSpotlightUser.Columns.USERNAME, "*" + name + "*") .beginGroup()
.like(RealmSpotlightUser.Columns.USERNAME, "*" + name + "*", Case.INSENSITIVE)
.isNull(RealmSpotlightUser.Columns.NAME)
.endGroup()
.or()
.beginGroup()
.like(RealmSpotlightUser.Columns.NAME, "*" + name + "*", Case.INSENSITIVE)
.isNotNull(RealmSpotlightUser.Columns.USERNAME)
.endGroup()
.findAllSorted(RealmSpotlightUser.Columns.USERNAME, .findAllSorted(RealmSpotlightUser.Columns.USERNAME,
direction.equals(SortDirection.ASC) ? Sort.ASCENDING : Sort.DESCENDING) direction.equals(SortDirection.ASC) ? Sort.ASCENDING : Sort.DESCENDING)
.asObservable()), .asObservable()),
......
...@@ -5,6 +5,7 @@ import android.support.v4.util.Pair; ...@@ -5,6 +5,7 @@ import android.support.v4.util.Pair;
import com.fernandocejas.arrow.optional.Optional; import com.fernandocejas.arrow.optional.Optional;
import io.reactivex.Flowable; import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.realm.Case;
import io.realm.RealmResults; import io.realm.RealmResults;
import io.realm.Sort; import io.realm.Sort;
...@@ -54,7 +55,7 @@ public class RealmUserRepository extends RealmRepository implements UserReposito ...@@ -54,7 +55,7 @@ public class RealmUserRepository extends RealmRepository implements UserReposito
() -> new Pair<>(RealmStore.getRealm(hostname), Looper.myLooper()), () -> new Pair<>(RealmStore.getRealm(hostname), Looper.myLooper()),
pair -> RxJavaInterop.toV2Flowable( pair -> RxJavaInterop.toV2Flowable(
pair.first.where(RealmUser.class) pair.first.where(RealmUser.class)
.like(RealmUser.USERNAME, "*" + name + "*") .like(RealmUser.USERNAME, "*" + name + "*", Case.INSENSITIVE)
.findAllSorted(RealmUser.USERNAME, .findAllSorted(RealmUser.USERNAME,
direction.equals(SortDirection.ASC) ? Sort.ASCENDING : Sort.DESCENDING) direction.equals(SortDirection.ASC) ? Sort.ASCENDING : Sort.DESCENDING)
.asObservable()), .asObservable()),
......
...@@ -11,6 +11,9 @@ public abstract class SpotlightUser { ...@@ -11,6 +11,9 @@ public abstract class SpotlightUser {
public abstract String getUsername(); public abstract String getUsername();
@Nullable
public abstract String getName();
@Nullable @Nullable
public abstract String getStatus(); public abstract String getStatus();
...@@ -25,6 +28,8 @@ public abstract class SpotlightUser { ...@@ -25,6 +28,8 @@ public abstract class SpotlightUser {
public abstract Builder setUsername(String username); public abstract Builder setUsername(String username);
public abstract Builder setName(String name);
public abstract Builder setStatus(String status); public abstract Builder setStatus(String status);
public abstract SpotlightUser build(); public abstract SpotlightUser build();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment