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) {
try {
File file = attachment.getFile(context);
Uri uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, file);
// TODO: consider using getUriForFile(..., displayName)
new ShareCompat.IntentBuilder(context)
.setType(attachment.getMimeType())
.addStream(uri)
.addStream(attachment.getUri(context))
.setChooserTitle(R.string.title_select_app)
.startChooser();

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

@ -23,9 +23,11 @@ import static androidx.room.ForeignKey.CASCADE;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.core.content.FileProvider;
import androidx.preference.PreferenceManager;
import androidx.room.Entity;
import androidx.room.ForeignKey;
@ -153,6 +155,14 @@ public class EntityAttachment {
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) {
return getFile(context, id, name);
}

Loading…
Cancel
Save