From e9925fbddddb8958acafd5531583df8718ba89f0 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Thu, 29 Oct 2020 11:58:08 +0200 Subject: [PATCH] Clean up sorting in tracks to follow --- OsmAnd/res/layout/follow_track_options.xml | 19 +--- .../FollowTrackFragment.java | 86 +++++++------------ .../cards/TracksToFollowCard.java | 40 ++++----- 3 files changed, 54 insertions(+), 91 deletions(-) diff --git a/OsmAnd/res/layout/follow_track_options.xml b/OsmAnd/res/layout/follow_track_options.xml index 7e7843d510..0877fcc307 100644 --- a/OsmAnd/res/layout/follow_track_options.xml +++ b/OsmAnd/res/layout/follow_track_options.xml @@ -60,14 +60,11 @@ android:layout_width="@dimen/wikipedia_options_button_width" android:layout_height="@dimen/dialog_button_height" android:layout_gravity="center" - osmand:srcCompat="@drawable/ic_sort_waypoint_dark" - android:tint="?attr/color_dialog_buttons" - android:background="?attr/bg_dash_line" - android:visibility="gone" - tools:visibility="visible" android:layout_marginEnd="@dimen/content_padding" - android:layout_marginRight="@dimen/content_padding" /> - + android:layout_marginRight="@dimen/content_padding" + android:background="?attr/bg_dash_line" + android:tint="?attr/color_dialog_buttons" + osmand:srcCompat="@drawable/ic_sort_waypoint_dark" /> @@ -95,14 +92,6 @@ android:orientation="vertical" android:paddingBottom="@dimen/dialog_button_ex_height"> - - diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java index f304123de8..b01e49bd12 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java @@ -1,11 +1,8 @@ package net.osmand.plus.routepreparationmenu; -import android.animation.Animator; -import android.animation.AnimatorListenerAdapter; import android.app.Activity; import android.content.ActivityNotFoundException; import android.content.Intent; -import android.graphics.drawable.AnimationDrawable; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Build; @@ -19,21 +16,16 @@ import android.view.ViewGroup.MarginLayoutParams; import android.view.ViewTreeObserver.OnScrollChangedListener; import android.widget.FrameLayout; import android.widget.ImageButton; -import android.widget.ImageView; import android.widget.LinearLayout; import androidx.annotation.NonNull; import androidx.fragment.app.FragmentManager; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; import net.osmand.AndroidUtils; import net.osmand.CallbackWithObject; -import net.osmand.Collator; import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.WptPt; import net.osmand.IndexConstants; -import net.osmand.OsmAndCollator; import net.osmand.PlatformUtil; import net.osmand.ValueHolder; import net.osmand.data.QuadRect; @@ -41,7 +33,7 @@ import net.osmand.data.RotatedTileBox; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; -import net.osmand.plus.SimplePopUpMenuItemAdapter; +import net.osmand.plus.SimplePopUpMenuItemAdapter.SimplePopUpMenuItem; import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities.DialogButtonType; import net.osmand.plus.activities.MapActivity; @@ -78,8 +70,6 @@ import org.apache.commons.logging.Log; import java.io.File; import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; import java.util.List; @@ -98,12 +88,14 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca private GPXFile gpxFile; private View buttonsShadow; + private ImageButton sortButton; + private TracksToFollowCard tracksCard; + private TracksSortByMode sortByMode = TracksSortByMode.BY_DATE; private boolean editingTrack; private boolean selectingTrack; private int menuTitleHeight; - TracksSortByMode sortByMode = TracksSortByMode.BY_DATE; @Override public int getMainLayoutId() { @@ -162,42 +154,6 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = super.onCreateView(inflater, container, savedInstanceState); if (view != null) { - final ImageButton sortButton = view.findViewById(R.id.sort_button); - Drawable background = app.getUIUtilities().getIcon(R.drawable.bg_dash_line_dark, - isNightMode() - ? R.color.inactive_buttons_and_links_bg_dark - : R.color.inactive_buttons_and_links_bg_light); - sortButton.setImageResource(sortByMode.getIconId()); - AndroidUtils.setBackground(sortButton, background); - sortButton.setVisibility(View.VISIBLE); - final RecyclerView filesRecyclerView = view.findViewById(R.id.gpx_track_list); - filesRecyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - sortButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - final List items = new ArrayList<>(); - for (final TracksSortByMode mode : TracksSortByMode.values()) { - items.add(new SimplePopUpMenuItemAdapter.SimplePopUpMenuItem( - getString(mode.getNameId()), - app.getUIUtilities().getThemedIcon(mode.getIconId()), - new View.OnClickListener() { - @Override - public void onClick(View v) { - sortByMode = mode; - sortButton.setImageResource(mode.getIconId()); - if (tracksCard != null) { - List list = tracksCard.getGpxInfoList(); - tracksCard.setSortByMode(mode); - tracksCard.setGpxInfoList(list); - - } - } - }, sortByMode == mode - )); - } - UiUtilities.showPopUpMenu(v, items); - } - }); ImageButton closeButton = view.findViewById(R.id.close_button); buttonsShadow = view.findViewById(R.id.buttons_shadow); closeButton.setImageDrawable(getContentIcon(AndroidUtils.getNavigationIconResId(app))); @@ -213,6 +169,7 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca } setupCards(); setupButtons(view); + setupSortButton(view); setupScrollShadow(); if (!isPortrait()) { int widthNoShadow = getLandscapeNoShadowWidth(); @@ -249,9 +206,6 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca cardsContainer.removeAllViews(); if (gpxFile == null || selectingTrack) { - ImportTrackCard importTrackCard = new ImportTrackCard(mapActivity); - importTrackCard.setListener(this); - setupTracksCard(); } else { String fileName = null; @@ -318,8 +272,6 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca } } - - private void setupNavigateOptionsCard(GPXRouteParamsBuilder rparams) { MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { @@ -649,6 +601,34 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca } } + private void setupSortButton(View view) { + final ImageButton sortButton = view.findViewById(R.id.sort_button); + int colorId = isNightMode() ? R.color.inactive_buttons_and_links_bg_dark : R.color.inactive_buttons_and_links_bg_light; + Drawable background = app.getUIUtilities().getIcon(R.drawable.bg_dash_line_dark, colorId); + sortButton.setImageResource(sortByMode.getIconId()); + AndroidUtils.setBackground(sortButton, background); + sortButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + List items = new ArrayList<>(); + for (final TracksSortByMode mode : TracksSortByMode.values()) { + items.add(new SimplePopUpMenuItem(getString(mode.getNameId()), + app.getUIUtilities().getThemedIcon(mode.getIconId()), + new View.OnClickListener() { + @Override + public void onClick(View v) { + sortByMode = mode; + tracksCard.setSortByMode(mode); + sortButton.setImageResource(mode.getIconId()); + } + }, sortByMode == mode + )); + } + UiUtilities.showPopUpMenu(v, items); + } + }); + } + private void setupButtons(View view) { View buttonsContainer = view.findViewById(R.id.buttons_container); buttonsContainer.setBackgroundColor(AndroidUtils.getColorFromAttr(view.getContext(), R.attr.bg_color)); diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/TracksToFollowCard.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/TracksToFollowCard.java index c6cfe7247d..0897894730 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/TracksToFollowCard.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/TracksToFollowCard.java @@ -24,19 +24,15 @@ import java.util.Map; public class TracksToFollowCard extends BaseCard { + private List gpxInfoList; private Map> gpxInfoCategories; - private List gpxInfoList; - private String selectedCategory; + private GpxTrackAdapter tracksAdapter; + private TracksSortByMode sortByMode = TracksSortByMode.BY_DATE; + private String defaultCategory; private String visibleCategory; - TracksSortByMode sortByMode = TracksSortByMode.BY_DATE; - - public void setSortByMode(TracksSortByMode sortByMode) { - this.sortByMode = sortByMode; - } - - private GpxTrackAdapter tracksAdapter; + private String selectedCategory; public TracksToFollowCard(MapActivity mapActivity, List gpxInfoList, String selectedCategory) { super(mapActivity); @@ -44,24 +40,19 @@ public class TracksToFollowCard extends BaseCard { this.selectedCategory = selectedCategory; defaultCategory = app.getString(R.string.shared_string_all); visibleCategory = app.getString(R.string.shared_string_visible); - sortGPXInfoItems(gpxInfoList); gpxInfoCategories = getGpxInfoCategories(); } - public void setGpxInfoList(List gpxInfoList) { - this.gpxInfoList = gpxInfoList; - sortGPXInfoItems(gpxInfoList); + public void setSortByMode(TracksSortByMode sortByMode) { + this.sortByMode = sortByMode; gpxInfoCategories = getGpxInfoCategories(); - List items = gpxInfoCategories.get(selectedCategory); - tracksAdapter.setGpxInfoList(items != null ? items : new ArrayList()); - tracksAdapter.notifyDataSetChanged(); + updateTracksAdapter(); } public List getGpxInfoList() { return gpxInfoList; } - public String getSelectedCategory() { return selectedCategory; } @@ -107,11 +98,8 @@ public class TracksToFollowCard extends BaseCard { @Override public void onItemSelected(HorizontalSelectionAdapter.HorizontalSelectionItem item) { selectedCategory = item.getTitle(); - List items = gpxInfoCategories.get(selectedCategory); tracksAdapter.setShowFolderName(showFoldersName()); - tracksAdapter.setGpxInfoList(items != null ? items : new ArrayList()); - tracksAdapter.notifyDataSetChanged(); - + updateTracksAdapter(); selectionAdapter.notifyDataSetChanged(); } }); @@ -122,6 +110,12 @@ public class TracksToFollowCard extends BaseCard { selectionAdapter.notifyDataSetChanged(); } + private void updateTracksAdapter() { + List items = gpxInfoCategories.get(selectedCategory); + tracksAdapter.setGpxInfoList(items != null ? items : new ArrayList()); + tracksAdapter.notifyDataSetChanged(); + } + private boolean showFoldersName() { return defaultCategory.equals(selectedCategory) || visibleCategory.equals(selectedCategory); } @@ -132,6 +126,7 @@ public class TracksToFollowCard extends BaseCard { gpxInfoCategories.put(visibleCategory, new ArrayList()); gpxInfoCategories.put(defaultCategory, new ArrayList()); + sortGPXInfoItems(gpxInfoList); for (GPXInfo info : gpxInfoList) { if (info.isSelected()) { addGpxInfoCategory(gpxInfoCategories, info, visibleCategory); @@ -178,5 +173,4 @@ public class TracksToFollowCard extends BaseCard { } }); } -} - +} \ No newline at end of file