Fix custom regions icon color
This commit is contained in:
parent
cc661a567a
commit
81125cca8d
2 changed files with 30 additions and 19 deletions
|
@ -45,6 +45,7 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -368,7 +369,7 @@ public class CustomOsmandPlugin extends OsmandPlugin {
|
|||
|
||||
public static List<CustomRegion> collectRegionsFromJson(@NonNull Context ctx, JSONArray jsonArray) throws JSONException {
|
||||
List<CustomRegion> customRegions = new ArrayList<>();
|
||||
Map<String, CustomRegion> flatRegions = new HashMap<>();
|
||||
Map<String, CustomRegion> flatRegions = new LinkedHashMap<>();
|
||||
for (int i = 0; i < jsonArray.length(); i++) {
|
||||
JSONObject regionJson = jsonArray.getJSONObject(i);
|
||||
CustomRegion region = CustomRegion.fromJson(ctx, regionJson);
|
||||
|
|
|
@ -4,6 +4,8 @@ import android.graphics.drawable.Drawable;
|
|||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.DrawableRes;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.plus.CustomRegion;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
|
@ -45,35 +47,43 @@ public class DownloadGroupViewHolder {
|
|||
String iconName = ((CustomRegion) group.getRegion()).getIconName(ctx);
|
||||
int iconId = AndroidUtils.getDrawableId(app, iconName);
|
||||
if (iconId != 0) {
|
||||
return cache.getThemedIcon(iconId);
|
||||
iconStart = getIconForDownloadedItems(group, iconId);
|
||||
return iconStart != null ? iconStart : cache.getThemedIcon(iconId);
|
||||
}
|
||||
}
|
||||
if (isParentWorld(group) || isParentWorld(group.getParentGroup())) {
|
||||
iconStart = cache.getThemedIcon(R.drawable.ic_world_globe_dark);
|
||||
} else {
|
||||
DownloadResourceGroup ggr = group.getSubGroupById(DownloadResourceGroupType.REGION_MAPS.getDefaultId());
|
||||
iconStart = cache.getThemedIcon(R.drawable.ic_map);
|
||||
if (ggr != null && ggr.getIndividualResources() != null) {
|
||||
IndexItem item = null;
|
||||
for (IndexItem ii : ggr.getIndividualResources()) {
|
||||
if (ii.getType() == DownloadActivityType.NORMAL_FILE
|
||||
|| ii.getType() == DownloadActivityType.ROADS_FILE) {
|
||||
if (ii.isDownloaded() || ii.isOutdated()) {
|
||||
item = ii;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (item != null) {
|
||||
int color = item.isOutdated() ? R.color.color_distance : R.color.color_ok;
|
||||
iconStart = cache.getIcon(R.drawable.ic_map, color);
|
||||
}
|
||||
iconStart = getIconForDownloadedItems(group, R.drawable.ic_map);
|
||||
if (iconStart == null) {
|
||||
iconStart = cache.getThemedIcon(R.drawable.ic_map);
|
||||
}
|
||||
}
|
||||
}
|
||||
return iconStart;
|
||||
}
|
||||
|
||||
private Drawable getIconForDownloadedItems(DownloadResourceGroup group, @DrawableRes int iconId) {
|
||||
DownloadResourceGroup ggr = group.getSubGroupById(DownloadResourceGroupType.REGION_MAPS.getDefaultId());
|
||||
if (ggr != null && ggr.getIndividualResources() != null) {
|
||||
IndexItem item = null;
|
||||
for (IndexItem ii : ggr.getIndividualResources()) {
|
||||
if (ii.getType() == DownloadActivityType.NORMAL_FILE
|
||||
|| ii.getType() == DownloadActivityType.ROADS_FILE) {
|
||||
if (ii.isDownloaded() || ii.isOutdated()) {
|
||||
item = ii;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (item != null) {
|
||||
int color = item.isOutdated() ? R.color.color_distance : R.color.color_ok;
|
||||
return ctx.getMyApplication().getUIUtilities().getIcon(iconId, color);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void bindItem(DownloadResourceGroup group) {
|
||||
String name = group.getName(ctx);
|
||||
textView.setText(name);
|
||||
|
|
Loading…
Reference in a new issue