use of cx.ring.model.DataTransfer in project ring-client-android by savoirfairelinux.
the class HistoryService method getCallAndTextAsyncForAccount.
public void getCallAndTextAsyncForAccount(final String accountId) {
mApplicationExecutor.submit(() -> {
try {
List<HistoryCall> historyCalls = getAllForAccount(accountId);
List<HistoryText> historyTexts = getAllTextMessagesForAccount(accountId);
List<DataTransfer> historyTransfers = getHistoryDataTransfers(accountId);
ServiceEvent event = new ServiceEvent(ServiceEvent.EventType.HISTORY_LOADED);
event.addEventInput(ServiceEvent.EventInput.HISTORY_CALLS, historyCalls);
event.addEventInput(ServiceEvent.EventInput.HISTORY_TEXTS, historyTexts);
event.addEventInput(ServiceEvent.EventInput.HISTORY_TRANSFERS, historyTransfers);
setChanged();
notifyObservers(event);
} catch (SQLException e) {
Log.e(TAG, "Can't load calls and texts", e);
}
});
}
use of cx.ring.model.DataTransfer in project ring-client-android by savoirfairelinux.
the class ConversationAdapter method configureForFileInfoTextMessage.
private void configureForFileInfoTextMessage(final ConversationViewHolder conversationViewHolder, final IConversationElement conversationElement) {
if (conversationViewHolder == null || conversationElement == null) {
return;
}
DataTransfer file = (DataTransfer) conversationElement;
String timeSeparationString = computeTimeSeparationStringFromMsgTimeStamp(conversationViewHolder.itemView.getContext(), file.getDate());
if (file.getEventCode() == DataTransferEventCode.FINISHED) {
conversationViewHolder.mMsgDetailTxt.setText(String.format("%s - %s", timeSeparationString, FileUtils.readableFileSize(file.getTotalSize())));
} else {
conversationViewHolder.mMsgDetailTxt.setText(String.format("%s - %s - %s", timeSeparationString, FileUtils.readableFileSize(file.getTotalSize()), ResourceMapper.getReadableFileTransferStatus(conversationFragment.getActivity(), file.getEventCode())));
}
boolean showPicture = file.showPicture();
View longPressView = showPicture ? conversationViewHolder.mPhoto : conversationViewHolder.itemView;
longPressView.setOnCreateContextMenuListener((menu, v, menuInfo) -> {
menu.setHeaderTitle(file.getDisplayName());
conversationFragment.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = conversationFragment.getActivity().getMenuInflater();
inflater.inflate(R.menu.conversation_item_actions, menu);
if (!file.isComplete())
menu.removeItem(R.id.conv_action_download);
});
longPressView.setOnLongClickListener(v -> {
mCurrentLongItem = new RecyclerViewContextMenuInfo(conversationViewHolder.getLayoutPosition(), v.getId());
return false;
});
if (showPicture) {
Context context = conversationViewHolder.mPhoto.getContext();
File path = presenter.getDeviceRuntimeService().getConversationPath(file.getPeerId(), file.getStoragePath());
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) conversationViewHolder.mAnswerLayout.getLayoutParams();
params.gravity = (file.isOutgoing() ? Gravity.END : Gravity.START) | Gravity.BOTTOM;
conversationViewHolder.mAnswerLayout.setLayoutParams(params);
LinearLayout.LayoutParams imageParams = (LinearLayout.LayoutParams) conversationViewHolder.mPhoto.getLayoutParams();
imageParams.height = mPictureMaxSize;
conversationViewHolder.mPhoto.setLayoutParams(imageParams);
GlideApp.with(context).load(path).apply(PICTURE_OPTIONS).into(new ImageViewTarget<Drawable>(conversationViewHolder.mPhoto) {
@Override
protected void setResource(@Nullable Drawable resource) {
ImageView view = getView();
runJustBeforeBeingDrawn(view, () -> {
if (view.getDrawable() != null) {
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view.getLayoutParams();
params.height = LinearLayout.LayoutParams.WRAP_CONTENT;
view.setLayoutParams(params);
}
});
view.setImageDrawable(resource);
}
});
((LinearLayout) conversationViewHolder.mAnswerLayout).setGravity(file.isOutgoing() ? Gravity.END : Gravity.START);
conversationViewHolder.mPhoto.setOnClickListener(v -> {
Uri contentUri = FileProvider.getUriForFile(v.getContext(), ContentUriHandler.AUTHORITY_FILES, path);
Intent i = new Intent(context, MediaViewerActivity.class);
i.setAction(Intent.ACTION_VIEW).setDataAndType(contentUri, "image/*").setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(conversationFragment.getActivity(), conversationViewHolder.mPhoto, "picture");
conversationFragment.startActivityForResult(i, 3006, options.toBundle());
});
return;
}
if (file.getEventCode().isError()) {
conversationViewHolder.icon.setImageResource(R.drawable.ic_warning);
} else {
conversationViewHolder.icon.setImageResource(R.drawable.ic_clip_black);
}
conversationViewHolder.mMsgTxt.setText(file.getDisplayName());
((LinearLayout) conversationViewHolder.mLayout).setGravity(file.isOutgoing() ? Gravity.END : Gravity.START);
if (file.getEventCode() == DataTransferEventCode.WAIT_HOST_ACCEPTANCE) {
conversationViewHolder.mAnswerLayout.setVisibility(View.VISIBLE);
conversationViewHolder.btnAccept.setOnClickListener(v -> {
if (!presenter.getDeviceRuntimeService().hasWriteExternalStoragePermission()) {
conversationFragment.askWriteExternalStoragePermission();
return;
}
Context context = v.getContext();
File cacheDir = context.getCacheDir();
long spaceLeft = AndroidFileUtils.getSpaceLeft(cacheDir.toString());
if (spaceLeft == -1L || file.getTotalSize() > spaceLeft) {
presenter.noSpaceLeft();
return;
}
context.startService(new Intent(DRingService.ACTION_FILE_ACCEPT).setClass(context.getApplicationContext(), DRingService.class).putExtra(DRingService.KEY_TRANSFER_ID, file.getDataTransferId()));
});
conversationViewHolder.btnRefuse.setOnClickListener(v -> {
Context context = v.getContext();
context.startService(new Intent(DRingService.ACTION_FILE_CANCEL).setClass(context.getApplicationContext(), DRingService.class).putExtra(DRingService.KEY_TRANSFER_ID, file.getDataTransferId()));
});
} else {
conversationViewHolder.mAnswerLayout.setVisibility(View.GONE);
}
}
use of cx.ring.model.DataTransfer in project ring-client-android by savoirfairelinux.
the class ConversationAdapter method onContextItemSelected.
public boolean onContextItemSelected(MenuItem item) {
ConversationAdapter.RecyclerViewContextMenuInfo info = getCurrentLongItem();
if (info == null) {
return false;
}
IConversationElement conversationElement = mConversationElements.get(info.position);
if (conversationElement == null)
return false;
if (conversationElement.getType() != IConversationElement.CEType.FILE)
return false;
DataTransfer file = (DataTransfer) conversationElement;
Context context = conversationFragment.getActivity();
switch(item.getItemId()) {
case R.id.conv_action_download:
{
File downloadDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "Ring");
if (!downloadDir.mkdirs()) {
Log.e(TAG, "Directory not created");
}
File newFile = new File(downloadDir, file.getDisplayName());
if (newFile.exists())
newFile.delete();
if (presenter.downloadFile(file, newFile)) {
DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
if (downloadManager != null) {
downloadManager.addCompletedDownload(file.getDisplayName(), file.getDisplayName(), true, file.isPicture() ? "image/jpeg" : "text/plain", newFile.getAbsolutePath(), newFile.length(), true);
}
}
break;
}
case R.id.conv_action_delete:
presenter.deleteFile(file);
break;
}
return true;
}
use of cx.ring.model.DataTransfer in project ring-client-android by savoirfairelinux.
the class DRingService method handleFileAction.
private void handleFileAction(String action, Bundle extras) {
Long id = extras.getLong(KEY_TRANSFER_ID);
if (action.equals(ACTION_FILE_ACCEPT)) {
File cacheDir = getCacheDir();
if (!cacheDir.exists()) {
boolean mkdirs = cacheDir.mkdirs();
if (!mkdirs) {
Log.e(TAG, "handleFileAction: not able to create directory at " + cacheDir.toString());
return;
}
}
DataTransfer file = mAccountService.getDataTransfer(id);
if (file == null) {
Log.e(TAG, "handleFileAction: unknown data transfer " + id);
return;
}
File cacheFile = new File(cacheDir, file.getDisplayName());
if (cacheFile.exists()) {
boolean delete = cacheFile.delete();
if (!delete) {
Log.e(TAG, "configureForFileInfoTextMessage: not able to delete cache file at " + cacheFile.toString());
return;
}
}
Log.d(TAG, "configureForFileInfoTextMessage: cacheFile=" + cacheFile + ",exists=" + cacheFile.exists());
mAccountService.acceptFileTransfer(id, cacheFile.getAbsolutePath(), 0);
} else if (action.equals(ACTION_FILE_CANCEL)) {
mAccountService.cancelDataTransfer(id);
}
}
use of cx.ring.model.DataTransfer in project ring-client-android by savoirfairelinux.
the class HistoryService method clearHistoryForConversation.
/**
* Removes all the text messages and call histories from the database.
*
* @param conversation The conversation containing the elements to delete.
*/
public void clearHistoryForConversation(final Conversation conversation) {
if (conversation == null) {
Log.d(TAG, "clearHistoryForConversation: conversation is null");
return;
}
mApplicationExecutor.submit(() -> {
try {
Map<String, HistoryEntry> history = conversation.getRawHistory();
for (Map.Entry<String, HistoryEntry> entry : history.entrySet()) {
// ~ Deleting messages
ArrayList<Long> textMessagesIds = new ArrayList<>(entry.getValue().getTextMessages().size());
for (TextMessage textMessage : entry.getValue().getTextMessages().values()) {
textMessagesIds.add(textMessage.getId());
}
DeleteBuilder<HistoryText, Long> deleteTextHistoryBuilder = getTextHistoryDao().deleteBuilder();
deleteTextHistoryBuilder.where().in(HistoryText.COLUMN_ID_NAME, textMessagesIds);
deleteTextHistoryBuilder.delete();
// ~ Deleting calls
ArrayList<String> callIds = new ArrayList<>(entry.getValue().getCalls().size());
for (HistoryCall historyCall : entry.getValue().getCalls().values()) {
callIds.add(historyCall.getCallId().toString());
}
DeleteBuilder<HistoryCall, Integer> deleteCallsHistoryBuilder = getCallHistoryDao().deleteBuilder();
deleteCallsHistoryBuilder.where().in(HistoryCall.COLUMN_CALL_ID_NAME, callIds);
deleteCallsHistoryBuilder.delete();
// ~ Deleting data transfers
ArrayList<Long> dataTransferIds = new ArrayList<>(entry.getValue().getDataTransfers().size());
for (DataTransfer dataTransfer : entry.getValue().getDataTransfers().values()) {
dataTransferIds.add(dataTransfer.getId());
}
DeleteBuilder<DataTransfer, Long> deleteDataTransfersHistoryBuilder = getDataHistoryDao().deleteBuilder();
deleteDataTransfersHistoryBuilder.where().in(DataTransfer.COLUMN_ID_NAME, dataTransferIds);
deleteDataTransfersHistoryBuilder.delete();
}
// notify the observers
setChanged();
ServiceEvent event = new ServiceEvent(ServiceEvent.EventType.HISTORY_MODIFIED);
notifyObservers(event);
} catch (SQLException e) {
Log.e(TAG, "Error while clearing history for conversation", e);
}
});
}
Aggregations