use of net.iGap.request.RequestUserInfo in project iGap-Android by KianIranian-STDG.
the class MessageDataStorage method userAddViewStory.
public void userAddViewStory(long storyId, int viewdAt, long viewdUserId, long storyOwnerUserId) {
storageQueue.postRunnable(() -> {
FileLog.i(TAG, "deleteUserStoryId " + storyId);
try {
database.beginTransaction();
RealmRegisteredInfo realmRegisteredInfo = database.where(RealmRegisteredInfo.class).equalTo("id", viewdUserId).findFirst();
RealmStoryProto realmStoryProto = database.where(RealmStoryProto.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("isForReply", false).equalTo("storyId", storyId).findFirst();
if (realmStoryProto != null) {
realmStoryProto.setSeen(true);
realmStoryProto.setViewCount(realmStoryProto.getViewCount() + 1);
boolean isExist = false;
RealmStoryViewInfo realmStoryViewInfo;
realmStoryViewInfo = database.where(RealmStoryViewInfo.class).equalTo("id", storyId).equalTo("userId", viewdUserId).findFirst();
if (realmStoryViewInfo == null) {
realmStoryViewInfo = database.createObject(RealmStoryViewInfo.class);
} else {
isExist = true;
}
if (realmRegisteredInfo == null) {
realmStoryViewInfo.setDisplayName("");
new RequestUserInfo().userInfo(viewdUserId);
} else {
realmStoryViewInfo.setProfileColor(realmRegisteredInfo.getColor());
realmStoryViewInfo.setDisplayName(realmRegisteredInfo.getDisplayName());
}
realmStoryViewInfo.setId(storyId);
realmStoryViewInfo.setUserId(viewdUserId);
realmStoryViewInfo.setCreatedTime(viewdAt);
if (isExist) {
realmStoryProto.getRealmStoryViewInfos().remove(realmStoryViewInfo);
}
realmStoryProto.getRealmStoryViewInfos().add(realmStoryViewInfo);
isExist = false;
}
RealmStory realmStory = database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("userId", storyOwnerUserId).findFirst();
if (realmStory != null) {
int counter = 0;
for (int i = 0; i < realmStory.getRealmStoryProtos().size(); i++) {
if (realmStory.getRealmStoryProtos().get(i).isSeen()) {
counter++;
}
}
if (counter == realmStory.getRealmStoryProtos().size()) {
RealmStory userRealmStory = database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("userId", storyOwnerUserId).findFirst();
if (userRealmStory != null) {
userRealmStory.setSeenAll(true);
}
}
}
database.commitTransaction();
G.runOnUiThread(() -> getEventManager().postEvent(EventManager.STORY_USER_ADD_VIEW));
} catch (Exception e) {
FileLog.e(e);
}
});
}
use of net.iGap.request.RequestUserInfo 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);
}
use of net.iGap.request.RequestUserInfo in project iGap-Android by KianIranian-STDG.
the class AvatarHandler method getAvatarImage.
/**
* check avatar in Realm and download if needed
*/
private void getAvatarImage(BaseParam baseParam, Realm _realm, boolean requestUserInfo) {
RealmAvatar realmAvatar = getLastAvatar(baseParam.avatarOwnerId, _realm);
if (realmAvatar == null && requestUserInfo && RequestManager.getInstance(AccountManager.selectedAccount).isUserLogin()) {
new RequestUserInfo().userInfoWithCallBack(new OnComplete() {
@Override
public void complete(boolean result, String messageOne, String MessageTwo) {
getAvatar(baseParam, false);
}
}, baseParam.avatarOwnerId, "" + baseParam.avatarOwnerId);
}
if (realmAvatar == null && baseParam instanceof ParamWithAvatarType && ((ParamWithAvatarType) baseParam).registeredUser != null) {
insertRegisteredInfoToDB(((ParamWithAvatarType) baseParam).registeredUser, _realm);
realmAvatar = getLastAvatar(baseParam.avatarOwnerId, _realm);
}
if (realmAvatar != null) {
if (baseParam.showMain && realmAvatar.getFile().isFileExistsOnLocal()) {
final String path = realmAvatar.getFile().getLocalFilePath();
notifyAll(path, baseParam.avatarOwnerId, true, realmAvatar.getFile().getId(), realmAvatar.getId());
} else if (realmAvatar.getFile().isThumbnailExistsOnLocal()) {
final String path = realmAvatar.getFile().getLocalThumbnailPath();
notifyAll(path, baseParam.avatarOwnerId, false, realmAvatar.getFile().getId(), realmAvatar.getId());
} else {
DownloadObject object = DownloadObject.createForAvatar(realmAvatar.getFile());
if (object != null) {
Downloader.getInstance(AccountManager.selectedAccount).download(object, arg -> {
if (arg.status == Status.SUCCESS && arg.data != null) {
String filepath = arg.data.getFilePath();
String fileToken = arg.data.getToken();
if (!(new File(filepath).exists())) {
HelperLog.getInstance().setErrorLog(new Exception("File Dont Exist After Download !!" + filepath));
}
final ArrayList<Long> ownerIdList = new ArrayList<>();
final ArrayList<Long> fileIdList = new ArrayList<>();
final ArrayList<Long> avatarIdList = new ArrayList<>();
DbManager.getInstance().doRealmTransaction(realm -> {
for (RealmAvatar realmAvatar1 : realm.where(RealmAvatar.class).equalTo("file.token", fileToken).findAll()) {
realmAvatar1.getFile().setLocalThumbnailPath(filepath);
ownerIdList.add(realmAvatar1.getOwnerId());
fileIdList.add(realmAvatar1.getFile().getId());
avatarIdList.add(realmAvatar1.getId());
}
});
for (int i = 0; i < ownerIdList.size(); i++) {
AvatarHandler.this.notifyAll(filepath, ownerIdList.get(i), false, fileIdList.get(i), avatarIdList.get(i));
}
ownerIdList.clear();
fileIdList.clear();
avatarIdList.clear();
}
});
}
}
} else if (baseParam instanceof ParamWithAvatarType) {
String[] initials = showInitials(baseParam.avatarOwnerId, ((ParamWithAvatarType) baseParam).avatarType);
if (initials == null) {
getAvatarAfterTime(baseParam);
}
}
}
use of net.iGap.request.RequestUserInfo in project iGap-Android by KianIranian-STDG.
the class AvatarHandler method getAvatar.
public void getAvatar(BaseParam baseParam, boolean requestUserInfo) {
if (Looper.myLooper() != Looper.getMainLooper()) {
G.handler.post(new Runnable() {
@Override
public void run() {
getAvatar(baseParam);
}
});
return;
}
if (baseParam.imageView == null || baseParam.avatarOwnerId == null) {
return;
}
baseParam.imageView.setTag(baseParam.avatarOwnerId);
synchronized (mutex) {
Bitmap cacheValue = null;
if (baseParam.useCache) {
CacheValue mainCache = avatarCacheMain.get(baseParam.avatarOwnerId);
CacheValue thumbnailCache = avatarCache.get(baseParam.avatarOwnerId);
if (baseParam.showMain) {
if (mainCache == null) {
if (thumbnailCache != null) {
cacheValue = thumbnailCache.bitmap;
}
} else {
if (thumbnailCache == null) {
cacheValue = mainCache.bitmap;
} else {
if (mainCache.avatarId >= thumbnailCache.avatarId) {
cacheValue = mainCache.bitmap;
} else {
cacheValue = thumbnailCache.bitmap;
}
}
}
} else {
if (thumbnailCache != null)
cacheValue = thumbnailCache.bitmap;
}
}
if (cacheValue == null) {
if (baseParam instanceof ParamWithAvatarType) {
String[] initialsStart = showInitials(baseParam.avatarOwnerId, ((ParamWithAvatarType) baseParam).avatarType);
if (initialsStart != null) {
cacheValue = HelperImageBackColor.drawAlphabetOnPicture((int) context.getResources().getDimension(((ParamWithAvatarType) baseParam).avatarSize), initialsStart[0], initialsStart[1]);
}
} else if (baseParam instanceof ParamWithInitBitmap) {
cacheValue = ((ParamWithInitBitmap) baseParam).initAvatar;
}
}
baseParam.imageView.setImageBitmap(cacheValue);
if (baseParam.onInitSet != null)
baseParam.onInitSet.OnInitSet();
ImageHashValue imageHashValue = imageViewHashValue.get(baseParam.imageView);
if (imageHashValue != null) {
HashSet<ImageView> imageViews = avatarHashImages.get(imageHashValue.avatarOwnerId);
if (imageViews != null) {
imageViews.remove(baseParam.imageView);
avatarHashImages.put(imageHashValue.avatarOwnerId, imageViews);
}
}
imageViewHashValue.put(baseParam.imageView, new ImageHashValue(baseParam.avatarOwnerId, baseParam.onAvatarChange));
HashSet<ImageView> imageViews = avatarHashImages.get(baseParam.avatarOwnerId);
if (imageViews == null) {
imageViews = new HashSet<>();
}
imageViews.add(baseParam.imageView);
avatarHashImages.put(baseParam.avatarOwnerId, imageViews);
}
LooperThreadHelper.getInstance().getHandler().post(new Runnable() {
@Override
public void run() {
DbManager.getInstance().doRealmTask(realm -> {
getAvatarImage(baseParam, realm, requestUserInfo);
});
}
});
}
Aggregations