Add support for header color
This commit is contained in:
parent
e8bd532cd3
commit
cc661a567a
3 changed files with 31 additions and 4 deletions
|
@ -32,6 +32,8 @@ import java.util.Map;
|
|||
|
||||
public class CustomRegion extends WorldRegion {
|
||||
|
||||
public static final int INVALID_ID = -1;
|
||||
|
||||
private static final Log LOG = PlatformUtil.getLog(CustomRegion.class);
|
||||
|
||||
private String scopeId;
|
||||
|
@ -51,7 +53,7 @@ public class CustomRegion extends WorldRegion {
|
|||
private Map<String, String> icons = new HashMap<>();
|
||||
private Map<String, String> headers = new HashMap<>();
|
||||
|
||||
private int headerColor = -1;
|
||||
private int headerColor = INVALID_ID;
|
||||
|
||||
|
||||
private CustomRegion(String scopeId, String path, String type) {
|
||||
|
@ -75,6 +77,11 @@ public class CustomRegion extends WorldRegion {
|
|||
|
||||
@ColorInt
|
||||
public int getHeaderColor() {
|
||||
if (headerColor != INVALID_ID) {
|
||||
return headerColor;
|
||||
} else if (superregion instanceof CustomRegion) {
|
||||
return ((CustomRegion) superregion).getHeaderColor();
|
||||
}
|
||||
return headerColor;
|
||||
}
|
||||
|
||||
|
@ -121,9 +128,9 @@ public class CustomRegion extends WorldRegion {
|
|||
|
||||
String headerColor = object.optString("header-color", null);
|
||||
try {
|
||||
region.headerColor = Algorithms.isEmpty(headerColor) ? 0 : Algorithms.parseColor(headerColor);
|
||||
region.headerColor = Algorithms.isEmpty(headerColor) ? INVALID_ID : Algorithms.parseColor(headerColor);
|
||||
} catch (IllegalArgumentException e) {
|
||||
region.headerColor = 0;
|
||||
region.headerColor = INVALID_ID;
|
||||
}
|
||||
region.descriptionInfo = DownloadDescriptionInfo.fromJson(object.optJSONObject("description"));
|
||||
|
||||
|
@ -142,6 +149,9 @@ public class CustomRegion extends WorldRegion {
|
|||
JsonUtils.writeLocalizedMapToJson("icon", jsonObject, icons);
|
||||
JsonUtils.writeLocalizedMapToJson("header", jsonObject, headers);
|
||||
|
||||
if (headerColor != INVALID_ID) {
|
||||
jsonObject.putOpt("header-color", Algorithms.colorToString(headerColor));
|
||||
}
|
||||
if (descriptionInfo != null) {
|
||||
jsonObject.putOpt("description", descriptionInfo.toJson());
|
||||
}
|
||||
|
@ -264,7 +274,7 @@ public class CustomRegion extends WorldRegion {
|
|||
if (value instanceof String) {
|
||||
String key = (String) value;
|
||||
int index = key.indexOf("@");
|
||||
if (index != -1) {
|
||||
if (index != INVALID_ID) {
|
||||
key = key.substring(index + 1);
|
||||
}
|
||||
return json.opt(key);
|
||||
|
|
|
@ -19,6 +19,8 @@ import androidx.fragment.app.DialogFragment;
|
|||
import androidx.viewpager.widget.ViewPager;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.map.WorldRegion;
|
||||
import net.osmand.plus.CustomRegion;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
|
@ -161,6 +163,13 @@ public class DownloadItemFragment extends DialogFragment implements DownloadEven
|
|||
updateActionButtons(activity, descriptionInfo, indexItem, buttonsContainer, R.layout.bottom_buttons, nightMode);
|
||||
}
|
||||
}
|
||||
WorldRegion region = group.getParentGroup().getRegion();
|
||||
if (region instanceof CustomRegion) {
|
||||
int headerColor = ((CustomRegion) region).getHeaderColor();
|
||||
if (headerColor != CustomRegion.INVALID_ID) {
|
||||
toolbar.setBackgroundColor(headerColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void updateActionButtons(final DownloadActivity ctx, DownloadDescriptionInfo descriptionInfo,
|
||||
|
|
|
@ -26,6 +26,7 @@ import androidx.fragment.app.DialogFragment;
|
|||
|
||||
import net.osmand.AndroidNetworkUtils;
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.map.WorldRegion;
|
||||
import net.osmand.plus.CustomRegion;
|
||||
import net.osmand.plus.LockableViewPager;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
|
@ -431,6 +432,13 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow
|
|||
if (group != null) {
|
||||
listAdapter.update(group);
|
||||
toolbar.setTitle(group.getName(activity));
|
||||
WorldRegion region = group.getRegion();
|
||||
if (region instanceof CustomRegion) {
|
||||
int headerColor = ((CustomRegion) region).getHeaderColor();
|
||||
if (headerColor != CustomRegion.INVALID_ID) {
|
||||
toolbar.setBackgroundColor(headerColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
expandAllGroups();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue