Fix lang sorting (wiki dialog)
This commit is contained in:
parent
ea15865333
commit
4b62beaeb3
2 changed files with 36 additions and 11 deletions
|
@ -24,8 +24,13 @@ import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static android.util.TypedValue.COMPLEX_UNIT_DIP;
|
import static android.util.TypedValue.COMPLEX_UNIT_DIP;
|
||||||
|
|
||||||
|
@ -196,4 +201,19 @@ public class AndroidUtils {
|
||||||
}
|
}
|
||||||
return new PointF(centroidX, centroidY);
|
return new PointF(centroidX, centroidY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map) {
|
||||||
|
List<Map.Entry<K, V>> list = new LinkedList<>(map.entrySet());
|
||||||
|
Collections.sort(list, new Comparator<Map.Entry<K, V>>() {
|
||||||
|
public int compare(Map.Entry<K, V> o1, Map.Entry<K, V> o2) {
|
||||||
|
return (o1.getValue()).compareTo(o2.getValue());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Map<K, V> result = new LinkedHashMap<>();
|
||||||
|
for (Map.Entry<K, V> entry : list) {
|
||||||
|
result.put(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,8 @@ import android.widget.LinearLayout;
|
||||||
import android.widget.LinearLayout.LayoutParams;
|
import android.widget.LinearLayout.LayoutParams;
|
||||||
import android.widget.ScrollView;
|
import android.widget.ScrollView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.ResultMatcher;
|
import net.osmand.ResultMatcher;
|
||||||
import net.osmand.ValueHolder;
|
import net.osmand.ValueHolder;
|
||||||
|
@ -43,16 +45,12 @@ import net.osmand.data.QuadRect;
|
||||||
import net.osmand.data.QuadTree;
|
import net.osmand.data.QuadTree;
|
||||||
import net.osmand.data.RotatedTileBox;
|
import net.osmand.data.RotatedTileBox;
|
||||||
import net.osmand.osm.PoiType;
|
import net.osmand.osm.PoiType;
|
||||||
import net.osmand.plus.OsmAndFormatter;
|
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.OsmandSettings;
|
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.helpers.FileNameTranslationHelper;
|
import net.osmand.plus.helpers.FileNameTranslationHelper;
|
||||||
import net.osmand.plus.poi.PoiFiltersHelper;
|
|
||||||
import net.osmand.plus.poi.PoiUIFilter;
|
import net.osmand.plus.poi.PoiUIFilter;
|
||||||
import net.osmand.plus.render.RenderingIcons;
|
import net.osmand.plus.render.RenderingIcons;
|
||||||
import net.osmand.plus.resources.ResourceManager;
|
|
||||||
import net.osmand.plus.routing.RoutingHelper;
|
import net.osmand.plus.routing.RoutingHelper;
|
||||||
import net.osmand.plus.routing.RoutingHelper.IRouteInformationListener;
|
import net.osmand.plus.routing.RoutingHelper.IRouteInformationListener;
|
||||||
import net.osmand.plus.views.MapTextLayer.MapTextProvider;
|
import net.osmand.plus.views.MapTextLayer.MapTextProvider;
|
||||||
|
@ -61,7 +59,9 @@ import net.osmand.util.Algorithms;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
|
@ -451,18 +451,23 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
|
||||||
protected static void showPopupLangMenu(final Context ctx, Toolbar tb,
|
protected static void showPopupLangMenu(final Context ctx, Toolbar tb,
|
||||||
final OsmandApplication app, final Amenity a, final Dialog dialog) {
|
final OsmandApplication app, final Amenity a, final Dialog dialog) {
|
||||||
final PopupMenu optionsMenu = new PopupMenu(ctx, tb, Gravity.RIGHT);
|
final PopupMenu optionsMenu = new PopupMenu(ctx, tb, Gravity.RIGHT);
|
||||||
Set<String> names = new TreeSet<>();
|
Set<String> namesSet = new TreeSet<>();
|
||||||
names.addAll(a.getNames("content", "en"));
|
namesSet.addAll(a.getNames("content", "en"));
|
||||||
names.addAll(a.getNames("description", "en"));
|
namesSet.addAll(a.getNames("description", "en"));
|
||||||
|
|
||||||
for (final String n : names) {
|
Map<String, String> names = new HashMap<>();
|
||||||
String vn = FileNameTranslationHelper.getVoiceName(ctx, n);
|
for (String n : namesSet) {
|
||||||
MenuItem item = optionsMenu.getMenu().add(vn);
|
names.put(n, FileNameTranslationHelper.getVoiceName(ctx, n));
|
||||||
|
}
|
||||||
|
Map<String, String> sortedNames = AndroidUtils.sortByValue(names);
|
||||||
|
|
||||||
|
for (final Map.Entry<String, String> e : sortedNames.entrySet()) {
|
||||||
|
MenuItem item = optionsMenu.getMenu().add(e.getValue());
|
||||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
showWiki(ctx, app, a, n);
|
showWiki(ctx, app, a, e.getKey());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue