mirror of
https://github.com/M66B/FairEmail.git
synced 2026-01-02 19:10:11 +01:00
Long press image to save image
This commit is contained in:
@@ -20,6 +20,7 @@ package eu.faircode.email;
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
@@ -35,6 +36,7 @@ import androidx.lifecycle.Lifecycle;
|
||||
import androidx.lifecycle.LifecycleObserver;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.OnLifecycleEvent;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
import androidx.recyclerview.widget.DiffUtil;
|
||||
import androidx.recyclerview.widget.ListUpdateCallback;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
@@ -52,7 +54,7 @@ public class AdapterImage extends RecyclerView.Adapter<AdapterImage.ViewHolder>
|
||||
|
||||
private List<EntityAttachment> items = new ArrayList<>();
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||
private View view;
|
||||
private ImageView ivImage;
|
||||
private TextView tvCaption;
|
||||
@@ -67,10 +69,12 @@ public class AdapterImage extends RecyclerView.Adapter<AdapterImage.ViewHolder>
|
||||
|
||||
private void wire() {
|
||||
view.setOnClickListener(this);
|
||||
view.setOnLongClickListener(this);
|
||||
}
|
||||
|
||||
private void unwire() {
|
||||
view.setOnClickListener(null);
|
||||
view.setOnLongClickListener(null);
|
||||
}
|
||||
|
||||
private void bindTo(EntityAttachment attachment) {
|
||||
@@ -143,6 +147,25 @@ public class AdapterImage extends RecyclerView.Adapter<AdapterImage.ViewHolder>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
int pos = getAdapterPosition();
|
||||
if (pos == RecyclerView.NO_POSITION)
|
||||
return false;
|
||||
|
||||
EntityAttachment attachment = items.get(pos);
|
||||
if (!attachment.available)
|
||||
return false;
|
||||
|
||||
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
|
||||
lbm.sendBroadcast(
|
||||
new Intent(FragmentMessages.ACTION_STORE_ATTACHMENT)
|
||||
.putExtra("id", attachment.id)
|
||||
.putExtra("name", Helper.sanitizeFilename(attachment.name))
|
||||
.putExtra("type", attachment.getMimeType()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
AdapterImage(Fragment parentFragment) {
|
||||
|
||||
Reference in New Issue
Block a user