io.realm.RealmChangeListener Java Examples

The following examples show how to use io.realm.RealmChangeListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DbManager.java    From Socket.io-FLSocketIM-Android with MIT License 6 votes vote down vote up
public static void queryAllConversation(final QueryDbCallBack<ConversationDbObject> callBack) {

        mainHandler.post(new Runnable() {
            @Override
            public void run() {

                final RealmResults<ConversationDbObject> results = mRealm.where(ConversationDbObject.class).findAllAsync();
                results.addChangeListener(new RealmChangeListener<RealmResults<ConversationDbObject>>() {
                    @Override
                    public void onChange(RealmResults<ConversationDbObject> element) {

                        element = element.sort("latestmsgtimestamp");

                        List<ConversationDbObject> objects = mRealm.copyFromRealm(element);

                        callBack.querySuccess(objects, false);
                        results.removeAllChangeListeners();
                    }
                });
            }
        });
    }
 
Example #2
Source File: SettingsActivity.java    From redgram-for-reddit with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setupActionBar();

    realm = ((App)getApplication()).getDatabaseManager().getInstance();
    Log.d("REALM_PATH", realm.getPath());
    user = DatabaseHelper.getSessionUser(realm);

    user.addChangeListener(new RealmChangeListener() {
        @Override
        public void onChange() {
            if(!userChanged){
                userChanged = true;
            }
        }
    });

}
 
Example #3
Source File: Database.java    From udacity-p1-p2-popular-movies with MIT License 6 votes vote down vote up
private <T extends RealmObject> void readAllAsync(@NonNull final ReadAction<T> readAction) {
    Realm realm = null;
    try {
        realm = Realm.getDefaultInstance();
        RealmQuery<T> query = readAction.getQuery(realm);
        final RealmResults<T> results = query.findAllAsync();
        results.addChangeListener(new RealmChangeListener() {
            @Override
            public void onChange() {
                results.removeChangeListener(this);
                readAction.onResults(results);
            }
        });
    } finally {
        if (realm != null) {
            realm.close();
        }
    }
}
 
Example #4
Source File: RealmRoomMessage.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
public static void fetchNotDeliveredMessages(final OnActivityMainStart callback) {
    // if client get message and before send status lost connection, will be need to this method
    // and this step is very uncommon so don't need to do this action and get performance,if client
    // needed this method will be used in ActivityMain later
    final Realm realm = Realm.getDefaultInstance();
    RealmResults<RealmRoomMessage> sentMessages = realm.where(RealmRoomMessage.class).notEqualTo(RealmRoomMessageFields.USER_ID, G.userId).equalTo(RealmRoomMessageFields.STATUS, ProtoGlobal.RoomMessageStatus.SENT.toString()).findAllAsync().sort(new String[]{RealmRoomMessageFields.ROOM_ID, RealmRoomMessageFields.MESSAGE_ID}, new Sort[]{Sort.DESCENDING, Sort.ASCENDING});
    sentMessages.addChangeListener(new RealmChangeListener<RealmResults<RealmRoomMessage>>() {
        @Override
        public void onChange(RealmResults<RealmRoomMessage> element) {
            for (RealmRoomMessage roomMessage : element) {
                if (roomMessage == null) {
                    return;
                }
                final RealmRoom realmRoom = realm.where(RealmRoom.class).equalTo(RealmRoomFields.ID, roomMessage.getRoomId()).findFirst();
                if (realmRoom == null) {
                    return;
                }

                callback.sendDeliveredStatus(realmRoom, roomMessage);
            }

            element.removeAllChangeListeners();
            realm.close();
        }
    });
}
 
Example #5
Source File: FragmentContactsProfileViewModel.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
public void onResume() {
    mRoom = getRealm().where(RealmRoom.class).equalTo(RealmRoomFields.ID, shearedId).findFirst();
    if (mRoom != null) {
        if (changeListener == null) {
            changeListener = new RealmChangeListener<RealmModel>() {
                @Override
                public void onChange(final RealmModel element) {
                    G.handler.post(new Runnable() {
                        @Override
                        public void run() {
                            if (!((RealmRoom) element).isValid()) {
                                return;
                            }

                            sharedMedia.set(((RealmRoom) element).getSharedMediaCount());
                        }
                    });
                }
            };
        }
        mRoom.addChangeListener(changeListener);
        changeListener.onChange(mRoom);
    } else {
        sharedMedia.set(context.getString(R.string.there_is_no_sheared_media));
    }
}
 
Example #6
Source File: Monarchy.java    From realm-monarchy with Apache License 2.0 5 votes vote down vote up
<T extends RealmModel> void createAndObserveRealmQuery(final LiveResults<T> liveResults) {
    Realm realm = realmThreadLocal.get();
    checkRealmValid(realm);
    if(liveResults == null) {
        return;
    }
    RealmResults<T> results = liveResults.createQuery(realm);
    resultsRefs.get().put(liveResults, results);
    results.addChangeListener(new RealmChangeListener<RealmResults<T>>() {
        @Override
        public void onChange(@Nonnull RealmResults<T> realmResults) {
            liveResults.updateResults(realmResults);
        }
    });
}
 
Example #7
Source File: HomeActivity.java    From android-realm-sample with MIT License 5 votes vote down vote up
private void loadUserListAsync() {
    final RealmResults<User> dataList = RealmManager.createUserDao().loadAllAsync();
    dataList.addChangeListener(new RealmChangeListener() {
        @Override
        public void onChange() {
            updateRecyclerView(dataList);
        }
    });
}
 
Example #8
Source File: FragmentGroupProfileViewModel.java    From iGap-Android with GNU Affero General Public License v3.0 5 votes vote down vote up
public void onResume() {

        mRoom = getRealm().where(RealmRoom.class).equalTo(RealmRoomFields.ID, roomId).findFirst();
        if (mRoom != null) {

            if (changeListener == null) {

                changeListener = new RealmChangeListener<RealmModel>() {
                    @Override
                    public void onChange(final RealmModel element) {
                        G.handler.post(new Runnable() {
                            @Override
                            public void run() {
                                if (((RealmRoom) element).isValid()) {
                                    String countText = ((RealmRoom) element).getSharedMediaCount();
                                    if (HelperCalander.isPersianUnicode) {
                                        callbackGroupShearedMedia.set(HelperCalander.convertToUnicodeFarsiNumber(countText));
                                    } else {
                                        callbackGroupShearedMedia.set(countText);
                                    }
                                }
                            }
                        });
                    }
                };
            }

            mRoom.addChangeListener(changeListener);
            changeListener.onChange(mRoom);
        } else {

            callbackGroupShearedMedia.set(context.getString(R.string.there_is_no_sheared_media));
        }
    }
 
Example #9
Source File: FragmentChannelProfileViewModel.java    From iGap-Android with GNU Affero General Public License v3.0 5 votes vote down vote up
public void onResume() {

        mRoom = getRealm().where(RealmRoom.class).equalTo(RealmRoomFields.ID, roomId).findFirst();
        if (mRoom != null) {

            if (changeListener == null) {
                changeListener = new RealmChangeListener<RealmModel>() {
                    @Override
                    public void onChange(final RealmModel element) {
                        G.handler.post(new Runnable() {
                            @Override
                            public void run() {
                                if (((RealmRoom) element).isValid()) {
                                    String countText = ((RealmRoom) element).getSharedMediaCount();
                                    if (HelperCalander.isPersianUnicode) {
                                        callbackChannelSharedMedia.set(HelperCalander.convertToUnicodeFarsiNumber(countText));
                                    } else {
                                        callbackChannelSharedMedia.set(countText);
                                    }
                                }
                            }
                        });
                    }
                };
            }

            mRoom.addChangeListener(changeListener);
            changeListener.onChange(mRoom);
        } else {
            if (callbackChannelSharedMedia.get() != null) {
                callbackChannelSharedMedia.set(context.getString(R.string.there_is_no_sheared_media));
            }
        }
    }
 
Example #10
Source File: FragmentPrivacyAndSecurityViewModel.java    From iGap-Android with GNU Affero General Public License v3.0 5 votes vote down vote up
private void getInfo() {
    realmPrivacy = realm.where(RealmPrivacy.class).findFirst();
    realmUserInfo = realm.where(RealmUserInfo.class).findFirst();
    RealmPrivacy.getUpdatePrivacyFromServer();
    sharedPreferences = G.fragmentActivity.getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE);
    poSelfRemove = sharedPreferences.getInt(SHP_SETTING.KEY_POSITION_SELF_REMOVE, 2);

    updatePrivacyUI(realmPrivacy);

    userInfoListener = new RealmChangeListener<RealmModel>() {
        @Override
        public void onChange(RealmModel element) {

            if (((RealmUserInfo) element).isValid()) {
                selfRemove = ((RealmUserInfo) element).getSelfRemove();
                setTextSelfDestructs();
            }
        }
    };

    privacyListener = new RealmChangeListener<RealmModel>() {
        @Override
        public void onChange(RealmModel element) {
            updatePrivacyUI((RealmPrivacy) element);
        }
    };
}
 
Example #11
Source File: FragmentMediaPlayer.java    From iGap-Android with GNU Affero General Public License v3.0 5 votes vote down vote up
private void setListener() {
    changeListener = new RealmChangeListener<RealmResults<RealmRoomMessage>>() {
        @Override
        public void onChange(RealmResults<RealmRoomMessage> element) {
            getInfoRealm();
        }
    };

    if (changeListener != null) {
        mRealmList.addChangeListener(changeListener);
    }
}
 
Example #12
Source File: FragmentShowAvatars.java    From iGap-Android with GNU Affero General Public License v3.0 4 votes vote down vote up
private void fillListAvatar(From from) {

        realm = Realm.getDefaultInstance();

        boolean isRoomExist = false;

        switch (from) {
            case chat:
            case setting:
                RealmRegisteredInfo user = RealmRegisteredInfo.getRegistrationInfo(realm, mPeerId);
                if (user != null) {
                    new RequestUserAvatarGetList().userAvatarGetList(mPeerId);
                    isRoomExist = true;
                }
                break;
            case group:
                RealmRoom roomGroup = realm.where(RealmRoom.class).equalTo(RealmRoomFields.ID, mPeerId).findFirst();
                if (roomGroup != null) {
                    new RequestGroupAvatarGetList().groupAvatarGetList(mPeerId);
                    isRoomExist = true;
                    roleGroup = roomGroup.getGroupRoom().getRole();
                }
                break;
            case channel:
                RealmRoom roomChannel = realm.where(RealmRoom.class).equalTo(RealmRoomFields.ID, mPeerId).findFirst();
                if (roomChannel != null) {
                    new RequestChannelAvatarGetList().channelAvatarGetList(mPeerId);
                    isRoomExist = true;
                    roleChannel = roomChannel.getChannelRoom().getRole();
                }
                break;
        }

        if (isRoomExist) {

            avatarList = realm.where(RealmAvatar.class).equalTo(RealmAvatarFields.OWNER_ID, mPeerId).findAll().sort(RealmAvatarFields.ID, Sort.DESCENDING);
            avatarList.addChangeListener(new RealmChangeListener<RealmResults<RealmAvatar>>() {
                @Override
                public void onChange(RealmResults<RealmAvatar> element) {

                    if (avatarListSize != element.size()) {

                        avatarListSize = element.size();

                        viewPager.setAdapter(new FragmentShowAvatars.AdapterViewPager());

                        if (avatarListSize > 0) {
                            viewPager.getAdapter().notifyDataSetChanged();
                            txtImageNumber.setText(viewPager.getCurrentItem() + 1 + " " + G.fragmentActivity.getResources().getString(R.string.of) + " " + avatarListSize);
                            if (HelperCalander.isPersianUnicode) {
                                txtImageNumber.setText(HelperCalander.convertToUnicodeFarsiNumber(txtImageNumber.getText().toString()));
                            }
                        } else {
                            //  G.fragmentActivity.getSupportFragmentManager().beginTransaction().remove(FragmentShowAvatars.this).commit();

                            popBackStackFragment();
                        }
                    }
                }
            });

            avatarListSize = avatarList.size();
        }
    }
 
Example #13
Source File: SubscriptionActivity.java    From redgram-for-reddit with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected RealmChangeListener getRealmSessionChangeListener() {
    return null;
}
 
Example #14
Source File: ProfileActivity.java    From redgram-for-reddit with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected RealmChangeListener getRealmSessionChangeListener() {
    return null;
}
 
Example #15
Source File: FragmentShearedMedia.java    From iGap-Android with GNU Affero General Public License v3.0 4 votes vote down vote up
private void setListener() {

        changeListener = new RealmChangeListener<RealmResults<RealmRoomMessage>>() {
            @Override
            public void onChange(RealmResults<RealmRoomMessage> element) {

                if (isChangeSelectType) {
                    return;
                }

                if (changeSize - element.size() != 0) {

                    mNewList.clear();
                    mNewList.addAll(addTimeToList(element));

                    int position = ((LinearLayoutManager) recyclerView.getLayoutManager()).findFirstVisibleItemPosition();

                    if (adapter instanceof ImageAdapter) {
                        adapter = new ImageAdapter(fragmentActivity, mNewList);
                    } else if (adapter instanceof VideoAdapter) {
                        adapter = new VideoAdapter(fragmentActivity, mNewList);
                    } else if (adapter instanceof VoiceAdapter) {
                        adapter = new VoiceAdapter(fragmentActivity, mNewList);
                    } else if (adapter instanceof GifAdapter) {
                        adapter = new GifAdapter(fragmentActivity, mNewList);
                    } else if (adapter instanceof FileAdapter) {
                        adapter = new FileAdapter(fragmentActivity, mNewList);
                    } else if (adapter instanceof LinkAdapter) {
                        adapter = new LinkAdapter(fragmentActivity, mNewList);
                    }

                    recyclerView.setAdapter(adapter);

                    recyclerView.scrollToPosition(position);

                    listCount = element.size();
                    changeSize = element.size();
                }
            }
        };

        mRealmList.addChangeListener(changeListener);
    }
 
Example #16
Source File: MainActivity.java    From redgram-for-reddit with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected RealmChangeListener getRealmSessionChangeListener() {
    //keep null as
    return realmSessionListener;
}
 
Example #17
Source File: AuthActivity.java    From redgram-for-reddit with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected RealmChangeListener getRealmSessionChangeListener() {
    return null;
}
 
Example #18
Source File: ThreadActivity.java    From redgram-for-reddit with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected RealmChangeListener getRealmSessionChangeListener() {
    return null;
}
 
Example #19
Source File: BaseActivity.java    From redgram-for-reddit with GNU General Public License v3.0 votes vote down vote up
protected abstract RealmChangeListener getRealmSessionChangeListener();