diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/CollapsableView.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/CollapsableView.java new file mode 100644 index 0000000000..19c0d0983f --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/CollapsableView.java @@ -0,0 +1,65 @@ +package net.osmand.plus.mapcontextmenu; + +import android.view.View; + +import androidx.annotation.NonNull; + +import net.osmand.plus.OsmandSettings.OsmandPreference; +import net.osmand.plus.mapcontextmenu.MenuBuilder.CollapseExpandListener; + +public class CollapsableView { + + private View contentView; + private MenuBuilder menuBuilder; + + private OsmandPreference collapsedPref; + private CollapseExpandListener collapseExpandListener; + private boolean collapsed; + + public CollapsableView(@NonNull View contentView, MenuBuilder menuBuilder, + @NonNull OsmandPreference collapsedPref) { + this.contentView = contentView; + this.menuBuilder = menuBuilder; + this.collapsedPref = collapsedPref; + } + + public CollapsableView(@NonNull View contentView, MenuBuilder menuBuilder, boolean collapsed) { + this.contentView = contentView; + this.collapsed = collapsed; + this.menuBuilder = menuBuilder; + } + + public View getContentView() { + return contentView; + } + + public boolean isCollapsed() { + if (collapsedPref != null) { + return collapsedPref.get(); + } else { + return collapsed; + } + } + + public void setCollapsed(boolean collapsed) { + if (collapsedPref != null) { + collapsedPref.set(collapsed); + } else { + this.collapsed = collapsed; + } + if (collapseExpandListener != null) { + collapseExpandListener.onCollapseExpand(collapsed); + } + if (menuBuilder != null && menuBuilder.getCollapseExpandListener() != null) { + menuBuilder.getCollapseExpandListener().onCollapseExpand(collapsed); + } + } + + public CollapseExpandListener getCollapseExpandListener() { + return collapseExpandListener; + } + + public void setCollapseExpandListener(MenuBuilder.CollapseExpandListener collapseExpandListener) { + this.collapseExpandListener = collapseExpandListener; + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index c4ed47eba7..2263c43838 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -45,7 +45,6 @@ import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; -import net.osmand.plus.OsmandSettings.OsmandPreference; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; @@ -109,118 +108,6 @@ public class MenuBuilder { void onCollapseExpand(boolean collapsed); } - public class PlainMenuItem { - private int iconId; - private String buttonText; - private String text; - private boolean needLinks; - private boolean url; - private boolean collapsable; - private CollapsableView collapsableView; - private OnClickListener onClickListener; - - public PlainMenuItem(int iconId, String buttonText, String text, boolean needLinks, boolean url, - boolean collapsable, CollapsableView collapsableView, - OnClickListener onClickListener) { - this.iconId = iconId; - this.buttonText = buttonText; - this.text = text; - this.needLinks = needLinks; - this.url = url; - this.collapsable = collapsable; - this.collapsableView = collapsableView; - this.onClickListener = onClickListener; - } - - public int getIconId() { - return iconId; - } - - public String getButtonText() { - return buttonText; - } - - public String getText() { - return text; - } - - public boolean isNeedLinks() { - return needLinks; - } - - public boolean isUrl() { - return url; - } - - public boolean isCollapsable() { - return collapsable; - } - - public CollapsableView getCollapsableView() { - return collapsableView; - } - - public OnClickListener getOnClickListener() { - return onClickListener; - } - } - - public static class CollapsableView { - - private View contenView; - private MenuBuilder menuBuilder; - private OsmandPreference collapsedPref; - private boolean collapsed; - private CollapseExpandListener collapseExpandListener; - - public CollapsableView(@NonNull View contenView, MenuBuilder menuBuilder, - @NonNull OsmandPreference collapsedPref) { - this.contenView = contenView; - this.menuBuilder = menuBuilder; - this.collapsedPref = collapsedPref; - } - - public CollapsableView(@NonNull View contenView, MenuBuilder menuBuilder, boolean collapsed) { - this.contenView = contenView; - this.collapsed = collapsed; - this.menuBuilder = menuBuilder; - } - - public View getContenView() { - return contenView; - } - - public boolean isCollapsed() { - if (collapsedPref != null) { - return collapsedPref.get(); - } else { - return collapsed; - } - } - - public void setCollapsed(boolean collapsed) { - if (collapsedPref != null) { - collapsedPref.set(collapsed); - } else { - this.collapsed = collapsed; - } - if (collapseExpandListener != null) { - collapseExpandListener.onCollapseExpand(collapsed); - } - if (menuBuilder != null && menuBuilder.collapseExpandListener != null) { - menuBuilder.collapseExpandListener.onCollapseExpand(collapsed); - } - } - - public CollapseExpandListener getCollapseExpandListener() { - return collapseExpandListener; - } - - public void setCollapseExpandListener(CollapseExpandListener collapseExpandListener) { - this.collapseExpandListener = collapseExpandListener; - } - } - public MenuBuilder(@NonNull MapActivity mapActivity) { this.mapActivity = mapActivity; this.app = mapActivity.getMyApplication(); @@ -234,6 +121,10 @@ public class MenuBuilder { transliterateNames = app.getSettings().MAP_TRANSLITERATE_NAMES.get(); } + public CollapseExpandListener getCollapseExpandListener() { + return collapseExpandListener; + } + public void setCollapseExpandListener(CollapseExpandListener collapseExpandListener) { this.collapseExpandListener = collapseExpandListener; } @@ -355,7 +246,7 @@ public class MenuBuilder { protected void buildPlainMenuItems(View view) { for (PlainMenuItem item : plainMenuItems) { - buildRow(view, item.getIconId(), item.getButtonText(), item.getText(), 0, item.collapsable, item.collapsableView, + buildRow(view, item.getIconId(), item.getButtonText(), item.getText(), 0, item.isCollapsable(), item.getCollapsableView(), item.isNeedLinks(), 0, item.isUrl(), item.getOnClickListener(), false); } } @@ -668,31 +559,31 @@ public class MenuBuilder { llIconCollapseParams.gravity = Gravity.CENTER_VERTICAL; iconViewCollapse.setLayoutParams(llIconCollapseParams); iconViewCollapse.setScaleType(ImageView.ScaleType.CENTER_INSIDE); - iconViewCollapse.setImageDrawable(getCollapseIcon(collapsableView.getContenView().getVisibility() == View.GONE)); + iconViewCollapse.setImageDrawable(getCollapseIcon(collapsableView.getContentView().getVisibility() == View.GONE)); llIconCollapse.addView(iconViewCollapse); ll.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (collapsableView.getContenView().getVisibility() == View.VISIBLE) { - collapsableView.getContenView().setVisibility(View.GONE); + if (collapsableView.getContentView().getVisibility() == View.VISIBLE) { + collapsableView.getContentView().setVisibility(View.GONE); iconViewCollapse.setImageDrawable(getCollapseIcon(true)); collapsableView.setCollapsed(true); } else { - collapsableView.getContenView().setVisibility(View.VISIBLE); + collapsableView.getContentView().setVisibility(View.VISIBLE); iconViewCollapse.setImageDrawable(getCollapseIcon(false)); collapsableView.setCollapsed(false); } } }); if (collapsableView.isCollapsed()) { - collapsableView.getContenView().setVisibility(View.GONE); + collapsableView.getContentView().setVisibility(View.GONE); iconViewCollapse.setImageDrawable(getCollapseIcon(true)); } - if (collapsableView.getContenView().getParent() != null) { - ((ViewGroup) collapsableView.getContenView().getParent()) - .removeView(collapsableView.getContenView()); + if (collapsableView.getContentView().getParent() != null) { + ((ViewGroup) collapsableView.getContentView().getParent()) + .removeView(collapsableView.getContentView()); } - baseView.addView(collapsableView.getContenView()); + baseView.addView(collapsableView.getContentView()); } if (onClickListener != null) { @@ -1179,4 +1070,4 @@ public class MenuBuilder { public static

void execute(AsyncTask task, P... requests) { task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, requests); } -} +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java index 8f1a762e0e..5ce2472c63 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java @@ -15,7 +15,6 @@ import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.content.res.AppCompatResources; -import androidx.core.content.ContextCompat; import net.osmand.GPXUtilities.WptPt; import net.osmand.IndexConstants; @@ -48,7 +47,6 @@ import net.osmand.plus.download.DownloadValidationManager; import net.osmand.plus.download.IndexItem; import net.osmand.plus.helpers.AvoidSpecificRoads; import net.osmand.plus.helpers.SearchHistoryHelper; -import net.osmand.plus.mapcontextmenu.MenuBuilder.CollapsableView; import net.osmand.plus.mapcontextmenu.MenuBuilder.CollapseExpandListener; import net.osmand.plus.mapcontextmenu.controllers.AMapPointMenuController; import net.osmand.plus.mapcontextmenu.controllers.AmenityMenuController; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/PlainMenuItem.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/PlainMenuItem.java new file mode 100644 index 0000000000..383cdf6fb6 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/PlainMenuItem.java @@ -0,0 +1,60 @@ +package net.osmand.plus.mapcontextmenu; + +import android.view.View; + +public class PlainMenuItem { + + private int iconId; + private String buttonText; + private String text; + private boolean needLinks; + private boolean url; + private boolean collapsable; + private CollapsableView collapsableView; + private View.OnClickListener onClickListener; + + public PlainMenuItem(int iconId, String buttonText, String text, boolean needLinks, boolean url, + boolean collapsable, CollapsableView collapsableView, + View.OnClickListener onClickListener) { + this.iconId = iconId; + this.buttonText = buttonText; + this.text = text; + this.needLinks = needLinks; + this.url = url; + this.collapsable = collapsable; + this.collapsableView = collapsableView; + this.onClickListener = onClickListener; + } + + public int getIconId() { + return iconId; + } + + public String getButtonText() { + return buttonText; + } + + public String getText() { + return text; + } + + public boolean isNeedLinks() { + return needLinks; + } + + public boolean isUrl() { + return url; + } + + public boolean isCollapsable() { + return collapsable; + } + + public CollapsableView getCollapsableView() { + return collapsableView; + } + + public View.OnClickListener getOnClickListener() { + return onClickListener; + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java index b381ecdcc4..4791e401d0 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java @@ -35,6 +35,7 @@ import net.osmand.plus.Version; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.FontCache; import net.osmand.plus.mapcontextmenu.MenuBuilder; +import net.osmand.plus.mapcontextmenu.CollapsableView; import net.osmand.plus.osmedit.OsmEditingPlugin; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.views.POIMapLayer; @@ -223,27 +224,27 @@ public class AmenityMenuBuilder extends MenuBuilder { llIconCollapseParams.gravity = Gravity.CENTER_VERTICAL; iconViewCollapse.setLayoutParams(llIconCollapseParams); iconViewCollapse.setScaleType(ImageView.ScaleType.CENTER_INSIDE); - iconViewCollapse.setImageDrawable(getCollapseIcon(collapsableView.getContenView().getVisibility() == View.GONE)); + iconViewCollapse.setImageDrawable(getCollapseIcon(collapsableView.getContentView().getVisibility() == View.GONE)); llIconCollapse.addView(iconViewCollapse); ll.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (collapsableView.getContenView().getVisibility() == View.VISIBLE) { - collapsableView.getContenView().setVisibility(View.GONE); + if (collapsableView.getContentView().getVisibility() == View.VISIBLE) { + collapsableView.getContentView().setVisibility(View.GONE); iconViewCollapse.setImageDrawable(getCollapseIcon(true)); collapsableView.setCollapsed(true); } else { - collapsableView.getContenView().setVisibility(View.VISIBLE); + collapsableView.getContentView().setVisibility(View.VISIBLE); iconViewCollapse.setImageDrawable(getCollapseIcon(false)); collapsableView.setCollapsed(false); } } }); if (collapsableView.isCollapsed()) { - collapsableView.getContenView().setVisibility(View.GONE); + collapsableView.getContentView().setVisibility(View.GONE); iconViewCollapse.setImageDrawable(getCollapseIcon(true)); } - baseView.addView(collapsableView.getContenView()); + baseView.addView(collapsableView.getContentView()); } if (isWiki) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java index a2eb9efe1c..1e6df280a3 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java @@ -20,6 +20,7 @@ import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapcontextmenu.MenuBuilder; +import net.osmand.plus.mapcontextmenu.CollapsableView; import net.osmand.plus.myplaces.FavoritesActivity; import net.osmand.plus.widgets.TextViewEx; import net.osmand.util.Algorithms; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/WptPtMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/WptPtMenuBuilder.java index d9b2f6c7b9..a25a1d8326 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/WptPtMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/WptPtMenuBuilder.java @@ -22,6 +22,7 @@ import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.TrackActivity; import net.osmand.plus.mapcontextmenu.MenuBuilder; +import net.osmand.plus.mapcontextmenu.CollapsableView; import net.osmand.plus.views.POIMapLayer; import net.osmand.plus.widgets.TextViewEx; import net.osmand.util.Algorithms; diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteDetailsFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteDetailsFragment.java index f0a0550400..3b628dae68 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteDetailsFragment.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteDetailsFragment.java @@ -68,7 +68,7 @@ import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType; import net.osmand.plus.helpers.GpxUiHelper.OrderedLineDataSet; import net.osmand.plus.mapcontextmenu.InterceptorLinearLayout; -import net.osmand.plus.mapcontextmenu.MenuBuilder.CollapsableView; +import net.osmand.plus.mapcontextmenu.CollapsableView; import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu; import net.osmand.plus.render.MapRenderRepositories; import net.osmand.plus.routepreparationmenu.cards.BaseCard; @@ -870,12 +870,12 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT llIconCollapseParams.gravity = Gravity.CENTER_VERTICAL|Gravity.START; iconViewCollapse.setLayoutParams(llIconCollapseParams); iconViewCollapse.setScaleType(ImageView.ScaleType.CENTER_INSIDE); - iconViewCollapse.setImageDrawable(getCollapseIcon(collapsableView.getContenView().getVisibility() == View.GONE)); + iconViewCollapse.setImageDrawable(getCollapseIcon(collapsableView.getContentView().getVisibility() == View.GONE)); llIconCollapse.addView(iconViewCollapse); ll.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - LinearLayout contentView = (LinearLayout) collapsableView.getContenView(); + LinearLayout contentView = (LinearLayout) collapsableView.getContentView(); if (contentView.getVisibility() == View.VISIBLE) { contentView.setVisibility(View.GONE); iconViewCollapse.setImageDrawable(getCollapseIcon(true)); @@ -890,10 +890,10 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT } }); if (collapsableView.isCollapsed()) { - collapsableView.getContenView().setVisibility(View.GONE); + collapsableView.getContentView().setVisibility(View.GONE); iconViewCollapse.setImageDrawable(getCollapseIcon(true)); } - baseView.addView(collapsableView.getContenView()); + baseView.addView(collapsableView.getContentView()); } if (onClickListener != null) {