Skip to content

Commit 8969480

Browse files
committed
Release version 1.0.5
1 parent e9dbda5 commit 8969480

File tree

4 files changed

+55
-18
lines changed

4 files changed

+55
-18
lines changed

README.md

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
Add a dependency code to your **module**'s `build.gradle` file.
2727
```gradle
2828
dependencies {
29-
implementation "com.github.skydoves:only:1.0.4"
29+
implementation "com.github.skydoves:only:1.0.5"
3030
}
3131
```
3232

@@ -209,30 +209,64 @@ Only.init(this)
209209
## Usage in Java
210210
Here are some usages for Java developers.
211211
```java
212-
int times = Only.INSTANCE.getOnlyTimes("IntroPopup") ;
212+
int times = Only.getOnlyTimes("IntroPopup") ;
213213
if (times < 3) {
214-
Only.INSTANCE.setOnlyTimes("IntroPopup", times + 1);
214+
Only.setOnlyTimes("IntroPopup", times + 1);
215215
showIntroPopup();
216216
}
217217
```
218-
Or we can run `Only` in java project using `Only.Builder` and `Function0`.
218+
### Builder
219+
we can run `Only` in java project using `Only.Builder` and `Runnable`.
219220
```java
220221
new Only.Builder("introPopup", 1)
221-
.onDo(new Function0<Unit>() {
222-
@Override
223-
public Unit invoke() {
224-
doSomethingOnlyOnce();
225-
return Unit.INSTANCE;
222+
.onDo(new Runnable() {
223+
@Override
224+
public void run() {
225+
doSomethingOnlyOnce();
226226
}
227227
})
228-
.onDone(new Function0<Unit>() {
229-
@Override
230-
public Unit invoke() {
231-
doSOmethingAfterDone();
232-
return Unit.INSTANCE;
233-
}
228+
.onDone(new Runnable() {
229+
@Override
230+
public void run() {
231+
doSOmethingAfterDone();
232+
}
233+
}).run(); // run the Only
234+
```
235+
### Java8 lambda expression
236+
We can make it more simple using Java8 lambda expression.<br>
237+
Add below codes on your `build.gradle` file.
238+
```gradle
239+
android {
240+
compileOptions {
241+
sourceCompatibility JavaVersion.VERSION_1_8
242+
targetCompatibility JavaVersion.VERSION_1_8
243+
}
244+
}
245+
```
246+
Then you can run the Only like below.
247+
```java
248+
new Only.Builder("introPopup", 1)
249+
.onDo(() -> {
250+
doSomethingOnlyOnce();
251+
})
252+
.onDone(() -> {
253+
doSOmethingAfterDone();
234254
}).run(); // run the Only
235255
```
256+
### Custom util class
257+
We can create custom util class like what Kotlin's `onlyOnce`.
258+
```java
259+
public class OnlyUtils {
260+
261+
public static void onlyOnce(
262+
String name, Runnable runnableOnDo, Runnable runnableOnDone) {
263+
new Only.Builder(name, 1)
264+
.onDo(runnableOnDo)
265+
.onDone(runnableOnDone)
266+
.run(); // run the Only
267+
}
268+
}
269+
```
236270

237271
## Find this library useful? :heart:
238272
Support it by joining __[stargazers](https://github.com/skydoves/only/stargazers)__ for this repository. :star:

app/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ android {
1212
versionCode versions.versionCode
1313
versionName versions.versionName
1414
}
15+
compileOptions {
16+
sourceCompatibility JavaVersion.VERSION_1_8
17+
targetCompatibility JavaVersion.VERSION_1_8
18+
}
1519
}
1620

1721
dependencies {

dependencies.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
ext.versions = [
22
minSdk : 15,
33
compileSdk : 29,
4-
versionCode : 5,
5-
versionName : '1.0.4',
4+
versionCode : 6,
5+
versionName : '1.0.5',
66

77
gradleBuildTool : '3.6.3',
88
spotlessGradle : '3.28.1',

only/src/main/java/com/skydoves/only/Only.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,6 @@ object Only {
409409
editor.apply()
410410
}
411411

412-
413412
/** Builder class for creating [Only]. */
414413
@OnlyDsl
415414
class Builder(

0 commit comments

Comments
 (0)