Browse Source

Show swipe action icons

Fixes #59
main
M66B 6 years ago
parent
commit
13de85a3d3
4 changed files with 107 additions and 49 deletions
  1. BIN
      .idea/caches/build_file_checksums.ser
  2. +87
    -49
      app/src/main/java/eu/faircode/email/FragmentMessages.java
  3. +10
    -0
      app/src/main/res/drawable/baseline_inbox_24.xml
  4. +10
    -0
      app/src/main/res/drawable/baseline_move_to_inbox_24.xml

BIN
.idea/caches/build_file_checksums.ser View File


+ 87
- 49
app/src/main/java/eu/faircode/email/FragmentMessages.java View File

@ -22,6 +22,8 @@ package eu.faircode.email;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.text.TextUtils; import android.text.TextUtils;
@ -160,64 +162,100 @@ public class FragmentMessages extends FragmentEx {
} }
@Override @Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
public void onChildDraw(Canvas canvas, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
int pos = viewHolder.getAdapterPosition(); int pos = viewHolder.getAdapterPosition();
if (pos != RecyclerView.NO_POSITION) {
TupleMessageEx message = ((AdapterMessage) rvMessage.getAdapter()).getCurrentList().get(pos);
Log.i(Helper.TAG, "Swiped dir=" + direction + " message=" + message.id);
Bundle args = new Bundle();
args.putLong("id", message.id);
args.putInt("direction", direction);
new SimpleTask<String>() {
@Override
protected String onLoad(Context context, Bundle args) {
long id = args.getLong("id");
int direction = args.getInt("direction");
EntityFolder target = null;
DB db = DB.getInstance(context);
try {
db.beginTransaction();
EntityMessage message = db.message().getMessage(id);
EntityFolder folder = db.folder().getFolder(message.folder);
if (EntityFolder.ARCHIVE.equals(folder.type) || EntityFolder.TRASH.equals(folder.type))
target = db.folder().getFolderByType(message.account, EntityFolder.INBOX);
else {
if (direction == ItemTouchHelper.RIGHT)
target = db.folder().getFolderByType(message.account, EntityFolder.ARCHIVE);
if (direction == ItemTouchHelper.LEFT || target == null)
target = db.folder().getFolderByType(message.account, EntityFolder.TRASH);
}
if (pos == RecyclerView.NO_POSITION)
return;
TupleMessageEx message = ((AdapterMessage) rvMessage.getAdapter()).getCurrentList().get(pos);
boolean inbox = (EntityFolder.ARCHIVE.equals(message.folderType) || EntityFolder.TRASH.equals(message.folderType));
View itemView = viewHolder.itemView;
int margin = Math.round(12 * (getResources().getDisplayMetrics().density));
if (dX > margin) {
// Right swipe
Drawable d = getResources().getDrawable(inbox ? R.drawable.baseline_inbox_24 : R.drawable.baseline_archive_24, getContext().getTheme());
d.setBounds(
itemView.getLeft() + margin,
itemView.getTop() + d.getIntrinsicHeight() / 2,
itemView.getLeft() + margin + d.getIntrinsicWidth(),
itemView.getTop() + (itemView.getHeight() - d.getIntrinsicHeight() / 2));
d.draw(canvas);
} else if (dX < -margin) {
// Left swipe
Drawable d = getResources().getDrawable(inbox ? R.drawable.baseline_inbox_24 : R.drawable.baseline_delete_24, getContext().getTheme());
d.setBounds(
itemView.getLeft() + itemView.getWidth() - d.getIntrinsicWidth() - margin,
itemView.getTop() + d.getIntrinsicHeight() / 2,
itemView.getLeft() + itemView.getWidth() - margin,
itemView.getTop() + (itemView.getHeight() - d.getIntrinsicHeight() / 2));
d.draw(canvas);
}
db.message().setMessageUiHide(message.id, true);
EntityOperation.queue(db, message, EntityOperation.MOVE, target.id);
super.onChildDraw(canvas, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
}
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
int pos = viewHolder.getAdapterPosition();
if (pos == RecyclerView.NO_POSITION)
return;
db.setTransactionSuccessful();
} finally {
db.endTransaction();
TupleMessageEx message = ((AdapterMessage) rvMessage.getAdapter()).getCurrentList().get(pos);
Log.i(Helper.TAG, "Swiped dir=" + direction + " message=" + message.id);
Bundle args = new Bundle();
args.putLong("id", message.id);
args.putInt("direction", direction);
new SimpleTask<String>() {
@Override
protected String onLoad(Context context, Bundle args) {
long id = args.getLong("id");
int direction = args.getInt("direction");
EntityFolder target = null;
DB db = DB.getInstance(context);
try {
db.beginTransaction();
EntityMessage message = db.message().getMessage(id);
EntityFolder folder = db.folder().getFolder(message.folder);
if (EntityFolder.ARCHIVE.equals(folder.type) || EntityFolder.TRASH.equals(folder.type))
target = db.folder().getFolderByType(message.account, EntityFolder.INBOX);
else {
if (direction == ItemTouchHelper.RIGHT)
target = db.folder().getFolderByType(message.account, EntityFolder.ARCHIVE);
if (direction == ItemTouchHelper.LEFT || target == null)
target = db.folder().getFolderByType(message.account, EntityFolder.TRASH);
} }
EntityOperation.process(context);
db.message().setMessageUiHide(message.id, true);
EntityOperation.queue(db, message, EntityOperation.MOVE, target.id);
return target.name;
db.setTransactionSuccessful();
} finally {
db.endTransaction();
} }
@Override
protected void onLoaded(Bundle args, String folder) {
Snackbar.make(
view,
getString(R.string.title_moving, Helper.localizeFolderName(getContext(), folder)),
Snackbar.LENGTH_SHORT).show();
}
EntityOperation.process(context);
@Override
protected void onException(Bundle args, Throwable ex) {
Toast.makeText(getContext(), ex.toString(), Toast.LENGTH_LONG).show();
}
}.load(FragmentMessages.this, args);
}
return target.name;
}
@Override
protected void onLoaded(Bundle args, String folder) {
Snackbar.make(
view,
getString(R.string.title_moving, Helper.localizeFolderName(getContext(), folder)),
Snackbar.LENGTH_SHORT).show();
}
@Override
protected void onException(Bundle args, Throwable ex) {
Toast.makeText(getContext(), ex.toString(), Toast.LENGTH_LONG).show();
}
}.load(FragmentMessages.this, args);
} }
}).attachToRecyclerView(rvMessage); }).attachToRecyclerView(rvMessage);


+ 10
- 0
app/src/main/res/drawable/baseline_inbox_24.xml View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M19,3L4.99,3c-1.11,0 -1.98,0.89 -1.98,2L3,19c0,1.1 0.88,2 1.99,2L19,21c1.1,0 2,-0.9 2,-2L21,5c0,-1.11 -0.9,-2 -2,-2zM19,15h-4c0,1.66 -1.35,3 -3,3s-3,-1.34 -3,-3L4.99,15L4.99,5L19,5v10z"/>
</vector>

+ 10
- 0
app/src/main/res/drawable/baseline_move_to_inbox_24.xml View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M19,3L4.99,3c-1.11,0 -1.98,0.9 -1.98,2L3,19c0,1.1 0.88,2 1.99,2L19,21c1.1,0 2,-0.9 2,-2L21,5c0,-1.1 -0.9,-2 -2,-2zM19,15h-4c0,1.66 -1.35,3 -3,3s-3,-1.34 -3,-3L4.99,15L4.99,5L19,5v10zM16,10h-2L14,7h-4v3L8,10l4,4 4,-4z"/>
</vector>

Loading…
Cancel
Save