Skip to content

Instantly share code, notes, and snippets.

@KryptKode
Last active October 31, 2019 19:58
Show Gist options
  • Save KryptKode/f17c0cd54a702e5f67ccbab477d16d73 to your computer and use it in GitHub Desktop.
Save KryptKode/f17c0cd54a702e5f67ccbab477d16d73 to your computer and use it in GitHub Desktop.
class ActivityOrFragment{
private lateinit val shimmerLayout: ShimmerFrameLayout
private fun initViews() {
val shimmerLifeCycle = ShimmerLifeCycle(shimmerLayout)
lifecycle.addObserver(shimmerLifeCycle)
}
}
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
import com.facebook.shimmer.ShimmerFrameLayout
import timber.log.Timber
class ShimmerLifeCycle (private val shimmerFrameLayout: ShimmerFrameLayout) : LifecycleObserver{
var loading: Boolean = false
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
fun stopShimmer(){
Timber.d("Attempting to stop shimmer")
if(shimmerFrameLayout.isShimmerStarted){
Timber.d("Stopped shimmer...")
shimmerFrameLayout.stopShimmer()
}
}
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
fun startShimmer(){
Timber.d("Attempting to start shimmer")
if(loading){
Timber.d("Starting shimmer...")
shimmerFrameLayout.startShimmer()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment