Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

Commit

Permalink
Use rxjava3
Browse files Browse the repository at this point in the history
  • Loading branch information
p1gp1g committed Mar 6, 2023
1 parent 94b3e4d commit 773862c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 36 deletions.
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ dependencies {
implementation("com.github.nextcloud:Android-SingleSignOn:0.6.1")
implementation("com.squareup.retrofit2:retrofit:$retrofitVersion")
implementation("com.squareup.retrofit2:converter-gson:$retrofitVersion")
implementation("com.squareup.retrofit2:adapter-rxjava2:$retrofitVersion")
implementation("io.reactivex.rxjava2:rxjava:2.2.21")
implementation("com.squareup.retrofit2:adapter-rxjava3:$retrofitVersion")
implementation("io.reactivex.rxjava3:rxjava:3.1.5")
implementation("io.reactivex.rxjava3:rxandroid:3.0.2")
implementation("androidx.work:work-runtime-ktx:2.8.0")
implementation("com.google.android.material:material:1.8.0")
}
46 changes: 15 additions & 31 deletions app/src/main/java/org/unifiedpush/distributor/nextpush/api/Api.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package org.unifiedpush.distributor.nextpush.api
import android.content.Context
import android.os.Build
import android.util.Log
import io.reactivex.Observer
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.observers.DisposableObserver
import io.reactivex.rxjava3.schedulers.Schedulers
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.sse.EventSource
Expand Down Expand Up @@ -50,13 +50,9 @@ class Api(val context: Context) {
try {
withApiProvider { apiProvider ->
apiProvider.createDevice(parameters)
?.subscribeOn(Schedulers.newThread())
?.observeOn(Schedulers.newThread())
?.subscribe(object : Observer<ApiResponse?> {
override fun onSubscribe(d: Disposable) {
Log.d(TAG, "onSubscribe")
}

?.subscribeOn(Schedulers.io())
?.observeOn(AndroidSchedulers.mainThread())
?.subscribe(object : DisposableObserver<ApiResponse?>() {
override fun onNext(response: ApiResponse) {
response.deviceId.let {
context.deviceId = it
Expand Down Expand Up @@ -102,13 +98,9 @@ class Api(val context: Context) {
try {
withApiProvider { apiProvider ->
apiProvider.deleteDevice(deviceId)
?.subscribeOn(Schedulers.newThread())
?.observeOn(Schedulers.newThread())
?.subscribe(object : Observer<ApiResponse?> {
override fun onSubscribe(d: Disposable) {
Log.d(TAG, "Subscribed to deleteDevice.")
}

?.subscribeOn(Schedulers.io())
?.observeOn(AndroidSchedulers.mainThread())
?.subscribe(object : DisposableObserver<ApiResponse?>() {
override fun onNext(response: ApiResponse) {
if (response.success) {
Log.d(TAG, "Device successfully deleted.")
Expand Down Expand Up @@ -146,13 +138,9 @@ class Api(val context: Context) {
try {
withApiProvider { apiProvider ->
apiProvider.createApp(parameters)
?.subscribeOn(Schedulers.newThread())
?.observeOn(Schedulers.newThread())
?.subscribe(object : Observer<ApiResponse?> {
override fun onSubscribe(d: Disposable) {
Log.d(TAG, "Subscribed to createApp.")
}

?.subscribeOn(Schedulers.io())
?.observeOn(AndroidSchedulers.mainThread())
?.subscribe(object : DisposableObserver<ApiResponse?>() {
override fun onNext(response: ApiResponse) {
val nextpushToken = if (response.success) {
Log.d(TAG, "App successfully created.")
Expand Down Expand Up @@ -181,13 +169,9 @@ class Api(val context: Context) {
try {
withApiProvider { apiProvider ->
apiProvider.deleteApp(nextpushToken)
?.subscribeOn(Schedulers.newThread())
?.observeOn(Schedulers.newThread())
?.subscribe(object : Observer<ApiResponse?> {
override fun onSubscribe(d: Disposable) {
Log.d(TAG, "Subscribed to deleteApp.")
}

?.subscribeOn(Schedulers.io())
?.observeOn(AndroidSchedulers.mainThread())
?.subscribe(object : DisposableObserver<ApiResponse?>() {
override fun onNext(response: ApiResponse) {
if (response.success) {
Log.d(TAG, "App successfully deleted.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import okhttp3.* // ktlint-disable no-wildcard-imports
import org.unifiedpush.distributor.nextpush.account.Account.getAccount
import org.unifiedpush.distributor.nextpush.api.provider.ApiProvider.Companion.mApiEndpoint
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory

class ApiDirectFactory(val context: Context) : ApiProviderFactory {
Expand All @@ -23,7 +23,7 @@ class ApiDirectFactory(val context: Context) : ApiProviderFactory {
Retrofit.Builder()
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addCallAdapterFactory(RxJava3CallAdapterFactory.create())
.baseUrl("$url$mApiEndpoint").build()
.create(ApiProvider::class.java).let {
block(it)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.unifiedpush.distributor.nextpush.api.provider

import io.reactivex.Observable
import io.reactivex.rxjava3.core.Observable
import org.unifiedpush.distributor.nextpush.api.response.ApiResponse
import retrofit2.http.Body
import retrofit2.http.DELETE
Expand Down

0 comments on commit 773862c

Please sign in to comment.