Search in sources :

Example 1 with OnUserInfoResponse

use of net.iGap.observers.interfaces.OnUserInfoResponse in project iGap-Android by KianIranian-STDG.

the class ViewUserDialogFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    EventManager.getInstance(AccountManager.selectedAccount).addObserver(EventManager.STORY_USER_INFO, this);
    EventManager.getInstance(AccountManager.selectedAccount).addObserver(EventManager.STORY_VIEWS_FETCHED, this);
    userId = new ArrayList<>();
    storyIdList = new ArrayList<>();
    createdAtList = new ArrayList<>();
    displayNameList = new ArrayList<>();
    Collections.sort(userIdList);
    for (int i = 0; i < userIdList.size(); i++) {
        userId.add(userIdList.get(i).userId);
        storyIdList.add(userIdList.get(i).id);
        createdAtList.add(userIdList.get(i).createdTime);
        displayNameList.add(userIdList.get(i).displayName);
    }
    mOffset = userId.size();
    this.storyId = userIdList.get(0).id;
    G.onUserInfoResponse = new OnUserInfoResponse() {

        @Override
        public void onUserInfo(ProtoGlobal.RegisteredUser user, String identity) {
        }

        @Override
        public void onUserInfoTimeOut() {
        }

        @Override
        public void onUserInfoError(int majorCode, int minorCode) {
        }
    };
    recyclerView.setAdapter(listAdapter);
    listAdapter.addRow();
    LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    recyclerView.setLayoutManager(layoutManager);
    EndlessRecyclerViewScrollListener scrollListener = new EndlessRecyclerViewScrollListener(layoutManager) {

        @Override
        public void onLoadMore(int iPage, int totalItemsCount, RecyclerView view) {
            Log.e("fkldsjfklsjjf", "onLoadMore: ");
            if (!storyViewListFetched && mOffset > 0 && userIdList.size() < count) {
                progressBar.setVisibility(View.VISIBLE);
                AbstractObject req = null;
                IG_RPC.Story_Get_Own_Story_Views story_get_own_story_views = new IG_RPC.Story_Get_Own_Story_Views();
                story_get_own_story_views.offset = mOffset;
                story_get_own_story_views.limit = 50;
                req = story_get_own_story_views;
                MessageDataStorage.getInstance(AccountManager.selectedAccount).getRequestManager().sendRequest(req, (response, error) -> {
                    if (error == null) {
                        IG_RPC.Res_Story_Get_Own_Story_Views res = (IG_RPC.Res_Story_Get_Own_Story_Views) response;
                        mOffset += 50;
                        if (res.groupedViews.size() > 0) {
                            MessageDataStorage.getInstance(AccountManager.selectedAccount).updateOwnViews(res.groupedViews);
                        } else if (userIdList.size() >= count) {
                            storyViewListFetched = true;
                        } else {
                            progressBar.setVisibility(View.GONE);
                        }
                    } else {
                        progressBar.setVisibility(View.GONE);
                    }
                });
            }
        }
    };
    recyclerView.addOnScrollListener(scrollListener);
// recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
// private boolean scrollUpdated;
// private boolean scrollingManually;
// private int prevTop;
// private int prevPosition;
// 
// @Override
// public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
// super.onScrollStateChanged(recyclerView, newState);
// scrollingManually = newState == RecyclerView.SCROLL_STATE_DRAGGING;
// }
// 
// @Override
// public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
// super.onScrolled(recyclerView, dx, dy);
// 
// LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
// firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition();
// View view = layoutManager.getChildAt(0);
// if (firstVisibleItemPosition > 0 && view != null) {
// firstVisibleItemPositionOffset = view.getTop();
// }
// 
// if (!storyListFetched) {
// if (mOffset > 0) {
// int lastVisiblePosition = ((LinearLayoutManager) recyclerView.getLayoutManager()).findLastVisibleItemPosition();
// if (lastVisiblePosition + 10 >= mOffset) {
// AbstractObject req = null;
// IG_RPC.Story_Get_Own_Story_Views story_get_own_story_views = new IG_RPC.Story_Get_Own_Story_Views();
// story_get_own_story_views.offset = mOffset;
// story_get_own_story_views.limit = 50;
// req = story_get_own_story_views;
// MessageDataStorage.getInstance(AccountManager.selectedAccount).getRequestManager().sendRequest(req, (response, error) -> {
// if (error == null) {
// IG_RPC.Res_Story_Get_Own_Story_Views res = (IG_RPC.Res_Story_Get_Own_Story_Views) response;
// mOffset += res.groupedViews.size();
// MessageDataStorage.getInstance(AccountManager.selectedAccount).updateOwnViews(res.groupedViews);
// 
// } else {
// }
// });
// }
// }
// }
// 
// int firstVisibleItem = layoutManager.findFirstVisibleItemPosition();
// if (firstVisibleItem != RecyclerView.NO_POSITION) {
// RecyclerView.ViewHolder holder = recyclerView.findViewHolderForAdapterPosition(firstVisibleItem);
// if (holder != null && holder.getAdapterPosition() != 0) {
// int firstViewTop = holder.itemView.getTop();
// boolean goingDown;
// boolean changed = true;
// if (prevPosition == firstVisibleItem) {
// final int topDelta = prevTop - firstViewTop;
// goingDown = firstViewTop < prevTop;
// changed = Math.abs(topDelta) > 1;
// } else {
// goingDown = firstVisibleItem > prevPosition;
// }
// prevPosition = firstVisibleItem;
// prevTop = firstViewTop;
// scrollUpdated = true;
// }
// }
// }
// });
}
Also used : IG_RPC(net.iGap.network.IG_RPC) ProtoGlobal(net.iGap.proto.ProtoGlobal) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) OnUserInfoResponse(net.iGap.observers.interfaces.OnUserInfoResponse) EndlessRecyclerViewScrollListener(net.iGap.module.EndlessRecyclerViewScrollListener) AbstractObject(net.iGap.network.AbstractObject) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 2 with OnUserInfoResponse

use of net.iGap.observers.interfaces.OnUserInfoResponse in project iGap-Android by KianIranian-STDG.

the class RegisterRepository method getUserInfo.

private void getUserInfo() {
    Log.wtf(this.getClass().getName(), "getUserInfo");
    G.onUserInfoResponse = new OnUserInfoResponse() {

        @Override
        public void onUserInfo(final ProtoGlobal.RegisteredUser user, String identity) {
            if (user.getId() == userId) {
                AccountManager.getInstance().updateCurrentNickName(user.getDisplayName());
                AccountManager.getInstance().updatePhoneNumber(String.valueOf(user.getPhone()));
                DbManager.getInstance().doRealmTask(realm -> {
                    realm.executeTransactionAsync(realm1 -> RealmUserInfo.putOrUpdate(realm1, user), () -> G.onUserInfoResponse = null);
                });
                if (newUser) {
                    goToSyncContactPageForNewUser.postValue(userId);
                } else {
                    goToMainPage.postValue(new GoToMainFromRegister(forgetTwoStepVerification, userId));
                }
            }
        }

        @Override
        public void onUserInfoTimeOut() {
            requestUserInfo();
        }

        @Override
        public void onUserInfoError(int majorCode, int minorCode) {
        }
    };
}
Also used : MutableLiveData(androidx.lifecycle.MutableLiveData) WebSocketClient(net.iGap.WebSocketClient) OnReceiveInfoLocation(net.iGap.observers.interfaces.OnReceiveInfoLocation) RequestInfoLocation(net.iGap.request.RequestInfoLocation) GoToMainFromRegister(net.iGap.model.GoToMainFromRegister) AccountManager(net.iGap.module.accountManager.AccountManager) TwoStepVerificationVerifyPassword(net.iGap.observers.interfaces.TwoStepVerificationVerifyPassword) ProtoUserVerify(net.iGap.proto.ProtoUserVerify) OnUserRegistration(net.iGap.observers.interfaces.OnUserRegistration) RequestUserLogin(net.iGap.request.RequestUserLogin) OnUserProfileSetRepresentative(net.iGap.observers.interfaces.OnUserProfileSetRepresentative) RequestUserProfileSetRepresentative(net.iGap.request.RequestUserProfileSetRepresentative) G(net.iGap.G) OnUserInfoResponse(net.iGap.observers.interfaces.OnUserInfoResponse) RealmUserInfo(net.iGap.realm.RealmUserInfo) LocationModel(net.iGap.model.LocationModel) Handler(android.os.Handler) TwoStepVerificationGetPasswordDetail(net.iGap.observers.interfaces.TwoStepVerificationGetPasswordDetail) RequestInfoPage(net.iGap.request.RequestInfoPage) OnUserVerification(net.iGap.observers.interfaces.OnUserVerification) RequestWrapper(net.iGap.request.RequestWrapper) RequestUserInfo(net.iGap.request.RequestUserInfo) Log(android.util.Log) RequestUserProfileSetNickname(net.iGap.request.RequestUserProfileSetNickname) UserPasswordDetail(net.iGap.model.UserPasswordDetail) ProtoUserRegister(net.iGap.proto.ProtoUserRegister) HelperTracker(net.iGap.helper.HelperTracker) BuildConfig(net.iGap.BuildConfig) SingleLiveEvent(net.iGap.module.SingleLiveEvent) RequestUserTwoStepVerificationGetPasswordDetail(net.iGap.request.RequestUserTwoStepVerificationGetPasswordDetail) BotInit(net.iGap.module.BotInit) RealmAvatar(net.iGap.realm.RealmAvatar) OnInfoCountryResponse(net.iGap.observers.interfaces.OnInfoCountryResponse) List(java.util.List) RequestInfoCountry(net.iGap.request.RequestInfoCountry) HelperString(net.iGap.helper.HelperString) ProtoGlobal(net.iGap.proto.ProtoGlobal) RequestQueue(net.iGap.request.RequestQueue) OnUserProfileSetNickNameResponse(net.iGap.observers.interfaces.OnUserProfileSetNickNameResponse) ProtoRequest(net.iGap.proto.ProtoRequest) RequestUserTwoStepVerificationVerifyPassword(net.iGap.request.RequestUserTwoStepVerificationVerifyPassword) NotNull(org.jetbrains.annotations.NotNull) DbManager(net.iGap.module.accountManager.DbManager) OnUserLogin(net.iGap.observers.interfaces.OnUserLogin) OnUserInfoResponse(net.iGap.observers.interfaces.OnUserInfoResponse) GoToMainFromRegister(net.iGap.model.GoToMainFromRegister) ProtoGlobal(net.iGap.proto.ProtoGlobal) HelperString(net.iGap.helper.HelperString)

Example 3 with OnUserInfoResponse

use of net.iGap.observers.interfaces.OnUserInfoResponse in project iGap-Android by KianIranian-STDG.

the class HelperGetOwnerInfo method checkUserExist.

private static void checkUserExist(long userId, final Listener listener) {
    DbManager.getInstance().doRealmTask(realm -> {
        RealmRegisteredInfo registeredInfo = RealmRegisteredInfo.getRegistrationInfo(realm, userId);
        if (registeredInfo == null) {
            G.onUserInfoResponse = new OnUserInfoResponse() {

                @Override
                public void onUserInfo(ProtoGlobal.RegisteredUser user, String identity) {
                    if (listener != null) {
                        listener.OnResponse();
                    }
                }

                @Override
                public void onUserInfoTimeOut() {
                }

                @Override
                public void onUserInfoError(int majorCode, int minorCode) {
                }
            };
            new RequestUserInfo().userInfo(userId);
        } else {
            if (listener != null) {
                listener.OnResponse();
            }
        }
    });
}
Also used : OnUserInfoResponse(net.iGap.observers.interfaces.OnUserInfoResponse) RequestUserInfo(net.iGap.request.RequestUserInfo) ProtoGlobal(net.iGap.proto.ProtoGlobal) RealmRegisteredInfo(net.iGap.realm.RealmRegisteredInfo)

Example 4 with OnUserInfoResponse

use of net.iGap.observers.interfaces.OnUserInfoResponse in project iGap-Android by KianIranian-STDG.

the class HelperPublicMethod method getUserInfo.

private static void getUserInfo(final long peerId, final long roomId, final OnComplete onComplete, final OnError onError) {
    G.onUserInfoResponse = new OnUserInfoResponse() {

        @Override
        public void onUserInfo(final ProtoGlobal.RegisteredUser user, String identity) {
            if (user.getId() == peerId) {
                G.handler.post(new Runnable() {

                    @Override
                    public void run() {
                        DbManager.getInstance().doRealmTask(realm -> {
                            realm.executeTransactionAsync(new Realm.Transaction() {

                                @Override
                                public void execute(Realm realm) {
                                    RealmRegisteredInfo.putOrUpdate(realm, user);
                                }
                            }, () -> {
                                try {
                                    if (onComplete != null) {
                                        onComplete.complete();
                                    }
                                    goToRoom(roomId, peerId);
                                    G.onUserInfoResponse = null;
                                } catch (IllegalStateException e) {
                                    e.printStackTrace();
                                }
                            });
                        });
                    }
                });
            }
        }

        @Override
        public void onUserInfoTimeOut() {
            if (onError != null) {
                onError.error();
            }
        }

        @Override
        public void onUserInfoError(int majorCode, int minorCode) {
            if (onError != null) {
                onError.error();
            }
        }
    };
    new RequestUserInfo().userInfo(peerId);
}
Also used : OnUserInfoResponse(net.iGap.observers.interfaces.OnUserInfoResponse) RequestUserInfo(net.iGap.request.RequestUserInfo) ProtoGlobal(net.iGap.proto.ProtoGlobal) Realm(io.realm.Realm)

Aggregations

OnUserInfoResponse (net.iGap.observers.interfaces.OnUserInfoResponse)4 ProtoGlobal (net.iGap.proto.ProtoGlobal)4 RequestUserInfo (net.iGap.request.RequestUserInfo)3 Handler (android.os.Handler)1 Log (android.util.Log)1 MutableLiveData (androidx.lifecycle.MutableLiveData)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 Realm (io.realm.Realm)1 List (java.util.List)1 BuildConfig (net.iGap.BuildConfig)1 G (net.iGap.G)1 WebSocketClient (net.iGap.WebSocketClient)1 HelperString (net.iGap.helper.HelperString)1 HelperTracker (net.iGap.helper.HelperTracker)1 GoToMainFromRegister (net.iGap.model.GoToMainFromRegister)1 LocationModel (net.iGap.model.LocationModel)1 UserPasswordDetail (net.iGap.model.UserPasswordDetail)1 BotInit (net.iGap.module.BotInit)1 EndlessRecyclerViewScrollListener (net.iGap.module.EndlessRecyclerViewScrollListener)1