Refactoring

This commit is contained in:
M66B 2021-08-09 16:24:53 +02:00
parent 046316d122
commit f338214be4
1 changed files with 59 additions and 60 deletions

View File

@ -314,7 +314,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
public class ViewHolder extends RecyclerView.ViewHolder implements public class ViewHolder extends RecyclerView.ViewHolder implements
View.OnClickListener, View.OnClickListener,
View.OnLongClickListener, View.OnLongClickListener,
View.OnTouchListener,
View.OnLayoutChangeListener { View.OnLayoutChangeListener {
private ViewCardOptional card; private ViewCardOptional card;
private View view; private View view;
@ -483,7 +482,63 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
private TwoStateOwner cowner = new TwoStateOwner(owner, "MessageAttachments"); private TwoStateOwner cowner = new TwoStateOwner(owner, "MessageAttachments");
private TwoStateOwner powner = new TwoStateOwner(owner, "MessagePopup"); private TwoStateOwner powner = new TwoStateOwner(owner, "MessagePopup");
private ScaleGestureDetector gestureDetector; private View.OnTouchListener touchListener = new View.OnTouchListener() {
private ScaleGestureDetector gestureDetector = new ScaleGestureDetector(context, new ScaleGestureDetector.SimpleOnScaleGestureListener() {
private Toast toast = null;
@Override
public boolean onScale(ScaleGestureDetector detector) {
TupleMessageEx message = getMessage();
if (message != null) {
// Scale factor
float factor = detector.getScaleFactor();
float size = tvBody.getTextSize() * factor;
float scale = (textSize == 0 ? 1.0f : size / (textSize * message_zoom / 100f));
if (scale > 10)
return true;
// Text size
properties.setSize(message.id, size);
tvBody.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
// Image size
Spanned spanned = (Spanned) tvBody.getText();
for (ImageSpan img : spanned.getSpans(0, spanned.length(), ImageSpan.class)) {
Drawable d = img.getDrawable();
ImageHelper.AnnotatedSource a = new ImageHelper.AnnotatedSource(img.getSource());
ImageHelper.fitDrawable(d, a, scale, tvBody);
}
// Feedback
String perc = Math.round(scale * 100) + " %";
if (toast != null)
toast.cancel();
toast = ToastEx.makeText(context, perc, Toast.LENGTH_SHORT);
toast.show();
}
return true;
}
});
@Override
public boolean onTouch(View view, MotionEvent ev) {
if (ev.getPointerCount() > 1) {
view.getParent().requestDisallowInterceptTouchEvent(true);
if (view.getId() == R.id.tvBody) {
gestureDetector.onTouchEvent(ev);
return true;
} else
return false;
} else {
//view.getParent().requestDisallowInterceptTouchEvent(false);
//return (view.getId() == R.id.wvBody && ev.getAction() == MotionEvent.ACTION_MOVE);
boolean intercept = (view.getId() == R.id.wvBody && ((WebViewEx) wvBody).isZoomedY());
view.getParent().requestDisallowInterceptTouchEvent(intercept);
return false;
}
}
};
private MovementMethod movementMethod = new ArrowKeyMovementMethod() { private MovementMethod movementMethod = new ArrowKeyMovementMethod() {
private GestureDetector gestureDetector = new GestureDetector(context, private GestureDetector gestureDetector = new GestureDetector(context,
@ -874,7 +929,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
ibMoveBottom.setOnClickListener(this); ibMoveBottom.setOnClickListener(this);
ibSeenBottom.setOnClickListener(this); ibSeenBottom.setOnClickListener(this);
tvBody.setOnTouchListener(this); tvBody.setOnTouchListener(touchListener);
tvBody.setMovementMethod(movementMethod); tvBody.setMovementMethod(movementMethod);
tvBody.addOnLayoutChangeListener(this); tvBody.addOnLayoutChangeListener(this);
@ -886,44 +941,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
btnCalendarAccept.setOnLongClickListener(this); btnCalendarAccept.setOnLongClickListener(this);
btnCalendarDecline.setOnLongClickListener(this); btnCalendarDecline.setOnLongClickListener(this);
btnCalendarMaybe.setOnLongClickListener(this); btnCalendarMaybe.setOnLongClickListener(this);
gestureDetector = new ScaleGestureDetector(context, new ScaleGestureDetector.SimpleOnScaleGestureListener() {
private Toast toast = null;
@Override
public boolean onScale(ScaleGestureDetector detector) {
TupleMessageEx message = getMessage();
if (message != null) {
// Scale factor
float factor = detector.getScaleFactor();
float size = tvBody.getTextSize() * factor;
float scale = (textSize == 0 ? 1.0f : size / (textSize * message_zoom / 100f));
if (scale > 10)
return true;
// Text size
properties.setSize(message.id, size);
tvBody.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
// Image size
Spanned spanned = (Spanned) tvBody.getText();
for (ImageSpan img : spanned.getSpans(0, spanned.length(), ImageSpan.class)) {
Drawable d = img.getDrawable();
ImageHelper.AnnotatedSource a = new ImageHelper.AnnotatedSource(img.getSource());
ImageHelper.fitDrawable(d, a, scale, tvBody);
}
// Feedback
String perc = Math.round(scale * 100) + " %";
if (toast != null)
toast.cancel();
toast = ToastEx.makeText(context, perc, Toast.LENGTH_SHORT);
toast.show();
}
return true;
}
});
} }
if (accessibility) { if (accessibility) {
@ -2341,7 +2358,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
} }
}); });
webView.setImages(show_images, inline); webView.setImages(show_images, inline);
webView.setOnTouchListener(ViewHolder.this); webView.setOnTouchListener(touchListener);
tvBody.setVisibility(View.GONE); tvBody.setVisibility(View.GONE);
wvBody.setVisibility(View.VISIBLE); wvBody.setVisibility(View.VISIBLE);
@ -3238,24 +3255,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
return differ.getItem(pos); return differ.getItem(pos);
} }
@Override
public boolean onTouch(View view, MotionEvent ev) {
if (ev.getPointerCount() > 1) {
view.getParent().requestDisallowInterceptTouchEvent(true);
if (view.getId() == R.id.tvBody) {
gestureDetector.onTouchEvent(ev);
return true;
} else
return false;
} else {
//view.getParent().requestDisallowInterceptTouchEvent(false);
//return (view.getId() == R.id.wvBody && ev.getAction() == MotionEvent.ACTION_MOVE);
boolean intercept = (view.getId() == R.id.wvBody && ((WebViewEx) wvBody).isZoomedY());
view.getParent().requestDisallowInterceptTouchEvent(intercept);
return false;
}
}
@Override @Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
TupleMessageEx message = getMessage(); TupleMessageEx message = getMessage();