Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add docs and annotations for colors #16

Merged
merged 2 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/src/main/java/com/shopify/checkoutkit/CheckoutDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import android.view.WindowManager
import android.widget.FrameLayout
import android.widget.ProgressBar
import androidx.activity.ComponentActivity
import androidx.annotation.ColorInt
import androidx.appcompat.widget.Toolbar
import androidx.core.content.ContextCompat.getColor

Expand Down Expand Up @@ -132,15 +133,19 @@ internal class CheckoutDialog(
findViewById<CheckoutWebViewContainer>(R.id.checkoutSdkContainer).visibility = VISIBLE
}

@ColorInt
private fun ColorScheme.headerBackgroundColor() =
this.headerBackgroundColor(context.isDarkTheme()).getValue(context)

@ColorInt
private fun ColorScheme.webViewBackgroundColor() =
this.webViewBackgroundColor(context.isDarkTheme()).getValue(context)

@ColorInt
private fun ColorScheme.headerFontColor() =
this.headerFontColor(context.isDarkTheme()).getValue(context)

@ColorInt
private fun ColorScheme.loadingSpinnerColor() =
this.loadingSpinnerColor(context.isDarkTheme()).getValue(context)

Expand Down
22 changes: 21 additions & 1 deletion lib/src/main/java/com/shopify/checkoutkit/ColorScheme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
package com.shopify.checkoutkit

import android.content.Context
import androidx.annotation.ColorInt
import androidx.annotation.ColorRes
import androidx.core.content.ContextCompat.getColor
import kotlinx.serialization.Serializable

Expand Down Expand Up @@ -110,13 +112,31 @@ public data class Colors(
val spinnerColor: Color,
)

/**
* Represents a color which can be either a resource id or an sRGB value.
*/
@Serializable
public sealed class Color {
/**
* Represents a color in sRGB color space.
* @property sRGB The sRGB value of the color.
*/
@Serializable
public data class SRGB(public val sRGB: Int): Color()

/**
* Represents a color as a resource id (e.g. {@code android.R.color.black}).
* @property id The resource id of the color.
*/
@Serializable
public data class ResourceId(public val id: Int): Color()
public data class ResourceId(@ColorRes public val id: Int): Color()

/**
* Returns the color value.
* @param context The context to use when retrieving the color.
* @return The color value.
*/
@ColorInt
public fun getValue(context: Context): Int = when (this) {
is ResourceId -> getColor(context, this.id)
is SRGB -> this.sRGB
Expand Down