use of net.iGap.module.StructWallpaper 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.module.StructWallpaper in project iGap-Android by KianIranian-STDG.
the class ChatBackgroundViewModel method fillList.
private void fillList(boolean getInfoFromServer) {
if (wList == null)
wList = new ArrayList<>();
wList.clear();
DbManager.getInstance().doRealmTask(realm -> {
RealmWallpaper realmWallpaper = realm.where(RealmWallpaper.class).equalTo("type", ProtoInfoWallpaper.InfoWallpaper.Type.CHAT_BACKGROUND_VALUE).findFirst();
if (realmWallpaper != null) {
Log.wtf(this.getClass().getName(), "realmWallpaper != null");
if (realmWallpaper.getLocalList() != null) {
Log.wtf(this.getClass().getName(), "realmWallpaper.getLocalList() != null");
for (String localPath : realmWallpaper.getLocalList()) {
if (new File(localPath).exists()) {
StructWallpaper _swl = new StructWallpaper();
_swl.setWallpaperType(FragmentChatBackground.WallpaperType.local);
_swl.setPath(localPath);
wList.add(_swl);
loadChatBackgroundImage.postValue(wList);
}
}
}
if (realmWallpaper.getWallPaperList() != null) {
Log.wtf(this.getClass().getName(), "realmWallpaper.getWallPaperList() != null");
for (RealmWallpaperProto wallpaper : realmWallpaper.getWallPaperList()) {
StructWallpaper _swp = new StructWallpaper();
_swp.setWallpaperType(FragmentChatBackground.WallpaperType.proto);
_swp.setProtoWallpaper(realm.copyFromRealm(wallpaper));
wList.add(_swp);
loadChatBackgroundImage.postValue(wList);
}
} else if (getInfoFromServer) {
Log.wtf(this.getClass().getName(), "getInfoFromServer");
long time = realmWallpaper.getLastTimeGetList();
if (time > 0) {
if (time + (2 * 60 * 60 * 1000) < TimeUtils.currentLocalTime()) {
getImageListFromServer();
}
} else {
getImageListFromServer();
}
}
} else {
Log.wtf(this.getClass().getName(), "realmWallpaper == null");
if (getInfoFromServer) {
getImageListFromServer();
}
}
});
}
Aggregations