Skip to content

Commit

Permalink
Fixed issues #1, #2, #3
Browse files Browse the repository at this point in the history
  • Loading branch information
tehras committed Apr 12, 2017
1 parent 5c7c007 commit f0990c8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.tehras.loadingskeleton

import android.content.Context
import android.graphics.Canvas
import android.util.AttributeSet
import android.view.View
import android.view.ViewGroup
Expand All @@ -18,6 +19,9 @@ class LoadingSkeleton constructor(context: Context, attrs: AttributeSet?, defSty
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
constructor(context: Context) : this(context, null)

private var layoutFinished: Boolean = false
private var startWhenLayoutFinished: Boolean = false

/**
* This is assigned to the temporary Container layout
*/
Expand Down Expand Up @@ -57,7 +61,24 @@ class LoadingSkeleton constructor(context: Context, attrs: AttributeSet?, defSty
this.addView(child)
}

override fun onDraw(canvas: Canvas?) {
super.onDraw(canvas)

layoutFinished = true
if (startWhenLayoutFinished) {
startWhenLayoutFinished()
}
}

fun start() {
if (layoutFinished) {
startWhenLayoutFinished()
} else {
startWhenLayoutFinished = true
}
}

private fun startWhenLayoutFinished() {
if (childCount != 1)
throw RuntimeException("View must have 1 child")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,27 @@ class LoadingSkeletonViewConverter private constructor() {

@Suppress("unused")
class Builder {
internal var converters: ArrayList<LoadingSkeletonViewStreamer<*>>? = null
var converters: ArrayList<LoadingSkeletonViewStreamer<*>>? = null
private set
internal var color: Int = R.color.loading_skeleton_default_animation_color
var color: Int = R.color.loading_skeleton_default_animation_color
private set
internal var cornerRadius: Float = 5f
var cornerRadius: Float = 5f
private set
internal var gradient: Boolean = true
var gradient: Boolean = true
private set
internal var shimmer: Boolean = true
var shimmer: Boolean = true
private set

fun color(color: Int): Builder {
this.color = color
return this
}

fun cornerRadius(radius: Float): Builder {
this.cornerRadius = radius
return this
}

fun gradient(gradient: Boolean): Builder {
this.gradient = gradient
return this
Expand Down

0 comments on commit f0990c8

Please sign in to comment.