Search in sources :

Example 36 with RealmRegisteredInfo

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;
    });
}
Also used : RealmRoom(net.iGap.realm.RealmRoom) RealmRegisteredInfo(net.iGap.realm.RealmRegisteredInfo)

Example 37 with RealmRegisteredInfo

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);
            }
        }
    });
}
Also used : RealmRegisteredInfo(net.iGap.realm.RealmRegisteredInfo)

Aggregations

RealmRegisteredInfo (net.iGap.realm.RealmRegisteredInfo)37 ArrayList (java.util.ArrayList)15 View (android.view.View)13 RealmRoom (net.iGap.realm.RealmRoom)12 List (java.util.List)11 TextView (android.widget.TextView)10 RecyclerView (androidx.recyclerview.widget.RecyclerView)10 G (net.iGap.G)10 R (net.iGap.R)10 DbManager (net.iGap.module.accountManager.DbManager)10 ProtoGlobal (net.iGap.proto.ProtoGlobal)10 ViewGroup (android.view.ViewGroup)9 AvatarHandler (net.iGap.helper.avatar.AvatarHandler)9 Bundle (android.os.Bundle)8 AppCompatTextView (androidx.appcompat.widget.AppCompatTextView)8 File (java.io.File)8 Log (android.util.Log)7 LayoutInflater (android.view.LayoutInflater)7 Nullable (androidx.annotation.Nullable)7 RequestUserInfo (net.iGap.request.RequestUserInfo)7