use of cx.ring.model.IConversationElement 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;
}
Aggregations