Rewrite UI in OrderByBottomSheetDialogFragment

This commit is contained in:
Alexander Sytnyk 2018-02-28 18:25:58 +02:00
parent b127d8c992
commit 0ab22fe00d
2 changed files with 92 additions and 281 deletions

View file

@ -1,224 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/bg_color"
android:orientation="vertical">
<ScrollView
android:id="@+id/marker_order_by_scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="@dimen/bottom_sheet_content_padding_small">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/order_by_title"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_title_height"
android:gravity="center_vertical"
android:paddingEnd="@dimen/content_padding"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:paddingStart="@dimen/content_padding"
android:text="@string/sort_by"
android:textAppearance="@style/TextAppearance.ListItemTitle"
osmand:typeface="@string/font_roboto_medium"/>
<LinearLayout
android:id="@+id/name_row"
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:paddingEnd="@dimen/content_padding"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:paddingStart="@dimen/content_padding">
<ImageView
android:id="@+id/name_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
tools:src="@drawable/ic_action_sort_by_name"/>
<TextView
android:id="@+id/name_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="@string/shared_string_name"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
</LinearLayout>
<View
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_marginBottom="@dimen/bottom_sheet_divider_margin_bottom"
android:layout_marginLeft="@dimen/bottom_sheet_divider_margin_start"
android:layout_marginStart="@dimen/bottom_sheet_divider_margin_start"
android:layout_marginTop="@dimen/bottom_sheet_divider_margin_top"
android:background="?attr/dashboard_divider"/>
<LinearLayout
android:id="@+id/distance_nearest_row"
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:paddingEnd="@dimen/content_padding"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:paddingStart="@dimen/content_padding">
<ImageView
android:id="@+id/distance_nearest_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
tools:src="@drawable/ic_action_markers_dark"/>
<TextView
android:id="@+id/distance_nearest_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="@string/distance_nearest"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
</LinearLayout>
<LinearLayout
android:id="@+id/distance_farthest_row"
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:paddingEnd="@dimen/content_padding"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:paddingStart="@dimen/content_padding">
<ImageView
android:id="@+id/distance_farthest_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
tools:src="@drawable/ic_action_markers_dark"/>
<TextView
android:id="@+id/distance_farthest_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="@string/distance_farthest"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
</LinearLayout>
<View
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_marginBottom="@dimen/bottom_sheet_divider_margin_bottom"
android:layout_marginLeft="@dimen/bottom_sheet_divider_margin_start"
android:layout_marginStart="@dimen/bottom_sheet_divider_margin_start"
android:layout_marginTop="@dimen/bottom_sheet_divider_margin_top"
android:background="?attr/dashboard_divider"/>
<LinearLayout
android:id="@+id/date_added_asc_row"
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:paddingEnd="@dimen/content_padding"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:paddingStart="@dimen/content_padding">
<ImageView
android:id="@+id/date_added_asc_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
tools:src="@drawable/ic_action_sort_by_date"/>
<TextView
android:id="@+id/date_added_asc_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.ListItemTitle"
tools:text="Date added (Ascendingly)"/>
</LinearLayout>
<LinearLayout
android:id="@+id/date_added_desc_row"
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:paddingEnd="@dimen/content_padding"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:paddingStart="@dimen/content_padding">
<ImageView
android:id="@+id/date_added_desc_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
tools:src="@drawable/ic_action_sort_by_date"/>
<TextView
android:id="@+id/date_added_desc_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.ListItemTitle"
tools:text="Date added (Descendingly)"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dashboard_divider"/>
<FrameLayout
android:id="@+id/close_row"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_cancel_button_height"
android:background="?attr/selectableItemBackground">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/shared_string_close"
android:textAllCaps="true"
android:textColor="?attr/color_dialog_buttons"
android:textSize="@dimen/default_desc_text_size"
android:textStyle="bold"/>
</FrameLayout>
</LinearLayout>

View file

@ -2,18 +2,18 @@ package net.osmand.plus.mapmarkers;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarkersSortByDef;
import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
public class OrderByBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
@ -27,66 +27,101 @@ public class OrderByBottomSheetDialogFragment extends MenuBottomSheetDialogFragm
@Override
public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes),
R.layout.fragment_marker_order_by_bottom_sheet_dialog, container);
if (nightMode) {
((TextView) mainView.findViewById(R.id.order_by_title)).setTextColor(
ContextCompat.getColor(getContext(), R.color.ctx_menu_info_text_dark)
);
}
Drawable distanceIcon = getContentIcon(R.drawable.ic_action_markers_dark);
Drawable dateIcon = getContentIcon(R.drawable.ic_action_sort_by_date);
((ImageView) mainView.findViewById(R.id.name_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_sort_by_name));
((ImageView) mainView.findViewById(R.id.distance_nearest_icon)).setImageDrawable(distanceIcon);
((ImageView) mainView.findViewById(R.id.distance_farthest_icon)).setImageDrawable(distanceIcon);
((ImageView) mainView.findViewById(R.id.date_added_asc_icon)).setImageDrawable(dateIcon);
((ImageView) mainView.findViewById(R.id.date_added_desc_icon)).setImageDrawable(dateIcon);
((TextView) mainView.findViewById(R.id.date_added_asc_text)).setText(getString(R.string.date_added) + " (" + getString(R.string.ascendingly) + ")");
((TextView) mainView.findViewById(R.id.date_added_desc_text)).setText(getString(R.string.date_added) + " (" + getString(R.string.descendingly) + ")");
items.add(new TitleItem(getString(R.string.sort_by)));
View.OnClickListener onClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
int sortByMode = -1;
switch (v.getId()) {
case R.id.name_row:
sortByMode = MapMarkersHelper.BY_NAME;
break;
case R.id.distance_nearest_row:
sortByMode = MapMarkersHelper.BY_DISTANCE_ASC;
break;
case R.id.distance_farthest_row:
sortByMode = MapMarkersHelper.BY_DISTANCE_DESC;
break;
case R.id.date_added_asc_row:
sortByMode = MapMarkersHelper.BY_DATE_ADDED_ASC;
break;
case R.id.date_added_desc_row:
sortByMode = MapMarkersHelper.BY_DATE_ADDED_DESC;
break;
}
if (sortByMode != -1 && listener != null) {
listener.onMapMarkersOrderByModeChanged(sortByMode);
}
dismiss();
}
};
BaseBottomSheetItem byNameItem = new SimpleBottomSheetItem.Builder()
.setIcon(getContentIcon(R.drawable.ic_action_sort_by_name))
.setTitle(getString(R.string.shared_string_name))
.setLayoutId(R.layout.bottom_sheet_item_simple)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
listener.onMapMarkersOrderByModeChanged(MapMarkersHelper.BY_NAME);
}
dismiss();
}
})
.create();
items.add(byNameItem);
mainView.findViewById(R.id.name_row).setOnClickListener(onClickListener);
mainView.findViewById(R.id.distance_nearest_row).setOnClickListener(onClickListener);
mainView.findViewById(R.id.distance_farthest_row).setOnClickListener(onClickListener);
mainView.findViewById(R.id.date_added_asc_row).setOnClickListener(onClickListener);
mainView.findViewById(R.id.date_added_desc_row).setOnClickListener(onClickListener);
mainView.findViewById(R.id.close_row).setOnClickListener(onClickListener);
items.add(new DividerHalfItem(getContext()));
setupHeightAndBackground(mainView, R.id.marker_order_by_scroll_view);
BaseBottomSheetItem distNearestItem = new SimpleBottomSheetItem.Builder()
.setIcon(distanceIcon)
.setTitle(getString(R.string.distance_nearest))
.setLayoutId(R.layout.bottom_sheet_item_simple)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
listener.onMapMarkersOrderByModeChanged(MapMarkersHelper.BY_DISTANCE_ASC);
}
dismiss();
}
})
.create();
items.add(distNearestItem);
return mainView;
BaseBottomSheetItem distFarthestItem = new SimpleBottomSheetItem.Builder()
.setIcon(distanceIcon)
.setTitle(getString(R.string.distance_farthest))
.setLayoutId(R.layout.bottom_sheet_item_simple)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
listener.onMapMarkersOrderByModeChanged(MapMarkersHelper.BY_DISTANCE_DESC);
}
dismiss();
}
})
.create();
items.add(distFarthestItem);
items.add(new DividerHalfItem(getContext()));
BaseBottomSheetItem dateAscItem = new SimpleBottomSheetItem.Builder()
.setIcon(dateIcon)
.setTitle(getString(R.string.date_added) + " (" + getString(R.string.ascendingly) + ")")
.setLayoutId(R.layout.bottom_sheet_item_simple)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
listener.onMapMarkersOrderByModeChanged(MapMarkersHelper.BY_DATE_ADDED_ASC);
}
dismiss();
}
})
.create();
items.add(dateAscItem);
BaseBottomSheetItem dateDescItem = new SimpleBottomSheetItem.Builder()
.setIcon(dateIcon)
.setTitle(getString(R.string.date_added) + " (" + getString(R.string.descendingly) + ")")
.setLayoutId(R.layout.bottom_sheet_item_simple)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
listener.onMapMarkersOrderByModeChanged(MapMarkersHelper.BY_DATE_ADDED_DESC);
}
dismiss();
}
})
.create();
items.add(dateDescItem);
return null;
}
@Override
protected int getCloseRowTextId() {
return R.string.shared_string_close;
}
interface OrderByFragmentListener {