Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2015-10-07 21:10:51 +02:00
commit 77a7033df0
4 changed files with 48 additions and 5 deletions

View file

@ -6,7 +6,6 @@ import net.osmand.PlatformUtil;
import net.osmand.map.OsmandRegions;
import net.osmand.plus.download.DownloadActivityType;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
@ -15,7 +14,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
public class WorldRegion implements Serializable {
public class WorldRegion {
public static final String AFRICA_REGION_ID = "africa";
public static final String ASIA_REGION_ID = "asia";

View file

@ -17,6 +17,7 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.WorldRegion;
import net.osmand.plus.activities.ActionBarProgressActivity;
import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.download.items.ItemsListBuilder;
@ -130,6 +131,14 @@ public class BaseDownloadActivity extends ActionBarProgressActivity {
}
}
public Map<String, IndexItem> getIndexItemsByRegion(WorldRegion region) {
if (downloadListIndexThread.isDataPrepared()) {
return downloadListIndexThread.getResourcesByRegions().get(region);
} else {
return null;
}
}
public boolean startDownload(IndexItem item) {
if (downloadListIndexThread.getCurrentRunningTask() != null && getEntriesToDownload().get(item) == null) {
downloadQueue.add(item);

View file

@ -61,6 +61,17 @@ public class SearchDialogFragment extends DialogFragment {
search.setLayoutParams(params);
toolbar.addView(search);
search.setOnCloseListener(new SearchView.OnCloseListener() {
@Override
public boolean onClose() {
if (search.getQuery().length() == 0) {
dismiss();
return true;
}
return false;
}
});
search.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {

View file

@ -35,6 +35,7 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
public class SearchItemsFragment extends Fragment {
@ -268,22 +269,45 @@ public class SearchItemsFragment extends Fragment {
conds.add(cond);
}
}
List<Object> filter = new ArrayList<>();
Context c = getDownloadActivity();
List<Object> filter = new ArrayList<>();
List<WorldRegion> regions = new ArrayList<>();
for (WorldRegion region : worldRegions) {
String indexLC = region.getName().toLowerCase();
if (isMatch(conds, false, indexLC)) {
filter.add(region);
regions.add(region);
}
}
for (WorldRegion region : regions) {
Map<String, IndexItem> indexItems = getDownloadActivity().getIndexItemsByRegion(region);
List<IndexItem> items = new LinkedList<>();
if (region.getSubregions().size() > 0) {
filter.add(region);
}
for (IndexItem item : indexItems.values()) {
items.add(item);
}
if (items.size() > 1) {
if (!filter.contains(region)) {
filter.add(region);
}
} else {
filter.addAll(items);
}
}
/*
Context c = getDownloadActivity();
for (IndexItem item : indexItems) {
String indexLC = item.getVisibleName(c, osmandRegions).toLowerCase();
if (isMatch(conds, false, indexLC)) {
filter.add(item);
}
}
*/
final Collator collator = OsmAndCollator.primaryCollator();
Collections.sort(filter, new Comparator<Object>() {