Search in sources :

Example 1 with IConversationElement

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;
}
Also used : Context(android.content.Context) IConversationElement(cx.ring.model.IConversationElement) DataTransfer(cx.ring.model.DataTransfer) File(java.io.File) DownloadManager(android.app.DownloadManager)

Aggregations

DownloadManager (android.app.DownloadManager)1 Context (android.content.Context)1 DataTransfer (cx.ring.model.DataTransfer)1 IConversationElement (cx.ring.model.IConversationElement)1 File (java.io.File)1