Contact swipe reveal icon

pull/214/head
M66B 1 year ago
parent 43734bb387
commit 53e74abbef

@ -27,6 +27,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.Rect;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
@ -112,6 +113,14 @@ public class AdapterContact extends RecyclerView.Adapter<AdapterContact.ViewHold
ivFavorite = itemView.findViewById(R.id.ivFavorite); ivFavorite = itemView.findViewById(R.id.ivFavorite);
} }
Rect getItemRect() {
return new Rect(
super.itemView.getLeft(),
super.itemView.getTop(),
super.itemView.getRight(),
super.itemView.getBottom());
}
private void wire() { private void wire() {
view.setOnClickListener(this); view.setOnClickListener(this);
view.setOnLongClickListener(this); view.setOnLongClickListener(this);

@ -21,11 +21,16 @@ package eu.faircode.email;
import static android.app.Activity.RESULT_OK; import static android.app.Activity.RESULT_OK;
import static androidx.recyclerview.widget.RecyclerView.NO_POSITION;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.graphics.Canvas;
import android.graphics.Rect;
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.text.TextUtils;
@ -34,6 +39,7 @@ import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.CompoundButton; import android.widget.CompoundButton;
@ -45,6 +51,7 @@ import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.SearchView; import androidx.appcompat.widget.SearchView;
import androidx.constraintlayout.widget.Group; import androidx.constraintlayout.widget.Group;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.Lifecycle; import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver; import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.Observer; import androidx.lifecycle.Observer;
@ -145,6 +152,54 @@ public class FragmentContacts extends FragmentBase {
return false; return false;
} }
@Override
public void onChildDraw(
@NonNull Canvas canvas, @NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder,
float dX, float dY, int actionState, boolean isCurrentlyActive) {
super.onChildDraw(canvas, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
Context context = getContext();
if (context == null)
return;
AdapterContact.ViewHolder holder = ((AdapterContact.ViewHolder) viewHolder);
Rect rect = holder.getItemRect();
int margin = Helper.dp2pixels(context, 12);
int size = Helper.dp2pixels(context, 24);
Drawable d = ContextCompat.getDrawable(context, R.drawable.twotone_delete_forever_24).mutate();
d.setTint(Helper.resolveColor(context, android.R.attr.textColorSecondary));
int half = rect.width() / 2;
if (dX > 0) {
// Right swipe
if (dX < half)
d.setAlpha(Math.round(255 * Math.min(dX / (2 * margin + size), 1.0f)));
else
d.setAlpha(Math.round(255 * (1.0f - (dX - half) / half)));
int padding = (rect.height() - size);
d.setBounds(
rect.left + margin,
rect.top + padding / 2,
rect.left + margin + size,
rect.top + padding / 2 + size);
d.draw(canvas);
} else if (dX < 0) {
// Left swipe
if (-dX < half)
d.setAlpha(Math.round(255 * Math.min(-dX / (2 * margin + size), 1.0f)));
else
d.setAlpha(Math.round(255 * (1.0f - (-dX - half) / half)));
int padding = (rect.height() - size);
d.setBounds(
rect.left + rect.width() - size - margin,
rect.top + padding / 2,
rect.left + rect.width() - margin,
rect.top + padding / 2 + size);
d.draw(canvas);
}
}
@Override @Override
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) { public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
try { try {

Loading…
Cancel
Save