Refactor some code; rewrite UI in ExportOptionsBottomSheetDialogFragment

This commit is contained in:
Alexander Sytnyk 2018-02-27 20:00:30 +02:00
parent fa4a8ef876
commit 29b164350b
12 changed files with 173 additions and 287 deletions

View file

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_descr_height"
android:ellipsize="end"
android:maxLines="2"
android:minHeight="@dimen/bottom_sheet_descr_height"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size"
tools:text="Some long description"/>

View file

@ -6,7 +6,9 @@
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_title_height"
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"

View file

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_list_item_height"
android:background="?attr/selectableItemBackground"
android:minHeight="@dimen/bottom_sheet_list_item_height"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding">
<ImageView
android:id="@+id/icon"
android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
tools:src="@drawable/ic_action_info_dark"/>
<TextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.ListItemTitle"
tools:text="Title"/>
<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_list_text_size"
tools:text="Description"/>
</LinearLayout>

View file

@ -1,195 +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/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/title_text_view"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_title_height"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="1"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:text="@string/shared_string_export"
android:textAppearance="@style/TextAppearance.ListItemTitle"
osmand:typeface="@string/font_roboto_medium"/>
<TextView
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_descr_height"
android:ellipsize="end"
android:maxLines="2"
android:paddingEnd="@dimen/content_padding"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:paddingStart="@dimen/content_padding"
android:text="@string/osm_edits_export_desc"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size"/>
<LinearLayout
android:id="@+id/poi_row"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_list_item_height"
android:background="?attr/selectableItemBackground"
android:minHeight="@dimen/bottom_sheet_list_item_height"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding">
<ImageView
android:id="@+id/poi_icon"
android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
tools:src="@drawable/ic_action_info_dark"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
android:text="@string/poi"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
<TextView
android:id="@+id/poi_count_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_list_text_size"
tools:text="13"/>
</LinearLayout>
<LinearLayout
android:id="@+id/osm_notes_row"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_list_item_height"
android:background="?attr/selectableItemBackground"
android:minHeight="@dimen/bottom_sheet_list_item_height"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding">
<ImageView
android:id="@+id/osm_notes_icon"
android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
tools:src="@drawable/ic_action_bug_dark"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
android:text="@string/osm_notes"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
<TextView
android:id="@+id/osm_notes_count_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_list_text_size"
tools:text="5"/>
</LinearLayout>
<LinearLayout
android:id="@+id/all_data_row"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_list_item_height"
android:background="?attr/selectableItemBackground"
android:minHeight="@dimen/bottom_sheet_list_item_height"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding">
<ImageView
android:id="@+id/all_data_icon"
android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
tools:src="@drawable/ic_action_folder"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
android:text="@string/all_data"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
<TextView
android:id="@+id/all_data_count_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_list_text_size"
tools:text="18"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dashboard_divider"/>
<FrameLayout
android:id="@+id/cancel_row"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_cancel_button_height"
android:background="?attr/selectableItemBackground">
<TextView
android:id="@+id/cancel_row_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/shared_string_cancel"
android:textAllCaps="true"
android:textColor="?attr/color_dialog_buttons"
android:textSize="@dimen/default_desc_text_size"
android:textStyle="bold"/>
</FrameLayout>
</LinearLayout>

View file

@ -15,10 +15,10 @@ public class BaseBottomSheetItem {
protected View view;
@LayoutRes
private int layoutId;
protected int layoutId = INVALID_ID;
private boolean disabled;
private View.OnClickListener onClickListener;
protected int position;
protected int position = INVALID_POSITION;
public BaseBottomSheetItem(View view,
@LayoutRes int layoutId,
@ -32,7 +32,7 @@ public class BaseBottomSheetItem {
this.position = position;
}
BaseBottomSheetItem() {
protected BaseBottomSheetItem() {
}

View file

@ -13,9 +13,9 @@ import net.osmand.plus.R;
public class BottomSheetItemWithDescription extends SimpleBottomSheetItem {
private String description;
protected String description;
@ColorRes
private int descriptionColorId;
private int descriptionColorId = INVALID_ID;
public BottomSheetItemWithDescription(View customView,
@LayoutRes int layoutId,
@ -32,6 +32,10 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem {
this.descriptionColorId = descriptionColorId;
}
protected BottomSheetItemWithDescription() {
}
@Override
public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) {
super.inflate(app, container, nightMode);

View file

@ -15,9 +15,9 @@ import net.osmand.plus.R;
public class SimpleBottomSheetItem extends BaseBottomSheetItem {
private Drawable icon;
private String title;
protected String title;
@ColorRes
private int titleColorId;
protected int titleColorId = INVALID_ID;
public SimpleBottomSheetItem(View customView,
@LayoutRes int layoutId,
@ -33,6 +33,10 @@ public class SimpleBottomSheetItem extends BaseBottomSheetItem {
this.titleColorId = titleColorId;
}
protected SimpleBottomSheetItem() {
}
@Override
public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) {
super.inflate(app, container, nightMode);

View file

@ -0,0 +1,12 @@
package net.osmand.plus.base.bottomsheetmenu.simpleitems;
import net.osmand.plus.R;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
public class DescriptionItem extends BottomSheetItemWithDescription {
public DescriptionItem(String description) {
this.description = description;
this.layoutId = R.layout.bottom_sheet_item_description;
}
}

View file

@ -1,4 +1,4 @@
package net.osmand.plus.base.bottomsheetmenu;
package net.osmand.plus.base.bottomsheetmenu.simpleitems;
import android.content.Context;
import android.support.annotation.ColorRes;
@ -10,21 +10,22 @@ import android.widget.LinearLayout;
import net.osmand.AndroidUtils;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
public class DividerHalfBottomSheetItem extends BaseBottomSheetItem {
public class DividerHalfItem extends BaseBottomSheetItem {
@ColorRes
private int colorId;
public DividerHalfBottomSheetItem(Context context) {
public DividerHalfItem(Context context) {
setupView(context, INVALID_ID, INVALID_POSITION);
}
public DividerHalfBottomSheetItem(Context context, @ColorRes int colorId) {
public DividerHalfItem(Context context, @ColorRes int colorId) {
setupView(context, colorId, INVALID_POSITION);
}
public DividerHalfBottomSheetItem(Context context, @ColorRes int colorId, int position) {
public DividerHalfItem(Context context, @ColorRes int colorId, int position) {
setupView(context, colorId, position);
}

View file

@ -0,0 +1,21 @@
package net.osmand.plus.base.bottomsheetmenu.simpleitems;
import android.view.ViewGroup;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
public class TitleItem extends SimpleBottomSheetItem {
public TitleItem(String title) {
this.title = title;
this.layoutId = R.layout.bottom_sheet_item_title;
}
@Override
public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) {
titleColorId = nightMode ? R.color.ctx_menu_info_text_dark : INVALID_ID;
super.inflate(app, container, nightMode);
}
}

View file

@ -21,8 +21,8 @@ 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.BottomSheetItemWithDescription;
import net.osmand.plus.base.bottomsheetmenu.DividerHalfBottomSheetItem;
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 AddWaypointBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
@ -38,11 +38,7 @@ public class AddWaypointBottomSheetDialogFragment extends MenuBottomSheetDialogF
final PointDescription name = PointDescription.deserializeFromString(args.getString(POINT_DESCRIPTION_KEY), latLon);
final TargetPointsHelper targetPointsHelper = getMyApplication().getTargetPointsHelper();
BaseBottomSheetItem titleItem = new SimpleBottomSheetItem.Builder()
.setTitle(getString(R.string.new_destination_point_dialog))
.setLayoutId(R.layout.bottom_sheet_item_title)
.create();
items.add(titleItem);
items.add(new TitleItem(getString(R.string.new_destination_point_dialog)));
BaseBottomSheetItem replaceDestItem = new BottomSheetItemWithDescription.Builder()
.setDescription(getCurrentPointName(targetPointsHelper.getPointToNavigate(), false))
@ -79,7 +75,7 @@ public class AddWaypointBottomSheetDialogFragment extends MenuBottomSheetDialogF
.create();
items.add(replaceStartItem);
items.add(new DividerHalfBottomSheetItem(getContext(), getCloseRowDividerColorId()));
items.add(new DividerHalfItem(getContext(), getCloseRowDividerColorId()));
BaseBottomSheetItem subsequentDestItem = new BottomSheetItemWithDescription.Builder()
.setDescription(getString(R.string.subsequent_dest_description))

View file

@ -1,17 +1,17 @@
package net.osmand.plus.osmedit;
import android.os.Bundle;
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.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DescriptionItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.osmedit.OsmEditsFragment.ExportTypesDef;
import net.osmand.plus.widgets.TextViewEx;
public class ExportOptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
@ -30,31 +30,23 @@ public class ExportOptionsBottomSheetDialogFragment extends MenuBottomSheetDialo
@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_osm_export_options_bottom_sheet_dialog, container);
Bundle args = getArguments();
if (args != null) {
poiCount = args.getInt(POI_COUNT_KEY);
osmNotesCount = args.getInt(NOTES_COUNT_KEY);
}
if (nightMode) {
((TextViewEx) mainView.findViewById(R.id.title_text_view)).setTextColor(getResources().getColor(R.color.ctx_menu_info_text_dark));
}
items.add(new TitleItem(getString(R.string.shared_string_export)));
((ImageView) mainView.findViewById(R.id.poi_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_info_dark));
((ImageView) mainView.findViewById(R.id.osm_notes_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_bug_dark));
((ImageView) mainView.findViewById(R.id.all_data_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_folder));
items.add(new DescriptionItem(getString(R.string.osm_edits_export_desc)));
((TextView) mainView.findViewById(R.id.poi_count_text_view)).setText(String.valueOf(poiCount));
((TextView) mainView.findViewById(R.id.osm_notes_count_text_view)).setText(String.valueOf(osmNotesCount));
((TextView) mainView.findViewById(R.id.all_data_count_text_view)).setText(String.valueOf(poiCount + osmNotesCount));
View poiRow = mainView.findViewById(R.id.poi_row);
if (poiCount > 0) {
poiRow.setOnClickListener(new View.OnClickListener() {
BaseBottomSheetItem poiItem = new BottomSheetItemWithDescription.Builder()
.setDescription(String.valueOf(poiCount))
.setIcon(getContentIcon(R.drawable.ic_action_info_dark))
.setTitle(getString(R.string.poi))
.setLayoutId(R.layout.bottom_sheet_item_with_right_descr)
.setDisabled(!(poiCount > 0))
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
@ -62,14 +54,17 @@ public class ExportOptionsBottomSheetDialogFragment extends MenuBottomSheetDialo
}
dismiss();
}
});
} else {
disable(poiRow);
}
})
.create();
items.add(poiItem);
View osmNotesRow = mainView.findViewById(R.id.osm_notes_row);
if (osmNotesCount > 0) {
osmNotesRow.setOnClickListener(new View.OnClickListener() {
BaseBottomSheetItem osmNotesItem = new BottomSheetItemWithDescription.Builder()
.setDescription(String.valueOf(osmNotesCount))
.setIcon(getContentIcon(R.drawable.ic_action_bug_dark))
.setTitle(getString(R.string.osm_notes))
.setLayoutId(R.layout.bottom_sheet_item_with_right_descr)
.setDisabled(!(osmNotesCount > 0))
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
@ -77,14 +72,17 @@ public class ExportOptionsBottomSheetDialogFragment extends MenuBottomSheetDialo
}
dismiss();
}
});
} else {
disable(osmNotesRow);
}
})
.create();
items.add(osmNotesItem);
View allDataRow = mainView.findViewById(R.id.all_data_row);
if ((poiCount + osmNotesCount) > 0) {
allDataRow.setOnClickListener(new View.OnClickListener() {
BaseBottomSheetItem allDataItem = new BottomSheetItemWithDescription.Builder()
.setDescription(String.valueOf(poiCount + osmNotesCount))
.setIcon(getContentIcon(R.drawable.ic_action_folder))
.setTitle(getString(R.string.all_data))
.setLayoutId(R.layout.bottom_sheet_item_with_right_descr)
.setDisabled(!(poiCount + osmNotesCount > 0))
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
@ -92,26 +90,11 @@ public class ExportOptionsBottomSheetDialogFragment extends MenuBottomSheetDialo
}
dismiss();
}
});
} else {
disable(allDataRow);
}
})
.create();
items.add(allDataItem);
mainView.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dismiss();
}
});
setupHeightAndBackground(mainView, R.id.scroll_view);
return mainView;
}
private void disable(View view) {
view.setEnabled(false);
view.setAlpha(.5f);
return null;
}
public interface ExportOptionsFragmentListener {