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;
// }
// }
// }
// });
}
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) {
}
};
}
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();
}
}
});
}
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);
}
Aggregations