Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nazar-kutz committed Nov 22, 2024
1 parent 1dbe52d commit 3123ae0
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class TrackFolderAnalysis(folder: TracksGroup) {
timeSpan = timeSpanSum.toInt()
tracksCount = items.size

log.info(">>>> ${folder.getName()} = (tracks: $tracksCount, totalDistance: ${"%.2f".format(totalDistance)}, " +
log.info(">>>> ${folder.getId()} = (tracks: $tracksCount, totalDistance: ${"%.2f".format(totalDistance)}, " +
"timeSpan: $timeSpan, fileSize: $fileSize, diffElevationUp: ${"%.2f".format(diffElevationUp)}, diffElevationDown: ${"%.2f".format(diffElevationDown)}")
}
}
12 changes: 6 additions & 6 deletions OsmAnd/src/net/osmand/plus/configmap/tracks/TrackTabsHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,21 @@ public ItemsSelectionHelper<TrackItem> getItemsSelectionHelper() {

@NonNull
public List<TrackTab> getSortedTrackTabs(boolean useExtendedName) {
List<TrackTab> result = new ArrayList<>(trackTabs.values());
List<TrackTab> result = getTrackTabs();
result.sort(new TracksComparator(getRootSortMode(), getDefaultLocation(), useExtendedName));
return result;
}

@NonNull
public List<TrackTab> getTrackTabs() {
return new ArrayList<>(trackTabs.values());
}

@Nullable
public TrackTab getTrackTab(@NonNull String id) {
return trackTabs.get(id);
}

@NonNull
public Map<String, TrackTab> getTrackTabs() {
return trackTabs;
}

@NonNull
public Set<TrackItem> getRecentlyVisibleTracks() {
return new HashSet<>(recentlyVisibleTrackItem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ public int compare(Object o1, Object o2) {
}
if (o1 instanceof ComparableTracksGroup folder1) {
if (o2 instanceof ComparableTracksGroup folder2) {
int order1 = folder1.getDefaultOrder();
int order2 = folder2.getDefaultOrder();
if (order1 != order2) {
return Integer.compare(order1, order2);
int predefinedOrder1 = folder1.getDefaultOrder();
int predefinedOrder2 = folder2.getDefaultOrder();
if (predefinedOrder1 != predefinedOrder2) {
return Integer.compare(predefinedOrder1, predefinedOrder2);
}
return compareTrackFolders(folder1, folder2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,22 @@

public class TracksTabAdapter extends FragmentStatePagerAdapter {

private final OsmandApplication app;
private final List<TrackTab> trackTabs = new ArrayList<>();

public TracksTabAdapter(@NonNull OsmandApplication app, @NonNull FragmentManager manager, @NonNull List<TrackTab> tabs) {
public TracksTabAdapter(@NonNull FragmentManager manager, @NonNull List<TrackTab> tabs) {
super(manager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
this.app = app;
trackTabs.addAll(tabs);
}

public void setTrackTabs(@NonNull Map<String, TrackTab> tabs) {
public void setTrackTabs(@NonNull List<TrackTab> tabs) {
trackTabs.clear();
trackTabs.addAll(tabs.values());
trackTabs.addAll(tabs);
notifyDataSetChanged();
}

@Override
public int getItemPosition(@NonNull Object object) {
if (object instanceof TrackItemsFragment) {
TrackItemsFragment fragment = (TrackItemsFragment) object;
if (object instanceof TrackItemsFragment fragment) {
int index = trackTabs.indexOf(fragment.getTrackTab());
return index >= 0 ? index : POSITION_NONE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public void changeAppearance() {
protected void addTrackItem(@NonNull TrackItem item) {
trackTabsHelper.addTrackItem(item);
updateTrackTabs();
setSelectedTab(IndexConstants.GPX_IMPORT_DIR);
setSelectedTab("import");
updateTabsContent();
updateButtonsState();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@ public void showSortByDialog() {
@NonNull
@Override
public TracksSortMode getTracksSortMode() {
return settings.getTrackSortModes().requireSortMode(getSortEntryId());
TrackSortModesCollection sortModes = settings.getTrackSortModes(rootFolder);
return sortModes.requireSortMode(getSortEntryId());
}

@Nullable
Expand All @@ -341,22 +342,23 @@ public void setTracksSortMode(@NonNull TracksSortMode sortMode, boolean sortSubF
sortSubFolder(sortMode);
} else {
TracksGroup folder = smartFolder != null ? smartFolder : selectedFolder;
TrackSortModesCollection sortModes = settings.getTrackSortModes();
TrackSortModesCollection sortModes = settings.getTrackSortModes(rootFolder);
sortModes.setSortMode(folder.getId(), sortMode);
sortModes.syncSettings();
updateContent();
}
}

private void sortSubFolder(@NonNull TracksSortMode sortMode) {
TrackSortModesCollection sortModes = settings.getTrackSortModes();
TrackSortModesCollection sortModes = settings.getTrackSortModes(rootFolder);
sortFolders(selectedFolder, sortModes, sortMode);
sortModes.syncSettings();

app.showToastMessage(app.getString(R.string.sorted_sufolders_toast, selectedFolder.getName(), app.getString(sortMode.getNameId())));
}

private void sortFolders(@NonNull TrackFolder trackFolder, @NonNull TrackSortModesCollection sortModes,
private void sortFolders(@NonNull TrackFolder trackFolder,
@NonNull TrackSortModesCollection sortModes,
@NonNull TracksSortMode sortMode) {
for (TrackFolder folder : trackFolder.getFlattenedSubFolders()) {
sortModes.setSortMode(folder.getId(), sortMode);
Expand Down
23 changes: 17 additions & 6 deletions OsmAnd/src/net/osmand/plus/track/BaseTracksTabsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import androidx.fragment.app.FragmentManager;
import androidx.viewpager.widget.ViewPager;

import net.osmand.plus.OsmandApplication;
import net.osmand.plus.shared.SharedUtil;
import net.osmand.plus.R;
import net.osmand.plus.base.BaseOsmAndDialogFragment;
Expand Down Expand Up @@ -107,7 +108,7 @@ public ItemsSelectionHelper<TrackItem> getSelectionHelper() {
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
importHelper = app.getImportHelper();
trackTabsHelper = new TrackTabsHelper(app);
trackTabsHelper = createTrackTabsHelper(app);
gpxSelectionHelper = app.getSelectedGpxHelper();
itemsSelectionHelper = trackTabsHelper.getItemsSelectionHelper();
}
Expand Down Expand Up @@ -153,18 +154,28 @@ public void tabStylesUpdated(View tabsContainer, int currentPosition) {
setTabs(tabs);
}

@NonNull
protected TrackTabsHelper createTrackTabsHelper(@NonNull OsmandApplication app) {
return new TrackTabsHelper(app);
}

@NonNull
public List<TrackTab> getTrackTabs() {
return trackTabsHelper.getTrackTabs();
}

@NonNull
public List<TrackTab> getSortedTrackTabs() {
return getSortedTrackTabs(false);
}

@NonNull
public List<TrackTab> getSortedTrackTabs(boolean checkParentName) {
return trackTabsHelper.getSortedTrackTabs(checkParentName);
public List<TrackTab> getSortedTrackTabs(boolean useExtendedName) {
return trackTabsHelper.getSortedTrackTabs(useExtendedName);
}

protected void setViewPagerAdapter(@NonNull ViewPager pager, List<TrackTab> items) {
adapter = new TracksTabAdapter(app, getChildFragmentManager(), items);
adapter = new TracksTabAdapter(getChildFragmentManager(), items);
pager.setAdapter(adapter);
}

Expand All @@ -187,7 +198,7 @@ public void setSelectedTab(@NonNull String id) {

@Nullable
public TrackTab getTab(@NonNull String id) {
for (TrackTab trackTab : getSortedTrackTabs()) {
for (TrackTab trackTab : getTrackTabs()) {
if (Algorithms.stringsEqual(id, trackTab.getId())) {
return trackTab;
}
Expand Down Expand Up @@ -242,7 +253,7 @@ public void loadTracksStarted() {
}

protected void updateTrackTabs() {
adapter.setTrackTabs(trackTabsHelper.getTrackTabs());
adapter.setTrackTabs(trackTabsHelper.getSortedTrackTabs(false));
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions OsmAnd/src/net/osmand/plus/track/SelectTrackTabsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void onTrackFolderSelected(@NonNull TrackFolder trackFolder) {
protected void addTrackItem(@NonNull TrackItem item) {
trackTabsHelper.addTrackItem(item);
updateTrackTabs();
setSelectedTab(IndexConstants.GPX_IMPORT_DIR);
setSelectedTab("import");
updateTabsContent();
}

Expand Down Expand Up @@ -170,7 +170,7 @@ public void onTrackItemsSelected(@NonNull Set<TrackItem> trackItems, boolean sel
@Nullable
@Override
public TrackTab getTab(@NonNull String id) {
for (TrackTab trackTab : getSortedTrackTabs()) {
for (TrackTab trackTab : getTrackTabs()) {
if (Algorithms.stringsEqual(id, trackTab.getId())) {
updateTrackItemsVisibility(trackTab);
return trackTab;
Expand Down

0 comments on commit 3123ae0

Please sign in to comment.