use of net.iGap.realm.RealmRegisteredInfo in project iGap-Android by KianIranian-STDG.
the class AvatarHandler method showInitials.
/**
* read from user and room db in local for find initials and color
*
* @param ownerId if is user set userId and if is room set roomId
* @return initials[0] , color[1]
*/
public String[] showInitials(long ownerId, AvatarType avatarType) {
return DbManager.getInstance().doRealmTask(realm -> {
String initials = null;
String color = null;
if (avatarType == AvatarType.USER) {
RealmRegisteredInfo realmRegisteredInfo = RealmRegisteredInfo.getRegistrationInfo(realm, ownerId);
if (realmRegisteredInfo != null) {
initials = realmRegisteredInfo.getInitials();
color = realmRegisteredInfo.getColor();
} else {
RealmRoom realmRoom = realm.where(RealmRoom.class).equalTo("chatRoom.peer_id", ownerId).findFirst();
if (realmRoom != null) {
initials = realmRoom.getInitials();
color = realmRoom.getColor();
}
}
} else if (avatarType == AvatarType.ROOM) {
RealmRoom realmRoom = realm.where(RealmRoom.class).equalTo("id", ownerId).findFirst();
if (realmRoom != null) {
initials = realmRoom.getInitials();
color = realmRoom.getColor();
}
}
if (initials != null && color != null) {
return new String[] { initials, color };
}
return null;
});
}
use of net.iGap.realm.RealmRegisteredInfo in project iGap-Android by KianIranian-STDG.
the class SearchFragment method fillBot.
private void fillBot(String text) {
DbManager.getInstance().doRealmTask(realm -> {
final RealmResults<RealmRegisteredInfo> results;
if (searchTxt.startsWith("@")) {
results = realm.where(RealmRegisteredInfo.class).contains("username", text, Case.INSENSITIVE).equalTo("isBot", true).findAll();
} else {
results = realm.where(RealmRegisteredInfo.class).beginGroup().contains("username", text, Case.INSENSITIVE).or().contains("displayName", text).endGroup().equalTo("isBot", true).findAll();
}
if (results != null && results.size() > 0) {
addHeader(G.fragmentActivity.getResources().getString(R.string.bot));
for (RealmRegisteredInfo contact : results) {
StructSearch item = new StructSearch();
item.name = contact.getDisplayName();
item.isVerified = contact.isVerified();
item.time = contact.getLastSeen();
item.userName = contact.getUsername();
item.comment = "";
item.id = contact.getId();
item.idDetectAvatar = contact.getId();
item.type = SearchType.contact;
item.initials = contact.getInitials();
item.color = contact.getColor();
item.avatar = contact.getLastAvatar(realm);
list.add(item);
}
}
});
}
Aggregations