From 63623fb269a1ee14892ac2935267ccd41316a4d8 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 28 Feb 2018 14:34:16 +0200 Subject: [PATCH] Refactor dividers --- .../simpleitems/DividerHalfItem.java | 47 ++------------ .../simpleitems/DividerItem.java | 64 +++++++++++++++++++ 2 files changed, 70 insertions(+), 41 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DividerItem.java 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 6f55a2bb0b..a8b7ed9b6c 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DividerHalfItem.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DividerHalfItem.java @@ -2,60 +2,25 @@ package net.osmand.plus.base.bottomsheetmenu.simpleitems; import android.content.Context; import android.support.annotation.ColorRes; -import android.support.v4.content.ContextCompat; -import android.view.View; -import android.view.ViewGroup; -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 DividerHalfItem extends BaseBottomSheetItem { - - @ColorRes - private int colorId; +public class DividerHalfItem extends DividerItem { public DividerHalfItem(Context context) { - setupView(context, INVALID_ID, INVALID_POSITION); + super(context); } public DividerHalfItem(Context context, @ColorRes int colorId) { - setupView(context, colorId, INVALID_POSITION); + super(context, colorId); } public DividerHalfItem(Context context, @ColorRes int colorId, int position) { - setupView(context, colorId, position); - } - - private void setupView(Context context, @ColorRes int colorId, int position) { - view = new View(context); - this.colorId = colorId; - this.position = position; + super(context, colorId, position); } @Override - 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 marginLeft = app.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_divider_margin_start); - int height = AndroidUtils.dpToPx(app, 1); - - LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view.getLayoutParams(); - params.setMargins(marginLeft, marginTopBottom, 0, marginTopBottom); - params.height = height; - - view.setMinimumHeight(height); - view.setBackgroundColor(ContextCompat.getColor(app, getBgColorId(nightMode))); - } - - @ColorRes - private int getBgColorId(boolean nightMode) { - if (colorId != INVALID_ID) { - return colorId; - } - return nightMode ? R.color.dashboard_divider_dark : R.color.dashboard_divider_light; + 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 new file mode 100644 index 0000000000..b199554f90 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DividerItem.java @@ -0,0 +1,64 @@ +package net.osmand.plus.base.bottomsheetmenu.simpleitems; + +import android.content.Context; +import android.support.annotation.ColorRes; +import android.support.v4.content.ContextCompat; +import android.view.View; +import android.view.ViewGroup; +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 DividerItem extends BaseBottomSheetItem { + + @ColorRes + private int colorId; + + public DividerItem(Context context) { + setupView(context, INVALID_ID, INVALID_POSITION); + } + + public DividerItem(Context context, @ColorRes int colorId) { + setupView(context, colorId, INVALID_POSITION); + } + + public DividerItem(Context context, @ColorRes int colorId, int position) { + setupView(context, colorId, position); + } + + private void setupView(Context context, @ColorRes int colorId, int position) { + view = new View(context); + this.colorId = colorId; + this.position = position; + } + + @Override + 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.height = height; + + view.setMinimumHeight(height); + view.setBackgroundColor(ContextCompat.getColor(app, getBgColorId(nightMode))); + } + + protected int getLeftMargin(Context context) { + return 0; + } + + @ColorRes + private int getBgColorId(boolean nightMode) { + if (colorId != INVALID_ID) { + return colorId; + } + return nightMode ? R.color.dashboard_divider_dark : R.color.dashboard_divider_light; + } +}