Left/right experiment

Refs #116
pull/125/head
M66B 6 years ago
parent 82023bd564
commit 790c09af9f

@ -0,0 +1,92 @@
package eu.faircode.email;
import android.content.Context;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.MotionEvent;
import androidx.constraintlayout.widget.ConstraintLayout;
public class ConstraintLayoutTouch extends ConstraintLayout {
private IGestureListener listener = null;
enum Direction {Left, Right, Up, Down}
private static final long VELOCITY_THRESHOLD = 3000;
public ConstraintLayoutTouch(Context context) {
super(context);
}
public ConstraintLayoutTouch(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ConstraintLayoutTouch(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (listener != null)
gestureDetector.onTouchEvent(ev);
return super.onInterceptTouchEvent(ev);
}
void setGestureListener(IGestureListener listener) {
this.listener = listener;
}
private GestureDetector gestureDetector = new GestureDetector(getContext(), new GestureDetector.OnGestureListener() {
@Override
public boolean onDown(final MotionEvent e) {
return false;
}
@Override
public void onShowPress(final MotionEvent e) {
}
@Override
public boolean onSingleTapUp(final MotionEvent e) {
return false;
}
@Override
public boolean onScroll(final MotionEvent e1, final MotionEvent e2, final float distanceX,
final float distanceY) {
return false;
}
@Override
public void onLongPress(final MotionEvent e) {
}
@Override
public boolean onFling(final MotionEvent e1, final MotionEvent e2,
final float velocityX,
final float velocityY) {
if (Math.abs(velocityX) < VELOCITY_THRESHOLD && Math.abs(velocityY) < VELOCITY_THRESHOLD)
return false;
if (Math.abs(velocityX) > Math.abs(velocityY)) {
if (velocityX >= 0)
listener.onSwipe(Direction.Right);
else
listener.onSwipe(Direction.Left);
} else {
if (velocityY >= 0)
listener.onSwipe(Direction.Down);
else
listener.onSwipe(Direction.Up);
}
return true;
}
});
interface IGestureListener {
void onSwipe(Direction direction);
}
}

@ -160,6 +160,23 @@ public interface DaoMessage {
" ORDER BY message.received") " ORDER BY message.received")
LiveData<List<EntityMessage>> liveUnseenUnified(); LiveData<List<EntityMessage>> liveUnseenUnified();
@Query("SELECT message.*" +
", account.name AS accountName, account.color AS accountColor" +
", folder.name as folderName, folder.type as folderType" +
", (SELECT COUNT(m1.id) FROM message m1 WHERE m1.account = message.account AND m1.thread = message.thread AND NOT m1.ui_hide) AS count" +
", (SELECT COUNT(m2.id) FROM message m2 WHERE m2.account = message.account AND m2.thread = message.thread AND NOT m2.ui_hide AND NOT m2.ui_seen) AS unseen" +
", (SELECT COUNT(a.id) FROM attachment a WHERE a.message = message.id) AS attachments" +
" FROM message related" +
" JOIN message ON message.folder = related.folder" +
" JOIN account ON account.id = message.account" +
" JOIN folder ON folder.id = message.folder" +
" WHERE related.id = :id" +
" ORDER BY" +
" CASE WHEN :next OR message.sent IS NULL THEN message.sent ELSE -message.sent END, " +
" CASE WHEN :next OR message.received IS NULL THEN message.received ELSE -message.received END" +
" LIMIT 1")
TupleMessageEx getMessage(long id, boolean next);
@Query("SELECT uid FROM message" + @Query("SELECT uid FROM message" +
" WHERE folder = :folder" + " WHERE folder = :folder" +
" AND received >= :received" + " AND received >= :received" +

@ -100,7 +100,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
public class FragmentMessage extends FragmentEx { public class FragmentMessage extends FragmentEx {
private ViewGroup view; private ConstraintLayoutTouch view;
private View vwAnswerAnchor; private View vwAnswerAnchor;
private ImageView ivFlagged; private ImageView ivFlagged;
private ImageView ivAvatar; private ImageView ivAvatar;
@ -157,7 +157,7 @@ public class FragmentMessage extends FragmentEx {
@Override @Override
@Nullable @Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = (ViewGroup) inflater.inflate(R.layout.fragment_message, container, false); view = (ConstraintLayoutTouch) inflater.inflate(R.layout.fragment_message, container, false);
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
debug = prefs.getBoolean("debug", false); debug = prefs.getBoolean("debug", false);
@ -405,6 +405,38 @@ public class FragmentMessage extends FragmentEx {
} }
}); });
view.setGestureListener(new ConstraintLayoutTouch.IGestureListener() {
@Override
public void onSwipe(ConstraintLayoutTouch.Direction direction) {
if (message == null)
return;
Bundle args = new Bundle();
args.putLong("id", message.id);
args.putBoolean("next",
direction == ConstraintLayoutTouch.Direction.Down ||
direction == ConstraintLayoutTouch.Direction.Right);
new SimpleTask<TupleMessageEx>() {
@Override
protected TupleMessageEx onLoad(Context context, Bundle args) throws Throwable {
long id = args.getLong("id");
boolean next = args.getBoolean("next");
return DB.getInstance(context).message().getMessage(id, next);
}
@Override
protected void onLoaded(Bundle args, TupleMessageEx message) {
if (message != null) {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext());
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_VIEW_MESSAGE)
.putExtra("message", message));
}
}
}.load(FragmentMessage.this, args);
}
});
// Initialize // Initialize
grpHeader.setVisibility(View.GONE); grpHeader.setVisibility(View.GONE);
grpAddresses.setVisibility(View.GONE); grpAddresses.setVisibility(View.GONE);

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <eu.faircode.email.ConstraintLayoutTouch xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -438,4 +438,4 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
app:constraint_referenced_ids="scroll" /> app:constraint_referenced_ids="scroll" />
</androidx.constraintlayout.widget.ConstraintLayout> </eu.faircode.email.ConstraintLayoutTouch>

Loading…
Cancel
Save