Clean up sorting in tracks to follow
This commit is contained in:
parent
8e4a619229
commit
e9925fbddd
3 changed files with 54 additions and 91 deletions
|
@ -60,14 +60,11 @@
|
||||||
android:layout_width="@dimen/wikipedia_options_button_width"
|
android:layout_width="@dimen/wikipedia_options_button_width"
|
||||||
android:layout_height="@dimen/dialog_button_height"
|
android:layout_height="@dimen/dialog_button_height"
|
||||||
android:layout_gravity="center"
|
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_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" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
@ -95,14 +92,6 @@
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingBottom="@dimen/dialog_button_ex_height">
|
android:paddingBottom="@dimen/dialog_button_ex_height">
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
|
||||||
android:id="@+id/gpx_track_list"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="0dp"
|
|
||||||
android:layout_weight="1"
|
|
||||||
tools:itemCount="1"
|
|
||||||
tools:listitem="@layout/gpx_track_select_item" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</androidx.core.widget.NestedScrollView>
|
</androidx.core.widget.NestedScrollView>
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
package net.osmand.plus.routepreparationmenu;
|
package net.osmand.plus.routepreparationmenu;
|
||||||
|
|
||||||
import android.animation.Animator;
|
|
||||||
import android.animation.AnimatorListenerAdapter;
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.drawable.AnimationDrawable;
|
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
@ -19,21 +16,16 @@ import android.view.ViewGroup.MarginLayoutParams;
|
||||||
import android.view.ViewTreeObserver.OnScrollChangedListener;
|
import android.view.ViewTreeObserver.OnScrollChangedListener;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.CallbackWithObject;
|
import net.osmand.CallbackWithObject;
|
||||||
import net.osmand.Collator;
|
|
||||||
import net.osmand.GPXUtilities.GPXFile;
|
import net.osmand.GPXUtilities.GPXFile;
|
||||||
import net.osmand.GPXUtilities.WptPt;
|
import net.osmand.GPXUtilities.WptPt;
|
||||||
import net.osmand.IndexConstants;
|
import net.osmand.IndexConstants;
|
||||||
import net.osmand.OsmAndCollator;
|
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.ValueHolder;
|
import net.osmand.ValueHolder;
|
||||||
import net.osmand.data.QuadRect;
|
import net.osmand.data.QuadRect;
|
||||||
|
@ -41,7 +33,7 @@ import net.osmand.data.RotatedTileBox;
|
||||||
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
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;
|
||||||
import net.osmand.plus.UiUtilities.DialogButtonType;
|
import net.osmand.plus.UiUtilities.DialogButtonType;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
|
@ -78,8 +70,6 @@ import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
@ -98,12 +88,14 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
|
||||||
private GPXFile gpxFile;
|
private GPXFile gpxFile;
|
||||||
|
|
||||||
private View buttonsShadow;
|
private View buttonsShadow;
|
||||||
|
private ImageButton sortButton;
|
||||||
|
|
||||||
private TracksToFollowCard tracksCard;
|
private TracksToFollowCard tracksCard;
|
||||||
|
private TracksSortByMode sortByMode = TracksSortByMode.BY_DATE;
|
||||||
|
|
||||||
private boolean editingTrack;
|
private boolean editingTrack;
|
||||||
private boolean selectingTrack;
|
private boolean selectingTrack;
|
||||||
private int menuTitleHeight;
|
private int menuTitleHeight;
|
||||||
TracksSortByMode sortByMode = TracksSortByMode.BY_DATE;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMainLayoutId() {
|
public int getMainLayoutId() {
|
||||||
|
@ -162,42 +154,6 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
View view = super.onCreateView(inflater, container, savedInstanceState);
|
View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||||
if (view != null) {
|
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<SimplePopUpMenuItemAdapter.SimplePopUpMenuItem> 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<GPXInfo> list = tracksCard.getGpxInfoList();
|
|
||||||
tracksCard.setSortByMode(mode);
|
|
||||||
tracksCard.setGpxInfoList(list);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, sortByMode == mode
|
|
||||||
));
|
|
||||||
}
|
|
||||||
UiUtilities.showPopUpMenu(v, items);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
ImageButton closeButton = view.findViewById(R.id.close_button);
|
ImageButton closeButton = view.findViewById(R.id.close_button);
|
||||||
buttonsShadow = view.findViewById(R.id.buttons_shadow);
|
buttonsShadow = view.findViewById(R.id.buttons_shadow);
|
||||||
closeButton.setImageDrawable(getContentIcon(AndroidUtils.getNavigationIconResId(app)));
|
closeButton.setImageDrawable(getContentIcon(AndroidUtils.getNavigationIconResId(app)));
|
||||||
|
@ -213,6 +169,7 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
|
||||||
}
|
}
|
||||||
setupCards();
|
setupCards();
|
||||||
setupButtons(view);
|
setupButtons(view);
|
||||||
|
setupSortButton(view);
|
||||||
setupScrollShadow();
|
setupScrollShadow();
|
||||||
if (!isPortrait()) {
|
if (!isPortrait()) {
|
||||||
int widthNoShadow = getLandscapeNoShadowWidth();
|
int widthNoShadow = getLandscapeNoShadowWidth();
|
||||||
|
@ -249,9 +206,6 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
|
||||||
cardsContainer.removeAllViews();
|
cardsContainer.removeAllViews();
|
||||||
|
|
||||||
if (gpxFile == null || selectingTrack) {
|
if (gpxFile == null || selectingTrack) {
|
||||||
ImportTrackCard importTrackCard = new ImportTrackCard(mapActivity);
|
|
||||||
importTrackCard.setListener(this);
|
|
||||||
|
|
||||||
setupTracksCard();
|
setupTracksCard();
|
||||||
} else {
|
} else {
|
||||||
String fileName = null;
|
String fileName = null;
|
||||||
|
@ -318,8 +272,6 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void setupNavigateOptionsCard(GPXRouteParamsBuilder rparams) {
|
private void setupNavigateOptionsCard(GPXRouteParamsBuilder rparams) {
|
||||||
MapActivity mapActivity = getMapActivity();
|
MapActivity mapActivity = getMapActivity();
|
||||||
if (mapActivity != null) {
|
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<SimplePopUpMenuItem> 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) {
|
private void setupButtons(View view) {
|
||||||
View buttonsContainer = view.findViewById(R.id.buttons_container);
|
View buttonsContainer = view.findViewById(R.id.buttons_container);
|
||||||
buttonsContainer.setBackgroundColor(AndroidUtils.getColorFromAttr(view.getContext(), R.attr.bg_color));
|
buttonsContainer.setBackgroundColor(AndroidUtils.getColorFromAttr(view.getContext(), R.attr.bg_color));
|
||||||
|
|
|
@ -24,19 +24,15 @@ import java.util.Map;
|
||||||
|
|
||||||
public class TracksToFollowCard extends BaseCard {
|
public class TracksToFollowCard extends BaseCard {
|
||||||
|
|
||||||
|
private List<GPXInfo> gpxInfoList;
|
||||||
private Map<String, List<GPXInfo>> gpxInfoCategories;
|
private Map<String, List<GPXInfo>> gpxInfoCategories;
|
||||||
|
|
||||||
private List<GPXInfo> gpxInfoList;
|
private GpxTrackAdapter tracksAdapter;
|
||||||
private String selectedCategory;
|
private TracksSortByMode sortByMode = TracksSortByMode.BY_DATE;
|
||||||
|
|
||||||
private String defaultCategory;
|
private String defaultCategory;
|
||||||
private String visibleCategory;
|
private String visibleCategory;
|
||||||
TracksSortByMode sortByMode = TracksSortByMode.BY_DATE;
|
private String selectedCategory;
|
||||||
|
|
||||||
public void setSortByMode(TracksSortByMode sortByMode) {
|
|
||||||
this.sortByMode = sortByMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
private GpxTrackAdapter tracksAdapter;
|
|
||||||
|
|
||||||
public TracksToFollowCard(MapActivity mapActivity, List<GPXInfo> gpxInfoList, String selectedCategory) {
|
public TracksToFollowCard(MapActivity mapActivity, List<GPXInfo> gpxInfoList, String selectedCategory) {
|
||||||
super(mapActivity);
|
super(mapActivity);
|
||||||
|
@ -44,24 +40,19 @@ public class TracksToFollowCard extends BaseCard {
|
||||||
this.selectedCategory = selectedCategory;
|
this.selectedCategory = selectedCategory;
|
||||||
defaultCategory = app.getString(R.string.shared_string_all);
|
defaultCategory = app.getString(R.string.shared_string_all);
|
||||||
visibleCategory = app.getString(R.string.shared_string_visible);
|
visibleCategory = app.getString(R.string.shared_string_visible);
|
||||||
sortGPXInfoItems(gpxInfoList);
|
|
||||||
gpxInfoCategories = getGpxInfoCategories();
|
gpxInfoCategories = getGpxInfoCategories();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGpxInfoList(List<GPXInfo> gpxInfoList) {
|
public void setSortByMode(TracksSortByMode sortByMode) {
|
||||||
this.gpxInfoList = gpxInfoList;
|
this.sortByMode = sortByMode;
|
||||||
sortGPXInfoItems(gpxInfoList);
|
|
||||||
gpxInfoCategories = getGpxInfoCategories();
|
gpxInfoCategories = getGpxInfoCategories();
|
||||||
List<GPXInfo> items = gpxInfoCategories.get(selectedCategory);
|
updateTracksAdapter();
|
||||||
tracksAdapter.setGpxInfoList(items != null ? items : new ArrayList<GPXInfo>());
|
|
||||||
tracksAdapter.notifyDataSetChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<GPXInfo> getGpxInfoList() {
|
public List<GPXInfo> getGpxInfoList() {
|
||||||
return gpxInfoList;
|
return gpxInfoList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getSelectedCategory() {
|
public String getSelectedCategory() {
|
||||||
return selectedCategory;
|
return selectedCategory;
|
||||||
}
|
}
|
||||||
|
@ -107,11 +98,8 @@ public class TracksToFollowCard extends BaseCard {
|
||||||
@Override
|
@Override
|
||||||
public void onItemSelected(HorizontalSelectionAdapter.HorizontalSelectionItem item) {
|
public void onItemSelected(HorizontalSelectionAdapter.HorizontalSelectionItem item) {
|
||||||
selectedCategory = item.getTitle();
|
selectedCategory = item.getTitle();
|
||||||
List<GPXInfo> items = gpxInfoCategories.get(selectedCategory);
|
|
||||||
tracksAdapter.setShowFolderName(showFoldersName());
|
tracksAdapter.setShowFolderName(showFoldersName());
|
||||||
tracksAdapter.setGpxInfoList(items != null ? items : new ArrayList<GPXInfo>());
|
updateTracksAdapter();
|
||||||
tracksAdapter.notifyDataSetChanged();
|
|
||||||
|
|
||||||
selectionAdapter.notifyDataSetChanged();
|
selectionAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -122,6 +110,12 @@ public class TracksToFollowCard extends BaseCard {
|
||||||
selectionAdapter.notifyDataSetChanged();
|
selectionAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateTracksAdapter() {
|
||||||
|
List<GPXInfo> items = gpxInfoCategories.get(selectedCategory);
|
||||||
|
tracksAdapter.setGpxInfoList(items != null ? items : new ArrayList<GPXInfo>());
|
||||||
|
tracksAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
private boolean showFoldersName() {
|
private boolean showFoldersName() {
|
||||||
return defaultCategory.equals(selectedCategory) || visibleCategory.equals(selectedCategory);
|
return defaultCategory.equals(selectedCategory) || visibleCategory.equals(selectedCategory);
|
||||||
}
|
}
|
||||||
|
@ -132,6 +126,7 @@ public class TracksToFollowCard extends BaseCard {
|
||||||
gpxInfoCategories.put(visibleCategory, new ArrayList<GPXInfo>());
|
gpxInfoCategories.put(visibleCategory, new ArrayList<GPXInfo>());
|
||||||
gpxInfoCategories.put(defaultCategory, new ArrayList<GPXInfo>());
|
gpxInfoCategories.put(defaultCategory, new ArrayList<GPXInfo>());
|
||||||
|
|
||||||
|
sortGPXInfoItems(gpxInfoList);
|
||||||
for (GPXInfo info : gpxInfoList) {
|
for (GPXInfo info : gpxInfoList) {
|
||||||
if (info.isSelected()) {
|
if (info.isSelected()) {
|
||||||
addGpxInfoCategory(gpxInfoCategories, info, visibleCategory);
|
addGpxInfoCategory(gpxInfoCategories, info, visibleCategory);
|
||||||
|
@ -179,4 +174,3 @@ public class TracksToFollowCard extends BaseCard {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue