Skip to content

Commit

Permalink
Merge pull request #172 from contentful/fix/migrate_to_rxjava3
Browse files Browse the repository at this point in the history
fix: Migrate to rxjava3
  • Loading branch information
rafalniski authored Feb 1, 2023
2 parents a48538e + e05f02f commit 379267f
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 74 deletions.
2 changes: 1 addition & 1 deletion compiler/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.contentful.vault</groupId>
<artifactId>vault-parent</artifactId>
<version>3.2.6-SNAPSHOT</version>
<version>3.2.7-SNAPSHOT</version>
</parent>

<artifactId>compiler</artifactId>
Expand Down
5 changes: 3 additions & 2 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.contentful.vault</groupId>
<artifactId>vault-parent</artifactId>
<version>3.2.6-SNAPSHOT</version>
<version>3.2.7-SNAPSHOT</version>
</parent>

<artifactId>core</artifactId>
Expand Down Expand Up @@ -33,8 +33,9 @@
</dependency>

<dependency>
<groupId>io.reactivex.rxjava2</groupId>
<groupId>io.reactivex.rxjava3</groupId>
<artifactId>rxjava</artifactId>
<version>3.0.0</version>
<scope>provided</scope>
</dependency>

Expand Down
24 changes: 13 additions & 11 deletions core/src/main/java/com/contentful/vault/ObserveQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@

import java.util.List;

import io.reactivex.BackpressureStrategy;
import io.reactivex.Flowable;
import io.reactivex.FlowableEmitter;
import io.reactivex.FlowableOnSubscribe;
import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.BackpressureStrategy;
import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.core.FlowableEmitter;
import io.reactivex.rxjava3.core.FlowableOnSubscribe;

public final class ObserveQuery<T extends Resource> extends AbsQuery<T, ObserveQuery<T>> {
ObserveQuery(Class<T> type, Vault vault) {
Expand All @@ -45,25 +46,26 @@ public AllOnSubscribe(ObserveQuery<T> query, String locale) {
this.locale = locale;
}

@Override public void subscribe(FlowableEmitter<T> flowableEmitter) throws Exception {
@Override
public void subscribe(@NonNull FlowableEmitter<T> emitter) {
try {
FetchQuery<T> fetchQuery = query.vault().fetch(query.type());
fetchQuery.setParams(query.params());
List<T> items = fetchQuery.all(locale);
for (T item : items) {
if (flowableEmitter.isCancelled()) {
if (emitter.isCancelled()) {
return;
}
flowableEmitter.onNext(item);
emitter.onNext(item);
}
} catch (Throwable t) {
if (!flowableEmitter.isCancelled()) {
flowableEmitter.onError(t);
if (!emitter.isCancelled()) {
emitter.onError(t);
}
return;
}
if (!flowableEmitter.isCancelled()) {
flowableEmitter.onComplete();
if (!emitter.isCancelled()) {
emitter.onComplete();
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions core/src/main/java/com/contentful/vault/Vault.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
import android.os.Handler;
import android.os.Looper;

import com.contentful.java.cda.CDAClient;
import io.reactivex.rxjava3.core.BackpressureStrategy;
import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.subjects.PublishSubject;
import io.reactivex.rxjava3.subjects.Subject;

import java.util.HashMap;
import java.util.LinkedHashMap;
Expand All @@ -31,11 +34,6 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import io.reactivex.BackpressureStrategy;
import io.reactivex.Flowable;
import io.reactivex.subjects.PublishSubject;
import io.reactivex.subjects.Subject;

public class Vault {
public static final String ACTION_SYNC_COMPLETE = "com.contentful.vault.ACTION_SYNC_COMPLETE";

Expand Down
42 changes: 0 additions & 42 deletions core/src/test/java/com/contentful/vault/ObserveTest.java

This file was deleted.

2 changes: 1 addition & 1 deletion last-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>vault-parent</artifactId>
<groupId>com.contentful.vault</groupId>
<version>3.2.6-SNAPSHOT</version>
<version>3.2.7-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<groupId>com.contentful.vault</groupId>
<artifactId>vault-parent</artifactId>
<version>3.2.6-SNAPSHOT</version>
<version>3.2.7-SNAPSHOT</version>
<packaging>pom</packaging>

<modules>
Expand Down Expand Up @@ -47,7 +47,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.7</java.version>

<android.platform>19</android.platform>
<android.platform>30</android.platform>
<android.version>4.1.1.4</android.version>
<cda.version>10.1.0</cda.version>
<commons-codec.version>1.10</commons-codec.version>
Expand All @@ -59,12 +59,12 @@
<junit.version>4.12</junit.version>
<okhttp.version>3.10.0</okhttp.version>
<robolectric.version>3.8</robolectric.version>
<rxjava.version>2.1.1</rxjava.version>
<rxjava.version>3.1.6</rxjava.version>
<truth.version>0.34</truth.version>
<mockito.version>2.8.47</mockito.version>

<!-- Build Dependencies -->
<build-helper.version>3.0.0</build-helper.version>
<build-helper.version>3.3.0</build-helper.version>
</properties>

<dependencyManagement>
Expand All @@ -82,7 +82,7 @@
</dependency>

<dependency>
<groupId>io.reactivex.rxjava2</groupId>
<groupId>io.reactivex.rxjava3</groupId>
<artifactId>rxjava</artifactId>
<version>${rxjava.version}</version>
</dependency>
Expand Down Expand Up @@ -233,7 +233,7 @@
<plugin>
<groupId>com.simpligility.maven.plugins</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>4.5.0</version>
<version>4.6.0</version>
<configuration>
<sdk>
<platform>${android.platform}</platform>
Expand Down
4 changes: 2 additions & 2 deletions tests-integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.contentful.vault</groupId>
<artifactId>vault-parent</artifactId>
<version>3.2.6-SNAPSHOT</version>
<version>3.2.7-SNAPSHOT</version>
</parent>

<artifactId>tests-integration</artifactId>
Expand Down Expand Up @@ -79,7 +79,7 @@
</dependency>

<dependency>
<groupId>io.reactivex.rxjava2</groupId>
<groupId>io.reactivex.rxjava3</groupId>
<artifactId>rxjava</artifactId>
<scope>test</scope>
</dependency>
Expand Down
2 changes: 1 addition & 1 deletion tests-integration/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
android:versionName="1.0"
package="com.contentful.vaultintegration">

<uses-sdk android:minSdkVersion="17" android:targetSdkVersion="19"/>
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="30"/>

<application android:label="label" />
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
import com.contentful.vaultintegration.lib.demo.Cat$Fields;
import com.contentful.vaultintegration.lib.demo.DemoSpace;
import java.util.List;

import io.reactivex.rxjava3.subscribers.TestSubscriber;
import org.junit.Test;
import org.robolectric.RuntimeEnvironment;

import io.reactivex.subscribers.TestSubscriber;

import static com.google.common.truth.Truth.assertThat;

Expand Down
2 changes: 1 addition & 1 deletion tests-integration/src/test/resources/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
android:versionName="1.0"
package="com.contentful.vaultintegration">

<uses-sdk android:minSdkVersion="17" android:targetSdkVersion="19"/>
<uses-sdk android:minSdkVersion="17" android:targetSdkVersion="21"/>

<application android:label="label" />
</manifest>

0 comments on commit 379267f

Please sign in to comment.