mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-27 07:56:38 +00:00
Adjusted sorting for Quickfinder to ensure natural order of
leaderboardGroups and regattas
This commit is contained in:
+22
-20
@@ -1,7 +1,9 @@
|
||||
package com.sap.sailing.gwt.home.mobile.places;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.sap.sailing.gwt.home.communication.event.EventMetadataDTO;
|
||||
@@ -10,39 +12,41 @@ import com.sap.sailing.gwt.home.communication.eventview.RegattaMetadataDTO;
|
||||
import com.sap.sailing.gwt.home.mobile.partials.quickfinder.Quickfinder;
|
||||
import com.sap.sailing.gwt.home.shared.app.PlaceNavigation;
|
||||
import com.sap.sailing.gwt.ui.client.StringMessages;
|
||||
import com.sap.sse.common.Util;
|
||||
|
||||
public class QuickfinderPresenter {
|
||||
private static final StringMessages MSG = StringMessages.INSTANCE;
|
||||
|
||||
public static QuickfinderPresenter getForRegattaLeaderboards(Quickfinder quickfinder,
|
||||
final RegattaLeaderboardNavigationProvider navigator, Collection<RegattaMetadataDTO> regattaMetadatas) {
|
||||
public static QuickfinderPresenter getForRegattaLeaderboards(Quickfinder quickfinder,
|
||||
final RegattaLeaderboardNavigationProvider navigator,
|
||||
Map<String, Set<RegattaMetadataDTO>> regattasByLeaderboardGroupName) {
|
||||
return new QuickfinderPresenter(quickfinder, MSG.resultsQuickfinder(), new RegattaPlaceNaviationProvider() {
|
||||
@Override
|
||||
public PlaceNavigation<?> getPlaceNavigation(String regattaId) {
|
||||
return navigator.getRegattaMiniLeaderboardNavigation(regattaId);
|
||||
}
|
||||
}, regattaMetadatas);
|
||||
}, regattasByLeaderboardGroupName);
|
||||
}
|
||||
|
||||
public static QuickfinderPresenter getForRegattaRaces(Quickfinder quickfinder,
|
||||
final RegattaRacesNavigationProvider navigator, Collection<RegattaMetadataDTO> regattaMetadatas) {
|
||||
public static QuickfinderPresenter getForRegattaRaces(Quickfinder quickfinder,
|
||||
final RegattaRacesNavigationProvider navigator,
|
||||
Map<String, Set<RegattaMetadataDTO>> regattasByLeaderboardGroupName) {
|
||||
return new QuickfinderPresenter(quickfinder, MSG.racesQuickfinder(), new RegattaPlaceNaviationProvider() {
|
||||
@Override
|
||||
public PlaceNavigation<?> getPlaceNavigation(String regattaId) {
|
||||
return navigator.getRegattaRacesNavigation(regattaId);
|
||||
}
|
||||
}, regattaMetadatas);
|
||||
}, regattasByLeaderboardGroupName);
|
||||
}
|
||||
|
||||
public static QuickfinderPresenter getForRegattaOverview(Quickfinder quickfinder,
|
||||
final RegattaOverviewNavigationProvider navigator, Collection<RegattaMetadataDTO> regattaMetadatas) {
|
||||
public static QuickfinderPresenter getForRegattaOverview(Quickfinder quickfinder,
|
||||
final RegattaOverviewNavigationProvider navigator,
|
||||
Map<String, Set<RegattaMetadataDTO>> regattasByLeaderboardGroupName) {
|
||||
return new QuickfinderPresenter(quickfinder, MSG.regattaQuickfinder(), new RegattaPlaceNaviationProvider() {
|
||||
@Override
|
||||
public PlaceNavigation<?> getPlaceNavigation(String regattaId) {
|
||||
return navigator.getRegattaOverviewNavigation(regattaId);
|
||||
}
|
||||
}, regattaMetadatas);
|
||||
}, regattasByLeaderboardGroupName);
|
||||
}
|
||||
|
||||
public static QuickfinderPresenter getForSeriesLeaderboards(Quickfinder quickfinder, String seriesName,
|
||||
@@ -111,19 +115,17 @@ public class QuickfinderPresenter {
|
||||
}
|
||||
|
||||
private QuickfinderPresenter(Quickfinder quickfinder, String placeholder, RegattaPlaceNaviationProvider provider,
|
||||
Collection<RegattaMetadataDTO> regattaMetadatas) {
|
||||
if (regattaMetadatas == null) {
|
||||
Map<String, Set<RegattaMetadataDTO>> regattasByLeaderboardGroupName) {
|
||||
if (regattasByLeaderboardGroupName == null) {
|
||||
quickfinder.removeFromParent();
|
||||
return;
|
||||
}
|
||||
quickfinder.addPlaceholderItem(placeholder);
|
||||
for (RegattaMetadataDTO regattaMetadata : regattaMetadatas) {
|
||||
Iterable<String> leaderboardGroupNames = regattaMetadata.getLeaderboardGroupNames();
|
||||
if (leaderboardGroupNames == null || Util.isEmpty(leaderboardGroupNames)) {
|
||||
leaderboardGroupNames = Collections.singleton(MSG.regattas());
|
||||
}
|
||||
for (final String leaderboardGroupName : leaderboardGroupNames) {
|
||||
quickfinder.addItemToGroup(leaderboardGroupName, regattaMetadata.getDisplayName(), provider.getPlaceNavigation(regattaMetadata.getId()));
|
||||
for (Entry<String, Set<RegattaMetadataDTO>> entry : regattasByLeaderboardGroupName.entrySet()) {
|
||||
String leaderboardGroupName = entry.getKey() == null ? MSG.regattas() : entry.getKey();
|
||||
for (RegattaMetadataDTO regattaMetadata : entry.getValue()) {
|
||||
quickfinder.addItemToGroup(leaderboardGroupName, regattaMetadata.getDisplayName(),
|
||||
provider.getPlaceNavigation(regattaMetadata.getId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+25
-17
@@ -1,12 +1,12 @@
|
||||
package com.sap.sailing.gwt.home.mobile.places.event;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.google.gwt.activity.shared.AbstractActivity;
|
||||
@@ -44,7 +44,8 @@ import com.sap.sailing.gwt.home.shared.places.fakeseries.SeriesDefaultPlace;
|
||||
import com.sap.sailing.gwt.ui.client.EntryPointLinkFactory;
|
||||
import com.sap.sailing.gwt.ui.client.StringMessages;
|
||||
import com.sap.sailing.gwt.ui.client.refresh.ErrorAndBusyClientFactory;
|
||||
import com.sap.sailing.gwt.ui.shared.util.NullSafeComparableComparator;
|
||||
import com.sap.sse.common.Util;
|
||||
import com.sap.sse.common.util.NaturalComparator;
|
||||
|
||||
public abstract class AbstractEventActivity<PLACE extends AbstractEventPlace> extends AbstractActivity implements Presenter {
|
||||
private final MobileApplicationClientFactory clientFactory;
|
||||
@@ -85,7 +86,7 @@ public abstract class AbstractEventActivity<PLACE extends AbstractEventPlace> ex
|
||||
protected final void initQuickfinder(EventViewBase view, boolean showQuickfinder) {
|
||||
EventViewDTO event = eventDTO;
|
||||
if(showQuickfinder && event.getType() == EventType.MULTI_REGATTA) {
|
||||
view.setQuickFinderValues(getSortedQuickFinderValues());
|
||||
view.setQuickFinderValues(getRegattasByLeaderboardGroupName());
|
||||
} else if(showQuickfinder && event.getType() == EventType.SERIES_EVENT) {
|
||||
view.setQuickFinderValues(event.getSeriesName(), event.getEventsOfSeries());
|
||||
} else {
|
||||
@@ -93,19 +94,26 @@ public abstract class AbstractEventActivity<PLACE extends AbstractEventPlace> ex
|
||||
}
|
||||
}
|
||||
|
||||
private Collection<RegattaMetadataDTO> getSortedQuickFinderValues() {
|
||||
Collection<RegattaMetadataDTO> regattas = eventDTO.getRegattas();
|
||||
List<RegattaMetadataDTO> sortedRegattas = new ArrayList<RegattaMetadataDTO>(regattas);
|
||||
Collections.sort(sortedRegattas, new Comparator<RegattaMetadataDTO>() {
|
||||
private Comparator<String> leaderboardGroupNamesComparator = new NullSafeComparableComparator<String>();
|
||||
@Override
|
||||
public int compare(RegattaMetadataDTO o1, RegattaMetadataDTO o2) {
|
||||
int bootCategoryComparison = leaderboardGroupNamesComparator.compare(o1.getLeaderboardGroupNames().toString(),
|
||||
o2.getLeaderboardGroupNames().toString());
|
||||
return bootCategoryComparison == 0 ? o1.compareTo(o2) : bootCategoryComparison;
|
||||
private Map<String, Set<RegattaMetadataDTO>> getRegattasByLeaderboardGroupName() {
|
||||
Map<String, Set<RegattaMetadataDTO>> regattasByLeaderboardGroupName = new TreeMap<>(new NaturalComparator(false));
|
||||
for (RegattaMetadataDTO regatta : eventDTO.getRegattas()) {
|
||||
if (Util.isEmpty(regatta.getLeaderboardGroupNames())) {
|
||||
addRegattaToLeaderboardGroup(regattasByLeaderboardGroupName, null, regatta);
|
||||
}
|
||||
});
|
||||
return sortedRegattas;
|
||||
for (String leaderboardGroupName : regatta.getLeaderboardGroupNames()) {
|
||||
addRegattaToLeaderboardGroup(regattasByLeaderboardGroupName, leaderboardGroupName, regatta);
|
||||
}
|
||||
}
|
||||
return regattasByLeaderboardGroupName;
|
||||
}
|
||||
|
||||
private void addRegattaToLeaderboardGroup(Map<String, Set<RegattaMetadataDTO>> regattasByLeaderboardGroupName,
|
||||
String leaderboardGroupName, RegattaMetadataDTO regatta) {
|
||||
Set<RegattaMetadataDTO> regattasForLg = regattasByLeaderboardGroupName.get(leaderboardGroupName);
|
||||
if (regattasForLg == null) {
|
||||
regattasByLeaderboardGroupName.put(leaderboardGroupName, regattasForLg = new TreeSet<>());
|
||||
}
|
||||
regattasForLg.add(regatta);
|
||||
}
|
||||
|
||||
protected final void initMedia(final AbstractEventOverview view) {
|
||||
|
||||
+9
-7
@@ -1,6 +1,8 @@
|
||||
package com.sap.sailing.gwt.home.mobile.places.event;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
@@ -84,8 +86,8 @@ public abstract class AbstractEventView<P extends EventViewBase.Presenter> exten
|
||||
return currentPresenter.isMultiRegattaEvent();
|
||||
}
|
||||
|
||||
protected void setQuickFinderValues(Quickfinder quickfinder, Collection<RegattaMetadataDTO> regattaMetadatas) {
|
||||
QuickfinderPresenter.getForRegattaLeaderboards(quickfinder, currentPresenter, regattaMetadatas);
|
||||
protected void setQuickFinderValues(Quickfinder quickfinder, Map<String, Set<RegattaMetadataDTO>> regattasByLeaderboardGroupName) {
|
||||
QuickfinderPresenter.getForRegattaLeaderboards(quickfinder, currentPresenter, regattasByLeaderboardGroupName);
|
||||
}
|
||||
|
||||
protected void setQuickFinderValues(Quickfinder quickfinder, String seriesName, Collection<EventReferenceDTO> eventsOfSeries) {
|
||||
@@ -101,12 +103,12 @@ public abstract class AbstractEventView<P extends EventViewBase.Presenter> exten
|
||||
mobileSection.addHeader(header);
|
||||
container.add(mobileSection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setQuickFinderValues(Collection<RegattaMetadataDTO> regattaMetadatas) {
|
||||
setQuickFinderValues(layout.quickFinderUi, regattaMetadatas);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setQuickFinderValues(Map<String, Set<RegattaMetadataDTO>> regattasByLeaderboardGroupName) {
|
||||
setQuickFinderValues(layout.quickFinderUi, regattasByLeaderboardGroupName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setQuickFinderValues(String seriesName, Collection<EventReferenceDTO> eventsOfSeries) {
|
||||
setQuickFinderValues(layout.quickFinderUi, seriesName, eventsOfSeries);
|
||||
|
||||
+3
-1
@@ -1,6 +1,8 @@
|
||||
package com.sap.sailing.gwt.home.mobile.places.event;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.gwt.user.client.ui.IsWidget;
|
||||
import com.sap.sailing.gwt.home.communication.SailingDispatchSystem;
|
||||
@@ -21,7 +23,7 @@ import com.sap.sailing.gwt.ui.client.refresh.ErrorAndBusyClientFactory;
|
||||
|
||||
public interface EventViewBase extends IsWidget {
|
||||
|
||||
void setQuickFinderValues(Collection<RegattaMetadataDTO> regattaMetadatas);
|
||||
void setQuickFinderValues(Map<String, Set<RegattaMetadataDTO>> regattasByLeaderboardGroupName);
|
||||
|
||||
void setQuickFinderValues(String seriesName, Collection<EventReferenceDTO> eventsOfSeries);
|
||||
|
||||
|
||||
+4
-2
@@ -1,6 +1,8 @@
|
||||
package com.sap.sailing.gwt.home.mobile.places.event.overview.regatta;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.gwt.user.client.ui.FlowPanel;
|
||||
import com.google.gwt.user.client.ui.Panel;
|
||||
@@ -63,8 +65,8 @@ public class RegattaOverviewImpl extends AbstractEventOverview {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setQuickFinderValues(Quickfinder quickfinder, Collection<RegattaMetadataDTO> regattaMetadatas) {
|
||||
QuickfinderPresenter.getForRegattaOverview(quickfinder, currentPresenter, regattaMetadatas);
|
||||
protected void setQuickFinderValues(Quickfinder quickfinder, Map<String, Set<RegattaMetadataDTO>> regattasByLeaderboardGroupName) {
|
||||
QuickfinderPresenter.getForRegattaOverview(quickfinder, currentPresenter, regattasByLeaderboardGroupName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+4
-2
@@ -3,6 +3,8 @@ package com.sap.sailing.gwt.home.mobile.places.event.races;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.uibinder.client.UiBinder;
|
||||
@@ -44,8 +46,8 @@ public class RacesViewImpl extends AbstractEventView<RacesView.Presenter> implem
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setQuickFinderValues(Quickfinder quickfinder, Collection<RegattaMetadataDTO> regattaMetadatas) {
|
||||
QuickfinderPresenter.getForRegattaRaces(quickfinder, currentPresenter, regattaMetadatas);
|
||||
protected void setQuickFinderValues(Quickfinder quickfinder, Map<String, Set<RegattaMetadataDTO>> regattasByLeaderboardGroupName) {
|
||||
QuickfinderPresenter.getForRegattaRaces(quickfinder, currentPresenter, regattasByLeaderboardGroupName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user