Only
An easy way to persistence and run block codes only as many times as necessary on Android.
Download
Gradle
And add a dependency code to your module's build.gradle
file.
Usage
Initialize
Fisrt, initialize the Only
using init()
method like below.
This code can be initialized on Application
class only once.
onDo
Below codes will run the showIntroPopup()
only three times using onDo
method.
onDone
Below codes will run the doSomeThingAfterDone()
and toast("done")
after run the onDo
block codes three times.
Version Control
We can renew the persistence times for controlling the version using version
option.
If the version is different from the old version, run times will be initialized 0.
Create Using Builder
We can run Only using Only.Builder
class like below.
OnlyOnce, OnlyTwice, OnlyThrice
Here is some useful kotlin-dsl functions.
Clear Times
You can optionally delete the stored Only
times data or delete the entire Only
times data.
View Extension
Below codes will show the button
view only once.
Debug Mode
Sometimes on debug, we don't need to persist data and replay onDone block.
onlyOnDoDebugMode
helps that ignore persistence data and onDone block when initialization. It runs only onDo block.
Usage in Java
We can run Only
in java project using Only.Builder
and Function0
.