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.Map;
import java.util.Map.Entry;
import java.util.Set;
public class WorldRegion implements Serializable {
@ -36,7 +37,7 @@ public class WorldRegion implements Serializable {
private LatLon bboxTopLeft;
private LatLon bboxBottomRight;
private List<DownloadActivityType> resourceTypes;
private Set<DownloadActivityType> resourceTypes;
// Hierarchy
private WorldRegion superregion;
@ -66,11 +67,11 @@ public class WorldRegion implements Serializable {
return bboxBottomRight;
}
public List<DownloadActivityType> getResourceTypes() {
public Set<DownloadActivityType> getResourceTypes() {
return resourceTypes;
}
public void setResourceTypes(List<DownloadActivityType> resourceTypes) {
public void setResourceTypes(Set<DownloadActivityType> resourceTypes) {
this.resourceTypes = resourceTypes;
}
@ -129,14 +130,16 @@ public class WorldRegion implements Serializable {
String downloadName = osmandRegions.getDownloadName(regionId);
if (downloadName != null) {
downloadsIdPrefix = downloadName.toLowerCase() + ".";
if (name != null) {
this.name = name;
} else {
this.name = osmandRegions.getLocaleName(downloadName);
}
} else {
this.downloadsIdPrefix = regionId.toLowerCase() + ".";
}
if (name != null) {
this.name = name;
} else {
this.name = osmandRegions.getLocaleNameByFullName(regionId);
if (this.name == null) {
this.name = capitalize(regionId.replace('_', ' '));
}
}
return this;
}
@ -146,10 +149,12 @@ public class WorldRegion implements Serializable {
String downloadName = osmandRegions.getDownloadName(regionId);
if (downloadName != null) {
downloadsIdPrefix = downloadName.toLowerCase() + ".";
this.name = osmandRegions.getLocaleName(downloadName);
} else {
this.downloadsIdPrefix = regionId.toLowerCase() + ".";
this.name = regionId;
}
this.name = osmandRegions.getLocaleNameByFullName(regionId);
if (this.name == null) {
this.name = capitalize(regionId.replace('_', ' '));
}
return this;
}
@ -281,4 +286,19 @@ public class WorldRegion implements Serializable {
}
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.DownloadActivityType;
import net.osmand.plus.download.IndexItem;
import net.osmand.plus.mapcontextmenu.editors.PointEditor;
import net.osmand.util.Algorithms;
import java.util.Collections;
@ -18,6 +17,8 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
@ -235,8 +236,12 @@ public class ItemsListBuilder {
}
if (doInit) {
List<DownloadActivityType> typesArray = new LinkedList<>();
boolean hasSrtm = false;
Set<DownloadActivityType> typesSet = new TreeSet<>(new Comparator<DownloadActivityType>() {
@Override
public int compare(DownloadActivityType dat1, DownloadActivityType dat2) {
return dat1.getTag().compareTo(dat2.getTag());
}
});
for (IndexItem resource : resourcesInRepository) {
@ -244,36 +249,20 @@ public class ItemsListBuilder {
continue;
}
if (resource.getType() == DownloadActivityType.SRTM_COUNTRY_FILE) {
hasSrtm = true;
}
typesArray.add(resource.getType());
typesSet.add(resource.getType());
regionResources.put(resource.getSimplifiedFileName(), resource);
}
if (region.getSuperregion() != null && hasSrtm && region.getSuperregion().getSuperregion() != app.getWorldRegion()) {
if (!region.getSuperregion().getResourceTypes().contains(DownloadActivityType.SRTM_COUNTRY_FILE)) {
region.getSuperregion().getResourceTypes().add(DownloadActivityType.SRTM_COUNTRY_FILE);
Collections.sort(region.getSuperregion().getResourceTypes(), new Comparator<DownloadActivityType>() {
@Override
public int compare(DownloadActivityType dat1, DownloadActivityType dat2) {
return dat1.getTag().compareTo(dat2.getTag());
}
});
if (region.getSuperregion() != null && region.getSuperregion().getSuperregion() != app.getWorldRegion()) {
if (region.getSuperregion().getResourceTypes() == null) {
region.getSuperregion().setResourceTypes(typesSet);
} else {
region.getSuperregion().getResourceTypes().addAll(typesSet);
}
}
Collections.sort(typesArray, new Comparator<DownloadActivityType>() {
@Override
public int compare(DownloadActivityType dat1, DownloadActivityType dat2) {
return dat1.getTag().compareTo(dat2.getTag());
}
});
region.setResourceTypes(typesArray);
region.setResourceTypes(typesSet);
}
resourcesByRegions.put(region, regionResources);
}
return true;

View file

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

View file

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

View file

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