Search in sources :

Example 6 with RealmAvatar

use of net.iGap.realm.RealmAvatar 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 7 with RealmAvatar

use of net.iGap.realm.RealmAvatar in project iGap-Android by KianIranian-STDG.

the class AdapterChatBackground method startDownload.

private void startDownload(final int position, final MessageProgress messageProgress) {
    if (mList.get(position).getProtoWallpaper() != null) {
        messageProgress.withDrawable(R.drawable.ic_cancel, true);
        RealmAttachment pf = mList.get(position).getProtoWallpaper().getFile();
        messageProgress.withOnProgress(new OnProgress() {

            @Override
            public void onProgressFinished() {
                messageProgress.post(new Runnable() {

                    @Override
                    public void run() {
                        messageProgress.withProgress(0);
                        messageProgress.setVisibility(View.GONE);
                        notifyItemChanged(position);
                    }
                });
            }
        });
        DownloadObject downloadObject = DownloadObject.createForRoomMessage(AttachmentObject.create(pf), ProtoGlobal.RoomMessageType.IMAGE.getNumber());
        Downloader.getInstance(AccountManager.selectedAccount).download(downloadObject, 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));
                }
                DbManager.getInstance().doRealmTransaction(realm -> {
                    for (RealmAvatar realmAvatar1 : realm.where(RealmAvatar.class).equalTo("file.token", fileToken).findAll()) {
                        realmAvatar1.getFile().setLocalFilePath(filepath);
                    }
                });
            } else if (arg.status == Status.LOADING && arg.data != null) {
                messageProgress.post(new Runnable() {

                    @Override
                    public void run() {
                        messageProgress.withProgress(arg.data.getProgress());
                    }
                });
            } else if (arg.status == Status.ERROR) {
                messageProgress.post(new Runnable() {

                    @Override
                    public void run() {
                        messageProgress.withProgress(0);
                        messageProgress.withDrawable(R.drawable.ic_download, true);
                    }
                });
            }
        });
    }
}
Also used : DownloadObject(net.iGap.module.downloader.DownloadObject) RealmAttachment(net.iGap.realm.RealmAttachment) OnProgress(net.iGap.messageprogress.OnProgress) HelperDownloadFile(net.iGap.helper.HelperDownloadFile) File(java.io.File) RealmAvatar(net.iGap.realm.RealmAvatar)

Aggregations

RealmAvatar (net.iGap.realm.RealmAvatar)7 File (java.io.File)5 DownloadObject (net.iGap.module.downloader.DownloadObject)4 BitmapFactory (android.graphics.BitmapFactory)3 HelperDownloadFile (net.iGap.helper.HelperDownloadFile)3 RealmAttachment (net.iGap.realm.RealmAttachment)3 Bitmap (android.graphics.Bitmap)2 G (net.iGap.G)2 HelperLog (net.iGap.helper.HelperLog)2 OnProgress (net.iGap.messageprogress.OnProgress)2 AndroidUtils (net.iGap.module.AndroidUtils)2 AccountManager (net.iGap.module.accountManager.AccountManager)2 DbManager (net.iGap.module.accountManager.DbManager)2 Downloader (net.iGap.module.downloader.Downloader)2 Status (net.iGap.module.downloader.Status)2 ProtoGlobal (net.iGap.proto.ProtoGlobal)2 Color (android.graphics.Color)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 Environment (android.os.Environment)1 Handler (android.os.Handler)1