Skip to content

Commit

Permalink
Merge pull request #24 from EudyContreras/development
Browse files Browse the repository at this point in the history
introduces new apis and extensions for more convenience and ease of use
  • Loading branch information
EudyContreras committed Mar 7, 2021
2 parents 7f43cc4 + e536573 commit c9ebafb
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import android.os.Build
import android.view.View
import android.view.View.NO_ID
import android.view.ViewGroup
import android.widget.ImageView
import androidx.core.view.*
import com.eudycontreras.boneslibrary.bindings.addBoneLoader
import com.eudycontreras.boneslibrary.bindings.addSkeletonLoader
import com.eudycontreras.boneslibrary.bindings.getParentSkeletonDrawable
import com.eudycontreras.boneslibrary.doWith
import com.eudycontreras.boneslibrary.framework.bones.BoneDrawable
Expand Down Expand Up @@ -229,7 +230,7 @@ private fun findViews(
* @author Eudy Contreras
* @since Feburary 2021
*
* Disables skeleton loading for this view and its descendants
* Enables skeleton loading for this view and its descendants
*/
fun View.enableSkeletonLoading() = this.toggleSkeletonLoading(true)

Expand All @@ -238,29 +239,88 @@ fun View.enableSkeletonLoading() = this.toggleSkeletonLoading(true)
* @author Eudy Contreras
* @since Feburary 2021
*
* Enables skeleton loading for this view and its descendants
* Disables skeleton loading for this view and its descendants
*/
fun View.disableSkeletonLoading() = this.toggleSkeletonLoading(false)

/**
* @Project Project Bones
* @author Eudy Contreras
* @since Feburary 2021
*
* Enables skeleton loading for this view and its descendants
*/
fun ViewGroup.enableSkeletonLoading() = this.toggleSkeletonLoading(true)

/**
* @Project Project Bones
* @author Eudy Contreras
* @since Feburary 2021
*
* Disables skeleton loading for this view and its descendants
*/
fun ViewGroup.disableSkeletonLoading() = this.toggleSkeletonLoading(false)

/**
* @Project Project Bones
* @author Eudy Contreras
* @since Feburary 2021
*
* Toggles skeleton loading for this view and its descendants
*
* @return The bone loader associated with this View or null if known is found
*/
fun View.toggleSkeletonLoading(enabled: Boolean) {
fun View.toggleSkeletonLoading(enabled: Boolean): BoneDrawable? {
val id = generateId()
val parent = getParentSkeletonDrawable()
if (parent != null) {
parent.getProps().setStateOwner(id, false)
parent.getProps().getBoneProps(id).apply {
this.enabled = enabled
}
return null
} else {
var loaderDrawable: BoneDrawable? = null
doWith(foreground) {
if (it is BoneDrawable) {
it.enabled = enabled
loaderDrawable = it
} else {
loaderDrawable = addBoneLoader(enabled = enabled)
}
}
return loaderDrawable
}
doWith(foreground) {
if (it is BoneDrawable) {
it.getProps().enabled = enabled
}

/**
* @Project Project Bones
* @author Eudy Contreras
* @since Feburary 2021
*
* Toggles skeleton loading for this view and its descendants
*
* @return The skeleton associated with this ViewGroup or null if known is found
*/
fun ViewGroup.toggleSkeletonLoading(enabled: Boolean): SkeletonDrawable? {
val id = generateId()
val parent = getParentSkeletonDrawable()
if (parent != null) {
parent.getProps().setStateOwner(id, false)
parent.getProps().getBoneProps(id).apply {
this.enabled = enabled
}
return null
} else {
var loaderDrawable: SkeletonDrawable? = null
doWith(foreground) {
if (it is SkeletonDrawable) {
it.enabled = enabled
loaderDrawable = it
} else {
loaderDrawable = addSkeletonLoader(enabled = enabled)
}
}
return loaderDrawable
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ data class BoneBuilder(
internal var boneProperties: BoneProperties = BoneProperties()
) {

val properties: BoneProperties
get() = boneProperties

/**
* Allows building shimmer ray properties.
*
Expand Down Expand Up @@ -378,4 +381,12 @@ data class BoneBuilder(
this.boneProperties.enabled = enabled
return this
}

/**
* Creates a returns a Bone Drawable built with this
* builder
*/
fun get(): BoneDrawable {
return BoneDrawable.from(this)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ import com.eudycontreras.boneslibrary.extensions.clearProps
import com.eudycontreras.boneslibrary.extensions.saveProps
import com.eudycontreras.boneslibrary.framework.bones.BoneDrawable.Companion.create
import com.eudycontreras.boneslibrary.framework.shimmer.ShimmerRay
import com.eudycontreras.boneslibrary.framework.skeletons.SkeletonDrawable
import com.eudycontreras.boneslibrary.framework.skeletons.SkeletonManager
import com.eudycontreras.boneslibrary.framework.skeletons.SkeletonProperties
import com.eudycontreras.boneslibrary.properties.CornerRadii
import com.eudycontreras.boneslibrary.properties.ShapeType
import com.eudycontreras.boneslibrary.tryGet
Expand Down Expand Up @@ -254,6 +251,22 @@ class BoneDrawable internal constructor(
*/
fun builder(): BoneBuilder = boneManager.getBuilder()

/**
* Disables this bone drawable if it is enabled for for some
* View
*/
fun disable() {
this.enabled = false
}

/**
* Enables the bone drawable for the given View
* @param view The view this drawable will be attached to.
*/
fun enable(view: View) {
view.addBoneLoader(true, this)
}

override fun resetForReuse() {
owner = null
enabled = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ data class ShimmerRayBuilder(
private val shimmerRayProperties: ShimmerRayProperties = ShimmerRayProperties()
) {

val properties: ShimmerRayProperties
get() = shimmerRayProperties

/**
* @Project Project Bones
* @author Eudy Contreras
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class SkeletonBuilder(
internal var skeletonProperties: SkeletonProperties = SkeletonProperties()
) {

val properties: SkeletonProperties
get() = skeletonProperties

private val builderQueue: Queue<() -> Unit> = LinkedList()

/**
Expand Down Expand Up @@ -325,9 +328,15 @@ class SkeletonBuilder(

@Synchronized
internal fun applyBuilders(): SkeletonBuilder {
while (builderQueue.peek() != null) {
builderQueue.poll()?.invoke()
}
builderQueue.forEach { it.invoke() }
return this
}

/**
* Creates a returns a Skeleton Drawable built with this
* builder
*/
fun get(): SkeletonDrawable {
return SkeletonDrawable.from(this)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,22 @@ class SkeletonDrawable internal constructor(
@Synchronized
fun getProps(): SkeletonProperties = skeletonManager.properties

/**
* Disables this skeleton drawable if it is enabled for for some
* ViewGroup
*/
fun disable() {
this.enabled = false
}

/**
* Enables the skeleton drawable for the given ViewGroup
* @param viewGroup The view this drawable will be attached to.
*/
fun enable(viewGroup: ViewGroup) {
viewGroup.addSkeletonLoader(true, this)
}

/**
* Sets the properties use by this **SkeletonDrawable**
* @param properties The properties to be set on this drawable
Expand Down

0 comments on commit c9ebafb

Please sign in to comment.