|
|
|
@ -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);
|
|
|
|
|
setCardBackgroundColor(Color.TRANSPARENT);
|
|
|
|
|
init(context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
if (cards) {
|
|
|
|
|
int dp = Helper.dp2pixels(getContext(), compact ? 3 : 6);
|
|
|
|
|
margin = Helper.dp2pixels(context, compact ? 3 : 6);
|
|
|
|
|
ident = Helper.dp2pixels(context, 12 + (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);
|
|
|
|
|
setRadius(cards ? margin : 0);
|
|
|
|
|
setCardElevation(0);
|
|
|
|
|
setCardBackgroundColor(Color.TRANSPARENT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|