-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from EudyContreras/development
Development
- Loading branch information
Showing
17 changed files
with
235 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,49 @@ | ||
[![Dev Site Banner](media/images/android_dev_site_banner.png)](https://medium.com/android-dev-site) | ||
|
||
<div align="center"> | ||
|
||
![Banner Demo](./media/gifs/wide_banner_white.gif) | ||
|
||
## Examples coming soon! | ||
|
||
</div> | ||
|
||
## Using Skeleton Bones with Glide | ||
|
||
Bones can be easily combined with glide by allowing the glide request callback to notify the skeleton drawable that the image load process is completed. This can be done through the **`image.notifySkeletonImageLoaded()`** extension which is available for ImageViews. | ||
|
||
```kotlin | ||
Glide.with(context) | ||
.load(imageUrl) | ||
.addListener(object : RequestListener<Drawable> { | ||
override fun onLoadFailed( | ||
exception: GlideException?, | ||
model: Any?, | ||
target: Target<Drawable>?, | ||
isFirstResource: Boolean | ||
): Boolean { | ||
return this@loadImage.notifySkeletonImageLoaded() | ||
} | ||
|
||
override fun onResourceReady( | ||
resource: Drawable?, | ||
model: Any?, | ||
target: Target<Drawable>?, | ||
dataSource: DataSource?, | ||
isFirstResource: Boolean | ||
): Boolean { | ||
return this@loadImage.notifySkeletonImageLoaded() | ||
} | ||
|
||
}) | ||
.apply(RequestOptions().format(DecodeFormat.PREFER_ARGB_8888)) | ||
.into(this) | ||
|
||
``` | ||
|
||
Assuming that the skeleton or shimmer effect is being shown for the image being loaded, calling the **`image.notifySkeletonImageLoaded()`** extension function will switch the loading state to false and it will remove any actve shimmer effects or skeletons. | ||
|
||
The extension function allows this to work with any image loader that allows listening to request results. If the target ImageView is within a SkeletonParent, you must allow the image view to be its own state owner by setting the **` skeletonBoneStateOwener`** attribute to true. This only needed if you allowing the image view to listen to state changes with the **`skeletonBoneEnabled`** flag. | ||
|
||
### More examples coming soon! | ||
|
||
You are welcome to try out the demo app and inspect the xml for a full | ||
live example of Bones. | ||
live example of Bones. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
boneslibrary/src/main/java/com/eudycontreras/boneslibrary/extensions/ImageViewExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.eudycontreras.boneslibrary.extensions | ||
|
||
import android.widget.ImageView | ||
import com.eudycontreras.boneslibrary.bindings.getParentSkeletonDrawable | ||
import com.eudycontreras.boneslibrary.doWith | ||
import com.eudycontreras.boneslibrary.framework.bones.BoneDrawable | ||
|
||
/** | ||
* Copyright (C) 2020 Bones | ||
* | ||
* @Project Project Bones | ||
* @author Eudy Contreras. | ||
* @since March 2020 | ||
* | ||
* Notifies the backing bone for this ImageView that the image has | ||
* been loaded. | ||
*/ | ||
|
||
fun ImageView.notifySkeletonImageLoaded(): Boolean { | ||
val id = generateId() | ||
val parent = getParentSkeletonDrawable() | ||
if (parent != null) { | ||
parent.getProps().setStateOwner(id, false) | ||
parent.getProps().getBoneProps(id).apply { | ||
this.enabled = false | ||
return true | ||
} | ||
} | ||
doWith(foreground) { | ||
if (it is BoneDrawable) { | ||
it.getProps().enabled = false | ||
return true | ||
} | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.