use of com.xabber.android.data.database.messagerealm.Attachment in project xabber-android by redsolution.
the class MessageNotificationManager method getNotificationText.
private String getNotificationText(MessageItem message) {
String text = message.getText().trim();
if (message.haveAttachments() && message.getAttachments().size() > 0) {
Attachment attachment = message.getAttachments().get(0);
FileCategory category = FileCategory.determineFileCategory(attachment.getMimeType());
text = FileCategory.getCategoryName(category, false) + attachment.getTitle();
}
if (message.haveForwardedMessages() && message.getForwardedIds().size() > 0 && text.isEmpty()) {
String forwardText = message.getFirstForwardedMessageText();
if (forwardText != null && !forwardText.isEmpty())
text = forwardText;
else
text = context.getString(R.string.forwarded_messages_count, message.getForwardedIds().size());
}
return text;
}
use of com.xabber.android.data.database.messagerealm.Attachment in project xabber-android by redsolution.
the class ClipManager method messageToText.
private static String messageToText(Realm realm, MessageItem message, long previousMessageTimestamp, int level) {
String space = getSpace(level);
StringBuilder stringBuilder = new StringBuilder();
final String name = RosterManager.getDisplayAuthorName(message);
final String date = StringUtils.getDateStringForClipboard(message.getTimestamp());
if (!Utils.isSameDay(message.getTimestamp(), previousMessageTimestamp)) {
stringBuilder.append("\n");
stringBuilder.append(space);
stringBuilder.append(date);
}
stringBuilder.append("\n");
stringBuilder.append(space);
stringBuilder.append('[');
stringBuilder.append(StringUtils.getTimeTextWithSeconds(new Date(message.getTimestamp())));
stringBuilder.append("] ");
stringBuilder.append(name);
stringBuilder.append(":\n");
if (message.haveForwardedMessages()) {
stringBuilder.append(messagesToText(realm, message.getForwardedIdsAsArray(), level + 1));
stringBuilder.append("\n");
}
if (message.haveAttachments()) {
for (Attachment attachment : message.getAttachments()) {
stringBuilder.append(space);
stringBuilder.append(attachment.getFileUrl());
stringBuilder.append("\n");
}
}
if (!message.getText().isEmpty()) {
stringBuilder.append(space);
stringBuilder.append(message.getText());
}
return stringBuilder.toString();
}
use of com.xabber.android.data.database.messagerealm.Attachment in project xabber-android by redsolution.
the class HttpFileUploadManager method refMediaToAttachment.
private static Attachment refMediaToAttachment(RefMedia media) {
Attachment attachment = new Attachment();
attachment.setFileUrl(media.getUri());
attachment.setIsImage(FileManager.isImageUrl(media.getUri()));
RefFile file = media.getFile();
if (file != null) {
attachment.setTitle(file.getName());
attachment.setMimeType(file.getMediaType());
attachment.setDuration(file.getDuration());
attachment.setFileSize(file.getSize());
if (file.getHeight() > 0)
attachment.setImageHeight(file.getHeight());
if (file.getWidth() > 0)
attachment.setImageWidth(file.getWidth());
}
return attachment;
}
use of com.xabber.android.data.database.messagerealm.Attachment in project xabber-android by redsolution.
the class FileInteractionFragment method openFileOrDownload.
private void openFileOrDownload(String messageUID, int attachmentPosition) {
MessageItem messageItem = MessageDatabaseManager.getInstance().getRealmUiThread().where(MessageItem.class).equalTo(MessageItem.Fields.UNIQUE_ID, messageUID).findFirst();
if (messageItem == null) {
LogManager.w(LOG_TAG, "onMessageFileClick: null message item. UID: " + messageUID);
return;
}
if (messageItem.haveAttachments()) {
RealmList<Attachment> fileAttachments = new RealmList<>();
for (Attachment attachment : messageItem.getAttachments()) {
if (!attachment.isImage())
fileAttachments.add(attachment);
}
Attachment attachment = fileAttachments.get(attachmentPosition);
if (attachment == null)
return;
if (attachment.getFilePath() != null) {
File file = new File(attachment.getFilePath());
if (!file.exists()) {
MessageManager.setAttachmentLocalPathToNull(attachment.getUniqueId());
return;
}
Intent i = new Intent(Intent.ACTION_VIEW);
String path = attachment.getFilePath();
i.setDataAndType(FileProvider.getUriForFile(getActivity(), getActivity().getApplicationContext().getPackageName() + ".provider", new File(path)), attachment.getMimeType());
i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
try {
startActivity(i);
} catch (ActivityNotFoundException e) {
LogManager.exception(LOG_TAG, e);
Toast.makeText(getActivity(), R.string.toast_could_not_open_file, Toast.LENGTH_SHORT).show();
}
} else
DownloadManager.getInstance().downloadFile(attachment, account, getActivity());
}
}
use of com.xabber.android.data.database.messagerealm.Attachment in project xabber-android by redsolution.
the class MessageManager method updateMessageWithNewAttachments.
public void updateMessageWithNewAttachments(final String messageId, final List<File> files) {
Realm realm = MessageDatabaseManager.getInstance().getNewBackgroundRealm();
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
MessageItem messageItem = realm.where(MessageItem.class).equalTo(MessageItem.Fields.UNIQUE_ID, messageId).findFirst();
if (messageItem != null) {
RealmList<Attachment> attachments = messageItem.getAttachments();
// remove temporary attachments created from uri
// to replace it with attachments created from files
attachments.deleteAllFromRealm();
for (File file : files) {
Attachment attachment = new Attachment();
attachment.setFilePath(file.getPath());
attachment.setFileSize(file.length());
attachment.setTitle(file.getName());
attachment.setIsImage(FileManager.fileIsImage(file));
attachment.setMimeType(HttpFileUploadManager.getMimeType(file.getPath()));
attachment.setDuration((long) 0);
if (attachment.isImage()) {
HttpFileUploadManager.ImageSize imageSize = HttpFileUploadManager.getImageSizes(file.getPath());
attachment.setImageHeight(imageSize.getHeight());
attachment.setImageWidth(imageSize.getWidth());
}
attachments.add(attachment);
}
}
}
});
}
Aggregations