diff options
Diffstat (limited to 'app/src/main/java/it/niedermann/owncloud/notes/shared/model/Capabilities.java')
-rw-r--r-- | app/src/main/java/it/niedermann/owncloud/notes/shared/model/Capabilities.java | 46 |
1 files changed, 31 insertions, 15 deletions
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/Capabilities.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/Capabilities.java index b182ca63..1c1bed3d 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/Capabilities.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/Capabilities.java @@ -1,7 +1,9 @@ package it.niedermann.owncloud.notes.shared.model; +import android.graphics.Color; import android.util.Log; +import androidx.annotation.ColorInt; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -11,10 +13,12 @@ import com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException; import org.json.JSONException; import org.json.JSONObject; +import it.niedermann.android.util.ColorUtil; + import static java.net.HttpURLConnection.HTTP_UNAVAILABLE; /** - * This entity class is used to return relevant data of the HTTP reponse. + * This entity class is used to return relevant data of the HTTP response. */ public class Capabilities { @@ -32,10 +36,13 @@ public class Capabilities { private static final String JSON_OCS_DATA_CAPABILITIES_THEMING_COLOR_TEXT = "color-text"; private String apiVersion = null; - private String color = null; - private String textColor = null; + + @ColorInt + private Integer color = -16743735; + @ColorInt + private Integer textColor = -16777216; @Nullable - private String eTag; + private final String eTag; public Capabilities(@NonNull String response, @Nullable String eTag) throws NextcloudHttpRequestFailedException { this.eTag = eTag; @@ -64,10 +71,18 @@ public class Capabilities { if (capabilities.has(JSON_OCS_DATA_CAPABILITIES_THEMING)) { final JSONObject theming = capabilities.getJSONObject(JSON_OCS_DATA_CAPABILITIES_THEMING); if (theming.has(JSON_OCS_DATA_CAPABILITIES_THEMING_COLOR)) { - this.color = theming.getString(JSON_OCS_DATA_CAPABILITIES_THEMING_COLOR); + try { + this.color = Color.parseColor(ColorUtil.INSTANCE.formatColorToParsableHexString(theming.getString(JSON_OCS_DATA_CAPABILITIES_THEMING_COLOR))); + } catch (Exception e) { + e.printStackTrace(); + } } if (theming.has(JSON_OCS_DATA_CAPABILITIES_THEMING_COLOR_TEXT)) { - this.textColor = theming.getString(JSON_OCS_DATA_CAPABILITIES_THEMING_COLOR_TEXT); + try { + this.textColor = Color.parseColor(ColorUtil.INSTANCE.formatColorToParsableHexString(theming.getString(JSON_OCS_DATA_CAPABILITIES_THEMING_COLOR_TEXT))); + } catch (Exception e) { + e.printStackTrace(); + } } } } @@ -81,17 +96,17 @@ public class Capabilities { return apiVersion; } - public String getColor() { - return color; + @Nullable + public String getETag() { + return eTag; } - public String getTextColor() { - return textColor; + public Integer getColor() { + return color; } - @Nullable - public String getETag() { - return eTag; + public Integer getTextColor() { + return textColor; } @NonNull @@ -99,8 +114,9 @@ public class Capabilities { public String toString() { return "Capabilities{" + "apiVersion='" + apiVersion + '\'' + - ", color='" + color + '\'' + - ", textColor='" + textColor + '\'' + + ", color=" + color + + ", textColor=" + textColor + + ", eTag='" + eTag + '\'' + '}'; } }
\ No newline at end of file |