Skip to content

Commit

Permalink
Release version 1.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
skydoves committed Apr 29, 2020
1 parent e9dbda5 commit 8969480
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 18 deletions.
64 changes: 49 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
Add a dependency code to your **module**'s `build.gradle` file.
```gradle
dependencies {
implementation "com.github.skydoves:only:1.0.4"
implementation "com.github.skydoves:only:1.0.5"
}
```

Expand Down Expand Up @@ -209,30 +209,64 @@ Only.init(this)
## Usage in Java
Here are some usages for Java developers.
```java
int times = Only.INSTANCE.getOnlyTimes("IntroPopup") ;
int times = Only.getOnlyTimes("IntroPopup") ;
if (times < 3) {
Only.INSTANCE.setOnlyTimes("IntroPopup", times + 1);
Only.setOnlyTimes("IntroPopup", times + 1);
showIntroPopup();
}
```
Or we can run `Only` in java project using `Only.Builder` and `Function0`.
### Builder
we can run `Only` in java project using `Only.Builder` and `Runnable`.
```java
new Only.Builder("introPopup", 1)
.onDo(new Function0<Unit>() {
@Override
public Unit invoke() {
doSomethingOnlyOnce();
return Unit.INSTANCE;
.onDo(new Runnable() {
@Override
public void run() {
doSomethingOnlyOnce();
}
})
.onDone(new Function0<Unit>() {
@Override
public Unit invoke() {
doSOmethingAfterDone();
return Unit.INSTANCE;
}
.onDone(new Runnable() {
@Override
public void run() {
doSOmethingAfterDone();
}
}).run(); // run the Only
```
### Java8 lambda expression
We can make it more simple using Java8 lambda expression.<br>
Add below codes on your `build.gradle` file.
```gradle
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
```
Then you can run the Only like below.
```java
new Only.Builder("introPopup", 1)
.onDo(() -> {
doSomethingOnlyOnce();
})
.onDone(() -> {
doSOmethingAfterDone();
}).run(); // run the Only
```
### Custom util class
We can create custom util class like what Kotlin's `onlyOnce`.
```java
public class OnlyUtils {

public static void onlyOnce(
String name, Runnable runnableOnDo, Runnable runnableOnDone) {
new Only.Builder(name, 1)
.onDo(runnableOnDo)
.onDone(runnableOnDone)
.run(); // run the Only
}
}
```

## Find this library useful? :heart:
Support it by joining __[stargazers](https://github.com/skydoves/only/stargazers)__ for this repository. :star:
Expand Down
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ android {
versionCode versions.versionCode
versionName versions.versionName
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
Expand Down
4 changes: 2 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
ext.versions = [
minSdk : 15,
compileSdk : 29,
versionCode : 5,
versionName : '1.0.4',
versionCode : 6,
versionName : '1.0.5',

gradleBuildTool : '3.6.3',
spotlessGradle : '3.28.1',
Expand Down
1 change: 0 additions & 1 deletion only/src/main/java/com/skydoves/only/Only.kt
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,6 @@ object Only {
editor.apply()
}


/** Builder class for creating [Only]. */
@OnlyDsl
class Builder(
Expand Down

0 comments on commit 8969480

Please sign in to comment.