mirror of
https://github.com/M66B/FairEmail.git
synced 2026-01-02 19:10:11 +01:00
Indent in/outgoing messages in thread
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user