Skip to content

Commit

Permalink
address #20
Browse files Browse the repository at this point in the history
  • Loading branch information
EudyContreras committed Feb 23, 2021
1 parent 38e53cf commit 5bb56ec
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

package com.eudycontreras.boneslibrary.bindings

import android.view.View
import android.view.ViewGroup
import androidx.annotation.ColorInt
import androidx.databinding.BindingAdapter
Expand All @@ -12,7 +11,6 @@ import com.eudycontreras.boneslibrary.extensions.descendantViews
import com.eudycontreras.boneslibrary.extensions.findParent
import com.eudycontreras.boneslibrary.extensions.generateId
import com.eudycontreras.boneslibrary.extensions.getProps
import com.eudycontreras.boneslibrary.framework.bones.BoneDrawable
import com.eudycontreras.boneslibrary.framework.bones.BoneProperties
import com.eudycontreras.boneslibrary.framework.skeletons.SkeletonDrawable
import com.eudycontreras.boneslibrary.framework.skeletons.SkeletonManager
Expand Down Expand Up @@ -443,4 +441,21 @@ fun ViewGroup.hasSkeletonLoaderAncestor(): Boolean {
*/
fun ViewGroup.isSkeletonLoader(): Boolean {
return this.foreground is SkeletonDrawable
}

/**
* Returns the SkeletonDrawable loader of this ViewGroup or null if it does not have one
*/
fun ViewGroup.getSkeletonDrawable(): SkeletonDrawable? {
return this.foreground as? SkeletonDrawable?
}

/**
* Returns the SkeletonDrawable loader of this ViewGroup
* @throws IllegalStateException when this view does not contain a SkeletonDrawable
*/
fun ViewGroup.requireSkeletonDrawable(): SkeletonDrawable {
return runCatching { this.foreground as SkeletonDrawable }.getOrElse {
throw IllegalStateException("This view does not contain a SkeletonDrawable")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.eudycontreras.boneslibrary.bindings

import android.graphics.drawable.Drawable
import android.view.View
import android.view.ViewGroup
import androidx.annotation.ColorInt
import androidx.annotation.Dimension
import androidx.databinding.BindingAdapter
Expand Down Expand Up @@ -731,4 +732,21 @@ fun View.hasSkeletonLoaderAncestor(): Boolean {
*/
fun View.isBoneLoader(): Boolean {
return this.foreground is BoneDrawable
}

/**
* Returns the BoneDrawable loader of this View or null if it does not have one
*/
fun View.getBoneDrawable(): BoneDrawable? {
return this.foreground as? BoneDrawable?
}

/**
* Returns the BoneDrawable loader of this ViewGroup
* @throws IllegalStateException when this view does not contain a BoneDrawable
*/
fun ViewGroup.requireBoneDrawable(): BoneDrawable {
return runCatching { this.foreground as BoneDrawable }.getOrElse {
throw IllegalStateException("This view does not contain a BoneDrawable")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import com.eudycontreras.boneslibrary.properties.ShapeType
* @see BoneProperties
*/

data class BoneBuilder internal constructor(
data class BoneBuilder(
internal val boneProperties: BoneProperties = BoneProperties()
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import com.eudycontreras.boneslibrary.properties.MutableColor
* @see ShimmerRayProperties
*/

data class ShimmerRayBuilder internal constructor(
private val shimmerRayProperties: ShimmerRayProperties
data class ShimmerRayBuilder(
private val shimmerRayProperties: ShimmerRayProperties = ShimmerRayProperties()
) {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import com.eudycontreras.boneslibrary.properties.MutableColor
*
*/

class ShimmerRayProperties internal constructor(): Cloneable<ShimmerRayProperties> {
class ShimmerRayProperties: Cloneable<ShimmerRayProperties> {

/**
* @Project Project Bones
Expand Down

0 comments on commit 5bb56ec

Please sign in to comment.