use of im.actor.core.entity.content.FileLocalSource in project actor-platform by actorapp.
the class DocHolder method onClick.
@Override
public void onClick(final Message currentMessage) {
if (document.getSource() instanceof FileRemoteSource) {
FileRemoteSource remoteSource = (FileRemoteSource) document.getSource();
final FileReference location = remoteSource.getFileReference();
messenger().requestState(location.getFileId(), new FileCallback() {
@Override
public void onNotDownloaded() {
messenger().startDownloading(location);
}
@Override
public void onDownloading(float progress) {
messenger().cancelDownloading(location.getFileId());
}
@Override
public void onDownloaded(final FileSystemReference reference) {
im.actor.runtime.Runtime.postToMainThread(new Runnable() {
@Override
public void run() {
if (document instanceof PhotoContent) {
Intents.openMedia(getAdapter().getMessagesFragment().getActivity(), fileIcon, reference.getDescriptor(), currentMessage.getSenderId());
} else {
try {
Activity activity = getAdapter().getMessagesFragment().getActivity();
activity.startActivity(Intents.openDoc(document.getName(), reference.getDescriptor()));
} catch (Exception e) {
Toast.makeText(getAdapter().getMessagesFragment().getActivity(), R.string.toast_unable_open, Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
}
});
}
});
} else if (document.getSource() instanceof FileLocalSource) {
messenger().requestUploadState(currentMessage.getRid(), new UploadFileCallback() {
@Override
public void onNotUploading() {
messenger().resumeUpload(currentMessage.getRid());
}
@Override
public void onUploading(float progress) {
messenger().pauseUpload(currentMessage.getRid());
}
@Override
public void onUploaded() {
// Nothing to do
}
});
}
}
use of im.actor.core.entity.content.FileLocalSource in project actor-platform by actorapp.
the class DocHolder method bindData.
@Override
protected void bindData(Message message, long readDate, long receiveDate, boolean isUpdated, PreprocessedData preprocessedData) {
document = (DocumentContent) message.getContent();
// Update state
if (message.getSenderId() == myUid()) {
stateIcon.setVisibility(View.VISIBLE);
switch(message.getMessageState()) {
case ERROR:
stateIcon.setResource(R.drawable.msg_error);
stateIcon.setTint(errorColor);
break;
default:
case PENDING:
stateIcon.setResource(R.drawable.msg_clock);
stateIcon.setTint(waitColor);
break;
case SENT:
if (message.getSortDate() <= readDate) {
stateIcon.setResource(R.drawable.msg_check_2);
stateIcon.setTint(readColor);
} else if (message.getSortDate() <= receiveDate) {
stateIcon.setResource(R.drawable.msg_check_2);
stateIcon.setTint(deliveredColor);
} else {
stateIcon.setResource(R.drawable.msg_check_1);
stateIcon.setTint(sentColor);
}
break;
}
} else {
stateIcon.setVisibility(View.GONE);
}
// Update time
setTimeAndReactions(time);
// Content data
fileName.setText(document.getName());
fileSize.setText(messenger().getFormatter().formatFileSize(document.getSource().getSize()) + " " + document.getExt().toUpperCase());
//region File icon
if (isUpdated) {
boolean isAppliedThumb = false;
if (document.getFastThumb() != null) {
try {
Bitmap img = ImageLoading.loadBitmap(document.getFastThumb().getImage());
fileIcon.setImageBitmap(img);
fileIcon.setScaleType(ImageView.ScaleType.FIT_CENTER);
isAppliedThumb = true;
} catch (ImageLoadException e) {
e.printStackTrace();
}
}
if (!isAppliedThumb) {
int type = FileTypes.getType(document.getExt());
switch(type) {
default:
case FileTypes.TYPE_UNKNOWN:
fileIcon.setImageResource(R.drawable.picker_unknown);
break;
case FileTypes.TYPE_APK:
fileIcon.setImageResource(R.drawable.picker_apk);
break;
case FileTypes.TYPE_MUSIC:
fileIcon.setImageResource(R.drawable.picker_music);
break;
case FileTypes.TYPE_PICTURE:
fileIcon.setImageResource(R.drawable.picker_unknown);
break;
case FileTypes.TYPE_DOC:
fileIcon.setImageResource(R.drawable.picker_doc);
break;
case FileTypes.TYPE_RAR:
fileIcon.setImageResource(R.drawable.picker_rar);
break;
case FileTypes.TYPE_VIDEO:
fileIcon.setImageResource(R.drawable.picker_video);
break;
case FileTypes.TYPE_ZIP:
fileIcon.setImageResource(R.drawable.picker_zip);
break;
case FileTypes.TYPE_XLS:
fileIcon.setImageResource(R.drawable.picker_xls);
break;
case FileTypes.TYPE_PPT:
fileIcon.setImageResource(R.drawable.picker_ppt);
break;
case FileTypes.TYPE_CSV:
fileIcon.setImageResource(R.drawable.picker_csv);
break;
case FileTypes.TYPE_HTM:
fileIcon.setImageResource(R.drawable.picker_htm);
break;
case FileTypes.TYPE_HTML:
fileIcon.setImageResource(R.drawable.picker_html);
break;
case FileTypes.TYPE_PDF:
fileIcon.setImageResource(R.drawable.picker_pdf);
break;
}
fileIcon.setScaleType(ImageView.ScaleType.CENTER);
}
}
//endregion
// Update view
boolean needRebind = false;
if (isUpdated) {
// Resetting binding
if (downloadFileVM != null) {
downloadFileVM.detach();
downloadFileVM = null;
}
if (uploadFileVM != null) {
uploadFileVM.detach();
uploadFileVM = null;
}
needRebind = true;
} else {
if (document.getSource() instanceof FileLocalSource) {
if (uploadFileVM == null && downloadFileVM != null) {
downloadFileVM.detach();
downloadFileVM = null;
needRebind = true;
}
} else if (document.getSource() instanceof FileRemoteSource) {
if (uploadFileVM != null && downloadFileVM == null) {
uploadFileVM.detach();
uploadFileVM = null;
needRebind = true;
}
}
}
if (downloadFileVM == null && uploadFileVM == null) {
needRebind = true;
}
if (needRebind) {
downloadIcon.setVisibility(View.GONE);
progressView.setVisibility(View.GONE);
progressValue.setVisibility(View.GONE);
fileIcon.setVisibility(View.GONE);
menu.setVisibility(View.GONE);
status.setVisibility(View.GONE);
if (document.getSource() instanceof FileRemoteSource) {
FileRemoteSource remoteSource = (FileRemoteSource) document.getSource();
// < 1MB
boolean autoDownload = remoteSource.getFileReference().getFileSize() <= 1024 * 1024 && messenger().isDocAutoDownloadEnabled();
downloadFileVM = messenger().bindFile(remoteSource.getFileReference(), autoDownload, new DownloadVMCallback());
} else if (document.getSource() instanceof FileLocalSource) {
uploadFileVM = messenger().bindUpload(message.getRid(), new UploadVMCallback());
}
}
}
use of im.actor.core.entity.content.FileLocalSource in project actor-platform by actorapp.
the class PhotoHolder method bindData.
@Override
protected void bindData(Message message, long readDate, long receiveDate, boolean isNewMessage, PreprocessedData preprocessedData) {
// Update model
DocumentContent fileMessage = (DocumentContent) message.getContent();
// Update bubble
if (message.getSenderId() == myUid()) {
messageBubble.setBackgroundResource(R.drawable.conv_bubble_media_out);
} else {
messageBubble.setBackgroundResource(R.drawable.conv_bubble_media_in);
}
// Update state
if (message.getSenderId() == myUid()) {
stateIcon.setVisibility(View.VISIBLE);
switch(message.getMessageState()) {
case ERROR:
stateIcon.setResource(R.drawable.msg_error);
stateIcon.setTint(COLOR_ERROR);
break;
default:
case PENDING:
stateIcon.setResource(R.drawable.msg_clock);
stateIcon.setTint(COLOR_PENDING);
break;
case SENT:
if (message.getSortDate() <= readDate) {
stateIcon.setResource(R.drawable.msg_check_2);
stateIcon.setTint(COLOR_READ);
} else if (message.getSortDate() <= receiveDate) {
stateIcon.setResource(R.drawable.msg_check_2);
stateIcon.setTint(COLOR_RECEIVED);
} else {
stateIcon.setResource(R.drawable.msg_check_1);
stateIcon.setTint(COLOR_SENT);
}
break;
}
} else {
stateIcon.setVisibility(View.GONE);
}
// Update time
setTimeAndReactions(time);
Log.d(TAG, "isNewMessage: " + isNewMessage);
// Update size
if (isNewMessage) {
int w, h;
if (message.getContent() instanceof PhotoContent) {
w = ((PhotoContent) message.getContent()).getW();
h = ((PhotoContent) message.getContent()).getH();
isPhoto = true;
isAnimation = false;
duration.setVisibility(View.GONE);
} else if (message.getContent() instanceof AnimationContent) {
w = ((AnimationContent) message.getContent()).getW();
h = ((AnimationContent) message.getContent()).getH();
isPhoto = true;
isAnimation = true;
duration.setVisibility(View.VISIBLE);
duration.setText("");
} else if (message.getContent() instanceof VideoContent) {
w = ((VideoContent) message.getContent()).getW();
h = ((VideoContent) message.getContent()).getH();
isPhoto = false;
isAnimation = false;
duration.setVisibility(View.VISIBLE);
duration.setText(messenger().getFormatter().formatDuration(((VideoContent) message.getContent()).getDuration()));
} else {
throw new RuntimeException("Unsupported content");
}
int maxHeight = context.getResources().getDisplayMetrics().heightPixels - Screen.dp(96 + 32);
maxHeight = Math.min(Screen.dp(360), maxHeight);
int maxWidth = context.getResources().getDisplayMetrics().widthPixels - Screen.dp(32 + 48);
maxWidth = Math.min(Screen.dp(360), maxWidth);
float scale = Math.min(maxWidth / (float) w, maxHeight / (float) h);
int bubbleW = (int) (scale * w);
int bubbleH = (int) (scale * h);
previewView.setLayoutParams(new FrameLayout.LayoutParams(bubbleW, bubbleH));
overlay.setLayoutParams(new FrameLayout.LayoutParams(bubbleW, bubbleH));
}
// Update view
boolean needRebind = false;
if (isNewMessage) {
// Resetting old content state
// imageKitView.noRequest();
fastThumbLoader.cancel();
// Resetting binding
if (downloadFileVM != null) {
downloadFileVM.detach();
downloadFileVM = null;
}
if (uploadFileVM != null) {
uploadFileVM.detach();
uploadFileVM = null;
}
needRebind = true;
}
Log.d(TAG, "needRebind by new: " + needRebind);
updated = false;
// int updatedCounter = fileMessage.getUpdatedCounter();
// Log.d(TAG, "oldRid: " + currenrRid);
// Log.d(TAG, "newRid: " + currentMessage.getRid());
// Log.d(TAG, "oldCounter: " + lastUpdatedIndex);
// Log.d(TAG, "newCounter: " + updatedCounter);
// if (currenrRid == currentMessage.getRid() && lastUpdatedIndex != updatedCounter) {
// updated = true;
// needRebind = true;
// lastUpdatedIndex = updatedCounter;
// }
currenrRid = currentMessage.getRid();
Log.d(TAG, "updated: " + updated);
if (needRebind) {
anim = null;
if (!updated) {
playRequested = false;
}
// Resetting progress state
progressContainer.setVisibility(View.GONE);
progressView.setVisibility(View.GONE);
progressValue.setVisibility(View.GONE);
progressIcon.setVisibility(View.GONE);
if (fileMessage.getSource() instanceof FileRemoteSource) {
boolean autoDownload = false;
if (fileMessage instanceof PhotoContent) {
autoDownload = messenger().isImageAutoDownloadEnabled();
} else if (fileMessage instanceof AnimationContent) {
autoDownload = messenger().isAnimationAutoPlayEnabled();
} else if (fileMessage instanceof VideoContent) {
autoDownload = messenger().isVideoAutoDownloadEnabled();
}
if (!updated) {
previewView.setImageURI(null);
}
downloadFileVM = messenger().bindFile(((FileRemoteSource) fileMessage.getSource()).getFileReference(), autoDownload, new DownloadVMCallback(fileMessage));
} else if (fileMessage.getSource() instanceof FileLocalSource) {
uploadFileVM = messenger().bindUpload(message.getRid(), new UploadVMCallback());
if (isPhoto) {
Uri uri = Uri.fromFile(new File(((FileLocalSource) fileMessage.getSource()).getFileDescriptor()));
bindImage(uri);
} else {
if (!updated) {
previewView.setImageURI(null);
Log.d(TAG, "rebind video - setImageURI(null)!");
}
//TODO: better approach?
if (fileMessage.getFastThumb() != null && !updated) {
fastThumbLoader.request(fileMessage.getFastThumb().getImage());
Log.d(TAG, "rebind video- new thumb!");
}
}
} else {
throw new RuntimeException("Unknown file source type: " + fileMessage.getSource());
}
}
}
use of im.actor.core.entity.content.FileLocalSource in project actor-platform by actorapp.
the class PhotoHolder method onClick.
@Override
public void onClick(final Message currentMessage) {
final DocumentContent document = (DocumentContent) currentMessage.getContent();
if (document.getSource() instanceof FileRemoteSource) {
FileRemoteSource remoteSource = (FileRemoteSource) document.getSource();
final FileReference location = remoteSource.getFileReference();
messenger().requestState(location.getFileId(), new FileCallback() {
@Override
public void onNotDownloaded() {
messenger().startDownloading(location);
playRequested = true;
}
@Override
public void onDownloading(float progress) {
messenger().cancelDownloading(location.getFileId());
}
@Override
public void onDownloaded(final FileSystemReference reference) {
im.actor.runtime.Runtime.postToMainThread(new Runnable() {
@Override
public void run() {
if (document instanceof PhotoContent) {
Intents.openMedia(getAdapter().getMessagesFragment().getActivity(), previewView, reference.getDescriptor(), currentMessage.getSenderId());
} else if (document instanceof VideoContent) {
playVideo(document, reference);
} else if (document instanceof AnimationContent) {
toggleAnimation();
}
}
});
}
});
} else if (document.getSource() instanceof FileLocalSource) {
messenger().requestUploadState(currentMessage.getRid(), new UploadFileCallback() {
@Override
public void onNotUploading() {
messenger().resumeUpload(currentMessage.getRid());
}
@Override
public void onUploading(float progress) {
messenger().pauseUpload(currentMessage.getRid());
}
@Override
public void onUploaded() {
// Nothing to do
}
});
}
}
use of im.actor.core.entity.content.FileLocalSource in project actor-platform by actorapp.
the class AudioHolder method bindData.
@Override
protected void bindData(final Message message, long readDate, long receiveDate, boolean isUpdated, PreprocessedData preprocessedData) {
VoiceContent audioMsg = (VoiceContent) message.getContent();
if (message.getSenderId() == myUid()) {
// messageBubble.getBackground().setColorFilter(messageBubble.getContext().getResources().getColor(R.color.conv_bubble), PorterDuff.Mode.MULTIPLY);
messageBubble.setBackgroundResource(R.drawable.conv_bubble_media_out);
} else {
messageBubble.setBackgroundResource(R.drawable.conv_bubble_media_in);
messageBubble.getBackground().setColorFilter(null);
}
// Update state
if (message.getSenderId() == myUid()) {
stateIcon.setVisibility(View.VISIBLE);
switch(message.getMessageState()) {
case ERROR:
stateIcon.setResource(R.drawable.msg_error);
stateIcon.setTint(errorColor);
break;
default:
case PENDING:
stateIcon.setResource(R.drawable.msg_clock);
stateIcon.setTint(waitColor);
break;
case SENT:
if (message.getSortDate() <= readDate) {
stateIcon.setResource(R.drawable.msg_check_2);
stateIcon.setTint(readColor);
} else if (message.getSortDate() <= receiveDate) {
stateIcon.setResource(R.drawable.msg_check_2);
stateIcon.setTint(deliveredColor);
} else {
stateIcon.setResource(R.drawable.msg_check_1);
stateIcon.setTint(sentColor);
}
break;
}
} else {
stateIcon.setVisibility(View.GONE);
}
// Update time
setTimeAndReactions(time);
currentDuration = ((VoiceContent) message.getContent()).getDuration();
duration.setText(ActorSDK.sharedActor().getMessenger().getFormatter().formatDuration((int) (currentDuration / 1000)));
// Update view
boolean needRebind = false;
if (isUpdated) {
// Resetting binding
if (downloadFileVM != null) {
downloadFileVM.detach();
downloadFileVM = null;
}
if (uploadFileVM != null) {
uploadFileVM.detach();
uploadFileVM = null;
}
needRebind = true;
}
if (needRebind) {
if (audioMsg.getSource() instanceof FileRemoteSource) {
boolean autoDownload = false;
if (audioMsg instanceof VoiceContent) {
autoDownload = messenger().isAudioAutoDownloadEnabled();
}
downloadFileVM = ActorSDK.sharedActor().getMessenger().bindFile(((FileRemoteSource) audioMsg.getSource()).getFileReference(), autoDownload, new DownloadVMCallback(audioMsg));
} else if (audioMsg.getSource() instanceof FileLocalSource) {
uploadFileVM = ActorSDK.sharedActor().getMessenger().bindUpload(message.getRid(), new UploadVMCallback());
currentAudio = ((FileLocalSource) audioMsg.getSource()).getFileDescriptor();
stop();
bindPlayButton();
} else {
throw new RuntimeException("Unknown file source type: " + audioMsg.getSource());
}
}
}
Aggregations