diff --git a/build.gradle b/build.gradle index 8e5ea8c3..27fe6cb5 100644 --- a/build.gradle +++ b/build.gradle @@ -1,58 +1,21 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. - -subprojects { - ext { - artifactVersion = '2.7.0' - } +plugins { + alias(deps.plugins.kotlin.android).apply(false) + alias(deps.plugins.android.library).apply(false) + alias(deps.plugins.android.application).apply(false) } -buildscript { +subprojects { ext { - versions = [ - kotlin : '1.3.50', - code : 1, - name : '1.0.0', - sdk : [ - minimum: 14, - target : 28 - ], - android: [ - buildTools: '28.0.3', - appcompat : '1.1.0', - annotation : '1.1.0', - exifinterface : '1.0.0' - ], - rx : [ - rxJava1: '1.3.8', - rxJava2: '2.2.12' - ], - test : [ - junit : '4.12', - mockito: '2.23.0' - ] - ] + artifactVersion = '2.8.0' } - repositories { - google() - jcenter() + tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { + kotlinOptions { + jvmTarget = "11" + } } - dependencies { - classpath 'com.android.tools.build:gradle:3.5.1' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}" - - classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' - classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' + tasks.withType(JavaCompile).configureEach { + sourceCompatibility = "11" + targetCompatibility = "11" } } -allprojects { - repositories { - google() - jcenter() - } -} - -task clean(type: Delete) { - delete rootProject.buildDir -} - diff --git a/deploy.gradle b/deploy.gradle deleted file mode 100644 index daa57440..00000000 --- a/deploy.gradle +++ /dev/null @@ -1,100 +0,0 @@ -apply plugin: 'com.jfrog.bintray' -apply plugin: 'com.github.dcendents.android-maven' - -ext { - bintrayOrganisation = 'fotoapparat' - bintrayRepo = 'fotoapparat' - - publishedGroupId = 'io.fotoapparat' - - siteUrl = 'https://github.com/RedApparat/Fotoapparat' - gitUrl = 'https://github.com/RedApparat/Fotoapparat.git' - - developerId = 'fotoapparat' - developerName = 'Fotoapparat' - developerEmail = 'dmitry.zaicew@gmail.com' - - licenseName = 'The Apache Software License, Version 2.0' - licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt' - allLicenses = ["Apache-2.0"] -} - -group = publishedGroupId -version = libraryVersion - -install { - repositories.mavenInstaller { - pom.project { - packaging 'aar' - groupId publishedGroupId - artifactId artifact - - name libraryName - description libraryDescription - url siteUrl - - licenses { - license { - name licenseName - url licenseUrl - } - } - developers { - developer { - id developerId - name developerName - email developerEmail - } - } - scm { - connection gitUrl - developerConnection gitUrl - url siteUrl - } - } - } -} - -task sourcesJar(type: Jar) { - classifier = 'sources' - from android.sourceSets.main.java.srcDirs -} - -task javadoc(type: Javadoc) { - source = android.sourceSets.main.java.srcDirs - classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) - failOnError = false -} - -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir -} - -artifacts { - archives javadocJar - archives sourcesJar -} - -bintray { - user = project.properties["bintray.user"] ?: System.getenv('BINTRAY_USER') - key = project.properties["bintray.apikey"] ?: System.getenv('BINTRAY_API_KEY') - - configurations = ['archives'] - pkg { - userOrg = bintrayOrganisation - repo = bintrayRepo - name = bintrayName - desc = libraryDescription - websiteUrl = siteUrl - vcsUrl = gitUrl - licenses = allLicenses - dryRun = false - publish = true - override = false - publicDownloadNumbers = true - version { - desc = libraryDescription - } - } -} \ No newline at end of file diff --git a/fotoapparat-adapters/rxjava/README.md b/fotoapparat-adapters/rxjava/README.md deleted file mode 100644 index d021fa3c..00000000 --- a/fotoapparat-adapters/rxjava/README.md +++ /dev/null @@ -1,22 +0,0 @@ -# RxJava 1.x Adapter - -An `Adapter` for adapting RxJava 1.x types. - -Available types: - - * `Observable` - * `Single` - * `Completable` - - -## Set up - -Add dependency to your `build.gradle` - -```groovy -repositories { - maven { url 'https://jitpack.io' } -} - -compile 'io.fotoapparat.fotoapparat:adapter-rxjava:x.y.z' -``` diff --git a/fotoapparat-adapters/rxjava/build.gradle b/fotoapparat-adapters/rxjava/build.gradle deleted file mode 100644 index 88b90df9..00000000 --- a/fotoapparat-adapters/rxjava/build.gradle +++ /dev/null @@ -1,41 +0,0 @@ -apply plugin: 'com.android.library' -apply plugin: 'com.github.dcendents.android-maven' -apply plugin: 'kotlin-android' - -group = 'io.fotoapparat' - -android { - buildToolsVersion versions.android.buildTools - compileSdkVersion versions.sdk.target - - defaultConfig { - minSdkVersion versions.sdk.minimum - targetSdkVersion versions.sdk.target - } - - archivesBaseName = 'adapter-rxjava' - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } -} - -dependencies { - compileOnly project(':fotoapparat') - compileOnly "io.reactivex:rxjava:${versions.rx.rxJava1}" - implementation "org.jetbrains.kotlin:kotlin-stdlib:${versions.kotlin}" - testImplementation "io.reactivex:rxjava:${versions.rx.rxJava1}" - testImplementation "junit:junit:${versions.test.junit}" -} - -ext { - bintrayName = 'adapter-rxjava' - - libraryName = 'Fotoapparat Adapters - RxJava' - artifact = 'adapter-rxjava' - libraryVersion = artifactVersion - - libraryDescription = 'RxJava1 adapter for Fotoapparat.' -} - -apply from: '../../deploy.gradle' diff --git a/fotoapparat-adapters/rxjava/src/main/AndroidManifest.xml b/fotoapparat-adapters/rxjava/src/main/AndroidManifest.xml deleted file mode 100644 index 58eec1fe..00000000 --- a/fotoapparat-adapters/rxjava/src/main/AndroidManifest.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/fotoapparat-adapters/rxjava/src/main/java/io/fotoapparat/result/adapter/rxjava/CompletableAdapter.kt b/fotoapparat-adapters/rxjava/src/main/java/io/fotoapparat/result/adapter/rxjava/CompletableAdapter.kt deleted file mode 100644 index 0bd0198b..00000000 --- a/fotoapparat-adapters/rxjava/src/main/java/io/fotoapparat/result/adapter/rxjava/CompletableAdapter.kt +++ /dev/null @@ -1,27 +0,0 @@ -package io.fotoapparat.result.adapter.rxjava - -import io.fotoapparat.result.PendingResult -import rx.Completable -import java.util.concurrent.Future - -/** - * Adapter for [Completable]. - */ -object CompletableAdapter { - - /** - * @return Adapter which adapts result to [Completable]. - */ - @JvmStatic - fun toCompletable(): Function1, Completable> { - return { future -> Completable.fromFuture(future) } - } - -} - -/** - * @return A [Completable] from the given [PendingResult]. - */ -fun PendingResult.toCompletable(): Completable { - return adapt { future -> Completable.fromFuture(future) } -} diff --git a/fotoapparat-adapters/rxjava/src/main/java/io/fotoapparat/result/adapter/rxjava/ObservableAdapter.kt b/fotoapparat-adapters/rxjava/src/main/java/io/fotoapparat/result/adapter/rxjava/ObservableAdapter.kt deleted file mode 100644 index b1d4f6c0..00000000 --- a/fotoapparat-adapters/rxjava/src/main/java/io/fotoapparat/result/adapter/rxjava/ObservableAdapter.kt +++ /dev/null @@ -1,27 +0,0 @@ -package io.fotoapparat.result.adapter.rxjava - -import io.fotoapparat.result.PendingResult -import rx.Observable -import java.util.concurrent.Future - -/** - * Adapter for [Observable]. - */ -object ObservableAdapter { - - /** - * @return Adapter which adapts result to [Observable]. - */ - @JvmStatic - fun toObservable(): Function1, Observable> { - return { future -> Observable.from(future) } - } - -} - -/** - * @return A [Observable] from the given [PendingResult]. - */ -fun PendingResult.toObservable(): Observable { - return adapt { future -> Observable.from(future) } -} diff --git a/fotoapparat-adapters/rxjava/src/main/java/io/fotoapparat/result/adapter/rxjava/SingleAdapter.kt b/fotoapparat-adapters/rxjava/src/main/java/io/fotoapparat/result/adapter/rxjava/SingleAdapter.kt deleted file mode 100644 index f6bc0676..00000000 --- a/fotoapparat-adapters/rxjava/src/main/java/io/fotoapparat/result/adapter/rxjava/SingleAdapter.kt +++ /dev/null @@ -1,27 +0,0 @@ -package io.fotoapparat.result.adapter.rxjava - -import io.fotoapparat.result.PendingResult -import rx.Single -import java.util.concurrent.Future - -/** - * Adapter for [Single]. - */ -object SingleAdapter { - - /** - * @return Adapter which adapts result to [Single]. - */ - @JvmStatic - fun toSingle(): (Future) -> Single { - return { future -> Single.from(future) } - } - -} - -/** - * @return A [Single] from the given [PendingResult]. - */ -fun PendingResult.toSingle(): Single { - return adapt { future -> Single.from(future) } -} diff --git a/fotoapparat-adapters/rxjava/src/test/java/io/fotoapparat/result/adapter/rxjava/CompletableAdapterTest.java b/fotoapparat-adapters/rxjava/src/test/java/io/fotoapparat/result/adapter/rxjava/CompletableAdapterTest.java deleted file mode 100644 index 0347d20c..00000000 --- a/fotoapparat-adapters/rxjava/src/test/java/io/fotoapparat/result/adapter/rxjava/CompletableAdapterTest.java +++ /dev/null @@ -1,56 +0,0 @@ -package io.fotoapparat.result.adapter.rxjava; - -import org.junit.Test; - -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; - -import rx.observers.TestSubscriber; - -public class CompletableAdapterTest { - - private TestSubscriber subscriber = new TestSubscriber<>(); - - @Test - public void completed() throws Exception { - // Given - Future future = new CallableFuture<>(new Callable() { - @Override - public String call() throws Exception { - return "Hello"; - } - }); - - // When - CompletableAdapter.toCompletable() - .invoke(future) - .subscribe(subscriber); - - // Then - subscriber.assertNoValues(); - subscriber.assertNoErrors(); - subscriber.assertCompleted(); - } - - @Test - public void error() throws Exception { - // Given - Future future = new CallableFuture<>(new Callable() { - @Override - public String call() throws Exception { - throw new RuntimeException("What a failure"); - } - }); - - // When - CompletableAdapter.toCompletable() - .invoke(future) - .subscribe(subscriber); - - // Then - subscriber.assertNoValues(); - subscriber.assertError(ExecutionException.class); - } - -} \ No newline at end of file diff --git a/fotoapparat-adapters/rxjava/src/test/java/io/fotoapparat/result/adapter/rxjava/ObservableAdapterTest.java b/fotoapparat-adapters/rxjava/src/test/java/io/fotoapparat/result/adapter/rxjava/ObservableAdapterTest.java deleted file mode 100644 index 0154359f..00000000 --- a/fotoapparat-adapters/rxjava/src/test/java/io/fotoapparat/result/adapter/rxjava/ObservableAdapterTest.java +++ /dev/null @@ -1,56 +0,0 @@ -package io.fotoapparat.result.adapter.rxjava; - -import org.junit.Test; - -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; - -import rx.observers.TestSubscriber; - -public class ObservableAdapterTest { - - private TestSubscriber subscriber = new TestSubscriber<>(); - - @Test - public void completed() throws Exception { - // Given - Future future = new CallableFuture<>(new Callable() { - @Override - public String call() throws Exception { - return "Hello"; - } - }); - - // When - ObservableAdapter.toObservable() - .invoke(future) - .subscribe(subscriber); - - // Then - subscriber.assertValue("Hello"); - subscriber.assertNoErrors(); - subscriber.assertCompleted(); - } - - @Test - public void error() throws Exception { - // Given - Future future = new CallableFuture<>(new Callable() { - @Override - public String call() throws Exception { - throw new RuntimeException("What a failure"); - } - }); - - // When - ObservableAdapter.toObservable() - .invoke(future) - .subscribe(subscriber); - - // Then - subscriber.assertNoValues(); - subscriber.assertError(ExecutionException.class); - } - -} \ No newline at end of file diff --git a/fotoapparat-adapters/rxjava/src/test/java/io/fotoapparat/result/adapter/rxjava/SingleAdapterTest.java b/fotoapparat-adapters/rxjava/src/test/java/io/fotoapparat/result/adapter/rxjava/SingleAdapterTest.java deleted file mode 100644 index 8f0c47d4..00000000 --- a/fotoapparat-adapters/rxjava/src/test/java/io/fotoapparat/result/adapter/rxjava/SingleAdapterTest.java +++ /dev/null @@ -1,56 +0,0 @@ -package io.fotoapparat.result.adapter.rxjava; - -import org.junit.Test; - -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; - -import rx.observers.TestSubscriber; - -public class SingleAdapterTest { - - private TestSubscriber subscriber = new TestSubscriber<>(); - - @Test - public void completed() throws Exception { - // Given - Future future = new CallableFuture<>(new Callable() { - @Override - public String call() throws Exception { - return "Hello"; - } - }); - - // When - SingleAdapter.toSingle() - .invoke(future) - .subscribe(subscriber); - - // Then - subscriber.assertValue("Hello"); - subscriber.assertNoErrors(); - subscriber.assertCompleted(); - } - - @Test - public void error() throws Exception { - // Given - Future future = new CallableFuture<>(new Callable() { - @Override - public String call() throws Exception { - throw new RuntimeException("What a failure"); - } - }); - - // When - SingleAdapter.toSingle() - .invoke(future) - .subscribe(subscriber); - - // Then - subscriber.assertNoValues(); - subscriber.assertError(ExecutionException.class); - } - -} \ No newline at end of file diff --git a/fotoapparat-adapters/rxjava2/build.gradle b/fotoapparat-adapters/rxjava2/build.gradle deleted file mode 100644 index e8bfd202..00000000 --- a/fotoapparat-adapters/rxjava2/build.gradle +++ /dev/null @@ -1,41 +0,0 @@ -apply plugin: 'com.android.library' -apply plugin: 'com.github.dcendents.android-maven' -apply plugin: 'kotlin-android' - -group = 'io.fotoapparat' - -android { - buildToolsVersion versions.android.buildTools - compileSdkVersion versions.sdk.target - - defaultConfig { - minSdkVersion versions.sdk.minimum - targetSdkVersion versions.sdk.target - } - - archivesBaseName = 'adapter-rxjava2' - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } -} - -dependencies { - compileOnly project(':fotoapparat') - compileOnly "io.reactivex.rxjava2:rxjava:${versions.rx.rxJava2}" - implementation "org.jetbrains.kotlin:kotlin-stdlib:${versions.kotlin}" - testImplementation "io.reactivex.rxjava2:rxjava:${versions.rx.rxJava2}" - testImplementation "junit:junit:${versions.test.junit}" -} - -ext { - bintrayName = 'adapter-rxjava2' - - libraryName = 'Fotoapparat Adapters - RxJava2' - artifact = 'adapter-rxjava2' - libraryVersion = artifactVersion - - libraryDescription = 'RxJava2 adapter for Fotoapparat.' -} - -apply from: '../../deploy.gradle' diff --git a/fotoapparat-adapters/rxjava2/src/main/AndroidManifest.xml b/fotoapparat-adapters/rxjava2/src/main/AndroidManifest.xml deleted file mode 100644 index 65b80bfd..00000000 --- a/fotoapparat-adapters/rxjava2/src/main/AndroidManifest.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/fotoapparat-adapters/rxjava2/src/test/java/io/fotoapparat/result/adapter/rxjava2/CallableFuture.kt b/fotoapparat-adapters/rxjava2/src/test/java/io/fotoapparat/result/adapter/rxjava2/CallableFuture.kt deleted file mode 100644 index 55ede2f0..00000000 --- a/fotoapparat-adapters/rxjava2/src/test/java/io/fotoapparat/result/adapter/rxjava2/CallableFuture.kt +++ /dev/null @@ -1,44 +0,0 @@ -package io.fotoapparat.result.adapter.rxjava2 - -import java.util.concurrent.* - -/** - * Simply returns the value of the callable. - */ -class CallableFuture(private val callable: Callable) : Future { - - private val latch = CountDownLatch(1) - - override fun cancel(mayInterruptIfRunning: Boolean): Boolean { - return false - } - - override fun isCancelled(): Boolean { - return false - } - - override fun isDone(): Boolean { - return latch.count == 0L - } - - @Throws(InterruptedException::class, ExecutionException::class) - override fun get(): T { - return callCallable() - } - - @Throws(InterruptedException::class, ExecutionException::class, TimeoutException::class) - override fun get(timeout: Long, unit: TimeUnit): T { - return callCallable() - } - - @Throws(ExecutionException::class) - private fun callCallable(): T { - latch.countDown() - try { - return callable.call() - } catch (e: Exception) { - throw ExecutionException(e) - } - - } -} diff --git a/fotoapparat-adapters/rxjava2/README.md b/fotoapparat-adapters/rxjava3/README.md similarity index 100% rename from fotoapparat-adapters/rxjava2/README.md rename to fotoapparat-adapters/rxjava3/README.md diff --git a/fotoapparat-adapters/rxjava3/build.gradle b/fotoapparat-adapters/rxjava3/build.gradle new file mode 100644 index 00000000..1d96f8b8 --- /dev/null +++ b/fotoapparat-adapters/rxjava3/build.gradle @@ -0,0 +1,37 @@ +apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' + +group = 'io.fotoapparat' + +android { + buildToolsVersion deps.versions.buildTools.get() + compileSdkVersion deps.versions.compileSdk.get().toInteger() + defaultConfig { + minSdkVersion deps.versions.minSdk.get() + targetSdkVersion deps.versions.compileSdk.get() + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_11 + targetCompatibility JavaVersion.VERSION_11 + } + namespace = "io.fotoapparat.rxjava3" + archivesBaseName = 'adapter-rxjava3' +} + +dependencies { + compileOnly project(':fotoapparat') + compileOnly deps.rx.java + implementation deps.kotlin.stdlib + testImplementation deps.rx.java + testImplementation deps.junit +} + +ext { + bintrayName = 'adapter-rxjava2' + + libraryName = 'Fotoapparat Adapters - RxJava2' + artifact = 'adapter-rxjava2' + libraryVersion = artifactVersion + + libraryDescription = 'RxJava2 adapter for Fotoapparat.' +} diff --git a/fotoapparat-adapters/rxjava2/src/main/java/io/fotoapparat/result/adapter/rxjava2/CompletableAdapter.kt b/fotoapparat-adapters/rxjava3/src/main/java/io/fotoapparat/result/adapter/rxjava3/CompletableAdapter.kt similarity index 87% rename from fotoapparat-adapters/rxjava2/src/main/java/io/fotoapparat/result/adapter/rxjava2/CompletableAdapter.kt rename to fotoapparat-adapters/rxjava3/src/main/java/io/fotoapparat/result/adapter/rxjava3/CompletableAdapter.kt index 026fd946..841d3919 100644 --- a/fotoapparat-adapters/rxjava2/src/main/java/io/fotoapparat/result/adapter/rxjava2/CompletableAdapter.kt +++ b/fotoapparat-adapters/rxjava3/src/main/java/io/fotoapparat/result/adapter/rxjava3/CompletableAdapter.kt @@ -1,8 +1,8 @@ -package io.fotoapparat.result.adapter.rxjava2 +package io.fotoapparat.result.adapter.rxjava3 import android.annotation.SuppressLint import io.fotoapparat.result.PendingResult -import io.reactivex.Completable +import io.reactivex.rxjava3.core.Completable import java.util.concurrent.Future /** diff --git a/fotoapparat-adapters/rxjava2/src/main/java/io/fotoapparat/result/adapter/rxjava2/FlowableAdapter.kt b/fotoapparat-adapters/rxjava3/src/main/java/io/fotoapparat/result/adapter/rxjava3/FlowableAdapter.kt similarity index 70% rename from fotoapparat-adapters/rxjava2/src/main/java/io/fotoapparat/result/adapter/rxjava2/FlowableAdapter.kt rename to fotoapparat-adapters/rxjava3/src/main/java/io/fotoapparat/result/adapter/rxjava3/FlowableAdapter.kt index 5f028bde..4d06047d 100644 --- a/fotoapparat-adapters/rxjava2/src/main/java/io/fotoapparat/result/adapter/rxjava2/FlowableAdapter.kt +++ b/fotoapparat-adapters/rxjava3/src/main/java/io/fotoapparat/result/adapter/rxjava3/FlowableAdapter.kt @@ -1,8 +1,8 @@ -package io.fotoapparat.result.adapter.rxjava2 +package io.fotoapparat.result.adapter.rxjava3 import android.annotation.SuppressLint import io.fotoapparat.result.PendingResult -import io.reactivex.Flowable +import io.reactivex.rxjava3.core.Flowable import java.util.concurrent.Future /** @@ -15,7 +15,7 @@ object FlowableAdapter { */ @JvmStatic @SuppressLint("CheckResult") - fun toFlowable(): Function1, Flowable> { + fun toFlowable(): Function1, Flowable> { return { future -> Flowable.fromFuture(future) } } @@ -25,6 +25,6 @@ object FlowableAdapter { * @return A [Flowable] from the given [PendingResult]. */ @SuppressLint("CheckResult") -fun PendingResult.toFlowable(): Flowable { +fun PendingResult.toFlowable(): Flowable { return adapt { future -> Flowable.fromFuture(future) } } diff --git a/fotoapparat-adapters/rxjava2/src/main/java/io/fotoapparat/result/adapter/rxjava2/ObservableAdapter.kt b/fotoapparat-adapters/rxjava3/src/main/java/io/fotoapparat/result/adapter/rxjava3/ObservableAdapter.kt similarity index 70% rename from fotoapparat-adapters/rxjava2/src/main/java/io/fotoapparat/result/adapter/rxjava2/ObservableAdapter.kt rename to fotoapparat-adapters/rxjava3/src/main/java/io/fotoapparat/result/adapter/rxjava3/ObservableAdapter.kt index da33aa25..51427ea3 100644 --- a/fotoapparat-adapters/rxjava2/src/main/java/io/fotoapparat/result/adapter/rxjava2/ObservableAdapter.kt +++ b/fotoapparat-adapters/rxjava3/src/main/java/io/fotoapparat/result/adapter/rxjava3/ObservableAdapter.kt @@ -1,8 +1,8 @@ -package io.fotoapparat.result.adapter.rxjava2 +package io.fotoapparat.result.adapter.rxjava3 import android.annotation.SuppressLint import io.fotoapparat.result.PendingResult -import io.reactivex.Observable +import io.reactivex.rxjava3.core.Observable import java.util.concurrent.Future /** @@ -15,7 +15,7 @@ object ObservableAdapter { */ @JvmStatic @SuppressLint("CheckResult") - fun toObservable(): Function1, Observable> { + fun toObservable(): Function1, Observable> { return { future -> Observable.fromFuture(future) } } @@ -25,6 +25,6 @@ object ObservableAdapter { * @return A [Observable] from the given [PendingResult]. */ @SuppressLint("CheckResult") -fun PendingResult.toObservable(): Observable { +fun PendingResult.toObservable(): Observable { return adapt { future -> Observable.fromFuture(future) } } diff --git a/fotoapparat-adapters/rxjava2/src/main/java/io/fotoapparat/result/adapter/rxjava2/SingleAdapter.kt b/fotoapparat-adapters/rxjava3/src/main/java/io/fotoapparat/result/adapter/rxjava3/SingleAdapter.kt similarity index 69% rename from fotoapparat-adapters/rxjava2/src/main/java/io/fotoapparat/result/adapter/rxjava2/SingleAdapter.kt rename to fotoapparat-adapters/rxjava3/src/main/java/io/fotoapparat/result/adapter/rxjava3/SingleAdapter.kt index e9645547..b3fd5c95 100644 --- a/fotoapparat-adapters/rxjava2/src/main/java/io/fotoapparat/result/adapter/rxjava2/SingleAdapter.kt +++ b/fotoapparat-adapters/rxjava3/src/main/java/io/fotoapparat/result/adapter/rxjava3/SingleAdapter.kt @@ -1,8 +1,10 @@ -package io.fotoapparat.result.adapter.rxjava2 +@file:Suppress("unused") + +package io.fotoapparat.result.adapter.rxjava3 import android.annotation.SuppressLint import io.fotoapparat.result.PendingResult -import io.reactivex.Single +import io.reactivex.rxjava3.core.Single import java.util.concurrent.Future /** @@ -15,7 +17,7 @@ object SingleAdapter { */ @JvmStatic @SuppressLint("CheckResult") - fun toSingle(): (Future) -> Single { + fun toSingle(): (Future) -> Single { return { future -> Single.fromFuture(future) } } @@ -25,6 +27,6 @@ object SingleAdapter { * @return A [Single] from the given [PendingResult]. */ @SuppressLint("CheckResult") -fun PendingResult.toSingle(): Single { +fun PendingResult.toSingle(): Single { return adapt { future -> Single.fromFuture(future) } } diff --git a/fotoapparat-adapters/rxjava/src/test/java/io/fotoapparat/result/adapter/rxjava/CallableFuture.kt b/fotoapparat-adapters/rxjava3/src/test/java/io/fotoapparat/result/adapter/rxjava3/CallableFuture.kt similarity index 95% rename from fotoapparat-adapters/rxjava/src/test/java/io/fotoapparat/result/adapter/rxjava/CallableFuture.kt rename to fotoapparat-adapters/rxjava3/src/test/java/io/fotoapparat/result/adapter/rxjava3/CallableFuture.kt index cf245894..f2a6b97b 100644 --- a/fotoapparat-adapters/rxjava/src/test/java/io/fotoapparat/result/adapter/rxjava/CallableFuture.kt +++ b/fotoapparat-adapters/rxjava3/src/test/java/io/fotoapparat/result/adapter/rxjava3/CallableFuture.kt @@ -1,4 +1,4 @@ -package io.fotoapparat.result.adapter.rxjava +package io.fotoapparat.result.adapter.rxjava3 import java.util.concurrent.* diff --git a/fotoapparat-adapters/rxjava2/src/test/java/io/fotoapparat/result/adapter/rxjava2/CompletableAdapterTest.java b/fotoapparat-adapters/rxjava3/src/test/java/io/fotoapparat/result/adapter/rxjava3/CompletableAdapterTest.java similarity index 54% rename from fotoapparat-adapters/rxjava2/src/test/java/io/fotoapparat/result/adapter/rxjava2/CompletableAdapterTest.java rename to fotoapparat-adapters/rxjava3/src/test/java/io/fotoapparat/result/adapter/rxjava3/CompletableAdapterTest.java index c71d961a..cffa47bd 100644 --- a/fotoapparat-adapters/rxjava2/src/test/java/io/fotoapparat/result/adapter/rxjava2/CompletableAdapterTest.java +++ b/fotoapparat-adapters/rxjava3/src/test/java/io/fotoapparat/result/adapter/rxjava3/CompletableAdapterTest.java @@ -1,4 +1,4 @@ -package io.fotoapparat.result.adapter.rxjava2; +package io.fotoapparat.result.adapter.rxjava3; import org.junit.Test; @@ -6,21 +6,16 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; -import io.reactivex.observers.TestObserver; +import io.reactivex.rxjava3.observers.TestObserver; public class CompletableAdapterTest { - private TestObserver observer = new TestObserver<>(); + private final TestObserver observer = new TestObserver<>(); @Test - public void completed() throws Exception { + public void completed() { // Given - Future future = new CallableFuture<>(new Callable() { - @Override - public String call() throws Exception { - return "Hello"; - } - }); + Future future = new CallableFuture<>(() -> "Hello"); // When CompletableAdapter.toCompletable() @@ -35,11 +30,8 @@ public String call() throws Exception { @Test public void error() throws Exception { // Given - Future future = new CallableFuture<>(new Callable() { - @Override - public String call() throws Exception { - throw new RuntimeException("What a failure"); - } + Future future = new CallableFuture<>(() -> { + throw new RuntimeException("What a failure"); }); // When diff --git a/fotoapparat-adapters/rxjava2/src/test/java/io/fotoapparat/result/adapter/rxjava2/FlowableAdapterTest.java b/fotoapparat-adapters/rxjava3/src/test/java/io/fotoapparat/result/adapter/rxjava3/FlowableAdapterTest.java similarity index 51% rename from fotoapparat-adapters/rxjava2/src/test/java/io/fotoapparat/result/adapter/rxjava2/FlowableAdapterTest.java rename to fotoapparat-adapters/rxjava3/src/test/java/io/fotoapparat/result/adapter/rxjava3/FlowableAdapterTest.java index b0e91f36..94800327 100644 --- a/fotoapparat-adapters/rxjava2/src/test/java/io/fotoapparat/result/adapter/rxjava2/FlowableAdapterTest.java +++ b/fotoapparat-adapters/rxjava3/src/test/java/io/fotoapparat/result/adapter/rxjava3/FlowableAdapterTest.java @@ -1,4 +1,4 @@ -package io.fotoapparat.result.adapter.rxjava2; +package io.fotoapparat.result.adapter.rxjava3; import org.junit.Test; @@ -6,21 +6,16 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; -import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.rxjava3.subscribers.TestSubscriber; public class FlowableAdapterTest { - private TestSubscriber observer = new TestSubscriber<>(); + private final TestSubscriber observer = new TestSubscriber<>(); @Test - public void completed() throws Exception { + public void completed() { // Given - Future future = new CallableFuture<>(new Callable() { - @Override - public String call() throws Exception { - return "Hello"; - } - }); + Future future = new CallableFuture<>(() -> "Hello"); // When FlowableAdapter.toFlowable() @@ -33,13 +28,10 @@ public String call() throws Exception { } @Test - public void error() throws Exception { + public void error() { // Given - Future future = new CallableFuture<>(new Callable() { - @Override - public String call() throws Exception { - throw new RuntimeException("What a failure"); - } + Future future = new CallableFuture<>(() -> { + throw new RuntimeException("What a failure"); }); // When diff --git a/fotoapparat-adapters/rxjava2/src/test/java/io/fotoapparat/result/adapter/rxjava2/ObservableAdapterTest.java b/fotoapparat-adapters/rxjava3/src/test/java/io/fotoapparat/result/adapter/rxjava3/ObservableAdapterTest.java similarity index 51% rename from fotoapparat-adapters/rxjava2/src/test/java/io/fotoapparat/result/adapter/rxjava2/ObservableAdapterTest.java rename to fotoapparat-adapters/rxjava3/src/test/java/io/fotoapparat/result/adapter/rxjava3/ObservableAdapterTest.java index b445be34..0c6f9479 100644 --- a/fotoapparat-adapters/rxjava2/src/test/java/io/fotoapparat/result/adapter/rxjava2/ObservableAdapterTest.java +++ b/fotoapparat-adapters/rxjava3/src/test/java/io/fotoapparat/result/adapter/rxjava3/ObservableAdapterTest.java @@ -1,4 +1,4 @@ -package io.fotoapparat.result.adapter.rxjava2; +package io.fotoapparat.result.adapter.rxjava3; import org.junit.Test; @@ -6,21 +6,16 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; -import io.reactivex.observers.TestObserver; +import io.reactivex.rxjava3.observers.TestObserver; public class ObservableAdapterTest { - private TestObserver observer = new TestObserver<>(); + private final TestObserver observer = new TestObserver<>(); @Test - public void completed() throws Exception { + public void completed() { // Given - Future future = new CallableFuture<>(new Callable() { - @Override - public String call() throws Exception { - return "Hello"; - } - }); + Future future = new CallableFuture<>(() -> "Hello"); // When ObservableAdapter.toObservable() @@ -33,13 +28,10 @@ public String call() throws Exception { } @Test - public void error() throws Exception { + public void error() { // Given - Future future = new CallableFuture<>(new Callable() { - @Override - public String call() throws Exception { - throw new RuntimeException("What a failure"); - } + Future future = new CallableFuture<>(() -> { + throw new RuntimeException("What a failure"); }); // When diff --git a/fotoapparat-adapters/rxjava2/src/test/java/io/fotoapparat/result/adapter/rxjava2/SingleAdapterTest.java b/fotoapparat-adapters/rxjava3/src/test/java/io/fotoapparat/result/adapter/rxjava3/SingleAdapterTest.java similarity index 51% rename from fotoapparat-adapters/rxjava2/src/test/java/io/fotoapparat/result/adapter/rxjava2/SingleAdapterTest.java rename to fotoapparat-adapters/rxjava3/src/test/java/io/fotoapparat/result/adapter/rxjava3/SingleAdapterTest.java index f5f92a50..3854f693 100644 --- a/fotoapparat-adapters/rxjava2/src/test/java/io/fotoapparat/result/adapter/rxjava2/SingleAdapterTest.java +++ b/fotoapparat-adapters/rxjava3/src/test/java/io/fotoapparat/result/adapter/rxjava3/SingleAdapterTest.java @@ -1,4 +1,4 @@ -package io.fotoapparat.result.adapter.rxjava2; +package io.fotoapparat.result.adapter.rxjava3; import org.junit.Test; @@ -6,21 +6,16 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; -import io.reactivex.observers.TestObserver; +import io.reactivex.rxjava3.observers.TestObserver; public class SingleAdapterTest { - private TestObserver observer = new TestObserver<>(); + private final TestObserver observer = new TestObserver<>(); @Test - public void completed() throws Exception { + public void completed() { // Given - Future future = new CallableFuture<>(new Callable() { - @Override - public String call() throws Exception { - return "Hello"; - } - }); + Future future = new CallableFuture<>(() -> "Hello"); // When SingleAdapter.toSingle() @@ -33,13 +28,10 @@ public String call() throws Exception { } @Test - public void error() throws Exception { + public void error() { // Given - Future future = new CallableFuture<>(new Callable() { - @Override - public String call() throws Exception { - throw new RuntimeException("What a failure"); - } + Future future = new CallableFuture<>(() -> { + throw new RuntimeException("What a failure"); }); // When diff --git a/fotoapparat/build.gradle b/fotoapparat/build.gradle index 628043e7..ad49f090 100644 --- a/fotoapparat/build.gradle +++ b/fotoapparat/build.gradle @@ -1,41 +1,42 @@ -apply plugin: 'com.android.library' -apply plugin: 'com.github.dcendents.android-maven' -apply plugin: 'kotlin-android' +plugins { + alias(deps.plugins.android.library) + alias(deps.plugins.kotlin.android) +} group = 'io.fotoapparat' android { - buildToolsVersion versions.android.buildTools - compileSdkVersion versions.sdk.target + buildToolsVersion deps.versions.buildTools.get() + compileSdkVersion deps.versions.compileSdk.get().toInteger() defaultConfig { - minSdkVersion versions.sdk.minimum - targetSdkVersion versions.sdk.target + minSdkVersion deps.versions.minSdk.get() + targetSdkVersion deps.versions.compileSdk.get() } - buildTypes { release { minifyEnabled false } } - testOptions { unitTests.returnDefaultValues = true } compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_11 + targetCompatibility JavaVersion.VERSION_11 } + namespace = "io.fotoapparat" } dependencies { - implementation "androidx.annotation:annotation:${versions.android.annotation}" - implementation "androidx.exifinterface:exifinterface:${versions.android.exifinterface}" - implementation "org.jetbrains.kotlin:kotlin-stdlib:${versions.kotlin}" - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.0' - testImplementation "junit:junit:${versions.test.junit}" - testImplementation "org.jetbrains.kotlin:kotlin-test-junit:${versions.kotlin}" - testImplementation "org.mockito:mockito-core:${versions.test.mockito}" + implementation deps.kotlin.stdlib + implementation deps.kotlin.coroutines + implementation deps.androidx.annotation + implementation deps.androidx.exifinterface + + testImplementation deps.junit + testImplementation deps.kotlin.test + testImplementation deps.mockito.core } ext { @@ -47,5 +48,3 @@ ext { libraryDescription = 'Camera library for Android with a more user-friendly API.' } - -apply from: '../deploy.gradle' diff --git a/fotoapparat/src/main/AndroidManifest.xml b/fotoapparat/src/main/AndroidManifest.xml index 47506d04..50116418 100644 --- a/fotoapparat/src/main/AndroidManifest.xml +++ b/fotoapparat/src/main/AndroidManifest.xml @@ -1,8 +1,7 @@ - + - + - + diff --git a/fotoapparat/src/main/java/io/fotoapparat/coroutines/AwaitBroadcastChannel.kt b/fotoapparat/src/main/java/io/fotoapparat/coroutines/AwaitBroadcastChannel.kt index f22bbaf1..4488e1d8 100644 --- a/fotoapparat/src/main/java/io/fotoapparat/coroutines/AwaitBroadcastChannel.kt +++ b/fotoapparat/src/main/java/io/fotoapparat/coroutines/AwaitBroadcastChannel.kt @@ -1,3 +1,5 @@ +@file:Suppress("OPT_IN_USAGE", "OPT_IN_OVERRIDE", "OVERRIDE_DEPRECATION") + package io.fotoapparat.coroutines import kotlinx.coroutines.* @@ -23,7 +25,7 @@ internal class AwaitBroadcastChannel( override fun offer(element: T): Boolean { deferred.complete(true) - return channel.offer(element) + return channel.trySend(element).isSuccess } override suspend fun send(element: T) { diff --git a/fotoapparat/src/main/java/io/fotoapparat/hardware/CameraDevice.kt b/fotoapparat/src/main/java/io/fotoapparat/hardware/CameraDevice.kt index cc07f52f..bc357ae7 100644 --- a/fotoapparat/src/main/java/io/fotoapparat/hardware/CameraDevice.kt +++ b/fotoapparat/src/main/java/io/fotoapparat/hardware/CameraDevice.kt @@ -1,4 +1,4 @@ -@file:Suppress("DEPRECATION") +@file:Suppress("DEPRECATION", "OPT_IN_USAGE", "RemoveRedundantQualifierName", "unused") package io.fotoapparat.hardware @@ -32,6 +32,7 @@ import java.io.IOException import java.util.concurrent.CountDownLatch import java.util.concurrent.TimeUnit import java.util.concurrent.atomic.AtomicReference +import kotlinx.coroutines.ExperimentalCoroutinesApi typealias PreviewSize = io.fotoapparat.parameter.Resolution @@ -39,11 +40,12 @@ typealias PreviewSize = io.fotoapparat.parameter.Resolution * Camera. */ internal open class CameraDevice( - private val logger: Logger, - val characteristics: Characteristics + private val logger: Logger, + val characteristics: Characteristics, ) { private val capabilities = CompletableDeferred() + @OptIn(ExperimentalCoroutinesApi::class) private val cameraParameters = AwaitBroadcastChannel() private lateinit var previewStream: PreviewStream private lateinit var surface: Surface @@ -69,8 +71,8 @@ internal open class CameraDevice( previewStream = PreviewStream(camera) } catch (e: RuntimeException) { throw CameraException( - message = "Failed to open camera with lens position: $lensPosition and id: $cameraId", - cause = e + message = "Failed to open camera with lens position: $lensPosition and id: $cameraId", + cause = e ) } } @@ -94,9 +96,9 @@ internal open class CameraDevice( camera.startPreview() } catch (e: RuntimeException) { throw CameraException( - message = "Failed to start preview for camera with lens " + - "position: ${characteristics.lensPosition} and id: ${characteristics.cameraId}", - cause = e + message = "Failed to start preview for camera with lens " + + "position: ${characteristics.lensPosition} and id: ${characteristics.cameraId}", + cause = e ) } } @@ -168,8 +170,8 @@ internal open class CameraDevice( logger.log("New camera parameters are: $cameraParameters") cameraParameters.applyInto(cachedCameraParameters ?: camera.parameters) - .cacheLocally() - .setInCamera() + .cacheLocally() + .setInCamera() } /** @@ -188,30 +190,32 @@ internal open class CameraDevice( logger.recordMethod() imageOrientation = computeImageOrientation( - deviceOrientation = orientationState.deviceOrientation, - cameraOrientation = characteristics.cameraOrientation, - cameraIsMirrored = characteristics.isMirrored + deviceOrientation = orientationState.deviceOrientation, + cameraOrientation = characteristics.cameraOrientation, + cameraIsMirrored = characteristics.isMirrored ) displayOrientation = computeDisplayOrientation( - screenOrientation = orientationState.screenOrientation, - cameraOrientation = characteristics.cameraOrientation, - cameraIsMirrored = characteristics.isMirrored + screenOrientation = orientationState.screenOrientation, + cameraOrientation = characteristics.cameraOrientation, + cameraIsMirrored = characteristics.isMirrored ) previewOrientation = computePreviewOrientation( - screenOrientation = orientationState.screenOrientation, - cameraOrientation = characteristics.cameraOrientation, - cameraIsMirrored = characteristics.isMirrored + screenOrientation = orientationState.screenOrientation, + cameraOrientation = characteristics.cameraOrientation, + cameraIsMirrored = characteristics.isMirrored ) - logger.log("Orientations: $lineSeparator" + + logger.log( + "Orientations: $lineSeparator" + "Screen orientation (preview) is: ${orientationState.screenOrientation}. " + lineSeparator + "Camera sensor orientation is always at: ${characteristics.cameraOrientation}. " + lineSeparator + "Camera is " + if (characteristics.isMirrored) "mirrored." else "not mirrored." ) - logger.log("Orientation adjustments: $lineSeparator" + + logger.log( + "Orientation adjustments: $lineSeparator" + "Image orientation will be adjusted by: ${imageOrientation.degrees} degrees. " + lineSeparator + "Display orientation will be adjusted by: ${displayOrientation.degrees} degrees. " + lineSeparator + "Preview orientation will be adjusted by: ${previewOrientation.degrees} degrees." @@ -304,11 +308,11 @@ internal open class CameraDevice( private fun setZoomUnsafe(@FloatRange(from = 0.0, to = 1.0) level: Float) { (cachedCameraParameters ?: camera.parameters) - .apply { - zoom = (maxZoom * level).toInt() - } - .cacheLocally() - .setInCamera() + .apply { + zoom = (maxZoom * level).toInt() + } + .cacheLocally() + .setInCamera() } private fun Camera.Parameters.cacheLocally() = apply { @@ -341,8 +345,8 @@ internal open class CameraDevice( private suspend fun Camera.updateFocusingAreas(focalRequest: FocalRequest) { val focusingAreas = focalRequest.toFocusAreas( - displayOrientationDegrees = displayOrientation.degrees, - cameraIsMirrored = characteristics.isMirrored + displayOrientationDegrees = displayOrientation.degrees, + cameraIsMirrored = characteristics.isMirrored ) parameters = parameters.apply { @@ -377,17 +381,16 @@ private fun Camera.takePhoto(imageRotation: Int): Photo { val photoReference = AtomicReference() takePicture( - null, - null, - null, - Camera.PictureCallback { data, _ -> - photoReference.set( - Photo(data, imageRotation) - ) - - latch.countDown() - } - ) + null, + null, + null + ) { data, _ -> + photoReference.set( + Photo(data, imageRotation) + ) + + latch.countDown() + } latch.await() @@ -396,29 +399,29 @@ private fun Camera.takePhoto(imageRotation: Int): Photo { @Throws(IOException::class) private fun Camera.setDisplaySurface( - preview: Preview + preview: Preview, ): Surface = when (preview) { is Preview.Texture -> preview.surfaceTexture - .also(this::setPreviewTexture) - .let(::Surface) + .also(this::setPreviewTexture) + .let(::Surface) is Preview.Surface -> preview.surfaceHolder - .also(this::setPreviewDisplay) - .surface + .also(this::setPreviewDisplay) + .surface } private fun Camera.getPreviewResolution(previewOrientation: Orientation): Resolution { return parameters.previewSize - .run { - PreviewSize(width, height) - } - .run { - when (previewOrientation) { - is Orientation.Vertical -> this - is Orientation.Horizontal -> flipDimensions() - } + .run { + PreviewSize(width, height) + } + .run { + when (previewOrientation) { + is Orientation.Vertical -> this + is Orientation.Horizontal -> flipDimensions() } + } } private fun Capabilities.canSetFocusingAreas(): Boolean = - maxMeteringAreas > 0 || maxFocusAreas > 0 + maxMeteringAreas > 0 || maxFocusAreas > 0 diff --git a/fotoapparat/src/main/java/io/fotoapparat/hardware/Device.kt b/fotoapparat/src/main/java/io/fotoapparat/hardware/Device.kt index 452a8930..5f289c4d 100644 --- a/fotoapparat/src/main/java/io/fotoapparat/hardware/Device.kt +++ b/fotoapparat/src/main/java/io/fotoapparat/hardware/Device.kt @@ -1,4 +1,4 @@ -@file:Suppress("DEPRECATION") +@file:Suppress("DEPRECATION", "unused") package io.fotoapparat.hardware @@ -19,6 +19,7 @@ import io.fotoapparat.util.FrameProcessor import io.fotoapparat.view.CameraRenderer import io.fotoapparat.view.FocalPointSelector import kotlinx.coroutines.CompletableDeferred +import kotlinx.coroutines.ExperimentalCoroutinesApi /** * Phone. @@ -93,6 +94,7 @@ internal open class Device( * @throws IllegalStateException If no camera has been yet selected. * @throws UnsupportedLensException If no camera could get selected. */ + @OptIn(ExperimentalCoroutinesApi::class) open fun getSelectedCamera(): CameraDevice = try { selectedCameraDevice.getCompleted() } catch (e: IllegalStateException) { diff --git a/fotoapparat/src/main/java/io/fotoapparat/hardware/display/Display.kt b/fotoapparat/src/main/java/io/fotoapparat/hardware/display/Display.kt index d9b2866a..4c5e295b 100644 --- a/fotoapparat/src/main/java/io/fotoapparat/hardware/display/Display.kt +++ b/fotoapparat/src/main/java/io/fotoapparat/hardware/display/Display.kt @@ -14,12 +14,12 @@ import io.fotoapparat.hardware.orientation.Orientation.Vertical.ReversePortrait */ internal open class Display(context: Context) { - private val display = context.getDisplay() + private val display = context.getDefaultDisplay() /** * Returns the orientation of the screen. */ - open fun getOrientation(): Orientation = when (display.rotation) { + open fun getOrientation(): Orientation = when (display?.rotation) { Surface.ROTATION_0 -> Portrait Surface.ROTATION_90 -> Landscape Surface.ROTATION_180 -> ReversePortrait @@ -29,4 +29,5 @@ internal open class Display(context: Context) { } -private fun Context.getDisplay() = (getSystemService(Context.WINDOW_SERVICE) as WindowManager).defaultDisplay +@Suppress("DEPRECATION") +private fun Context.getDefaultDisplay() = (getSystemService(Context.WINDOW_SERVICE) as WindowManager).defaultDisplay diff --git a/fotoapparat/src/main/java/io/fotoapparat/selector/PreviewFpsRangeSelectors.kt b/fotoapparat/src/main/java/io/fotoapparat/selector/PreviewFpsRangeSelectors.kt index 033307bd..c050a510 100644 --- a/fotoapparat/src/main/java/io/fotoapparat/selector/PreviewFpsRangeSelectors.kt +++ b/fotoapparat/src/main/java/io/fotoapparat/selector/PreviewFpsRangeSelectors.kt @@ -77,8 +77,8 @@ fun lowestFixedFps(): FpsRangeSelector = filtered( predicate = { it.isFixed } ) -private fun highestRangeFps(): FpsRangeSelector = { maxWith(CompareFpsRangeByBounds) } +private fun highestRangeFps(): FpsRangeSelector = { maxWithOrNull(CompareFpsRangeByBounds) } -private fun lowestRangeFps(): FpsRangeSelector = { minWith(CompareFpsRangeByBounds) } +private fun lowestRangeFps(): FpsRangeSelector = { minWithOrNull(CompareFpsRangeByBounds) } private fun Float.toFpsIntRepresentation() = (this * 1000).toInt() \ No newline at end of file diff --git a/fotoapparat/src/main/java/io/fotoapparat/selector/ResolutionSelectors.kt b/fotoapparat/src/main/java/io/fotoapparat/selector/ResolutionSelectors.kt index 1d534b03..665d145f 100644 --- a/fotoapparat/src/main/java/io/fotoapparat/selector/ResolutionSelectors.kt +++ b/fotoapparat/src/main/java/io/fotoapparat/selector/ResolutionSelectors.kt @@ -7,9 +7,9 @@ typealias ResolutionSelector = Iterable.() -> Resolution? /** * @return Selector function which always provides the biggest resolution. */ -fun highestResolution(): ResolutionSelector = { maxBy(Resolution::area) } +fun highestResolution(): ResolutionSelector = { maxByOrNull(Resolution::area) } /** * @return Selector function which always provides the smallest resolution. */ -fun lowestResolution(): ResolutionSelector = { minBy(Resolution::area) } \ No newline at end of file +fun lowestResolution(): ResolutionSelector = { minByOrNull(Resolution::area) } \ No newline at end of file diff --git a/fotoapparat/src/main/java/io/fotoapparat/selector/Selectors.kt b/fotoapparat/src/main/java/io/fotoapparat/selector/Selectors.kt index 4a197211..c3fff647 100644 --- a/fotoapparat/src/main/java/io/fotoapparat/selector/Selectors.kt +++ b/fotoapparat/src/main/java/io/fotoapparat/selector/Selectors.kt @@ -19,12 +19,12 @@ fun single(preference: T): Iterable.() -> T? = { /** * @return Selector function which selects highest [Comparable] value. */ -fun > highest(): Iterable.() -> T? = Iterable::max +fun > highest(): Iterable.() -> T? = Iterable::maxOrNull /** * @return Selector function which selects lowest [Comparable] value. */ -fun > lowest(): Iterable.() -> T? = Iterable::min +fun > lowest(): Iterable.() -> T? = Iterable::minOrNull /** * @param functions functions in order of importance. @@ -33,7 +33,7 @@ fun > lowest(): Iterable.() -> T? = Iterable::min */ @SafeVarargs fun firstAvailable( - vararg functions: Input.() -> Output? + vararg functions: Input.() -> Output?, ): Input.() -> Output? = { functions.findNonNull { it(this) @@ -48,17 +48,15 @@ fun firstAvailable( * condition. */ fun filtered( - selector: Iterable.() -> T?, - predicate: (T) -> Boolean + selector: Iterable.() -> T?, + predicate: (T) -> Boolean, ): Iterable.() -> T? = { selector(filter(predicate = predicate)) } private fun Array.findNonNull(selector: (T) -> R?): R? { - forEach { - selector(it)?.let { - return it - } + forEach { outer -> + selector(outer)?.let { return it } } return null diff --git a/fotoapparat/src/main/java/io/fotoapparat/util/StringExtensions.kt b/fotoapparat/src/main/java/io/fotoapparat/util/StringExtensions.kt index 96c03c05..ac645725 100644 --- a/fotoapparat/src/main/java/io/fotoapparat/util/StringExtensions.kt +++ b/fotoapparat/src/main/java/io/fotoapparat/util/StringExtensions.kt @@ -3,7 +3,7 @@ package io.fotoapparat.util /** * System line separator. */ -internal val lineSeparator = System.getProperty("line.separator") +internal val lineSeparator = System.lineSeparator() /** * Prints a [Set] in logcat in a structured way. diff --git a/fotoapparat/src/test/java/io/fotoapparat/FotoapparatBuilderTest.kt b/fotoapparat/src/test/java/io/fotoapparat/FotoapparatBuilderTest.kt index 214c6bea..e65fe1fe 100644 --- a/fotoapparat/src/test/java/io/fotoapparat/FotoapparatBuilderTest.kt +++ b/fotoapparat/src/test/java/io/fotoapparat/FotoapparatBuilderTest.kt @@ -10,7 +10,9 @@ import io.fotoapparat.parameter.ScaleType import io.fotoapparat.selector.* import io.fotoapparat.util.FrameProcessor import io.fotoapparat.view.CameraRenderer -import junit.framework.Assert.* +import kotlin.test.assertEquals +import kotlin.test.assertNotNull +import kotlin.test.assertNull import org.junit.Before import org.junit.Test import org.junit.runner.RunWith @@ -55,7 +57,7 @@ class FotoapparatBuilderTest { @Before fun setUp() { given(context.getSystemService(Context.WINDOW_SERVICE)) - .willReturn(Mockito.mock(WindowManager::class.java)) + .willReturn(Mockito.mock(WindowManager::class.java)) } @Test @@ -94,12 +96,12 @@ class FotoapparatBuilderTest { fun `lens position is configurable`() { // When val builder = builderWithMandatoryArguments() - .lensPosition(lensPositionSelector) + .lensPosition(lensPositionSelector) // Then assertEquals( - lensPositionSelector, - builder.lensPositionSelector + lensPositionSelector, + builder.lensPositionSelector ) } @@ -116,12 +118,12 @@ class FotoapparatBuilderTest { fun `logger is configurable`() { // When val builder = builderWithMandatoryArguments() - .logger(logger) + .logger(logger) // Then assertEquals( - logger, - builder.logger + logger, + builder.logger ) } @@ -138,12 +140,12 @@ class FotoapparatBuilderTest { fun `focusMode is configurable`() { // When val builder = builderWithMandatoryArguments() - .focusMode(focusModeSelector) + .focusMode(focusModeSelector) // Then assertEquals( - focusModeSelector, - builder.configuration.focusMode + focusModeSelector, + builder.configuration.focusMode ) } @@ -160,12 +162,12 @@ class FotoapparatBuilderTest { fun `previewFpsRange is configurable`() { // When val builder = builderWithMandatoryArguments() - .previewFpsRange(previewFpsRangeSelector) + .previewFpsRange(previewFpsRangeSelector) // Then assertEquals( - previewFpsRangeSelector, - builder.configuration.previewFpsRange + previewFpsRangeSelector, + builder.configuration.previewFpsRange ) } @@ -182,12 +184,12 @@ class FotoapparatBuilderTest { fun `flashMode is configurable`() { // When val builder = builderWithMandatoryArguments() - .flash(flashSelector) + .flash(flashSelector) // Then assertEquals( - flashSelector, - builder.configuration.flashMode + flashSelector, + builder.configuration.flashMode ) } @@ -205,12 +207,12 @@ class FotoapparatBuilderTest { fun `sensorSensitivity is configurable`() { // When val builder = builderWithMandatoryArguments() - .sensorSensitivity(sensorSensitivitySelector) + .sensorSensitivity(sensorSensitivitySelector) // Then assertEquals( - sensorSensitivitySelector, - builder.configuration.sensorSensitivity + sensorSensitivitySelector, + builder.configuration.sensorSensitivity ) } @@ -227,12 +229,12 @@ class FotoapparatBuilderTest { fun `jpegQuality is configurable`() { // When val builder = builderWithMandatoryArguments() - .jpegQuality(jpegQualitySelector) + .jpegQuality(jpegQualitySelector) // Then assertEquals( - jpegQualitySelector, - builder.configuration.jpegQuality + jpegQualitySelector, + builder.configuration.jpegQuality ) } @@ -249,12 +251,12 @@ class FotoapparatBuilderTest { fun `frameProcessor is configurable`() { // When val builder = builderWithMandatoryArguments() - .frameProcessor(frameProcessor) + .frameProcessor(frameProcessor) // Then assertEquals( - frameProcessor, - builder.configuration.frameProcessor + frameProcessor, + builder.configuration.frameProcessor ) } @@ -262,12 +264,12 @@ class FotoapparatBuilderTest { fun `photoResolution is configurable`() { // When val builder = builderWithMandatoryArguments() - .photoResolution(photoResolutionSelector) + .photoResolution(photoResolutionSelector) // Then assertEquals( - photoResolutionSelector, - builder.configuration.pictureResolution + photoResolutionSelector, + builder.configuration.pictureResolution ) } @@ -284,12 +286,12 @@ class FotoapparatBuilderTest { fun `previewResolution is configurable`() { // When val builder = builderWithMandatoryArguments() - .previewResolution(previewResolutionSelector) + .previewResolution(previewResolutionSelector) // Then assertEquals( - previewResolutionSelector, - builder.configuration.previewResolution + previewResolutionSelector, + builder.configuration.previewResolution ) } @@ -306,12 +308,12 @@ class FotoapparatBuilderTest { fun `previewStyle is configurable`() { // When val builder = builderWithMandatoryArguments() - .previewScaleType(ScaleType.CenterInside) + .previewScaleType(ScaleType.CenterInside) // Then assertEquals( - ScaleType.CenterInside, - builder.scaleType + ScaleType.CenterInside, + builder.scaleType ) } @@ -328,17 +330,17 @@ class FotoapparatBuilderTest { fun `cameraErrorCallback is configurable`() { // When val builder = builderWithMandatoryArguments() - .cameraErrorCallback(cameraErrorCallback) + .cameraErrorCallback(cameraErrorCallback) // Then assertEquals( - cameraErrorCallback, - builder.cameraErrorCallback + cameraErrorCallback, + builder.cameraErrorCallback ) } private fun builderWithMandatoryArguments(): FotoapparatBuilder { return FotoapparatBuilder(context) - .into(cameraRenderer) + .into(cameraRenderer) } } \ No newline at end of file diff --git a/gradle/deps.versions.toml b/gradle/deps.versions.toml new file mode 100644 index 00000000..37f722dc --- /dev/null +++ b/gradle/deps.versions.toml @@ -0,0 +1,31 @@ +[versions] +kotlin = "1.8.10" +android-plugin = "7.4.2" +buildTools = "33.0.2" +compileSdk = "33" +minSdk = "21" + +junit = "4.13.2" +mockito = "4.11.0" +appcompat = "1.6.1" +annotation = "1.6.0" +exifinterface = "1.3.6" + + +[libraries] +rx-java = { module = "io.reactivex.rxjava3:rxjava", version = "3.1.6" } +rx-kotlin = { module = "io.reactivex.rxjava3:rxkotlin", version = "3.0.1" } +androidx-annotation = { module = "androidx.annotation:annotation", version.ref = "annotation" } +androidx-exifinterface = { module = "androidx.exifinterface:exifinterface", version.ref = "exifinterface" } +androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appcompat" } +kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" } +kotlin-coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version = "1.6.4" } +junit = { module = "junit:junit", version.ref = "junit" } +kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlin" } +mockito-core = { module = "org.mockito:mockito-core", version.ref = "mockito" } + +[plugins] +kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } +android-library = { id = "com.android.library", version.ref = "android-plugin" } +android-application = { id = "com.android.application", version.ref = "android-plugin" } + diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 29953ea1..943f0cbf 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index d757f3d3..bdc9a83b 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip +networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip diff --git a/gradlew b/gradlew index cccdd3d5..65dcd68d 100755 --- a/gradlew +++ b/gradlew @@ -1,78 +1,129 @@ -#!/usr/bin/env sh +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -81,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" + JAVACMD=java which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the @@ -89,84 +140,105 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=$((i+1)) + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=$(save "$@") - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" - -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" fi +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index e95643d6..6689b85b 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,4 +1,20 @@ -@if "%DEBUG%" == "" @echo off +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -9,19 +25,23 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -35,7 +55,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -45,38 +65,26 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/sample/build.gradle b/sample/build.gradle index 4d4096c5..13e1c9f3 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -1,15 +1,16 @@ -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' +plugins { + alias(deps.plugins.android.application) + alias(deps.plugins.kotlin.android) +} android { - buildToolsVersion versions.android.buildTools - compileSdkVersion versions.sdk.target + buildToolsVersion deps.versions.buildTools.get() + compileSdkVersion deps.versions.compileSdk.get().toInteger() defaultConfig { applicationId "io.fotoapparat.sample" - minSdkVersion versions.sdk.minimum - targetSdkVersion versions.sdk.target + minSdkVersion deps.versions.minSdk.get() + targetSdkVersion deps.versions.compileSdk.get() versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -20,10 +21,18 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + buildFeatures { + viewBinding true + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_11 + targetCompatibility JavaVersion.VERSION_11 + } + namespace = "io.fotoapparat.sample" } dependencies { implementation project(':fotoapparat') - implementation "org.jetbrains.kotlin:kotlin-stdlib:${versions.kotlin}" - implementation "androidx.appcompat:appcompat:${versions.android.appcompat}" + implementation deps.kotlin.stdlib + implementation deps.androidx.appcompat } diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index 8db8e5da..662d0e62 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -1,7 +1,6 @@ + xmlns:tools="http://schemas.android.com/tools"> diff --git a/sample/src/main/java/io/fotoapparat/sample/MainActivity.kt b/sample/src/main/java/io/fotoapparat/sample/MainActivity.kt index 0410994b..5efe9b0c 100644 --- a/sample/src/main/java/io/fotoapparat/sample/MainActivity.kt +++ b/sample/src/main/java/io/fotoapparat/sample/MainActivity.kt @@ -13,14 +13,15 @@ import io.fotoapparat.log.logcat import io.fotoapparat.parameter.Flash import io.fotoapparat.parameter.Zoom import io.fotoapparat.result.transformer.scaled +import io.fotoapparat.sample.databinding.ActivityMainBinding import io.fotoapparat.selector.* -import kotlinx.android.synthetic.main.activity_main.* import java.io.File import kotlin.math.roundToInt class MainActivity : AppCompatActivity() { private val permissionsDelegate = PermissionsDelegate(this) + private lateinit var binding: ActivityMainBinding private var permissionsGranted: Boolean = false private var activeCamera: Camera = Camera.Back @@ -37,24 +38,24 @@ class MainActivity : AppCompatActivity() { permissionsGranted = permissionsDelegate.hasCameraPermission() if (permissionsGranted) { - cameraView.visibility = View.VISIBLE + binding.cameraView.visibility = View.VISIBLE } else { permissionsDelegate.requestCameraPermission() } fotoapparat = Fotoapparat( context = this, - view = cameraView, - focusView = focusView, + view = binding.cameraView, + focusView = binding.focusView, logger = logcat(), lensPosition = activeCamera.lensPosition, cameraConfiguration = activeCamera.configuration, cameraErrorCallback = { Log.e(LOGGING_TAG, "Camera error: ", it) } ) - capture onClick takePicture() - switchCamera onClick changeCamera() - torchSwitch onCheckedChanged toggleFlash() + binding.capture onClick takePicture() + binding.switchCamera onClick changeCamera() + binding.torchSwitch onCheckedChanged toggleFlash() } private fun takePicture(): () -> Unit = { @@ -97,7 +98,7 @@ class MainActivity : AppCompatActivity() { adjustViewsVisibility() - torchSwitch.isChecked = false + binding.torchSwitch.isChecked = false Log.i(LOGGING_TAG, "New camera position: ${if (activeCamera is Camera.Back) "back" else "front"}") } @@ -140,7 +141,7 @@ class MainActivity : AppCompatActivity() { permissionsGranted = true fotoapparat.start() adjustViewsVisibility() - cameraView.visibility = View.VISIBLE + binding.cameraView.visibility = View.VISIBLE } } @@ -152,21 +153,21 @@ class MainActivity : AppCompatActivity() { (it.zoom as? Zoom.VariableZoom) ?.let { cameraZoom = it - focusView.scaleListener = this::scaleZoom - focusView.ptrListener = this::pointerChanged + binding.focusView.scaleListener = this::scaleZoom + binding.focusView.ptrListener = this::pointerChanged } ?: run { - zoomLvl?.visibility = View.GONE - focusView.scaleListener = null - focusView.ptrListener = null + binding.zoomLvl.visibility = View.GONE + binding.focusView.scaleListener = null + binding.focusView.ptrListener = null } - torchSwitch.visibility = if (it.flashModes.contains(Flash.Torch)) View.VISIBLE else View.GONE + binding.torchSwitch.visibility = if (it.flashModes.contains(Flash.Torch)) View.VISIBLE else View.GONE } ?: Log.e(LOGGING_TAG, "Couldn't obtain capabilities.") } - switchCamera.visibility = if (fotoapparat.isAvailable(front())) View.VISIBLE else View.GONE + binding.switchCamera.visibility = if (fotoapparat.isAvailable(front())) View.VISIBLE else View.GONE } //When zooming slowly, the values are approximately 0.9 ~ 1.1 @@ -182,13 +183,13 @@ class MainActivity : AppCompatActivity() { val value = cameraZoom.zoomRatios[progress] val roundedValue = ((value.toFloat()) / 10).roundToInt().toFloat() / 10 - zoomLvl.visibility = View.VISIBLE - zoomLvl.text = String.format("%.1f×", roundedValue) + binding.zoomLvl.visibility = View.VISIBLE + binding.zoomLvl.text = String.format("%.1f×", roundedValue) } private fun pointerChanged(fingerCount: Int){ if(fingerCount == 0) { - zoomLvl?.visibility = View.GONE + binding.zoomLvl.visibility = View.GONE } } } diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index d16de12d..00000000 --- a/settings.gradle +++ /dev/null @@ -1,6 +0,0 @@ -include ':fotoapparat' - -include ':fotoapparat-adapters:rxjava' -include ':fotoapparat-adapters:rxjava2' - -include ':sample' \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 00000000..081f4096 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,31 @@ +@file:Suppress("UnstableApiUsage") + +import org.gradle.api.initialization.resolve.RepositoriesMode + +pluginManagement { + repositories { + google(); mavenCentral(); gradlePluginPortal() + } +} + +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + // uncomment if you published local changes to test + // DO NOT MERGE THIS UNCOMMENTED + // mavenLocal() + google() + mavenCentral() + gradlePluginPortal() + } + versionCatalogs { + create("deps") { + from(files("gradle/deps.versions.toml")) + // Update versions and dependencies not used in tooling here. + } + } +} + +include(":fotoapparat") +include(":fotoapparat-adapters:rxjava3") +include(":sample") \ No newline at end of file