Refactor dividers

This commit is contained in:
Alexander Sytnyk 2018-02-28 14:34:16 +02:00
parent 679a28bde5
commit 63623fb269
2 changed files with 70 additions and 41 deletions

View file

@ -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);
}
}

View file

@ -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;
}
}