mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-24 07:01:05 +00:00
Contact swipe reveal icon
This commit is contained in:
parent
43734bb387
commit
53e74abbef
2 changed files with 64 additions and 0 deletions
|
@ -27,6 +27,7 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.Typeface;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
|
@ -112,6 +113,14 @@ public class AdapterContact extends RecyclerView.Adapter<AdapterContact.ViewHold
|
|||
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() {
|
||||
view.setOnClickListener(this);
|
||||
view.setOnLongClickListener(this);
|
||||
|
|
|
@ -21,11 +21,16 @@ package eu.faircode.email;
|
|||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
|
||||
import static androidx.recyclerview.widget.RecyclerView.NO_POSITION;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
|
@ -34,6 +39,7 @@ import android.view.Menu;
|
|||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewConfiguration;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
|
@ -45,6 +51,7 @@ import androidx.annotation.Nullable;
|
|||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.widget.SearchView;
|
||||
import androidx.constraintlayout.widget.Group;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.lifecycle.LifecycleObserver;
|
||||
import androidx.lifecycle.Observer;
|
||||
|
@ -145,6 +152,54 @@ public class FragmentContacts extends FragmentBase {
|
|||
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
|
||||
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
|
||||
try {
|
||||
|
|
Loading…
Reference in a new issue