use of net.iGap.realm.RealmAvatar in project iGap-Android by KianIranian-STDG.
the class AdapterChatBackground method onBindViewHolder.
@Override
public void onBindViewHolder(@NotNull RecyclerView.ViewHolder holder, int position) {
if (holder instanceof ViewHolderImage) {
if (position == 0) {
((ViewHolderImage) holder).messageProgress.setVisibility(View.GONE);
((ViewHolderImage) holder).imageView.setImageResource(R.drawable.add_chat_background_setting);
} else {
((ViewHolderImage) holder).messageProgress.setVisibility(View.VISIBLE);
((ViewHolderImage) holder).imageView.setImageDrawable(null);
StructWallpaper wallpaper = mList.get(position - 1);
String path = "";
if (wallpaper.getWallpaperType() == FragmentChatBackground.WallpaperType.proto) {
RealmAttachment pf = wallpaper.getProtoWallpaper().getFile();
// final String path = G.context.getExternalFilesDir(Environment.DIRECTORY_PICTURES) + "/" + pf.getCacheId() + "_" + pf.getName();
path = pf.getLocalFilePath() != null ? pf.getLocalFilePath() : "";
File file = new File(path);
if (file.exists()) {
G.imageLoader.displayImage(AndroidUtils.suitablePath(path), ((ViewHolderImage) holder).imageView);
} else {
path = pf.getLocalThumbnailPath() != null ? pf.getLocalThumbnailPath() : "";
file = new File(path);
if (file.exists()) {
G.imageLoader.displayImage(AndroidUtils.suitablePath(path), ((ViewHolderImage) holder).imageView);
} else {
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);
}
});
G.runOnUiThread(() -> G.handler.post(() -> {
if (((ViewHolderImage) holder).imageView != null) {
G.imageLoader.displayImage(AndroidUtils.suitablePath(filepath), ((ViewHolderImage) holder).imageView);
}
}));
}
});
}
}
} else {
G.imageLoader.displayImage(AndroidUtils.suitablePath(wallpaper.getPath()), ((ViewHolderImage) holder).imageView);
}
String bigImagePath;
bigImagePath = path;
if (new File(bigImagePath).exists()) {
((ViewHolderImage) holder).messageProgress.setVisibility(View.GONE);
} else {
((ViewHolderImage) holder).messageProgress.setVisibility(View.VISIBLE);
startDownload(position - 1, ((ViewHolderImage) holder).messageProgress);
}
}
holder.itemView.setOnClickListener(v -> {
if (position == 0) {
onImageClick.onAddImageClick();
} else {
onImageClick.onClick(type, holder.getAdapterPosition() - 1);
}
});
} else if (holder instanceof ViewHolderSolid) {
((ViewHolderSolid) holder).cardView.setCardBackgroundColor(Color.parseColor(solidColorList.get(position)));
holder.itemView.setOnClickListener(v -> onImageClick.onClick(type, holder.getAdapterPosition()));
}
}
use of net.iGap.realm.RealmAvatar in project iGap-Android by KianIranian-STDG.
the class FragmentiGapMap method avatarMark.
public static Drawable avatarMark(long userId, MarkerColor markerColor) {
Bitmap bitmap = DbManager.getInstance().doRealmTask(realm -> {
String pathName = "";
Bitmap bitmap1 = null;
for (RealmAvatar avatar : realm.where(RealmAvatar.class).equalTo("ownerId", userId).findAll().sort("id", Sort.DESCENDING)) {
if (avatar.getFile() != null) {
pathName = avatar.getFile().getLocalFilePath();
if (pathName == null) {
pathName = avatar.getFile().getLocalThumbnailPath();
}
break;
}
}
if (pathName == null || pathName.isEmpty()) {
bitmap1 = getInitials(realm, userId);
} else {
try {
File imgFile = new File(pathName);
bitmap1 = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
} catch (OutOfMemoryError e) {
try {
File imgFile = new File(pathName);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;
bitmap1 = BitmapFactory.decodeFile(imgFile.getAbsolutePath(), options);
} catch (OutOfMemoryError e1) {
try {
File imgFile = new File(pathName);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 4;
bitmap1 = BitmapFactory.decodeFile(imgFile.getAbsolutePath(), options);
} catch (OutOfMemoryError e2) {
e2.printStackTrace();
}
}
}
if (bitmap1 == null) {
bitmap1 = getInitials(realm, userId);
}
}
return bitmap1;
});
return new BitmapDrawable(G.context.getResources(), drawAvatar(bitmap, markerColor, userId == AccountManager.getInstance().getCurrentUser().getId()));
}
use of net.iGap.realm.RealmAvatar in project iGap-Android by KianIranian-STDG.
the class CallService method getAvatarBitmap.
private Bitmap getAvatarBitmap() {
return DbManager.getInstance().doRealmTask(realm -> {
String avatarPath = null;
RealmAvatar realmAvatarPath = RealmAvatar.getLastAvatar(userId, realm);
if (realmAvatarPath != null) {
if (realmAvatarPath.getFile().isFileExistsOnLocal()) {
avatarPath = realmAvatarPath.getFile().getLocalFilePath();
} else if (realmAvatarPath.getFile().isThumbnailExistsOnLocal()) {
avatarPath = realmAvatarPath.getFile().getLocalThumbnailPath();
}
}
if (avatarPath != null) {
try {
BitmapFactory.Options option = new BitmapFactory.Options();
option.outHeight = 64;
option.outWidth = 64;
return BitmapFactory.decodeFile(avatarPath, option);
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
});
}
use of net.iGap.realm.RealmAvatar in project iGap-Android by KianIranian-STDG.
the class UserProfileViewModel method getProfileWallpaper.
private void getProfileWallpaper(Realm realm) {
try {
RealmWallpaper realmWallpaper = realm.where(RealmWallpaper.class).equalTo("type", ProtoInfoWallpaper.InfoWallpaper.Type.PROFILE_WALLPAPER_VALUE).findFirst();
if (realmWallpaper != null) {
if (realmWallpaper.getWallPaperList() != null && realmWallpaper.getWallPaperList().size() > 0) {
RealmAttachment pf = realmWallpaper.getWallPaperList().get(realmWallpaper.getWallPaperList().size() - 1).getFile();
String bigImagePath = G.context.getExternalFilesDir(Environment.DIRECTORY_PICTURES).getAbsolutePath() + "/" + pf.getCacheId() + "_" + DownloadObject.extractMime(pf.getName());
if (!new File(bigImagePath).exists()) {
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(db -> {
for (RealmAvatar realmAvatar1 : db.where(RealmAvatar.class).equalTo("file.token", fileToken).findAll()) {
realmAvatar1.getFile().setLocalFilePath(filepath);
}
});
changeUserProfileWallpaperPath.postValue(bigImagePath);
}
});
} else {
changeUserProfileWallpaperPath.postValue(bigImagePath);
}
} else {
getProfileWallpaperFromServer();
}
} else {
getProfileWallpaperFromServer();
}
} catch (ArrayIndexOutOfBoundsException e) {
e.printStackTrace();
} catch (NullPointerException e2) {
e2.printStackTrace();
} catch (Exception e3) {
e3.printStackTrace();
}
}
use of net.iGap.realm.RealmAvatar in project iGap-Android by KianIranian-STDG.
the class MessageDataStorage method putUserAvatar.
public void putUserAvatar(long roomId, ProtoGlobal.Avatar avatar) {
storageQueue.postRunnable(() -> {
FileLog.i(TAG, "putUserAvatar: " + roomId);
try {
database.beginTransaction();
RealmAvatar realmAvatar = database.where(RealmAvatar.class).equalTo("id", avatar.getId()).findFirst();
if (realmAvatar == null) {
realmAvatar = database.createObject(RealmAvatar.class, avatar.getId());
}
realmAvatar.setOwnerId(roomId);
realmAvatar.setFile(RealmAttachment.build(database, avatar.getFile(), AttachmentFor.AVATAR, null));
database.commitTransaction();
} catch (Exception e) {
FileLog.e(e);
}
});
}
Aggregations