Select action on swipe

pull/157/head
M66B 6 years ago
parent 02f129ad07
commit bdf9478075

@ -198,6 +198,8 @@ public class EntityFolder extends EntityOrder implements Serializable {
} }
static int getIcon(String type) { static int getIcon(String type) {
if (type == null)
return R.drawable.baseline_list_24;
if (EntityFolder.INBOX.equals(type)) if (EntityFolder.INBOX.equals(type))
return R.drawable.baseline_inbox_24; return R.drawable.baseline_inbox_24;
if (EntityFolder.DRAFTS.equals(type)) if (EntityFolder.DRAFTS.equals(type))

@ -49,6 +49,7 @@ import android.text.TextUtils;
import android.text.format.DateUtils; import android.text.format.DateUtils;
import android.util.LongSparseArray; import android.util.LongSparseArray;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
@ -1111,14 +1112,17 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
if (message == null) if (message == null)
return 0; return 0;
if (EntityFolder.OUTBOX.equals(message.folderType))
return 0;
TupleAccountSwipes swipes = accountSwipes.get(message.account); TupleAccountSwipes swipes = accountSwipes.get(message.account);
if (swipes == null) if (swipes == null)
return 0; return 0;
int flags = 0; int flags = 0;
if (swipes.swipe_left != null && !swipes.swipe_left.equals(message.folder)) if (swipes.swipe_left == null || !swipes.swipe_left.equals(message.folder))
flags |= ItemTouchHelper.LEFT; flags |= ItemTouchHelper.LEFT;
if (swipes.swipe_right != null && !swipes.swipe_right.equals(message.folder)) if (swipes.swipe_right == null || !swipes.swipe_right.equals(message.folder))
flags |= ItemTouchHelper.RIGHT; flags |= ItemTouchHelper.RIGHT;
return makeMovementFlags(0, flags); return makeMovementFlags(0, flags);
@ -1195,20 +1199,92 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
@Override @Override
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) { public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
TupleMessageEx message = getMessage(viewHolder); final TupleMessageEx message = getMessage(viewHolder);
if (message == null) { if (message == null) {
super.clearView(rvMessage, viewHolder); adapter.notifyItemChanged(viewHolder.getAdapterPosition());
return; return;
} }
TupleAccountSwipes swipes = accountSwipes.get(message.account); TupleAccountSwipes swipes = accountSwipes.get(message.account);
if (swipes == null) { if (swipes == null) {
super.clearView(rvMessage, viewHolder); adapter.notifyItemChanged(viewHolder.getAdapterPosition());
return; return;
} }
Log.i("Swiped dir=" + direction + " message=" + message.id); Log.i("Swiped dir=" + direction + " message=" + message.id);
if (direction == ItemTouchHelper.LEFT ? swipes.swipe_left == null : swipes.swipe_right == null) {
adapter.notifyItemChanged(viewHolder.getAdapterPosition());
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(getContext(), getViewLifecycleOwner(), viewHolder.itemView);
popupMenu.setGravity(Gravity.RIGHT);
if (message.ui_seen)
popupMenu.getMenu().add(Menu.NONE, R.string.title_unseen, 2, R.string.title_unseen);
else
popupMenu.getMenu().add(Menu.NONE, R.string.title_seen, 1, R.string.title_seen);
popupMenu.getMenu().add(Menu.NONE, R.string.title_snooze, 3, R.string.title_snooze);
popupMenu.getMenu().add(Menu.NONE, R.string.title_flag_color, 3, R.string.title_flag_color);
popupMenu.getMenu().add(Menu.NONE, R.string.title_move, 3, R.string.title_move);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem target) {
switch (target.getItemId()) {
case R.string.title_seen:
onActionSeenSelection(true, message.id);
return true;
case R.string.title_unseen:
onActionSeenSelection(false, message.id);
return true;
case R.string.title_snooze:
onActionSnoozeSelection(message.id);
return true;
case R.string.title_flag_color:
onActionFlagColorSelection(message.color == null ? Color.TRANSPARENT : message.color, message.id);
return true;
case R.string.title_move:
onMenuMove();
return true;
default:
return false;
}
}
private void onMenuMove() {
Bundle args = new Bundle();
args.putLong("account", message.account);
new SimpleTask<List<TupleFolderEx>>() {
@Override
protected List<TupleFolderEx> onExecute(Context context, Bundle args) {
long account = args.getLong("account");
DB db = DB.getInstance(context);
return db.folder().getFoldersEx(account);
}
@Override
protected void onExecuted(Bundle args, List<TupleFolderEx> folders) {
onActionMoveSelectionAccount(
message.account,
folders,
Arrays.asList(new Long[]{message.folder}),
message.id);
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
}
}.execute(getContext(), getViewLifecycleOwner(), args, "message:move");
}
});
popupMenu.show();
} else {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", message.id); args.putLong("id", message.id);
args.putBoolean("thread", viewType != AdapterMessage.ViewType.THREAD); args.putBoolean("thread", viewType != AdapterMessage.ViewType.THREAD);
@ -1264,6 +1340,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
} }
}.execute(FragmentMessages.this, args, "messages:swipe"); }.execute(FragmentMessages.this, args, "messages:swipe");
} }
}
private TupleMessageEx getMessage(RecyclerView.ViewHolder viewHolder) { private TupleMessageEx getMessage(RecyclerView.ViewHolder viewHolder) {
if (selectionTracker != null && selectionTracker.hasSelection()) if (selectionTracker != null && selectionTracker.hasSelection())
@ -1527,22 +1604,22 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
public boolean onMenuItemClick(MenuItem target) { public boolean onMenuItemClick(MenuItem target) {
switch (target.getItemId()) { switch (target.getItemId()) {
case R.string.title_seen: case R.string.title_seen:
onActionSeenSelection(true); onActionSeenSelection(true, null);
return true; return true;
case R.string.title_unseen: case R.string.title_unseen:
onActionSeenSelection(false); onActionSeenSelection(false, null);
return true; return true;
case R.string.title_snooze: case R.string.title_snooze:
onActionSnoozeSelection(); onActionSnoozeSelection(null);
return true; return true;
case R.string.title_flag: case R.string.title_flag:
onActionFlagSelection(true, null); onActionFlagSelection(true, null, null);
return true; return true;
case R.string.title_unflag: case R.string.title_unflag:
onActionFlagSelection(false, null); onActionFlagSelection(false, null, null);
return true; return true;
case R.string.title_flag_color: case R.string.title_flag_color:
onActionFlagColorSelection(); onActionFlagColorSelection(Color.TRANSPARENT, null);
return true; return true;
case R.string.title_archive: case R.string.title_archive:
onActionMoveSelection(EntityFolder.ARCHIVE); onActionMoveSelection(EntityFolder.ARCHIVE);
@ -1558,7 +1635,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
return true; return true;
case R.string.title_move_to_account: case R.string.title_move_to_account:
long account = target.getIntent().getLongExtra("account", -1); long account = target.getIntent().getLongExtra("account", -1);
onActionMoveSelectionAccount(account, result.targets.get(account), result.folders); onActionMoveSelectionAccount(account, result.targets.get(account), result.folders, null);
return true; return true;
default: default:
return false; return false;
@ -1587,9 +1664,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
return ids; return ids;
} }
private void onActionSeenSelection(boolean seen) { private void onActionSeenSelection(boolean seen, Long id) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLongArray("ids", getSelection()); args.putLongArray("ids", id == null ? getSelection() : new long[]{id});
args.putBoolean("seen", seen); args.putBoolean("seen", seen);
selectionTracker.clearSelection(); selectionTracker.clearSelection();
@ -1629,7 +1706,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
}.execute(FragmentMessages.this, args, "messages:seen"); }.execute(FragmentMessages.this, args, "messages:seen");
} }
private void onActionSnoozeSelection() { private void onActionSnoozeSelection(final Long id) {
DialogDuration.show(getContext(), getViewLifecycleOwner(), R.string.title_snooze, DialogDuration.show(getContext(), getViewLifecycleOwner(), R.string.title_snooze,
new DialogDuration.IDialogDuration() { new DialogDuration.IDialogDuration() {
@Override @Override
@ -1641,7 +1718,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
} }
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLongArray("ids", getSelection()); args.putLongArray("ids", id == null ? getSelection() : new long[]{id});
args.putLong("wakeup", duration == 0 ? -1 : time); args.putLong("wakeup", duration == 0 ? -1 : time);
selectionTracker.clearSelection(); selectionTracker.clearSelection();
@ -1692,9 +1769,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
}); });
} }
private void onActionFlagSelection(boolean flagged, Integer color) { private void onActionFlagSelection(boolean flagged, Integer color, Long id) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLongArray("ids", getSelection()); args.putLongArray("ids", id == null ? getSelection() : new long[]{id});
args.putBoolean("flagged", flagged); args.putBoolean("flagged", flagged);
if (color != null) if (color != null)
args.putInt("color", color); args.putInt("color", color);
@ -1737,10 +1814,10 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
}.execute(FragmentMessages.this, args, "messages:flag"); }.execute(FragmentMessages.this, args, "messages:flag");
} }
private void onActionFlagColorSelection() { private void onActionFlagColorSelection(int color, final Long id) {
int[] colors = getResources().getIntArray(R.array.colorPicker); int[] colors = getResources().getIntArray(R.array.colorPicker);
ColorPickerDialog colorPickerDialog = new ColorPickerDialog(); ColorPickerDialog colorPickerDialog = new ColorPickerDialog();
colorPickerDialog.initialize(R.string.title_flag_color, colors, Color.TRANSPARENT, 4, colors.length); colorPickerDialog.initialize(R.string.title_flag_color, colors, color, 4, colors.length);
colorPickerDialog.setOnColorSelectedListener(new ColorPickerSwatch.OnColorSelectedListener() { colorPickerDialog.setOnColorSelectedListener(new ColorPickerSwatch.OnColorSelectedListener() {
@Override @Override
public void onColorSelected(int color) { public void onColorSelected(int color) {
@ -1750,7 +1827,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
return; return;
} }
onActionFlagSelection(true, color); onActionFlagSelection(true, color, id);
} }
}); });
colorPickerDialog.show(getFragmentManager(), "colorpicker"); colorPickerDialog.show(getFragmentManager(), "colorpicker");
@ -1908,7 +1985,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
}.execute(FragmentMessages.this, args, "messages:move"); }.execute(FragmentMessages.this, args, "messages:move");
} }
private void onActionMoveSelectionAccount(long account, List<TupleFolderEx> folders, List<Long> disabled) { private void onActionMoveSelectionAccount(long account, List<TupleFolderEx> folders, List<Long> disabled, final Long id) {
final View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_folder_select, null); final View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_folder_select, null);
final RecyclerView rvFolder = dview.findViewById(R.id.rvFolder); final RecyclerView rvFolder = dview.findViewById(R.id.rvFolder);
final ContentLoadingProgressBar pbWait = dview.findViewById(R.id.pbWait); final ContentLoadingProgressBar pbWait = dview.findViewById(R.id.pbWait);
@ -1927,7 +2004,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
@Override @Override
public void onFolderSelected(TupleFolderEx folder) { public void onFolderSelected(TupleFolderEx folder) {
dialog.dismiss(); dialog.dismiss();
onActionMoveSelection(folder.id); onActionMoveSelection(folder.id, id);
} }
}); });
@ -1941,9 +2018,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
dialog.show(); dialog.show();
} }
private void onActionMoveSelection(long target) { private void onActionMoveSelection(long target, Long id) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLongArray("ids", getSelection()); args.putLongArray("ids", id == null ? getSelection() : new long[]{id});
args.putLong("target", target); args.putLong("target", target);
new SimpleTask<ArrayList<MessageTarget>>() { new SimpleTask<ArrayList<MessageTarget>>() {

@ -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="M3,13h2v-2L3,11v2zM3,17h2v-2L3,15v2zM3,9h2L5,7L3,7v2zM7,13h14v-2L7,11v2zM7,17h14v-2L7,15v2zM7,7v2h14L21,7L7,7z"/>
</vector>
Loading…
Cancel
Save