use of net.iGap.realm.RealmAttachment in project iGap-Android by KianIranian-STDG.
the class MessageDataStorage method deleteFileFromStorage.
public void deleteFileFromStorage(MessageObject message, DatabaseDelegate delegate) {
storageQueue.postRunnable(() -> {
FileLog.i(TAG, "deleteFileFromStorage: " + message.id);
try {
database.beginTransaction();
RealmAttachment attachment = database.where(RealmAttachment.class).equalTo("token", message.attachment.token).findFirst();
if (attachment != null) {
attachment.setLocalFilePath("");
}
database.commitTransaction();
G.runOnUiThread(() -> delegate.run(null));
} catch (Exception e) {
FileLog.e(e);
}
});
}
use of net.iGap.realm.RealmAttachment in project iGap-Android by KianIranian-STDG.
the class MessageDataStorage method setAttachmentFilePath.
public void setAttachmentFilePath(String cacheId, String absolutePath, boolean isThumb) {
storageQueue.postRunnable(() -> {
FileLog.i(TAG, "setAttachmentFilePath: " + cacheId + " " + absolutePath);
try {
database.beginTransaction();
RealmResults<RealmAttachment> attachments = database.where(RealmAttachment.class).equalTo("cacheId", cacheId).findAll();
for (RealmAttachment attachment : attachments) {
if (isThumb) {
attachment.setLocalThumbnailPath(absolutePath);
} else {
attachment.setLocalFilePath(absolutePath);
}
}
database.commitTransaction();
} catch (Exception e) {
FileLog.e(e);
}
});
}
use of net.iGap.realm.RealmAttachment 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.RealmAttachment in project iGap-Android by KianIranian-STDG.
the class MyStatusStoryListFragment method sendRoomStory.
private void sendRoomStory(List<String> paths, ArrayList<StructBottomSheet> itemGalleryList, long roomId, int listMode, String roomTitle) {
G.runOnUiThread(() -> {
actionButtonsRootView.setVisibility(View.GONE);
progressBar.setVisibility(View.VISIBLE);
});
objectsCounter = 0;
if (paths.size() > 1) {
HttpUploader.isRoomMultiUpload = true;
}
for (int i = 0; i < paths.size(); i++) {
long storyId = SUID.id().get();
long lastUploadedStoryId = storyId + 1L;
int[] imageDimens = { 0, 0 };
long attachementId = SUID.id().get();
imageDimens = AndroidUtils.getImageDimens(paths.get(i));
RealmAttachment realmAttachment = getMessageDataStorage().createRealmObject(paths.get(i), imageDimens, attachementId);
StoryObject storyObject = new StoryObject();
storyObject.isSeen = false;
storyObject.realmAttachment = realmAttachment;
storyObject.userId = AccountManager.getInstance().getCurrentUser().getId();
storyObject.roomId = roomId;
storyObject.isForRoom = true;
storyObject.sessionId = AccountManager.getInstance().getCurrentUser().getId();
storyObject.displayName = roomTitle;
storyObject.createdAt = System.currentTimeMillis();
storyObject.caption = itemGalleryList.get(objectsCounter).getText();
storyObject.status = MessageObject.STATUS_SENDING;
storyObject.id = lastUploadedStoryId;
List<StoryObject> realmStories = getMessageDataStorage().getStoryWithIndexSort(storyObject.userId);
if (realmStories != null && realmStories.size() > 0) {
storyObject.index = realmStories.get(0).index + 1;
} else {
storyObject.index = i;
}
storyInLocal.add(storyObject);
getMessageDataStorage().putStoriesToDatabaseOffline(false, storyObject.userId, storyObject.roomId, storyInLocal, storyObject.displayName, true);
storyInLocal.remove(0);
HttpUploader.isStoryUploading = true;
Uploader.getInstance().upload(UploadObject.createForStory(lastUploadedStoryId, paths.get(i), null, itemGalleryList.get(objectsCounter).getText(), ProtoGlobal.RoomMessageType.STORY));
objectsCounter++;
if (objectsCounter == itemGalleryList.size()) {
G.runOnUiThread(() -> loadStories());
storyInLocal = new ArrayList<>();
}
}
}
use of net.iGap.realm.RealmAttachment in project iGap-Android by KianIranian-STDG.
the class FragmentChat method openMessage.
private void openMessage(MessageObject messageObject) {
String filePath = null;
String token = messageObject.forwardedMessage != null ? messageObject.forwardedMessage.getAttachment().token : messageObject.getAttachment().token;
RealmAttachment realmAttachment = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmAttachment.class).equalTo("token", token).findFirst();
});
if (realmAttachment != null) {
filePath = realmAttachment.getLocalFilePath();
} else if (messageObject.getAttachment() != null) {
filePath = messageObject.getAttachment().filePath;
}
if (filePath == null) {
filePath = messageObject.getCacheFile(false);
}
if (filePath == null || filePath.length() == 0) {
return;
}
Intent intent = HelperMimeType.appropriateProgram(filePath);
if (intent != null) {
try {
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(context, R.string.can_not_support_file, Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(context, R.string.can_not_open_file, Toast.LENGTH_SHORT).show();
}
}
Aggregations