diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 27f516d79..06f9a0eae 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -285,11 +285,6 @@ - - implements StickyHeaderDecoration.StickyHeaderAdapter { private final Calendar calendar; @@ -61,15 +57,9 @@ public class MediaDocumentsAdapter extends CursorRecyclerViewAdapter viewHolder.documentView.setVisibility(View.VISIBLE); viewHolder.date.setVisibility(View.VISIBLE); viewHolder.documentView.setOnClickListener(view -> { - Intent intent = new Intent(Intent.ACTION_VIEW); - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - intent.setDataAndType(PartAuthority.getAttachmentPublicUri(slide.getUri()), slide.getContentType()); - try { - getContext().startActivity(intent); - } catch (ActivityNotFoundException anfe) { - Log.w(TAG, "No activity existed to view the media."); - Toast.makeText(getContext(), R.string.ConversationItem_unable_to_open_media, Toast.LENGTH_LONG).show(); - } + int msgId = slide.getDcMsgId(); + ApplicationDcContext dcContext = DcHelper.getContext(getContext()); + dcContext.openForViewOrShare(msgId, Intent.ACTION_VIEW); }); } else { viewHolder.documentView.setVisibility(View.GONE); diff --git a/src/org/thoughtcrime/securesms/mms/PartAuthority.java b/src/org/thoughtcrime/securesms/mms/PartAuthority.java index 5f350dea3..c6fe8dfa3 100644 --- a/src/org/thoughtcrime/securesms/mms/PartAuthority.java +++ b/src/org/thoughtcrime/securesms/mms/PartAuthority.java @@ -7,11 +7,8 @@ import android.net.Uri; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import org.thoughtcrime.securesms.attachments.Attachment; import org.thoughtcrime.securesms.attachments.AttachmentId; -import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.providers.PersistentBlobProvider; -import org.thoughtcrime.securesms.providers.PartProvider; import org.thoughtcrime.securesms.providers.SingleUseBlobProvider; import java.io.IOException; @@ -87,11 +84,6 @@ public class PartAuthority { } } - public static Uri getAttachmentPublicUri(Uri uri) { - PartUriParser partUri = new PartUriParser(uri); - return PartProvider.getContentUri(partUri.getPartId()); - } - public static Uri getAttachmentDataUri(AttachmentId attachmentId) { Uri uri = Uri.withAppendedPath(PART_CONTENT_URI, String.valueOf(attachmentId.getUniqueId())); return ContentUris.withAppendedId(uri, attachmentId.getRowId()); diff --git a/src/org/thoughtcrime/securesms/providers/PartProvider.java b/src/org/thoughtcrime/securesms/providers/PartProvider.java deleted file mode 100644 index e215da957..000000000 --- a/src/org/thoughtcrime/securesms/providers/PartProvider.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (C) 2011 Whisper Systems - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.thoughtcrime.securesms.providers; - -import android.content.ContentProvider; -import android.content.ContentUris; -import android.content.ContentValues; -import android.content.UriMatcher; -import android.database.Cursor; -import android.database.MatrixCursor; -import android.net.Uri; -import android.os.MemoryFile; -import android.os.ParcelFileDescriptor; -import android.provider.OpenableColumns; -import android.support.annotation.NonNull; -import android.util.Log; - -import org.thoughtcrime.securesms.BuildConfig; -import org.thoughtcrime.securesms.attachments.AttachmentId; -import org.thoughtcrime.securesms.attachments.DatabaseAttachment; -import org.thoughtcrime.securesms.database.DatabaseFactory; -import org.thoughtcrime.securesms.mms.PartUriParser; -import org.thoughtcrime.securesms.util.MemoryFileUtil; -import org.thoughtcrime.securesms.util.Util; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -public class PartProvider extends ContentProvider { - - private static final String TAG = PartProvider.class.getSimpleName(); - - private static final String CONTENT_URI_STRING = "content://"+BuildConfig.APPLICATION_ID+".provider.securesms/part"; - private static final Uri CONTENT_URI = Uri.parse(CONTENT_URI_STRING); - private static final int SINGLE_ROW = 1; - - private static final UriMatcher uriMatcher; - - static { - uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); - uriMatcher.addURI(BuildConfig.APPLICATION_ID+".provider.securesms", "part/*/#", SINGLE_ROW); - } - - @Override - public boolean onCreate() { - Log.w(TAG, "onCreate()"); - return true; - } - - public static Uri getContentUri(AttachmentId attachmentId) { - Uri uri = Uri.withAppendedPath(CONTENT_URI, String.valueOf(attachmentId.getUniqueId())); - return ContentUris.withAppendedId(uri, attachmentId.getRowId()); - } - - @Override - public ParcelFileDescriptor openFile(@NonNull Uri uri, @NonNull String mode) throws FileNotFoundException { - Log.w(TAG, "openFile() called!"); - - switch (uriMatcher.match(uri)) { - case SINGLE_ROW: - Log.w(TAG, "Parting out a single row..."); - try { - final PartUriParser partUri = new PartUriParser(uri); - return getParcelStreamForAttachment(partUri.getPartId()); - } catch (IOException ioe) { - Log.w(TAG, ioe); - throw new FileNotFoundException("Error opening file"); - } - } - - throw new FileNotFoundException("Request for bad part."); - } - - @Override - public int delete(@NonNull Uri arg0, String arg1, String[] arg2) { - Log.w(TAG, "delete() called"); - return 0; - } - - @Override - public String getType(@NonNull Uri uri) { - Log.w(TAG, "getType() called: " + uri); - - switch (uriMatcher.match(uri)) { - case SINGLE_ROW: - PartUriParser partUriParser = new PartUriParser(uri); - DatabaseAttachment attachment = DatabaseFactory.getAttachmentDatabase(getContext()) - .getAttachment(partUriParser.getPartId()); - - if (attachment != null) { - return attachment.getContentType(); - } - } - - return null; - } - - @Override - public Uri insert(@NonNull Uri arg0, ContentValues arg1) { - Log.w(TAG, "insert() called"); - return null; - } - - @Override - public Cursor query(@NonNull Uri url, String[] projection, String selection, String[] selectionArgs, String sortOrder) { - Log.w(TAG, "query() called: " + url); - - if (projection == null || projection.length <= 0) return null; - - switch (uriMatcher.match(url)) { - case SINGLE_ROW: - PartUriParser partUri = new PartUriParser(url); - DatabaseAttachment attachment = DatabaseFactory.getAttachmentDatabase(getContext()).getAttachment(partUri.getPartId()); - - if (attachment == null) return null; - - MatrixCursor matrixCursor = new MatrixCursor(projection, 1); - Object[] resultRow = new Object[projection.length]; - - for (int i=0;i