Last active
October 31, 2019 19:58
-
-
Save KryptKode/f17c0cd54a702e5f67ccbab477d16d73 to your computer and use it in GitHub Desktop.
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
class ActivityOrFragment{ | |
private lateinit val shimmerLayout: ShimmerFrameLayout | |
private fun initViews() { | |
val shimmerLifeCycle = ShimmerLifeCycle(shimmerLayout) | |
lifecycle.addObserver(shimmerLifeCycle) | |
} | |
} |
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
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