refactored some code
This commit is contained in:
parent
f3883c888b
commit
0f2986283a
5 changed files with 149 additions and 167 deletions
|
@ -1,23 +1,23 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:osmand="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/relativeLayout1"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="top">
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_list_item_height"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="@dimen/bottom_sheet_list_item_height"
|
||||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingRight="@dimen/content_padding">
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/bottom_sheet_title_height"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/content_padding"
|
||||
android:layout_marginRight="@dimen/content_padding"
|
||||
android:layout_weight="1"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center_vertical"
|
||||
android:maxLines="1"
|
||||
android:minHeight="@dimen/bottom_sheet_title_height"
|
||||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingRight="@dimen/content_padding"
|
||||
android:text="Some Title"
|
||||
android:textAppearance="@style/TextAppearance.ListItemTitle"
|
||||
osmand:typeface="@string/font_roboto_medium" />
|
||||
|
@ -26,18 +26,18 @@
|
|||
android:id="@+id/text_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:drawablePadding="2dp"
|
||||
android:drawableRight="@drawable/ic_action_sort_by_name"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="@dimen/bottom_sheet_title_height"
|
||||
android:paddingRight="@dimen/content_padding"
|
||||
android:text="@string/sort_by_name"
|
||||
android:text="Text on button"
|
||||
android:textAllCaps="true"
|
||||
android:textAppearance="@style/TextAppearance.ListItemTitle"
|
||||
android:textColor="?attr/color_dialog_buttons"
|
||||
android:textSize="@dimen/default_desc_text_size"
|
||||
android:textStyle="bold"
|
||||
osmand:typeface="@string/font_roboto_medium" />
|
||||
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,108 @@
|
|||
package net.osmand.plus.base.bottomsheetmenu;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.ColorRes;
|
||||
import android.support.annotation.LayoutRes;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
|
||||
public class BottomSheetItemWithTitleAndButton extends SimpleBottomSheetItem {
|
||||
|
||||
private View.OnClickListener onClickListener;
|
||||
private Drawable leftCompoundDrawable;
|
||||
private Drawable rightCompoundDrawable;
|
||||
private String ButtonTitle;
|
||||
private TextView textButtonTV;
|
||||
@ColorRes
|
||||
private int buttonTextColor = INVALID_ID;
|
||||
|
||||
public BottomSheetItemWithTitleAndButton(View customView,
|
||||
@LayoutRes int layoutId,
|
||||
Object tag,
|
||||
boolean disabled,
|
||||
View.OnClickListener onClickListener,
|
||||
int position,
|
||||
Drawable leftCompoundDrawable,
|
||||
Drawable rightCompoundDrawable,
|
||||
Drawable icon,
|
||||
String title,
|
||||
String ButtonTitle,
|
||||
@ColorRes int titleColorId,
|
||||
@ColorRes int buttonTextColor) {
|
||||
super(customView, layoutId, tag, disabled, null, position, icon, title, titleColorId);
|
||||
this.leftCompoundDrawable = leftCompoundDrawable;
|
||||
this.rightCompoundDrawable = rightCompoundDrawable;
|
||||
this.ButtonTitle = ButtonTitle;
|
||||
this.onClickListener = onClickListener;
|
||||
this.buttonTextColor = buttonTextColor;
|
||||
}
|
||||
|
||||
public void setButtonIcon(Drawable leftCompoundDrawable, Drawable rightCompoundDrawable) {
|
||||
textButtonTV.setCompoundDrawablesWithIntrinsicBounds(leftCompoundDrawable, null, rightCompoundDrawable, null);
|
||||
}
|
||||
|
||||
public void setButtonText(String text) {
|
||||
textButtonTV.setText(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) {
|
||||
super.inflate(app, container, nightMode);
|
||||
textButtonTV = (TextView) view.findViewById(R.id.text_button);
|
||||
textButtonTV.setOnClickListener(onClickListener);
|
||||
setButtonIcon(leftCompoundDrawable, rightCompoundDrawable);
|
||||
setButtonText(ButtonTitle);
|
||||
if (buttonTextColor != INVALID_ID) {
|
||||
textButtonTV.setTextColor(ContextCompat.getColor(app, buttonTextColor));
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder extends SimpleBottomSheetItem.Builder {
|
||||
|
||||
protected String title;
|
||||
private String buttonTitle;
|
||||
protected View.OnClickListener onClickListener;
|
||||
private Drawable leftCompoundDrawable;
|
||||
private Drawable rightCompoundDrawable;
|
||||
@ColorRes
|
||||
protected int buttonTextColor = INVALID_ID;
|
||||
|
||||
public BottomSheetItemWithTitleAndButton.Builder setButtonIcon(Drawable leftCompoundDrawable, Drawable rightCompoundDrawable) {
|
||||
this.leftCompoundDrawable = leftCompoundDrawable;
|
||||
this.rightCompoundDrawable = rightCompoundDrawable;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BottomSheetItemWithTitleAndButton.Builder setOnClickListener(View.OnClickListener onClickListener) {
|
||||
this.onClickListener = onClickListener;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BottomSheetItemWithTitleAndButton.Builder setButtonTitle(String buttonTitle) {
|
||||
this.buttonTitle = buttonTitle;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BottomSheetItemWithTitleAndButton create() {
|
||||
return new BottomSheetItemWithTitleAndButton(
|
||||
customView,
|
||||
layoutId,
|
||||
tag,
|
||||
disabled,
|
||||
onClickListener,
|
||||
position,
|
||||
leftCompoundDrawable,
|
||||
rightCompoundDrawable,
|
||||
icon,
|
||||
title,
|
||||
buttonTitle,
|
||||
titleColorId,
|
||||
buttonTextColor);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,119 +0,0 @@
|
|||
package net.osmand.plus.base.bottomsheetmenu.simpleitems;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
|
||||
|
||||
public class TitleWithButtonItem extends SimpleBottomSheetItem {
|
||||
|
||||
public static final String textOnLeft = "LEFT";
|
||||
public static final String textOnTop = "TOP";
|
||||
public static final String textOnRight = "RIGHT";
|
||||
public static final String textOnBottom = "BOTTOM";
|
||||
|
||||
private View.OnClickListener onClickListener;
|
||||
private String iconPosition;
|
||||
private Drawable icon;
|
||||
private String textOnButton;
|
||||
private TextView textButtonTV;
|
||||
|
||||
public TitleWithButtonItem(View.OnClickListener onClickListener,
|
||||
Drawable icon,
|
||||
String title,
|
||||
String textOnButton,
|
||||
String iconPosition) {
|
||||
this.title = title;
|
||||
this.layoutId = R.layout.bottom_sheet_item_title_with_button;
|
||||
this.icon = icon;
|
||||
this.textOnButton = textOnButton;
|
||||
this.iconPosition = iconPosition;
|
||||
this.onClickListener = onClickListener;
|
||||
}
|
||||
|
||||
public void setButtonIcon(Drawable icon, String iconPosition) {
|
||||
this.icon = icon;
|
||||
if (this.icon != null) {
|
||||
switch (iconPosition) {
|
||||
case textOnLeft:
|
||||
textButtonTV.setCompoundDrawablesWithIntrinsicBounds(this.icon, null, null, null);
|
||||
break;
|
||||
case textOnTop:
|
||||
textButtonTV.setCompoundDrawablesWithIntrinsicBounds(null, this.icon, null, null);
|
||||
break;
|
||||
case textOnRight:
|
||||
textButtonTV.setCompoundDrawablesWithIntrinsicBounds(null, null, this.icon, null);
|
||||
break;
|
||||
case textOnBottom:
|
||||
textButtonTV.setCompoundDrawablesWithIntrinsicBounds(null, null, null, this.icon);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setButtonText(String text) {
|
||||
textOnButton = text;
|
||||
textButtonTV.setText(textOnButton);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) {
|
||||
super.inflate(app, container, nightMode);
|
||||
|
||||
if (textOnButton != null) {
|
||||
textButtonTV = (TextView) view.findViewById(R.id.text_button);
|
||||
textButtonTV.setOnClickListener(onClickListener);
|
||||
setButtonIcon(icon, iconPosition);
|
||||
setButtonText(textOnButton);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder extends BaseBottomSheetItem.Builder {
|
||||
|
||||
private Drawable textIcon;
|
||||
protected String title;
|
||||
private String textOnRight;
|
||||
protected View.OnClickListener onClickListener;
|
||||
|
||||
private String iconPosition;
|
||||
|
||||
public TitleWithButtonItem.Builder setIcon(Drawable textIcon) {
|
||||
this.textIcon = textIcon;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TitleWithButtonItem.Builder setIconPosition(String iconPosition) {
|
||||
this.iconPosition = iconPosition;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TitleWithButtonItem.Builder setOnClickListener(View.OnClickListener onClickListener) {
|
||||
this.onClickListener = onClickListener;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TitleWithButtonItem.Builder setTextOnRight(String textOnRight) {
|
||||
this.textOnRight = textOnRight;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TitleWithButtonItem.Builder setTitle(String title) {
|
||||
this.title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TitleWithButtonItem create() {
|
||||
return new TitleWithButtonItem(onClickListener,
|
||||
textIcon,
|
||||
title,
|
||||
textOnRight,
|
||||
iconPosition);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,14 +5,11 @@ import android.os.Parcelable;
|
|||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.Location;
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.plus.OsmAndLocationProvider;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -20,7 +17,7 @@ import net.osmand.plus.TargetPointsHelper;
|
|||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleWithButtonItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithTitleAndButton;
|
||||
import net.osmand.plus.dashboard.DashLocationFragment;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
|
@ -51,7 +48,7 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
|
|||
private boolean isSorted = false;
|
||||
private boolean locationUpdateStarted;
|
||||
private boolean compassUpdateAllowed = true;
|
||||
private TitleWithButtonItem title;
|
||||
private BaseBottomSheetItem title;
|
||||
private MapRouteInfoMenu routeMenu;
|
||||
|
||||
@Override
|
||||
|
@ -59,20 +56,17 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
|
|||
Bundle args = getArguments();
|
||||
target = args.getBoolean(TARGET);
|
||||
intermediate = args.getBoolean(INTERMEDIATE);
|
||||
// final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
|
||||
|
||||
FavouritesDbHelper favouritesDbHelper = getMyApplication().getFavorites();
|
||||
favouritePoints = favouritesDbHelper.getVisibleFavouritePoints();
|
||||
favouritePoints = getMyApplication().getFavorites().getVisibleFavouritePoints();
|
||||
routeMenu = ((MapActivity) getActivity()).getMapLayers().getMapControlsLayer().getMapRouteInfoMenu();
|
||||
recyclerView = new RecyclerView(getContext());
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
|
||||
title = new TitleWithButtonItem.Builder()
|
||||
.setIcon(getIcon(sortByDist ? R.drawable.ic_action_list_sort : R.drawable.ic_action_sort_by_name,
|
||||
title = new BottomSheetItemWithTitleAndButton.Builder()
|
||||
.setButtonIcon(null, 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))
|
||||
.setIconPosition(TitleWithButtonItem.textOnRight)
|
||||
.setButtonTitle(getString(sortByDist ? R.string.sort_by_distance : R.string.sort_by_name))
|
||||
.setTitle(getString(R.string.favourites))
|
||||
.setTextOnRight(getString(sortByDist ? R.string.sort_by_distance : R.string.sort_by_name))
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -80,11 +74,12 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
|
|||
return;
|
||||
}
|
||||
sortFavourites();
|
||||
title.setButtonIcon(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), TitleWithButtonItem.textOnRight);
|
||||
title.setButtonText(getString(sortByDist ? R.string.sort_by_distance : R.string.sort_by_name));
|
||||
((BottomSheetItemWithTitleAndButton) title).setButtonIcon(null, 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));
|
||||
((BottomSheetItemWithTitleAndButton) title).setButtonText(getString(sortByDist ? R.string.sort_by_distance : R.string.sort_by_name));
|
||||
}
|
||||
})
|
||||
.setLayoutId(R.layout.bottom_sheet_item_with_title_and_button)
|
||||
.create();
|
||||
items.add(title);
|
||||
|
||||
|
@ -107,9 +102,9 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
|
|||
compassUpdateAllowed = newState == RecyclerView.SCROLL_STATE_IDLE;
|
||||
}
|
||||
});
|
||||
items.add(new BaseBottomSheetItem.Builder().
|
||||
setCustomView(recyclerView).
|
||||
create());
|
||||
items.add(new BaseBottomSheetItem.Builder()
|
||||
.setCustomView(recyclerView)
|
||||
.create());
|
||||
|
||||
if (savedInstanceState != null && savedInstanceState.getBoolean(IS_SORTED)) {
|
||||
location = getMyApplication().getLocationProvider().getLastKnownLocation();
|
||||
|
@ -153,9 +148,7 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
|
|||
if (!intermediate && getActivity() instanceof MapActivity) {
|
||||
routeMenu.updateFromIcon();
|
||||
}
|
||||
if (routeMenu.mainView != null) {
|
||||
routeMenu.setupSpinners(routeMenu.mainView, target, intermediate);
|
||||
}
|
||||
routeMenu.setupSpinners(target, intermediate);
|
||||
dismiss();
|
||||
}
|
||||
|
||||
|
@ -262,8 +255,8 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
|
|||
@Override
|
||||
protected void onCloseRowClickAction() {
|
||||
super.onCloseRowClickAction();
|
||||
if (routeMenu.mainView != null) {
|
||||
routeMenu.setupSpinners(routeMenu.mainView, target, intermediate);
|
||||
}
|
||||
routeMenu.setupSpinners(target, intermediate);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
|
|||
private OnDismissListener onDismissListener;
|
||||
|
||||
private OnMarkerSelectListener onMarkerSelectListener;
|
||||
View mainView;
|
||||
private View mainView;
|
||||
|
||||
private static final long SPINNER_MY_LOCATION_ID = 1;
|
||||
public static final long SPINNER_FAV_ID = 2;
|
||||
|
@ -480,15 +480,15 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
|
|||
args.putBoolean(FavouritesBottomSheetMenuFragment.INTERMEDIATE, intermediate);
|
||||
fragment.setArguments(args);
|
||||
fragment.show(fragmentManager, FavouritesBottomSheetMenuFragment.TAG);
|
||||
setupSpinners(parentView, target, intermediate);
|
||||
setupSpinners(target, intermediate);
|
||||
}
|
||||
|
||||
public void setupSpinners(@Nullable final View parentView, final boolean target, final boolean intermediate) {
|
||||
if (!intermediate && parentView != null) {
|
||||
public void setupSpinners(final boolean target, final boolean intermediate) {
|
||||
if (!intermediate && mainView != null) {
|
||||
if (target) {
|
||||
setupToSpinner(parentView);
|
||||
setupToSpinner(mainView);
|
||||
} else {
|
||||
setupFromSpinner(parentView);
|
||||
setupFromSpinner(mainView);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue