Indent in/outgoing messages in thread

This commit is contained in:
M66B 2019-10-12 15:40:13 +02:00
parent 2b5bcdb13a
commit 4d1f8d6b6d
2 changed files with 44 additions and 28 deletions

View File

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

View File

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