Refactor code

This commit is contained in:
Alexander Sytnyk 2018-01-11 17:59:41 +02:00
parent 57016f0273
commit b654b3ee75

View file

@ -3,8 +3,8 @@ package net.osmand.plus.mapcontextmenu;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.widget.LinearLayout; import android.widget.LinearLayout;
@ -52,7 +52,6 @@ import net.osmand.plus.mapcontextmenu.controllers.RenderedObjectMenuController;
import net.osmand.plus.mapcontextmenu.controllers.TargetPointMenuController; import net.osmand.plus.mapcontextmenu.controllers.TargetPointMenuController;
import net.osmand.plus.mapcontextmenu.controllers.TransportRouteController; import net.osmand.plus.mapcontextmenu.controllers.TransportRouteController;
import net.osmand.plus.mapcontextmenu.controllers.TransportStopController; import net.osmand.plus.mapcontextmenu.controllers.TransportStopController;
import net.osmand.plus.transport.TransportStopRoute;
import net.osmand.plus.mapcontextmenu.controllers.WptPtMenuController; import net.osmand.plus.mapcontextmenu.controllers.WptPtMenuController;
import net.osmand.plus.mapcontextmenu.other.ShareMenu; import net.osmand.plus.mapcontextmenu.other.ShareMenu;
import net.osmand.plus.mapillary.MapillaryImage; import net.osmand.plus.mapillary.MapillaryImage;
@ -65,6 +64,7 @@ import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoDevice;
import net.osmand.plus.osmo.OsMoMenuController; import net.osmand.plus.osmo.OsMoMenuController;
import net.osmand.plus.parkingpoint.ParkingPositionMenuController; import net.osmand.plus.parkingpoint.ParkingPositionMenuController;
import net.osmand.plus.resources.ResourceManager; import net.osmand.plus.resources.ResourceManager;
import net.osmand.plus.transport.TransportStopRoute;
import net.osmand.plus.views.DownloadedRegionsLayer.DownloadMapObject; import net.osmand.plus.views.DownloadedRegionsLayer.DownloadMapObject;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControllerType; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControllerType;
@ -554,42 +554,37 @@ public abstract class MenuController extends BaseMenuController {
public Drawable rightIcon; public Drawable rightIcon;
public boolean enabled = true; public boolean enabled = true;
@Nullable
public Drawable getLeftIcon() { public Drawable getLeftIcon() {
if (leftIcon != null) { return getIconDrawable(true);
return leftIcon;
}
if (leftIconId != 0) {
if (needColorizeIcon) {
return getIcon(leftIconId, getColorRes());
}
return ContextCompat.getDrawable(getMapActivity(), leftIconId);
} else {
return null;
}
} }
@Nullable
public Drawable getRightIcon() { public Drawable getRightIcon() {
if (rightIcon != null) { return getIconDrawable(false);
return rightIcon;
} }
if (rightIconId != 0) {
@Nullable
private Drawable getIconDrawable(boolean left) {
Drawable drawable = left ? leftIcon : rightIcon;
if (drawable != null) {
return drawable;
}
int resId = left ? leftIconId : rightIconId;
if (resId != 0) {
if (needColorizeIcon) { if (needColorizeIcon) {
return getIcon(rightIconId, getColorRes()); return getIcon(resId, getColorRes());
}
return ContextCompat.getDrawable(getMapActivity(), resId);
} }
return ContextCompat.getDrawable(getMapActivity(), rightIconId);
} else {
return null; return null;
} }
}
private int getColorRes() { private int getColorRes() {
int colorRes;
if (enabled) { if (enabled) {
colorRes = isLight() ? R.color.map_widget_blue : R.color.osmand_orange; return isLight() ? R.color.map_widget_blue : R.color.osmand_orange;
} else {
colorRes = isLight() ? R.color.ctx_menu_controller_disabled_text_color_light : R.color.ctx_menu_controller_disabled_text_color_dark;
} }
return colorRes; return isLight() ? R.color.ctx_menu_controller_disabled_text_color_light : R.color.ctx_menu_controller_disabled_text_color_dark;
} }
public abstract void buttonPressed(); public abstract void buttonPressed();