use of com.xabber.android.data.database.messagerealm.Attachment in project xabber-android by redsolution.
the class ImageViewerActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image_viewer);
// get params
Intent intent = getIntent();
Bundle args = intent.getExtras();
if (args == null) {
finish();
return;
}
String imageUrl = args.getString(IMAGE_URL);
String messageId = args.getString(MESSAGE_ID);
int imagePosition = args.getInt(ATTACHMENT_POSITION);
// setup toolbar
toolbar = (Toolbar) findViewById(R.id.toolbar_default);
toolbar.setNavigationIcon(R.drawable.ic_arrow_left_white_24dp);
toolbar.inflateMenu(R.menu.menu_image_viewer);
toolbar.setOnMenuItemClickListener(this);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
NavUtils.navigateUpFromSameTask(ImageViewerActivity.this);
}
});
// get imageAttachments
Realm realm = MessageDatabaseManager.getInstance().getRealmUiThread();
MessageItem messageItem = realm.where(MessageItem.class).equalTo(MessageItem.Fields.UNIQUE_ID, messageId).findFirst();
if (imageUrl != null) {
Attachment attachment = new Attachment();
attachment.setFileUrl(imageUrl);
imageAttachments.add(attachment);
} else {
RealmList<Attachment> attachments = messageItem.getAttachments();
for (Attachment attachment : attachments) {
if (attachment.isImage())
imageAttachments.add(attachment);
}
}
// get account jid
this.accountJid = messageItem.getAccount();
// find views
progressBar = findViewById(R.id.progressBar);
ivCancelDownload = findViewById(R.id.ivCancelDownload);
ivCancelDownload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onCancelDownloadClick();
}
});
viewPager = findViewById(R.id.viewPager);
PagerAdapter pagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
@Override
public Fragment getItem(int position) {
Attachment attachment = imageAttachments.get(position);
return ImageViewerFragment.newInstance(attachment.getFilePath(), attachment.getFileUrl(), attachment.getUniqueId());
}
@Override
public int getCount() {
return imageAttachments.size();
}
};
viewPager.setAdapter(pagerAdapter);
viewPager.setCurrentItem(imagePosition);
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
updateToolbar();
unsubscribeAttachmentState();
subscribeForAttachment(imageAttachments.get(position));
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
if (imageAttachments.size() > imagePosition)
subscribeForAttachment(imageAttachments.get(imagePosition));
}
use of com.xabber.android.data.database.messagerealm.Attachment in project xabber-android by redsolution.
the class ImageViewerActivity method onProgressUpdated.
private void onProgressUpdated(DownloadManager.ProgressData progressData) {
int position = viewPager.getCurrentItem();
Attachment attachment = imageAttachments.get(position);
if (progressData.getAttachmentId().equals(attachment.getUniqueId())) {
if (progressData.isCompleted()) {
showProgress(false);
isDownloading = false;
updateToolbar();
} else if (progressData.getError() != null) {
showProgress(false);
showToast(progressData.getError());
isDownloading = false;
updateToolbar();
} else {
progressBar.setProgress(progressData.getProgress());
showProgress(true);
isDownloading = true;
updateToolbar();
}
} else
showProgress(false);
}
use of com.xabber.android.data.database.messagerealm.Attachment in project xabber-android by redsolution.
the class ContactVO method convert.
public static ContactVO convert(AbstractContact contact, ContactClickListener listener) {
int accountColorIndicator;
int accountColorIndicatorBack;
Drawable avatar;
int statusLevel;
int mucIndicatorLevel;
boolean isOutgoing = false;
Date time = null;
int messageStatus = 0;
int unreadCount = 0;
int forwardedCount = 0;
String messageOwner = null;
accountColorIndicator = ColorManager.getInstance().getAccountPainter().getAccountMainColor(contact.getAccount());
accountColorIndicatorBack = ColorManager.getInstance().getAccountPainter().getAccountIndicatorBackColor(contact.getAccount());
avatar = contact.getAvatar();
String name = contact.getName();
if (MUCManager.getInstance().hasRoom(contact.getAccount(), contact.getUser())) {
mucIndicatorLevel = 1;
} else if (MUCManager.getInstance().isMucPrivateChat(contact.getAccount(), contact.getUser())) {
mucIndicatorLevel = 2;
} else {
mucIndicatorLevel = 0;
}
statusLevel = contact.getStatusMode().getStatusLevel();
String messageText;
String statusText = contact.getStatusText().trim();
int statusId = contact.getStatusMode().getStringID();
String lastActivity = "";
if (contact instanceof RosterContact)
lastActivity = ((RosterContact) contact).getLastActivity();
MessageManager messageManager = MessageManager.getInstance();
AbstractChat chat = messageManager.getOrCreateChat(contact.getAccount(), contact.getUser());
MessageItem lastMessage = chat.getLastMessage();
if (lastMessage == null || lastMessage.getText() == null) {
messageText = statusText;
} else {
if (lastMessage.haveAttachments() && lastMessage.getAttachments().size() > 0) {
Attachment attachment = lastMessage.getAttachments().get(0);
messageText = StringUtils.getColoredText(attachment.getTitle().trim(), accountColorIndicator);
} else if (lastMessage.getFilePath() != null) {
messageText = new File(lastMessage.getFilePath()).getName();
} else if (ChatAction.available.toString().equals(lastMessage.getAction())) {
messageText = StringUtils.getColoredText(lastMessage.getText().trim(), accountColorIndicator);
} else {
messageText = lastMessage.getText().trim();
}
time = new Date(lastMessage.getTimestamp());
isOutgoing = !lastMessage.isIncoming();
if ((mucIndicatorLevel == 1 || mucIndicatorLevel == 2) && lastMessage.isIncoming() && lastMessage.getText() != null && !lastMessage.getText().trim().isEmpty())
messageOwner = lastMessage.getResource().toString();
// message status
if (isOutgoing) {
if (!MessageItem.isUploadFileMessage(lastMessage) && !lastMessage.isSent() && System.currentTimeMillis() - lastMessage.getTimestamp() > 1000) {
messageStatus = 5;
} else if (lastMessage.isDisplayed() || lastMessage.isReceivedFromMessageArchive()) {
messageStatus = 1;
} else if (lastMessage.isDelivered() || lastMessage.isForwarded()) {
messageStatus = 2;
} else if (lastMessage.isError()) {
messageStatus = 4;
} else if (lastMessage.isAcknowledged()) {
messageStatus = 3;
}
}
// forwarded
if (lastMessage.haveForwardedMessages()) {
forwardedCount = lastMessage.getForwardedIds().size();
if (messageText.isEmpty()) {
String forwardText = lastMessage.getFirstForwardedMessageText(accountColorIndicator);
if (forwardText != null)
messageText = forwardText;
}
}
}
if (!isOutgoing)
unreadCount = chat.getUnreadMessageCount();
// notification icon
NotificationState.NotificationMode mode = chat.getNotificationState().determineModeByGlobalSettings(chat instanceof RoomChat);
// custom notification
boolean isCustomNotification = CustomNotifyPrefsManager.getInstance().isPrefsExist(Key.createKey(contact.getAccount(), contact.getUser()));
return new ContactVO(accountColorIndicator, accountColorIndicatorBack, name, statusText, statusId, statusLevel, avatar, mucIndicatorLevel, contact.getUser(), contact.getAccount(), unreadCount, !chat.notifyAboutMessage(), mode, messageText, isOutgoing, time, messageStatus, messageOwner, chat.isArchived(), lastActivity, listener, forwardedCount, isCustomNotification, chat.isGroupchat());
}
use of com.xabber.android.data.database.messagerealm.Attachment in project xabber-android by redsolution.
the class AbstractChat method attachmentsFromFiles.
public RealmList<Attachment> attachmentsFromFiles(List<File> files) {
RealmList<Attachment> attachments = new RealmList<>();
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);
}
return attachments;
}
use of com.xabber.android.data.database.messagerealm.Attachment in project xabber-android by redsolution.
the class MessageManager method setAttachmentLocalPathToNull.
public static void setAttachmentLocalPathToNull(final String uniqId) {
final Realm realm = MessageDatabaseManager.getInstance().getRealmUiThread();
realm.executeTransactionAsync(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
Attachment first = realm.where(Attachment.class).equalTo(Attachment.Fields.UNIQUE_ID, uniqId).findFirst();
if (first != null) {
first.setFilePath(null);
}
}
});
}
Aggregations