Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgraded RxJava from version 2 to 3 #933

Open
wants to merge 7 commits into
base: gsoc2022
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ ext {
supportConstraintLayout = 'androidx.constraintlayout:constraintlayout:2.0.1'

androidxPreference = 'androidx.preference:preference:1.1.1'
androidRoom = 'androidx.room:room-runtime:2.2.5'
androidRoomRxJava = 'androidx.room:room-rxjava2:2.2.5'
supportRoom = 'androidx.room:room-compiler:2.2.5'
androidRoom = 'androidx.room:room-runtime:2.4.2'
androidRoomRxJava = 'androidx.room:room-rxjava3:2.4.2'
supportRoom = 'androidx.room:room-compiler:2.4.2'


def lifecycle_version = "2.2.0"
Expand All @@ -102,17 +102,19 @@ ext {
retrofit2 = "com.squareup.retrofit2:retrofit:$retrofit_version"
retrofitGson2 = "com.squareup.retrofit2:converter-gson:$retrofit_version"
retrofitAdapters2 = "com.squareup.retrofit2:retrofit-adapters:$retrofit_version"
retrofitRxJava2 = "com.squareup.retrofit2:adapter-rxjava2:$retrofit_version"
retrofitRxJava3 = "com.squareup.retrofit2:adapter-rxjava3:2.9.0"

// RxJava dependencies.
rxJava = 'io.reactivex.rxjava2:rxjava:2.2.21'
rxAndroid = 'io.reactivex.rxjava2:rxandroid:2.1.1'
rxPreferences = 'com.f2prateek.rx.preferences2:rx-preferences:2.0.1'
rxJava = 'io.reactivex.rxjava3:rxjava:3.1.5'
rxAndroid = 'io.reactivex.rxjava3:rxandroid:3.0.0'
//rxPreferences = 'com.f2prateek.rx.preferences2:rx-preferences:2.0.1'
rxPreferences= "dev.drewhamilton.rxpreferences:rxpreferences:3.0.0"
rxPreferences= "dev.drewhamilton.rxpreferences:rxpreferences-dagger:3.0.0"

// RxBindings
def rxbinding_version = "3.1.0"
rxBindingCore = "com.jakewharton.rxbinding3:rxbinding-core:$rxbinding_version"
rxBindingAppCompat = "com.jakewharton.rxbinding3:rxbinding-appcompat:$rxbinding_version"
def rxbinding_version = "4.0.0"
rxBindingCore = "com.jakewharton.rxbinding4:rxbinding-core:$rxbinding_version"
rxBindingAppCompat = "com.jakewharton.rxbinding4:rxbinding-appcompat:$rxbinding_version"


// Google dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.envirocar.obd.events.PropertyKeyEvent;
import org.envirocar.obd.events.Timestamped;

import io.reactivex.Observable;
import io.reactivex.rxjava3.core.Observable;

/**
* TODO JavaDoc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

import javax.inject.Inject;

import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.rxjava3.disposables.CompositeDisposable;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import com.f2prateek.rx.preferences2.RxSharedPreferences;

import com.squareup.otto.Bus;
import com.squareup.otto.ThreadEnforcer;

Expand Down Expand Up @@ -150,11 +150,6 @@ SharedPreferences provideSharedPreferences(@InjectApplicationScope Context conte
return PreferenceManager.getDefaultSharedPreferences(context);
}

@Provides
@Singleton
RxSharedPreferences provideRxSharedPreferences(SharedPreferences prefs){
return RxSharedPreferences.create(prefs);
}

/**
* Provides the CacheDirectoryProvider.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,26 @@
*/
package org.envirocar.app.handler;

import android.Manifest;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.util.Pair;

import androidx.core.app.ActivityCompat;
import androidx.preference.PreferenceManager;

import com.f2prateek.rx.preferences2.RxSharedPreferences;
import dev.drewhamilton.rxpreferences.dagger.RxPreferencesComponent;

import dev.drewhamilton.rxpreferences.dagger.RxPreferencesComponent;
import com.google.common.base.Preconditions;

import org.envirocar.app.R;
import org.envirocar.app.recording.RecordingType;

import io.reactivex.Observable;
import dev.drewhamilton.rxpreferences.RxPreferences;
import io.reactivex.rxjava3.core.Observable;

/**
* TODO JavaDoc
Expand Down Expand Up @@ -77,8 +83,7 @@ public class ApplicationSettings {
// General Settings settings
public static Observable<Boolean> getAutomaticUploadObservable(Context context){
return getRxSharedPreferences(context)
.getBoolean(s(context, R.string.prefkey_automatic_upload), DEFAULT_AUTOMATIC_UPLOAD)
.asObservable();
.getBooleanStream(s(context, R.string.prefkey_automatic_upload), DEFAULT_AUTOMATIC_UPLOAD);
}

public static boolean isDisplayStaysActive(Context context) {
Expand All @@ -87,8 +92,7 @@ public static boolean isDisplayStaysActive(Context context) {

public static Observable<Boolean> getDisplayStaysActiveObservable(Context context) {
return getRxSharedPreferences(context)
.getBoolean(s(context, R.string.prefkey_display_always_active), DEFAULT_DISPLAY_STAYS_ACTIVE)
.asObservable();
.getBooleanStream(s(context, R.string.prefkey_display_always_active), DEFAULT_DISPLAY_STAYS_ACTIVE);
}

public static boolean isObfuscationEnabled(Context context) {
Expand All @@ -101,8 +105,7 @@ public static boolean isTrackchunkUploadEnabled(Context context) {

public static Observable<Boolean> getObfuscationObservable(Context context) {
return getRxSharedPreferences(context)
.getBoolean(s(context, R.string.prefkey_privacy), false)
.asObservable();
.getBooleanStream(s(context, R.string.prefkey_privacy), false);
}

public static boolean isTextToSpeechEnabled(Context context) {
Expand All @@ -111,8 +114,7 @@ public static boolean isTextToSpeechEnabled(Context context) {

public static Observable<Boolean> getTextToSpeechObservable(Context context) {
return getRxSharedPreferences(context)
.getBoolean(s(context, R.string.prefkey_text_to_speech), DEFAULT_TEXT_TO_SPEECH)
.asObservable();
.getBooleanStream(s(context, R.string.prefkey_text_to_speech), DEFAULT_TEXT_TO_SPEECH);
}

public static boolean isAutorecordingEnabled(Context context) {
Expand All @@ -122,8 +124,7 @@ public static boolean isAutorecordingEnabled(Context context) {

public static Observable<Boolean> getAutoconnectEnabledObservable(final Context context) {
return getRxSharedPreferences(context)
.getBoolean(s(context, R.string.prefkey_automatic_recording), DEFAULT_BLUETOOTH_AUTOCONNECT)
.asObservable();
.getBooleanStream(s(context, R.string.prefkey_automatic_recording), DEFAULT_BLUETOOTH_AUTOCONNECT);
}

public static int getDiscoveryInterval(Context context) {
Expand All @@ -133,8 +134,7 @@ public static int getDiscoveryInterval(Context context) {

public static Observable<Integer> getDiscoveryIntervalObservable(Context context) {
return getRxSharedPreferences(context)
.getInteger(s(context, R.string.prefkey_search_interval), DEFAULT_BLUETOOTH_DISCOVERY_INTERVAL)
.asObservable();
.getIntStream(s(context, R.string.prefkey_search_interval), DEFAULT_BLUETOOTH_DISCOVERY_INTERVAL);
}

public static void setDiscoveryInterval(Context context, int discoveryInterval) {
Expand All @@ -158,14 +158,12 @@ public static void setSamplingRate(Context context, int samplingRate) {

public static Observable<Integer> getRxSharedSamplingRate(Context context) {
return getRxSharedPreferences(context)
.getInteger(s(context, R.string.prefkey_samplingrate), DEFAULT_SAMPLING_RATE)
.asObservable();
.getIntStream(s(context, R.string.prefkey_samplingrate), DEFAULT_SAMPLING_RATE);
}

public static Observable<Boolean> getDebugLoggingObservable(Context context) {
return getRxSharedPreferences(context)
.getBoolean(s(context, R.string.prefkey_enable_debug_logging), DEFAULT_DEBUG_LOGGING)
.asObservable();
.getBooleanStream(s(context, R.string.prefkey_enable_debug_logging), DEFAULT_DEBUG_LOGGING);
}

public static boolean isDieselConsumptionEnabled(Context context) {
Expand All @@ -174,14 +172,12 @@ public static boolean isDieselConsumptionEnabled(Context context) {

public static Observable<Boolean> getDieselConsumptionObservable(Context context) {
return getRxSharedPreferences(context)
.getBoolean(s(context, R.string.prefkey_enable_diesel_consumption), false)
.asObservable();
.getBooleanStream(s(context, R.string.prefkey_enable_diesel_consumption), false);
}

public static Observable<Integer> getTrackTrimDurationObservable(final Context context) {
return RxSharedPreferences.create(getSharedPreferences(context))
.getInteger(s(context, R.string.prefkey_track_trim_duration), DEFAULT_TRACK_TRIM_DURATION)
.asObservable();
return getRxSharedPreferences(context)
.getIntStream(s(context, R.string.prefkey_track_trim_duration), DEFAULT_TRACK_TRIM_DURATION);
}

public static void setTrackTrimDurationObservable(final Context context, int trackTrimDuration) {
Expand Down Expand Up @@ -209,14 +205,14 @@ public static void setSelectedRecordingType(final Context context, RecordingType
}

public static Observable<RecordingType> getSelectedRecordingTypeObservable(final Context context) {
return RxSharedPreferences.create(getSharedPreferences(context))
.getEnum(PREF_RECORDING_TYPE, DEFAULT_RECORDING_TYPE, RecordingType.class)
.asObservable();
return getRxSharedPreferences(context)
.getStringStream(PREF_RECORDING_TYPE, "OBD_ADAPTER_BASED")
.map(RecordingType::valueOf);
}

public static Observable<Pair<String, String>> getSelectedBluetoothAdapterObservable(Context context) {
return getRxSharedPreferences(context)
.getString(PREF_SELECTED_BLUETOOTH_ADDRESS).asObservable()
.getStringStream(PREF_SELECTED_BLUETOOTH_ADDRESS, "")
.map(address -> {
String name = getSharedPreferences(context).getString(PREF_SELECTED_BLUETOOTH_NAME, "");
return new Pair(name, address);
Expand All @@ -227,6 +223,10 @@ public static void setSelectedBluetoothAdapter(Context context, BluetoothDevice
if (device == null) {
resetSelectedBluetoothAdapter(context);
} else {
if (ActivityCompat.checkSelfPermission(context,
Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
return;
}
getSharedPreferences(context)
.edit()
.putString(PREF_SELECTED_BLUETOOTH_NAME, device.getName())
Expand All @@ -243,8 +243,8 @@ public static void resetSelectedBluetoothAdapter(Context context) {
.apply();
}

private static RxSharedPreferences getRxSharedPreferences(Context context) {
return RxSharedPreferences.create(getSharedPreferences(context));
private static RxPreferences getRxSharedPreferences(Context context) {
return RxPreferencesComponent.create(getSharedPreferences(context)).rxPreferences();
}

public static SharedPreferences getSharedPreferences(Context context) {
Expand All @@ -254,8 +254,7 @@ public static SharedPreferences getSharedPreferences(Context context) {

public static Observable<String> getCampaignProfileObservable(Context context){
return getRxSharedPreferences(context)
.getString(s(context, R.string.prefkey_campaign_profile), DEFAULT_CAMPAIGN_PROFILE)
.asObservable();
.getStringStream(s(context, R.string.prefkey_campaign_profile), DEFAULT_CAMPAIGN_PROFILE);
}

public static String getCampaignProfile(Context context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@
import javax.inject.Inject;
import javax.inject.Singleton;

import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.Scheduler;
import io.reactivex.observers.DisposableObserver;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.ObservableEmitter;
import io.reactivex.rxjava3.core.Scheduler;
import io.reactivex.rxjava3.observers.DisposableObserver;
import io.reactivex.rxjava3.schedulers.Schedulers;

/**
* @author dewall
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import java.util.List;
import java.util.Map;

import io.reactivex.Observable;
import io.reactivex.rxjava3.core.Observable;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
import javax.inject.Inject;
import javax.inject.Singleton;

import io.reactivex.Observable;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.schedulers.Schedulers;

/**
* TODO JavaDoc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@

import javax.inject.Inject;

import io.reactivex.Completable;
import io.reactivex.Observable;
import io.reactivex.Single;
import io.reactivex.functions.Function;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.rxjava3.core.Completable;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Single;
import io.reactivex.rxjava3.functions.Function;
import io.reactivex.rxjava3.schedulers.Schedulers;


/**
Expand Down Expand Up @@ -216,8 +216,7 @@ private Single<Track> getActiveTrackReference(boolean createNew) {
.flatMap(track -> track.isEmpty() ?
mEnvirocarDB.getActiveTrackObservable(false)
.map(t -> new Optional(t))
.singleOrError()
.onErrorResumeNext(Single.just(track)) :
.singleOrError():
Single.just(track))

.flatMap(validateTrackRef(createNew))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@
import javax.inject.Inject;
import javax.inject.Singleton;

import io.reactivex.Observable;
import io.reactivex.ObservableOperator;
import io.reactivex.ObservableTransformer;
import io.reactivex.Observer;
import io.reactivex.functions.Function;
import io.reactivex.observers.DisposableObserver;
import io.reactivex.rxjava3.core.Observable;

import io.reactivex.rxjava3.core.ObservableTransformer;
import io.reactivex.rxjava3.core.ObservableOperator;
import io.reactivex.rxjava3.core.ObservableOperator;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.functions.Function;
import io.reactivex.rxjava3.observers.DisposableObserver;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@
import javax.inject.Inject;
import javax.inject.Singleton;

import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.ObservableTransformer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Function;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.observers.DisposableCompletableObserver;
import io.reactivex.observers.DisposableObserver;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.ObservableTransformer;
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.ObservableSource;
import io.reactivex.rxjava3.functions.Function;
import io.reactivex.rxjava3.schedulers.Schedulers;
import io.reactivex.rxjava3.observers.DisposableCompletableObserver;
import io.reactivex.rxjava3.observers.DisposableObserver;

/**
* TODO JavaDoc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
import javax.inject.Inject;
import javax.inject.Singleton;

import io.reactivex.Observable;
import io.reactivex.rxjava3.core.Observable;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import javax.inject.Inject;
import javax.inject.Singleton;

import io.reactivex.Completable;
import io.reactivex.rxjava3.core.Completable;

/**
* TODO JavaDoc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

import javax.inject.Inject;

import io.reactivex.observers.DisposableObserver;
import io.reactivex.rxjava3.observers.DisposableObserver;


/**
Expand Down
Loading