Get attachment URI with name

pull/210/head
M66B 2 years ago
parent 35259ba80a
commit 2e07080feb

@ -299,13 +299,9 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
private boolean onShare(final EntityAttachment attachment) { private boolean onShare(final EntityAttachment attachment) {
try { try {
File file = attachment.getFile(context);
Uri uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, file);
// TODO: consider using getUriForFile(..., displayName)
new ShareCompat.IntentBuilder(context) new ShareCompat.IntentBuilder(context)
.setType(attachment.getMimeType()) .setType(attachment.getMimeType())
.addStream(uri) .addStream(attachment.getUri(context))
.setChooserTitle(R.string.title_select_app) .setChooserTitle(R.string.title_select_app)
.startChooser(); .startChooser();

@ -3971,11 +3971,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
ArrayList<Uri> result = new ArrayList<>(); ArrayList<Uri> result = new ArrayList<>();
for (EntityAttachment attachment : attachments) for (EntityAttachment attachment : attachments)
if (attachment.available && if (attachment.available &&
attachment.isAttachment() && attachment.isImage()) { attachment.isAttachment() && attachment.isImage())
File file = attachment.getFile(context); result.add(attachment.getUri(context));
Uri uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, file);
result.add(uri);
}
return result; return result;
} }
@ -5320,10 +5317,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
if (attachment == null) if (attachment == null)
return; return;
File file = attachment.getFile(context);
Uri uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, file);
context.startActivity(new Intent(context, ActivityAMP.class) context.startActivity(new Intent(context, ActivityAMP.class)
.setData(uri) .setData(attachment.getUri(context))
.putExtra("id", attachment.message)); .putExtra("id", attachment.message));
} }

@ -23,9 +23,11 @@ import static androidx.room.ForeignKey.CASCADE;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.net.Uri;
import android.text.TextUtils; import android.text.TextUtils;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.core.content.FileProvider;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import androidx.room.Entity; import androidx.room.Entity;
import androidx.room.ForeignKey; import androidx.room.ForeignKey;
@ -153,6 +155,14 @@ public class EntityAttachment {
return (encryption != null); return (encryption != null);
} }
Uri getUri(Context context) {
File file = getFile(context);
if (TextUtils.isEmpty(name))
return FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, file);
else
return FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, file, name);
}
File getFile(Context context) { File getFile(Context context) {
return getFile(context, id, name); return getFile(context, id, name);
} }

Loading…
Cancel
Save