Skip to content

Commit

Permalink
register to LifecycleOwner function
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars Werkman committed Apr 22, 2020
1 parent 85e0a17 commit 4b6da06
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class MainActivity : AppCompatActivity() {
setContentView(R.layout.activity_main)

loading = SkeletonLoading(this, R.drawable.skeleton, AlphaAnimation(.1f, .6f))
lifecycle.addObserver(loading)
loading.register(this)

val binder = loading.create {
bind(sample_text_view.skeleton(SkeletonTextView.TextWidth.LINES, 1.2))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.graphics.drawable.Drawable
import androidx.annotation.DrawableRes
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.OnLifecycleEvent
import java.util.concurrent.CopyOnWriteArrayList

Expand Down Expand Up @@ -37,6 +38,10 @@ class SkeletonLoading(
return binder
}

fun register(owner: LifecycleOwner) {
owner.lifecycle.addObserver(this)
}

@OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
fun onCreate() {
animation?.start { progress ->
Expand Down

0 comments on commit 4b6da06

Please sign in to comment.