Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2015-10-02 10:10:34 +02:00
commit f5d8b8cda2
5 changed files with 59 additions and 55 deletions

View file

@ -14,6 +14,7 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set;
public class WorldRegion implements Serializable { public class WorldRegion implements Serializable {
@ -36,7 +37,7 @@ public class WorldRegion implements Serializable {
private LatLon bboxTopLeft; private LatLon bboxTopLeft;
private LatLon bboxBottomRight; private LatLon bboxBottomRight;
private List<DownloadActivityType> resourceTypes; private Set<DownloadActivityType> resourceTypes;
// Hierarchy // Hierarchy
private WorldRegion superregion; private WorldRegion superregion;
@ -66,11 +67,11 @@ public class WorldRegion implements Serializable {
return bboxBottomRight; return bboxBottomRight;
} }
public List<DownloadActivityType> getResourceTypes() { public Set<DownloadActivityType> getResourceTypes() {
return resourceTypes; return resourceTypes;
} }
public void setResourceTypes(List<DownloadActivityType> resourceTypes) { public void setResourceTypes(Set<DownloadActivityType> resourceTypes) {
this.resourceTypes = resourceTypes; this.resourceTypes = resourceTypes;
} }
@ -129,14 +130,16 @@ public class WorldRegion implements Serializable {
String downloadName = osmandRegions.getDownloadName(regionId); String downloadName = osmandRegions.getDownloadName(regionId);
if (downloadName != null) { if (downloadName != null) {
downloadsIdPrefix = downloadName.toLowerCase() + "."; downloadsIdPrefix = downloadName.toLowerCase() + ".";
if (name != null) {
this.name = name;
} else {
this.name = osmandRegions.getLocaleName(downloadName);
}
} else { } else {
this.downloadsIdPrefix = regionId.toLowerCase() + "."; this.downloadsIdPrefix = regionId.toLowerCase() + ".";
}
if (name != null) {
this.name = name; this.name = name;
} else {
this.name = osmandRegions.getLocaleNameByFullName(regionId);
if (this.name == null) {
this.name = capitalize(regionId.replace('_', ' '));
}
} }
return this; return this;
} }
@ -146,10 +149,12 @@ public class WorldRegion implements Serializable {
String downloadName = osmandRegions.getDownloadName(regionId); String downloadName = osmandRegions.getDownloadName(regionId);
if (downloadName != null) { if (downloadName != null) {
downloadsIdPrefix = downloadName.toLowerCase() + "."; downloadsIdPrefix = downloadName.toLowerCase() + ".";
this.name = osmandRegions.getLocaleName(downloadName);
} else { } else {
this.downloadsIdPrefix = regionId.toLowerCase() + "."; this.downloadsIdPrefix = regionId.toLowerCase() + ".";
this.name = regionId; }
this.name = osmandRegions.getLocaleNameByFullName(regionId);
if (this.name == null) {
this.name = capitalize(regionId.replace('_', ' '));
} }
return this; return this;
} }
@ -281,4 +286,19 @@ public class WorldRegion implements Serializable {
} }
return worldRegion; return worldRegion;
} }
private String capitalize(String s) {
String[] words = s.split(" ");
if (words[0].length() > 0) {
StringBuilder sb = new StringBuilder();
sb.append(Character.toUpperCase(words[0].charAt(0))).append(words[0].subSequence(1, words[0].length()).toString().toLowerCase());
for (int i = 1; i < words.length; i++) {
sb.append(" ");
sb.append(Character.toUpperCase(words[i].charAt(0))).append(words[i].subSequence(1, words[i].length()).toString().toLowerCase());
}
return sb.toString();
} else {
return s;
}
}
} }

View file

@ -9,7 +9,6 @@ import net.osmand.plus.WorldRegion;
import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.IndexItem; import net.osmand.plus.download.IndexItem;
import net.osmand.plus.mapcontextmenu.editors.PointEditor;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import java.util.Collections; import java.util.Collections;
@ -18,6 +17,8 @@ import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
@ -235,8 +236,12 @@ public class ItemsListBuilder {
} }
if (doInit) { if (doInit) {
List<DownloadActivityType> typesArray = new LinkedList<>(); Set<DownloadActivityType> typesSet = new TreeSet<>(new Comparator<DownloadActivityType>() {
boolean hasSrtm = false; @Override
public int compare(DownloadActivityType dat1, DownloadActivityType dat2) {
return dat1.getTag().compareTo(dat2.getTag());
}
});
for (IndexItem resource : resourcesInRepository) { for (IndexItem resource : resourcesInRepository) {
@ -244,36 +249,20 @@ public class ItemsListBuilder {
continue; continue;
} }
if (resource.getType() == DownloadActivityType.SRTM_COUNTRY_FILE) { typesSet.add(resource.getType());
hasSrtm = true;
}
typesArray.add(resource.getType());
regionResources.put(resource.getSimplifiedFileName(), resource); regionResources.put(resource.getSimplifiedFileName(), resource);
} }
if (region.getSuperregion() != null && hasSrtm && region.getSuperregion().getSuperregion() != app.getWorldRegion()) { if (region.getSuperregion() != null && region.getSuperregion().getSuperregion() != app.getWorldRegion()) {
if (!region.getSuperregion().getResourceTypes().contains(DownloadActivityType.SRTM_COUNTRY_FILE)) { if (region.getSuperregion().getResourceTypes() == null) {
region.getSuperregion().getResourceTypes().add(DownloadActivityType.SRTM_COUNTRY_FILE); region.getSuperregion().setResourceTypes(typesSet);
Collections.sort(region.getSuperregion().getResourceTypes(), new Comparator<DownloadActivityType>() { } else {
@Override region.getSuperregion().getResourceTypes().addAll(typesSet);
public int compare(DownloadActivityType dat1, DownloadActivityType dat2) {
return dat1.getTag().compareTo(dat2.getTag());
}
});
} }
} }
Collections.sort(typesArray, new Comparator<DownloadActivityType>() { region.setResourceTypes(typesSet);
@Override
public int compare(DownloadActivityType dat1, DownloadActivityType dat2) {
return dat1.getTag().compareTo(dat2.getTag());
}
});
region.setResourceTypes(typesArray);
} }
resourcesByRegions.put(region, regionResources); resourcesByRegions.put(region, regionResources);
} }
return true; return true;

View file

@ -15,9 +15,9 @@ import net.osmand.plus.WorldRegion;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
public class LocalDialogFragment extends DialogFragment { public class RegionDialogFragment extends DialogFragment {
private static final Log LOG = PlatformUtil.getLog(LocalDialogFragment.class); private static final Log LOG = PlatformUtil.getLog(RegionDialogFragment.class);
public static final String TAG = "LocalDialogFragment"; public static final String TAG = "RegionDialogFragment";
private static final String REGION_DLG_KEY = "world_region_dialog_key"; private static final String REGION_DLG_KEY = "world_region_dialog_key";
private WorldRegion region; private WorldRegion region;
@ -62,7 +62,7 @@ public class LocalDialogFragment extends DialogFragment {
if (this.region != null) { if (this.region != null) {
getChildFragmentManager().beginTransaction().add(R.id.fragmentContainer, getChildFragmentManager().beginTransaction().add(R.id.fragmentContainer,
LocalItemsFragment.createInstance(region)).commit(); RegionItemsFragment.createInstance(region)).commit();
toolbar.setTitle(this.region.getName()); toolbar.setTitle(this.region.getName());
} }
@ -83,10 +83,10 @@ public class LocalDialogFragment extends DialogFragment {
createInstance(region).show(getChildFragmentManager(), TAG); createInstance(region).show(getChildFragmentManager(), TAG);
} }
public static LocalDialogFragment createInstance(WorldRegion region) { public static RegionDialogFragment createInstance(WorldRegion region) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putSerializable(REGION_DLG_KEY, region); bundle.putSerializable(REGION_DLG_KEY, region);
LocalDialogFragment fragment = new LocalDialogFragment(); RegionDialogFragment fragment = new RegionDialogFragment();
fragment.setArguments(bundle); fragment.setArguments(bundle);
return fragment; return fragment;
} }

View file

@ -9,29 +9,24 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter; import android.widget.ListAdapter;
import android.widget.ListView; import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.WorldRegion; import net.osmand.plus.WorldRegion;
import net.osmand.plus.download.BaseDownloadActivity;
import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.IndexItem;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.Locale; import java.util.Locale;
public class LocalItemsFragment extends Fragment { public class RegionItemsFragment extends Fragment {
public static final String TAG = "LocalItemsFragment"; public static final String TAG = "RegionItemsFragment";
private static final Log LOG = PlatformUtil.getLog(LocalItemsFragment.class); private static final Log LOG = PlatformUtil.getLog(RegionItemsFragment.class);
private static final MessageFormat formatGb = new MessageFormat("{0, number,<b>#.##</b>} GB", Locale.US); private static final MessageFormat formatGb = new MessageFormat("{0, number,<b>#.##</b>} GB", Locale.US);
private ItemsListBuilder builder; private ItemsListBuilder builder;
@ -95,7 +90,7 @@ public class LocalItemsFragment extends Fragment {
Object obj = regionsAdapter.getItem(position); Object obj = regionsAdapter.getItem(position);
if (obj instanceof WorldRegion) { if (obj instanceof WorldRegion) {
WorldRegion region = (WorldRegion) obj; WorldRegion region = (WorldRegion) obj;
((LocalDialogFragment) getParentFragment()) ((RegionDialogFragment) getParentFragment())
.onRegionSelected(region); .onRegionSelected(region);
} }
} }
@ -185,10 +180,10 @@ public class LocalItemsFragment extends Fragment {
return (DownloadActivity) getActivity(); return (DownloadActivity) getActivity();
} }
public static LocalItemsFragment createInstance(WorldRegion region) { public static RegionItemsFragment createInstance(WorldRegion region) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putSerializable(REGION_KEY, region); bundle.putSerializable(REGION_KEY, region);
LocalItemsFragment fragment = new LocalItemsFragment(); RegionItemsFragment fragment = new RegionItemsFragment();
fragment.setArguments(bundle); fragment.setArguments(bundle);
return fragment; return fragment;
} }

View file

@ -69,8 +69,8 @@ public class WorldItemsFragment extends Fragment {
FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction(); FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction();
fragmentTransaction.addToBackStack(null); fragmentTransaction.addToBackStack(null);
LocalDialogFragment.createInstance(region) RegionDialogFragment.createInstance(region)
.show(fragmentTransaction, LocalDialogFragment.TAG); .show(fragmentTransaction, RegionDialogFragment.TAG);
} }
}); });