redo
This commit is contained in:
parent
62995c120f
commit
06ecfe7e8c
2 changed files with 49 additions and 24 deletions
|
@ -99,6 +99,7 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
|
|||
|
||||
private View buttonsShadow;
|
||||
protected boolean nightMode;
|
||||
private TracksToFollowCard tracksCard;
|
||||
|
||||
private boolean editingTrack;
|
||||
private boolean selectingTrack;
|
||||
|
@ -184,7 +185,13 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
sortByMode = mode;
|
||||
setupCards();
|
||||
sortButton.setImageResource(mode.getIconId());
|
||||
if (tracksCard != null) {
|
||||
List<GPXInfo> list = tracksCard.getGpxInfoList();
|
||||
tracksCard.setSortByMode(mode);
|
||||
tracksCard.setGpxInfoList(list);
|
||||
|
||||
}
|
||||
}
|
||||
}, sortByMode == mode
|
||||
));
|
||||
|
@ -304,35 +311,15 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
|
|||
List<String> selectedTrackNames = GpxUiHelper.getSelectedTrackPaths(app);
|
||||
List<GPXInfo> list = GpxUiHelper.getSortedGPXFilesInfo(dir, selectedTrackNames, false);
|
||||
if (list.size() > 0) {
|
||||
sortGPXInfoItems(list);
|
||||
String defaultCategory = app.getString(R.string.shared_string_all);
|
||||
TracksToFollowCard tracksCard = new TracksToFollowCard(mapActivity, list, defaultCategory);
|
||||
tracksCard = new TracksToFollowCard(mapActivity, list, defaultCategory);
|
||||
tracksCard.setListener(FollowTrackFragment.this);
|
||||
getCardsContainer().addView(tracksCard.build(mapActivity));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void sortGPXInfoItems(List<GPXInfo> gpxInfoList) {
|
||||
final Collator collator = OsmAndCollator.primaryCollator();
|
||||
Collections.sort(gpxInfoList, new Comparator<GPXInfo>() {
|
||||
@Override
|
||||
public int compare(GPXInfo i1, GPXInfo i2) {
|
||||
if (sortByMode == TracksSortByMode.BY_NAME_ASCENDING) {
|
||||
return collator.compare(i1.getFileName(), i2.getFileName());
|
||||
} else if (sortByMode == TracksSortByMode.BY_NAME_DESCENDING) {
|
||||
return -collator.compare(i1.getFileName(), i2.getFileName());
|
||||
} else {
|
||||
long time1 = i1.getLastModified();
|
||||
long time2 = i2.getLastModified();
|
||||
if (time1 == time2) {
|
||||
return collator.compare(i1.getFileName(), i2.getFileName());
|
||||
}
|
||||
return -((time1 < time2) ? -1 : ((time1 == time2) ? 0 : 1));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void setupNavigateOptionsCard(GPXRouteParamsBuilder rparams) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
|
|
|
@ -3,16 +3,21 @@ package net.osmand.plus.routepreparationmenu.cards;
|
|||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import net.osmand.Collator;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.OsmAndCollator;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.helpers.GpxTrackAdapter;
|
||||
import net.osmand.plus.helpers.GpxUiHelper.GPXInfo;
|
||||
import net.osmand.plus.helpers.enums.TracksSortByMode;
|
||||
import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -25,6 +30,11 @@ public class TracksToFollowCard extends BaseCard {
|
|||
private String selectedCategory;
|
||||
private String defaultCategory;
|
||||
private String visibleCategory;
|
||||
TracksSortByMode sortByMode = TracksSortByMode.BY_DATE;
|
||||
|
||||
public void setSortByMode(TracksSortByMode sortByMode) {
|
||||
this.sortByMode = sortByMode;
|
||||
}
|
||||
|
||||
private GpxTrackAdapter tracksAdapter;
|
||||
|
||||
|
@ -34,18 +44,24 @@ 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<GPXInfo> gpxInfoList) {
|
||||
this.gpxInfoList = gpxInfoList;
|
||||
sortGPXInfoItems(gpxInfoList);
|
||||
gpxInfoCategories = getGpxInfoCategories();
|
||||
List<GPXInfo> items = gpxInfoCategories.get(selectedCategory);
|
||||
tracksAdapter.setGpxInfoList(items != null ? items : new ArrayList<GPXInfo>());
|
||||
tracksAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public List<GPXInfo> getGpxInfoList() {
|
||||
return gpxInfoList;
|
||||
}
|
||||
|
||||
|
||||
public String getSelectedCategory() {
|
||||
return selectedCategory;
|
||||
}
|
||||
|
@ -141,4 +157,26 @@ public class TracksToFollowCard extends BaseCard {
|
|||
}
|
||||
items.add(info);
|
||||
}
|
||||
}
|
||||
|
||||
public void sortGPXInfoItems(List<GPXInfo> gpxInfoList) {
|
||||
final Collator collator = OsmAndCollator.primaryCollator();
|
||||
Collections.sort(gpxInfoList, new Comparator<GPXInfo>() {
|
||||
@Override
|
||||
public int compare(GPXInfo i1, GPXInfo i2) {
|
||||
if (sortByMode == TracksSortByMode.BY_NAME_ASCENDING) {
|
||||
return collator.compare(i1.getFileName(), i2.getFileName());
|
||||
} else if (sortByMode == TracksSortByMode.BY_NAME_DESCENDING) {
|
||||
return -collator.compare(i1.getFileName(), i2.getFileName());
|
||||
} else {
|
||||
long time1 = i1.getLastModified();
|
||||
long time2 = i2.getLastModified();
|
||||
if (time1 == time2) {
|
||||
return collator.compare(i1.getFileName(), i2.getFileName());
|
||||
}
|
||||
return -((time1 < time2) ? -1 : ((time1 == time2) ? 0 : 1));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue