added description row

This commit is contained in:
Chumva 2018-03-17 13:18:22 +02:00
parent 43a304b00b
commit 267f3f5ef6
4 changed files with 67 additions and 49 deletions

View file

@ -3,34 +3,52 @@
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_title_height"
android:layout_height="@dimen/bottom_sheet_selected_item_title_height"
android:background="?attr/selectableItemBackground"
android:gravity="center_vertical"
android:minHeight="@dimen/bottom_sheet_title_height"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding">
android:minHeight="@dimen/bottom_sheet_selected_item_title_height"
android:paddingLeft="@dimen/content_padding">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/title"
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.ListItemTitle"
osmand:typeface="@string/font_roboto_medium"
tools:text="Some Title" />
android:orientation="vertical">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:ellipsize="end"
android:maxLines="1"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:text="Some Title" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_sub_text_size"
tools:text="Some description" />
</LinearLayout>
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/text_button"
android:layout_width="wrap_content"
android:layout_height="@dimen/bottom_sheet_title_height"
android:layout_height="@dimen/bottom_sheet_selected_item_title_height"
android:background="?attr/selectableItemBackground"
android:drawablePadding="2dp"
android:drawablePadding="@dimen/content_padding"
android:gravity="center_vertical"
android:minHeight="@dimen/bottom_sheet_title_height"
android:minHeight="@dimen/bottom_sheet_selected_item_title_height"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:textAllCaps="true"

View file

@ -17,6 +17,8 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem {
@ColorRes
private int descriptionColorId = INVALID_ID;
private TextView descriptionTv;
public BottomSheetItemWithDescription(View customView,
@LayoutRes int layoutId,
Object tag,
@ -37,16 +39,19 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem {
}
public void setDescription(CharSequence description) {
this.description = description;
descriptionTv.setText(description);
}
@Override
public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) {
super.inflate(app, container, nightMode);
if (description != null) {
TextView descriptionTv = (TextView) view.findViewById(R.id.description);
descriptionTv = (TextView) view.findViewById(R.id.description);
descriptionTv.setText(description);
if (descriptionColorId != INVALID_ID) {
descriptionTv.setTextColor(ContextCompat.getColor(app, descriptionColorId));
}
}
}
public static class Builder extends SimpleBottomSheetItem.Builder {

View file

@ -12,7 +12,7 @@ import android.widget.TextView;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
public class BottomSheetItemWithTitleAndButton extends SimpleBottomSheetItem {
public class BottomSheetItemWithTitleAndButton extends BottomSheetItemWithDescription {
private View.OnClickListener onButtonClickListener;
private Drawable leftCompoundDrawable;
@ -32,12 +32,14 @@ public class BottomSheetItemWithTitleAndButton extends SimpleBottomSheetItem {
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);
super(customView, layoutId, tag, disabled, onClickListener, position, icon, title, titleColorId, description, descriptionColorId);
this.buttonTitle = buttonTitle;
this.onButtonClickListener = onButtonClickListener;
this.leftCompoundDrawable = leftCompoundDrawable;
@ -68,7 +70,7 @@ public class BottomSheetItemWithTitleAndButton extends SimpleBottomSheetItem {
}
}
public static class Builder extends SimpleBottomSheetItem.Builder {
public static class Builder extends BottomSheetItemWithDescription.Builder {
protected String buttonTitle;
protected View.OnClickListener onButtonClickListener;
@ -108,6 +110,8 @@ public class BottomSheetItemWithTitleAndButton extends SimpleBottomSheetItem {
icon,
title,
titleColorId,
description,
descriptionColorId,
buttonTitle,
onButtonClickListener,
leftCompoundDrawable,

View file

@ -43,21 +43,23 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
private List<FavouritePoint> favouritePoints;
private FavouritesAdapter adapter;
private RecyclerView recyclerView;
private boolean sortByDist = false;
private boolean sortByDist = true;
private boolean isSorted = false;
private boolean locationUpdateStarted;
private boolean compassUpdateAllowed = true;
private boolean target;
private boolean intermediate;
private BottomSheetItemWithTitleAndButton title;
@Override
public void createMenuItems(Bundle savedInstanceState) {
public void createMenuItems(final Bundle savedInstanceState) {
Bundle args = getArguments();
if (args != null) {
target = args.getBoolean(TARGET);
intermediate = args.getBoolean(INTERMEDIATE);
}
if (savedInstanceState != null && savedInstanceState.getBoolean(IS_SORTED)) {
sortByDist = savedInstanceState.getBoolean(SORTED_BY_TYPE);
}
favouritePoints = getMyApplication().getFavorites().getVisibleFavouritePoints();
recyclerView = new RecyclerView(getContext());
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
@ -69,25 +71,25 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
latLon = new LatLon(location.getLatitude(), location.getLongitude());
}
adapter = new FavouritesAdapter(getContext(), favouritePoints);
if (savedInstanceState != null && savedInstanceState.getBoolean(IS_SORTED)) {
sortByDist = savedInstanceState.getBoolean(SORTED_BY_TYPE);
sortFavourites();
}
title = (BottomSheetItemWithTitleAndButton) new BottomSheetItemWithTitleAndButton.Builder()
sortFavourites();
final BottomSheetItemWithTitleAndButton[] title = new BottomSheetItemWithTitleAndButton[1];
title[0] = (BottomSheetItemWithTitleAndButton) new BottomSheetItemWithTitleAndButton.Builder()
.setButtonIcons(null, getIconForButton())
.setButtonTitle(getTextForButton())
.setButtonTitle(getTextForButton(sortByDist))
.setonButtonClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sortFavourites();
title.setButtonIcons(null, getIconForButton());
title.setButtonText(getTextForButton());
title[0].setButtonIcons(null, getIconForButton());
title[0].setButtonText(getTextForButton(sortByDist));
title[0].setDescription(getTextForButton(!sortByDist));
}
})
.setDescription(getTextForButton(!sortByDist))
.setTitle(getString(R.string.favourites))
.setLayoutId(R.layout.bottom_sheet_item_with_title_and_button)
.create();
items.add(title);
items.add(title[0]);
adapter.setItemClickListener(new View.OnClickListener() {
@Override
@ -114,10 +116,10 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
private Drawable getIconForButton() {
return getIcon(sortByDist ? R.drawable.ic_action_list_sort : R.drawable.ic_action_sort_by_name,
nightMode ? R.color.route_info_go_btn_inking_dark : R.color.dash_search_icon_light);
nightMode ? R.color.multi_selection_menu_close_btn_dark : R.color.multi_selection_menu_close_btn_light);
}
private String getTextForButton() {
private String getTextForButton(boolean sortByDist) {
return getString(sortByDist ? R.string.sort_by_distance : R.string.sort_by_name);
}
@ -284,18 +286,7 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
}
@Override
protected int getMaximumHeight() {
final int maxHeight = AndroidUtils.dpToPx(getContext(), 300);
final int screenHeight = AndroidUtils.getScreenHeight(getActivity());
final int statusBarHeight = AndroidUtils.getStatusBarHeight(getActivity());
final int availableHeight = screenHeight - statusBarHeight - AndroidUtils.getNavBarHeight(getContext())
- AndroidUtils.dpToPx(getContext(), 1) // divider height
- getResources().getDimensionPixelSize(R.dimen.bottom_sheet_cancel_button_height);
if (availableHeight < maxHeight) {
return availableHeight;
} else {
return maxHeight;
}
protected int getCustomHeight() {
return AndroidUtils.dpToPx(getContext(), 300);
}
}