From abbe3284d2d3d4f790d7bae393f8e8bc7b8984fa Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 28 Feb 2018 16:01:58 +0200 Subject: [PATCH] Rewrite UI in ImportGpxBottomSheetDialogFragment; fix some small issues --- ...ragment_import_gpx_bottom_sheet_dialog.xml | 142 ------------------ .../BottomSheetItemWithDescription.java | 8 +- .../simpleitems/DescriptionItem.java | 2 +- .../simpleitems/DividerHalfItem.java | 5 + .../simpleitems/DividerItem.java | 11 +- .../net/osmand/plus/helpers/ImportHelper.java | 84 ++++++----- 6 files changed, 64 insertions(+), 188 deletions(-) delete mode 100644 OsmAnd/res/layout/fragment_import_gpx_bottom_sheet_dialog.xml diff --git a/OsmAnd/res/layout/fragment_import_gpx_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_import_gpx_bottom_sheet_dialog.xml deleted file mode 100644 index 67525105f1..0000000000 --- a/OsmAnd/res/layout/fragment_import_gpx_bottom_sheet_dialog.xml +++ /dev/null @@ -1,142 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java index 5792e859f4..c6294d4384 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java @@ -13,7 +13,7 @@ import net.osmand.plus.R; public class BottomSheetItemWithDescription extends SimpleBottomSheetItem { - protected String description; + protected CharSequence description; @ColorRes private int descriptionColorId = INVALID_ID; @@ -25,7 +25,7 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem { Drawable icon, String title, @ColorRes int titleColorId, - String description, + CharSequence description, @ColorRes int descriptionColorId) { super(customView, layoutId, clickable, onClickListener, position, icon, title, titleColorId); this.description = description; @@ -50,11 +50,11 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem { public static class Builder extends SimpleBottomSheetItem.Builder { - protected String description; + protected CharSequence description; @ColorRes protected int descriptionColorId = INVALID_ID; - public Builder setDescription(String description) { + public Builder setDescription(CharSequence description) { this.description = description; return this; } diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DescriptionItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DescriptionItem.java index a271d15647..759c2273bb 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DescriptionItem.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DescriptionItem.java @@ -5,7 +5,7 @@ import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription; public class DescriptionItem extends BottomSheetItemWithDescription { - public DescriptionItem(String description) { + public DescriptionItem(CharSequence description) { this.description = description; this.layoutId = R.layout.bottom_sheet_item_description; } diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DividerHalfItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DividerHalfItem.java index a8b7ed9b6c..4d2b965a9e 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DividerHalfItem.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DividerHalfItem.java @@ -19,6 +19,11 @@ public class DividerHalfItem extends DividerItem { super(context, colorId, position); } + @Override + protected int getTopMargin(Context context) { + return context.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_divider_margin_top); + } + @Override protected int getLeftMargin(Context context) { return context.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_divider_margin_start); diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DividerItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DividerItem.java index b199554f90..749235b733 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DividerItem.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DividerItem.java @@ -39,21 +39,28 @@ public class DividerItem extends BaseBottomSheetItem { public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) { super.inflate(app, container, nightMode); - int marginTopBottom = app.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_content_padding_small); int height = AndroidUtils.dpToPx(app, 1); LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view.getLayoutParams(); - params.setMargins(getLeftMargin(app), marginTopBottom, 0, marginTopBottom); + params.setMargins(getLeftMargin(app), getTopMargin(app), 0, getBottomMargin(app)); params.height = height; view.setMinimumHeight(height); view.setBackgroundColor(ContextCompat.getColor(app, getBgColorId(nightMode))); } + protected int getTopMargin(Context context) { + return context.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_content_padding_small); + } + protected int getLeftMargin(Context context) { return 0; } + protected int getBottomMargin(Context context) { + return context.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_content_padding_small); + } + @ColorRes private int getBgColorId(boolean nightMode) { if (colorId != INVALID_ID) { diff --git a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java index b420dedcf5..b721b408d8 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java @@ -13,20 +13,18 @@ import android.os.Bundle; import android.os.ParcelFileDescriptor; import android.provider.OpenableColumns; import android.provider.Settings; +import android.support.annotation.ColorInt; +import android.support.annotation.ColorRes; import android.support.annotation.NonNull; -import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.text.SpannableStringBuilder; import android.text.Spanned; import android.text.style.ForegroundColorSpan; -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 android.widget.Toast; import net.osmand.IProgress; @@ -39,6 +37,11 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; 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.SimpleBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.DescriptionItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; import net.osmand.plus.myplaces.FavoritesActivity; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.util.Algorithms; @@ -744,50 +747,53 @@ public class ImportHelper { @Override public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; + items.add(new TitleItem(getString(R.string.import_file))); - final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_import_gpx_bottom_sheet_dialog, container); - - if (nightMode) { - ((TextView) mainView.findViewById(R.id.import_gpx_title)).setTextColor(ContextCompat.getColor(getActivity(), R.color.ctx_menu_info_text_dark)); - } - - ((ImageView) mainView.findViewById(R.id.import_as_favorites_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_fav_dark)); - ((ImageView) mainView.findViewById(R.id.import_as_gpx_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_polygom_dark)); - - int nameColor = ContextCompat.getColor(getContext(), nightMode ? R.color.osmand_orange : R.color.dashboard_blue); - int descrColor = ContextCompat.getColor(getContext(), nightMode ? R.color.dashboard_subheader_text_dark : R.color.dashboard_subheader_text_light); + int nameColor = getResolvedColor(nightMode ? R.color.osmand_orange : R.color.dashboard_blue); + int descrColor = getResolvedColor(nightMode ? R.color.dashboard_subheader_text_dark : R.color.dashboard_subheader_text_light); String descr = getString(R.string.import_gpx_file_description); SpannableStringBuilder text = new SpannableStringBuilder(fileName).append(" ").append(descr); text.setSpan(new ForegroundColorSpan(nameColor), 0, fileName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); text.setSpan(new ForegroundColorSpan(descrColor), fileName.length() + 1, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - ((TextView) mainView.findViewById(R.id.import_gpx_description)).setText(text); - mainView.findViewById(R.id.import_as_favorites_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - importHelper.importFavoritesImpl(gpxFile, fileName, false); - dismiss(); - } - }); - mainView.findViewById(R.id.import_as_gpx_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - importHelper.handleResult(gpxFile, fileName, save, useImportDir, false); - dismiss(); - } - }); + items.add(new DescriptionItem(text)); - mainView.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - dismiss(); - } - }); + BaseBottomSheetItem asFavoritesItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_fav_dark)) + .setTitle(getString(R.string.import_as_favorites)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + importHelper.importFavoritesImpl(gpxFile, fileName, false); + dismiss(); + } + }) + .create(); + items.add(asFavoritesItem); - setupHeightAndBackground(mainView, R.id.import_gpx_scroll_view); + items.add(new DividerHalfItem(getContext())); - return mainView; + BaseBottomSheetItem asGpxItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_polygom_dark)) + .setTitle(getString(R.string.import_as_gpx)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + importHelper.handleResult(gpxFile, fileName, save, useImportDir, false); + dismiss(); + } + }) + .create(); + items.add(asGpxItem); + + return null; + } + + @ColorInt + private int getResolvedColor(@ColorRes int colorId) { + return ContextCompat.getColor(getContext(), colorId); } } }