Add the ability to set maxLines for description in BottomSheetItemWithDescription

This commit is contained in:
Alex Sytnyk 2018-05-08 17:52:22 +03:00
parent 0d777ad3d8
commit 1d82dff065
4 changed files with 54 additions and 19 deletions

View file

@ -13,6 +13,7 @@ public class BaseBottomSheetItem {
public static final int INVALID_POSITION = -1;
public static final int INVALID_ID = -1;
public static final int INVALID_VALUE = -1;
protected View view;
@LayoutRes

View file

@ -24,22 +24,34 @@ public class BottomSheetItemTitleWithDescrAndButton extends BottomSheetItemWithD
private TextView textButtonTV;
public BottomSheetItemTitleWithDescrAndButton(View customView,
@LayoutRes int layoutId,
Object tag,
boolean disabled,
View.OnClickListener onClickListener,
int position,
Drawable icon,
String title,
@ColorRes int titleColorId,
CharSequence description,
@ColorRes int descriptionColorId,
String buttonTitle,
View.OnClickListener onButtonClickListener,
Drawable leftCompoundDrawable,
Drawable rightCompoundDrawable,
@ColorRes int buttonTextColor) {
super(customView, layoutId, tag, disabled, onClickListener, position, icon, title, titleColorId, description, descriptionColorId);
@LayoutRes int layoutId,
Object tag,
boolean disabled,
View.OnClickListener onClickListener,
int position,
Drawable icon,
String title,
@ColorRes int titleColorId,
CharSequence description,
@ColorRes int descriptionColorId,
int descriptionMaxLines,
String buttonTitle,
View.OnClickListener onButtonClickListener,
Drawable leftCompoundDrawable,
Drawable rightCompoundDrawable,
@ColorRes int buttonTextColor) {
super(customView,
layoutId,
tag,
disabled,
onClickListener,
position,
icon,
title,
titleColorId,
description,
descriptionColorId,
descriptionMaxLines);
this.buttonTitle = buttonTitle;
this.onButtonClickListener = onButtonClickListener;
this.leftCompoundDrawable = leftCompoundDrawable;
@ -112,6 +124,7 @@ public class BottomSheetItemTitleWithDescrAndButton extends BottomSheetItemWithD
titleColorId,
description,
descriptionColorId,
descriptionMaxLines,
buttonTitle,
onButtonClickListener,
leftCompoundDrawable,

View file

@ -36,6 +36,7 @@ public class BottomSheetItemWithCompoundButton extends BottomSheetItemWithDescri
@ColorRes int titleColorId,
CharSequence description,
@ColorRes int descriptionColorId,
int descriptionMaxLines,
boolean checked,
ColorStateList buttonTintList,
OnCheckedChangeListener onCheckedChangeListener) {
@ -49,7 +50,8 @@ public class BottomSheetItemWithCompoundButton extends BottomSheetItemWithDescri
title,
titleColorId,
description,
descriptionColorId);
descriptionColorId,
descriptionMaxLines);
this.checked = checked;
this.buttonTintList = buttonTintList;
this.onCheckedChangeListener = onCheckedChangeListener;
@ -102,6 +104,7 @@ public class BottomSheetItemWithCompoundButton extends BottomSheetItemWithDescri
titleColorId,
description,
descriptionColorId,
descriptionMaxLines,
checked,
buttonTintList,
onCheckedChangeListener);

View file

@ -16,6 +16,7 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem {
protected CharSequence description;
@ColorRes
private int descriptionColorId = INVALID_ID;
private int descriptionMaxLines = INVALID_VALUE;
private TextView descriptionTv;
@ -29,10 +30,12 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem {
String title,
@ColorRes int titleColorId,
CharSequence description,
@ColorRes int descriptionColorId) {
@ColorRes int descriptionColorId,
int descriptionMaxLines) {
super(customView, layoutId, tag, disabled, onClickListener, position, icon, title, titleColorId);
this.description = description;
this.descriptionColorId = descriptionColorId;
this.descriptionMaxLines = descriptionMaxLines;
}
protected BottomSheetItemWithDescription() {
@ -44,6 +47,11 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem {
descriptionTv.setText(description);
}
public void setDescriptionMaxLines(int maxLines) {
this.descriptionMaxLines = maxLines;
descriptionTv.setMaxLines(maxLines);
}
@Override
public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) {
super.inflate(app, container, nightMode);
@ -53,6 +61,9 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem {
if (descriptionColorId != INVALID_ID) {
descriptionTv.setTextColor(ContextCompat.getColor(app, descriptionColorId));
}
if (descriptionMaxLines != INVALID_VALUE) {
descriptionTv.setMaxLines(descriptionMaxLines);
}
}
}
@ -61,6 +72,7 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem {
protected CharSequence description;
@ColorRes
protected int descriptionColorId = INVALID_ID;
protected int descriptionMaxLines = INVALID_POSITION;
public Builder setDescription(CharSequence description) {
this.description = description;
@ -72,6 +84,11 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem {
return this;
}
public Builder setDescriptionMaxLines(int maxLines) {
this.descriptionMaxLines = maxLines;
return this;
}
public BottomSheetItemWithDescription create() {
return new BottomSheetItemWithDescription(customView,
layoutId,
@ -83,7 +100,8 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem {
title,
titleColorId,
description,
descriptionColorId);
descriptionColorId,
descriptionMaxLines);
}
}
}