Indent in/outgoing messages in thread

pull/163/head
M66B 5 years ago
parent 2b5bcdb13a
commit 4d1f8d6b6d

@ -3984,6 +3984,11 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
if (message == null || context == null) if (message == null || context == null)
return; return;
if (viewType == ViewType.THREAD) {
boolean outgoing = holder.isOutgoing(message);
holder.card.setOutgoing(outgoing);
}
if (filter_duplicates && message.duplicate) { if (filter_duplicates && message.duplicate) {
holder.tvFolder.setText(context.getString(R.string.title_duplicate_in, message.getFolderName(context))); holder.tvFolder.setText(context.getString(R.string.title_duplicate_in, message.getFolderName(context)));
holder.tvFolder.setTypeface(message.unseen > 0 ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT); holder.tvFolder.setTypeface(message.unseen > 0 ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT);

@ -31,51 +31,53 @@ import androidx.cardview.widget.CardView;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
public class ViewCardOptional extends CardView { public class ViewCardOptional extends CardView {
private boolean cards;
private boolean compact;
private boolean threading;
private int margin;
private int ident;
private Integer color = null;
public ViewCardOptional(@NonNull Context context) { public ViewCardOptional(@NonNull Context context) {
super(context); super(context);
setCardBackgroundColor(Color.TRANSPARENT); init(context);
} }
public ViewCardOptional(@NonNull Context context, @Nullable AttributeSet attrs) { public ViewCardOptional(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs); super(context, attrs);
setCardBackgroundColor(Color.TRANSPARENT); init(context);
} }
public ViewCardOptional(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { public ViewCardOptional(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr); super(context, attrs, defStyleAttr);
setCardBackgroundColor(Color.TRANSPARENT); init(context);
} }
private boolean initialized = false; private void init(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
@Override cards = prefs.getBoolean("cards", true);
protected void onAttachedToWindow() { compact = prefs.getBoolean("compact", false);
super.onAttachedToWindow(); threading = prefs.getBoolean("threading", true);
if (!initialized) {
initialized = true;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean cards = prefs.getBoolean("cards", true);
boolean compact = prefs.getBoolean("compact", false);
if (cards) { margin = Helper.dp2pixels(context, compact ? 3 : 6);
int dp = Helper.dp2pixels(getContext(), compact ? 3 : 6); ident = Helper.dp2pixels(context, 12 + (compact ? 3 : 6));
ViewGroup.MarginLayoutParams lparam = (ViewGroup.MarginLayoutParams) getLayoutParams(); setRadius(cards ? margin : 0);
lparam.setMargins(dp, dp, dp, dp); setCardElevation(0);
setLayoutParams(lparam); setCardBackgroundColor(Color.TRANSPARENT);
}
setRadius(dp);
setContentPadding(dp, dp, dp, dp);
} else
setRadius(0);
setCardElevation(0); @Override
protected void onAttachedToWindow() {
if (cards) {
ViewGroup.MarginLayoutParams lparam = (ViewGroup.MarginLayoutParams) getLayoutParams();
lparam.setMargins(margin, margin, margin, margin);
setLayoutParams(lparam);
setContentPadding(margin, margin, margin, margin);
} }
}
private Integer color = null; super.onAttachedToWindow();
}
@Override @Override
public void setCardBackgroundColor(int color) { public void setCardBackgroundColor(int color) {
@ -90,4 +92,13 @@ public class ViewCardOptional extends CardView {
super.setCardBackgroundColor(color); super.setCardBackgroundColor(color);
} }
} }
public void setOutgoing(boolean outgoing) {
if (cards && threading) {
ViewGroup.MarginLayoutParams lparam = (ViewGroup.MarginLayoutParams) getLayoutParams();
lparam.setMarginStart(outgoing ? margin : ident);
lparam.setMarginEnd(outgoing ? ident : margin);
setLayoutParams(lparam);
}
}
} }

Loading…
Cancel
Save