Search in sources :

Example 16 with RequestUserInfo

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

Example 17 with RequestUserInfo

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);
}
Also used : OnUserInfoResponse(net.iGap.observers.interfaces.OnUserInfoResponse) RequestUserInfo(net.iGap.request.RequestUserInfo) ProtoGlobal(net.iGap.proto.ProtoGlobal) Realm(io.realm.Realm)

Example 18 with RequestUserInfo

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);
        }
    }
}
Also used : AndroidUtils(net.iGap.module.AndroidUtils) OnAvatarAdd(net.iGap.observers.interfaces.OnAvatarAdd) AccountManager(net.iGap.module.accountManager.AccountManager) ImageView(android.widget.ImageView) BitmapFactory(android.graphics.BitmapFactory) HashMap(java.util.HashMap) G(net.iGap.G) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Handler(android.os.Handler) Looper(android.os.Looper) RequestUserInfo(net.iGap.request.RequestUserInfo) HelperImageBackColor(net.iGap.helper.HelperImageBackColor) Realm(io.realm.Realm) Status(net.iGap.module.downloader.Status) OnComplete(net.iGap.observers.interfaces.OnComplete) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) RealmRoom(net.iGap.realm.RealmRoom) IOException(java.io.IOException) Downloader(net.iGap.module.downloader.Downloader) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) RequestManager(net.iGap.network.RequestManager) File(java.io.File) RealmAvatar(net.iGap.realm.RealmAvatar) HelperLog(net.iGap.helper.HelperLog) RealmRegisteredInfo(net.iGap.realm.RealmRegisteredInfo) RealmAvatar.getLastAvatar(net.iGap.realm.RealmAvatar.getLastAvatar) Bitmap(android.graphics.Bitmap) LooperThreadHelper(net.iGap.helper.LooperThreadHelper) ProtoGlobal(net.iGap.proto.ProtoGlobal) G.context(net.iGap.G.context) DbManager(net.iGap.module.accountManager.DbManager) Collections(java.util.Collections) DownloadObject(net.iGap.module.downloader.DownloadObject) DownloadObject(net.iGap.module.downloader.DownloadObject) ArrayList(java.util.ArrayList) OnComplete(net.iGap.observers.interfaces.OnComplete) RealmAvatar(net.iGap.realm.RealmAvatar) IOException(java.io.IOException) RequestUserInfo(net.iGap.request.RequestUserInfo) File(java.io.File)

Example 19 with RequestUserInfo

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);
            });
        }
    });
}
Also used : AndroidUtils(net.iGap.module.AndroidUtils) OnAvatarAdd(net.iGap.observers.interfaces.OnAvatarAdd) AccountManager(net.iGap.module.accountManager.AccountManager) ImageView(android.widget.ImageView) BitmapFactory(android.graphics.BitmapFactory) HashMap(java.util.HashMap) G(net.iGap.G) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Handler(android.os.Handler) Looper(android.os.Looper) RequestUserInfo(net.iGap.request.RequestUserInfo) HelperImageBackColor(net.iGap.helper.HelperImageBackColor) Realm(io.realm.Realm) Status(net.iGap.module.downloader.Status) OnComplete(net.iGap.observers.interfaces.OnComplete) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) RealmRoom(net.iGap.realm.RealmRoom) IOException(java.io.IOException) Downloader(net.iGap.module.downloader.Downloader) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) RequestManager(net.iGap.network.RequestManager) File(java.io.File) RealmAvatar(net.iGap.realm.RealmAvatar) HelperLog(net.iGap.helper.HelperLog) RealmRegisteredInfo(net.iGap.realm.RealmRegisteredInfo) RealmAvatar.getLastAvatar(net.iGap.realm.RealmAvatar.getLastAvatar) Bitmap(android.graphics.Bitmap) LooperThreadHelper(net.iGap.helper.LooperThreadHelper) ProtoGlobal(net.iGap.proto.ProtoGlobal) G.context(net.iGap.G.context) DbManager(net.iGap.module.accountManager.DbManager) Collections(java.util.Collections) DownloadObject(net.iGap.module.downloader.DownloadObject) Bitmap(android.graphics.Bitmap) ImageView(android.widget.ImageView)

Aggregations

RequestUserInfo (net.iGap.request.RequestUserInfo)19 ProtoGlobal (net.iGap.proto.ProtoGlobal)9 RealmRegisteredInfo (net.iGap.realm.RealmRegisteredInfo)9 G (net.iGap.G)7 DbManager (net.iGap.module.accountManager.DbManager)7 AccountManager (net.iGap.module.accountManager.AccountManager)6 Handler (android.os.Handler)5 Realm (io.realm.Realm)4 HelperString (net.iGap.helper.HelperString)4 OnComplete (net.iGap.observers.interfaces.OnComplete)4 Looper (android.os.Looper)3 Log (android.util.Log)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 OnUserInfoResponse (net.iGap.observers.interfaces.OnUserInfoResponse)3 RealmAvatar (net.iGap.realm.RealmAvatar)3 RealmRoom (net.iGap.realm.RealmRoom)3 Bitmap (android.graphics.Bitmap)2 BitmapFactory (android.graphics.BitmapFactory)2 AsyncTask (android.os.AsyncTask)2