Skip to content

Commit

Permalink
Merge pull request #23 from EudyContreras/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
EudyContreras authored Feb 28, 2021
2 parents a220b59 + 8ceca0e commit 7f43cc4
Show file tree
Hide file tree
Showing 22 changed files with 733 additions and 196 deletions.
9 changes: 1 addition & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
Expand All @@ -79,17 +78,11 @@ dependencies {
// Lifecycle
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$livedata_version"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"

implementation project(":boneslibrary")

// Third party libs
implementation 'de.hdodenhof:circleimageview:2.2.0'

// Testing and mocking libs
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
11 changes: 5 additions & 6 deletions boneslibrary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'com.google.code.gson:gson:2.8.6'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation "androidx.appcompat:appcompat:$appcompat_version"
implementation "androidx.core:core-ktx:$ktx_version"

implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import androidx.annotation.ColorInt
import androidx.databinding.BindingAdapter
import com.eudycontreras.boneslibrary.MIN_OFFSET
import com.eudycontreras.boneslibrary.doWith
import com.eudycontreras.boneslibrary.extensions.*
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.BoneProperties
Expand Down Expand Up @@ -91,7 +93,7 @@ fun ViewGroup.addSkeletonLoader(enabled: Boolean?, properties: SkeletonPropertie
val drawableBackground = this.background
val drawableForeground = this.foreground

this.foreground = SkeletonDrawable(SkeletonManager(getProps(SkeletonProperties.TAG) ?:properties))
this.foreground = SkeletonDrawable(SkeletonManager(getProps(SkeletonProperties.TAG) ?: properties))

with (this.foreground as SkeletonDrawable) {
this.owner = this@addSkeletonLoader
Expand All @@ -104,6 +106,32 @@ fun ViewGroup.addSkeletonLoader(enabled: Boolean?, properties: SkeletonPropertie
return foreground as SkeletonDrawable
}

fun ViewGroup.addSkeletonLoader(enabled: Boolean?, skeletonLoaderDrawable: SkeletonDrawable): SkeletonDrawable {
doWith(foreground) {
if (it !is SkeletonDrawable) {

val drawableBackground = this.background
val drawableForeground = this.foreground

this.foreground = skeletonLoaderDrawable.apply {
skeletonLoaderDrawable.resetForReuse()
}

with (this.foreground as SkeletonDrawable) {
this.owner = this@addSkeletonLoader
this.enabled = enabled ?: true
this.baseDrawableForeground = drawableForeground
this.baseDrawableBackground = drawableBackground
this.skeletonManager
.getBuilder()
.applyBuilders()
}
}
}
return foreground as SkeletonDrawable
}


@BindingAdapter(SkeletonBindings.SKELETON_ENABLED)
internal fun ViewGroup.setSkeletonEnabled(enabled: Boolean?) {
doWith(foreground) {
Expand Down Expand Up @@ -235,7 +263,6 @@ internal fun ViewGroup.setSkeletonDissectLargeBones(dissect: Boolean?) {
}
} else {
val parent = getParentSkeletonDrawable()

if (parent != null) {
descendantViews().forEach { view ->
val id = view.generateId()
Expand Down Expand Up @@ -366,7 +393,7 @@ internal fun ViewGroup.setSkeletonBoneMinThickness(minThickness: Float?) {
descendantViews().forEach { view ->
val id = view.generateId()
it.getProps().getBoneProps(id).apply {
this.minThickness = minThickness ?: BoneProperties.MIN_THICKNESS
this.minThickness = minThickness ?: BoneProperties.MIN_THICKNESS.dp
}
}
} else {
Expand All @@ -376,7 +403,7 @@ internal fun ViewGroup.setSkeletonBoneMinThickness(minThickness: Float?) {
descendantViews().forEach { view ->
val id = view.generateId()
parent.getProps().getBoneProps(id).apply {
this.minThickness = minThickness ?: BoneProperties.MIN_THICKNESS
this.minThickness = minThickness ?: BoneProperties.MIN_THICKNESS.dp
}
}
} else {
Expand All @@ -394,7 +421,7 @@ internal fun ViewGroup.setSkeletonBoneMaxThickness(maxThickness: Float?) {
descendantViews().forEach { view ->
val id = view.generateId()
it.getProps().getBoneProps(id).apply {
this.maxThickness = maxThickness ?: BoneProperties.MAX_THICKNESS
this.maxThickness = maxThickness ?: BoneProperties.MAX_THICKNESS.dp
}
}
} else {
Expand All @@ -404,7 +431,7 @@ internal fun ViewGroup.setSkeletonBoneMaxThickness(maxThickness: Float?) {
descendantViews().forEach { view ->
val id = view.generateId()
parent.getProps().getBoneProps(id).apply {
this.maxThickness = maxThickness ?: BoneProperties.MAX_THICKNESS
this.maxThickness = maxThickness ?: BoneProperties.MAX_THICKNESS.dp
}
}
} else {
Expand All @@ -414,3 +441,47 @@ internal fun ViewGroup.setSkeletonBoneMaxThickness(maxThickness: Float?) {
}
}
}

/**
* Finds the nearest parent of this view that has
* an skeleton loader and returns the SkeletonDrawable loader
* associated with it.
* @see SkeletonDrawable
*/
fun ViewGroup.getParentSkeletonDrawable(): SkeletonDrawable? {
val skeletonParent = findParent { it.foreground is SkeletonDrawable }
return skeletonParent?.foreground as? SkeletonDrawable
}

/**
* Returns true if this view has an ancestor with an attached
* SkeletonDrawable loader
* @see SkeletonDrawable
*/
fun ViewGroup.hasSkeletonLoaderAncestor(): Boolean {
return getParentSkeletonDrawable() != null
}

/**
* Returns true if this view has SkeletonDrawable loader as its foreground
*/
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")
}
}
Loading

0 comments on commit 7f43cc4

Please sign in to comment.