From dff676afeab07005ffc6cb6a36ea8563f363d507 Mon Sep 17 00:00:00 2001 From: kaaveh Date: Sat, 11 Sep 2021 17:02:06 +0430 Subject: [PATCH] Migrate BazaarStorageCallback and BazaarSignInCallback to kotlin with SAM conversion --- .idea/.gitignore | 3 + .idea/.name | 1 + .idea/compiler.xml | 6 ++ .idea/gradle.xml | 22 +++++++ .idea/jarRepositories.xml | 30 ++++++++++ .idea/misc.xml | 9 +++ .idea/vcs.xml | 6 ++ .../core/callback/BazaarSignInCallback.java | 8 --- .../core/callback/BazaarSignInCallback.kt | 8 +++ .../callback/BazaarStorageCallback.java | 9 --- .../storage/callback/BazaarStorageCallback.kt | 7 +++ .../bazaar/util/AbortableCountDownLatch.java | 57 ------------------- .../bazaar/util/AbortableCountDownLatch.kt | 45 +++++++++++++++ version-manager.gradle | 2 +- 14 files changed, 138 insertions(+), 75 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/.name create mode 100644 .idea/compiler.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml delete mode 100644 core/src/main/java/com/farsitel/bazaar/core/callback/BazaarSignInCallback.java create mode 100644 core/src/main/java/com/farsitel/bazaar/core/callback/BazaarSignInCallback.kt delete mode 100644 core/src/main/java/com/farsitel/bazaar/storage/callback/BazaarStorageCallback.java create mode 100644 core/src/main/java/com/farsitel/bazaar/storage/callback/BazaarStorageCallback.kt delete mode 100644 core/src/main/java/com/farsitel/bazaar/util/AbortableCountDownLatch.java create mode 100644 core/src/main/java/com/farsitel/bazaar/util/AbortableCountDownLatch.kt diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..fb43257 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +BazaarAuth \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..fb7f4a8 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..ac97bff --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,22 @@ + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..eb2873e --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..2a4d5b5 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/core/src/main/java/com/farsitel/bazaar/core/callback/BazaarSignInCallback.java b/core/src/main/java/com/farsitel/bazaar/core/callback/BazaarSignInCallback.java deleted file mode 100644 index e559bc8..0000000 --- a/core/src/main/java/com/farsitel/bazaar/core/callback/BazaarSignInCallback.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.farsitel.bazaar.core.callback; - -import com.farsitel.bazaar.BazaarResponse; -import com.farsitel.bazaar.core.model.BazaarSignInAccount; - -public interface BazaarSignInCallback { - void onAccountReceived(BazaarResponse account); -} diff --git a/core/src/main/java/com/farsitel/bazaar/core/callback/BazaarSignInCallback.kt b/core/src/main/java/com/farsitel/bazaar/core/callback/BazaarSignInCallback.kt new file mode 100644 index 0000000..c06bbf8 --- /dev/null +++ b/core/src/main/java/com/farsitel/bazaar/core/callback/BazaarSignInCallback.kt @@ -0,0 +1,8 @@ +package com.farsitel.bazaar.core.callback + +import com.farsitel.bazaar.BazaarResponse +import com.farsitel.bazaar.core.model.BazaarSignInAccount + +fun interface BazaarSignInCallback { + fun onAccountReceived(account: BazaarResponse) +} \ No newline at end of file diff --git a/core/src/main/java/com/farsitel/bazaar/storage/callback/BazaarStorageCallback.java b/core/src/main/java/com/farsitel/bazaar/storage/callback/BazaarStorageCallback.java deleted file mode 100644 index 1cc0fac..0000000 --- a/core/src/main/java/com/farsitel/bazaar/storage/callback/BazaarStorageCallback.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.farsitel.bazaar.storage.callback; - -import androidx.annotation.Nullable; - -import com.farsitel.bazaar.BazaarResponse; - -public interface BazaarStorageCallback { - void onDataReceived(@Nullable BazaarResponse response); -} diff --git a/core/src/main/java/com/farsitel/bazaar/storage/callback/BazaarStorageCallback.kt b/core/src/main/java/com/farsitel/bazaar/storage/callback/BazaarStorageCallback.kt new file mode 100644 index 0000000..b86b2d6 --- /dev/null +++ b/core/src/main/java/com/farsitel/bazaar/storage/callback/BazaarStorageCallback.kt @@ -0,0 +1,7 @@ +package com.farsitel.bazaar.storage.callback + +import com.farsitel.bazaar.BazaarResponse + +fun interface BazaarStorageCallback { + fun onDataReceived(response: BazaarResponse?) +} \ No newline at end of file diff --git a/core/src/main/java/com/farsitel/bazaar/util/AbortableCountDownLatch.java b/core/src/main/java/com/farsitel/bazaar/util/AbortableCountDownLatch.java deleted file mode 100644 index f37ce84..0000000 --- a/core/src/main/java/com/farsitel/bazaar/util/AbortableCountDownLatch.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.farsitel.bazaar.util; - -import org.jetbrains.annotations.NotNull; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -public class AbortableCountDownLatch extends CountDownLatch { - - protected boolean aborted = false; - - public AbortableCountDownLatch(int count) { - super(count); - } - - /** - * Unblocks all threads waiting on this latch and cause them to receive an - * AbortedException. If the latch has already counted all the way down, - * this method does nothing. - */ - public void abort() { - if (getCount() == 0) { - return; - } - - this.aborted = true; - while (getCount() > 0) { - countDown(); - } - } - - @Override - public boolean await(long timeout, @NotNull TimeUnit unit) throws InterruptedException { - final boolean awaitForSuper = super.await(timeout, unit); - if (aborted) { - throw new AbortedException(); - } - return awaitForSuper; - } - - @Override - public void await() throws InterruptedException { - super.await(); - if (aborted) { - throw new AbortedException(); - } - } - - public static class AbortedException extends InterruptedException { - public AbortedException() { - } - - public AbortedException(String detailMessage) { - super(detailMessage); - } - } -} \ No newline at end of file diff --git a/core/src/main/java/com/farsitel/bazaar/util/AbortableCountDownLatch.kt b/core/src/main/java/com/farsitel/bazaar/util/AbortableCountDownLatch.kt new file mode 100644 index 0000000..e61e6fc --- /dev/null +++ b/core/src/main/java/com/farsitel/bazaar/util/AbortableCountDownLatch.kt @@ -0,0 +1,45 @@ +package com.farsitel.bazaar.util + +import java.util.concurrent.CountDownLatch +import java.util.concurrent.TimeUnit + +class AbortableCountDownLatch(count: Int) : CountDownLatch(count) { + protected var aborted = false + + /** + * Unblocks all threads waiting on this latch and cause them to receive an + * AbortedException. If the latch has already counted all the way down, + * this method does nothing. + */ + fun abort() { + if (count == 0L) { + return + } + aborted = true + while (count > 0) { + countDown() + } + } + + @Throws(InterruptedException::class) + override fun await(timeout: Long, unit: TimeUnit): Boolean { + val awaitForSuper = super.await(timeout, unit) + if (aborted) { + throw AbortedException() + } + return awaitForSuper + } + + @Throws(InterruptedException::class) + override fun await() { + super.await() + if (aborted) { + throw AbortedException() + } + } + + class AbortedException : InterruptedException { + constructor() + constructor(detailMessage: String?) : super(detailMessage) + } +} \ No newline at end of file diff --git a/version-manager.gradle b/version-manager.gradle index 925bb7c..75200fe 100644 --- a/version-manager.gradle +++ b/version-manager.gradle @@ -1,7 +1,7 @@ ext { libraryVersions = [ - 'kotlin' : '1.3.71', + 'kotlin' : '1.4.0', 'appcompat': '1.1.0', 'fragment' : '1.1.0', 'androidx' : '1.2.0',