Added long press to show full attachment name

pull/172/head
M66B 5 years ago
parent 68bf30dea0
commit f8136955b5

@ -27,6 +27,8 @@ import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -34,6 +36,7 @@ import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.core.content.FileProvider; import androidx.core.content.FileProvider;
@ -66,7 +69,7 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
private List<EntityAttachment> items = new ArrayList<>(); 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 View view;
private ImageButton ibDelete; private ImageButton ibDelete;
private ImageView ivType; private ImageView ivType;
@ -95,12 +98,14 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
private void wire() { private void wire() {
view.setOnClickListener(this); view.setOnClickListener(this);
view.setOnLongClickListener(this);
ibDelete.setOnClickListener(this); ibDelete.setOnClickListener(this);
ibSave.setOnClickListener(this); ibSave.setOnClickListener(this);
} }
private void unwire() { private void unwire() {
view.setOnClickListener(null); view.setOnClickListener(null);
view.setOnLongClickListener(null);
ibDelete.setOnClickListener(null); ibDelete.setOnClickListener(null);
ibSave.setOnClickListener(null); ibSave.setOnClickListener(null);
} }
@ -204,6 +209,7 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
int pos = getAdapterPosition(); int pos = getAdapterPosition();
if (pos == RecyclerView.NO_POSITION) if (pos == RecyclerView.NO_POSITION)
return; return;
EntityAttachment attachment = items.get(pos); EntityAttachment attachment = items.get(pos);
if (attachment == null) if (attachment == null)
return; return;
@ -222,6 +228,25 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
} }
} }
@Override
public boolean onLongClick(View v) {
int pos = getAdapterPosition();
if (pos == RecyclerView.NO_POSITION)
return false;
EntityAttachment attachment = items.get(pos);
if (attachment == null)
return false;
if (TextUtils.isEmpty(attachment.name))
return false;
Toast toast = ToastEx.makeText(context, attachment.name, Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
return true;
}
private void onDelete(final EntityAttachment attachment) { private void onDelete(final EntityAttachment attachment) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", attachment.id); args.putLong("id", attachment.id);

Loading…
Cancel
Save