Skip to content

Commit

Permalink
RxJava2升级为RxJava3
Browse files Browse the repository at this point in the history
  • Loading branch information
catchpig committed Nov 22, 2020
1 parent 126b8c9 commit 78853b4
Show file tree
Hide file tree
Showing 22 changed files with 90 additions and 89 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

### 5. 将在Application中初始化移至到ContentProvider中,从而不用封装BaseApplication

### 6. AOP(面向切面)封装注解:TimeLog、ClickGap
### 6. AOP(面向切面)封装注解:TimeLog、ClickGap、MethodLog

### 7. APT(编译时注解)封装注解:OnClickFirstDrawable、OnClickFirstText、OnClickSecondDrawable、OnClickSecondText、Prefs、PrefsField、StatusBar

Expand Down Expand Up @@ -220,7 +220,7 @@ kapt "com.github.catch-pig.kotlin-mvp:compiler:last_version"

### [Koin](https://github.com/InsertKoinIO/koin)

### [RxJava](https://github.com/ReactiveX/RxJava)
### [RxJava3](https://github.com/ReactiveX/RxJava)

### [RxAndroid](https://github.com/ReactiveX/RxAndroid)

Expand Down
3 changes: 0 additions & 3 deletions app/src/main/java/com/catchpig/kotlin_mvp/di/NetWorkModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ package com.catchpig.kotlin_mvp.di

import com.catchpig.kotlin_mvp.Config
import com.catchpig.kotlin_mvp.network.api.WanAndroidService
import okhttp3.OkHttpClient
import org.koin.dsl.module
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

val networkModule = module {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.catchpig.annotation.Title
import com.catchpig.kotlin_mvp.R
import com.catchpig.kotlin_mvp.mvp.apk.InstallApkContract
import com.catchpig.mvp.base.activity.BasePresenterActivity
import com.tbruyelle.rxpermissions2.RxPermissions
import com.tbruyelle.rxpermissions3.RxPermissions
import kotlinx.android.synthetic.main.activity_install_apk.*
import org.koin.core.parameter.parametersOf
import org.koin.core.scope.inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import android.view.View
import com.catchpig.annotation.*
import com.catchpig.kotlin_mvp.R
import com.catchpig.mvp.base.activity.BaseActivity
import io.reactivex.Flowable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.core.Flowable
import java.util.concurrent.TimeUnit

@Title(R.string.child_title)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package com.catchpig.kotlin_mvp.mvp.main

import com.catchpig.kotlin_mvp.network.Result
import com.catchpig.mvp.base.BaseContract
import com.catchpig.mvp.bean.DownloadInfo
import com.catchpig.mvp.network.listener.DownloadCallback
import io.reactivex.Flowable
import io.reactivex.rxjava3.core.Flowable

/**
* @author catchpig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ package com.catchpig.kotlin_mvp.mvp.main.model
import com.catchpig.kotlin_mvp.mvp.main.MainContract
import com.catchpig.kotlin_mvp.network.Result
import com.catchpig.kotlin_mvp.network.api.WanAndroidService
import com.catchpig.mvp.bean.DownloadInfo
import com.catchpig.mvp.network.listener.DownloadCallback
import com.catchpig.mvp.network.download.DownloadManager
import io.reactivex.Flowable
import io.reactivex.rxjava3.core.Flowable

class MainModel(private val wanAndroidService: WanAndroidService):MainContract.Model {
override fun banner(): Flowable<Result<Any>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import com.catchpig.utils.ext.logd
import com.google.android.material.appbar.AppBarLayout
import com.gyf.immersionbar.ktx.immersionBar
import com.scwang.smart.refresh.layout.api.RefreshLayout
import io.reactivex.Flowable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.subscribers.ResourceSubscriber
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.core.Flowable
import io.reactivex.rxjava3.subscribers.ResourceSubscriber
import kotlinx.android.synthetic.main.activity_recycle.*
import kotlinx.android.synthetic.main.layout_header.view.*
import java.util.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.catchpig.kotlin_mvp.network

import com.catchpig.utils.ext.loge
import io.reactivex.subscribers.ResourceSubscriber
import io.reactivex.rxjava3.subscribers.ResourceSubscriber

abstract class Callback<T>:ResourceSubscriber<T>() {
override fun onError(t: Throwable?) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.catchpig.kotlin_mvp.network.api

import com.catchpig.kotlin_mvp.network.Result
import io.reactivex.Flowable
import io.reactivex.rxjava3.core.Flowable
import retrofit2.http.GET


Expand Down
17 changes: 13 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ buildscript {
kotlin_mvp = '1.2.4'
koin_version = '2.2.1'
okhttp3_version = '3.14.0'
retrofit2_version = '2.6.0'
rxjava_version = '2.2.11'
rxandroid_version = '2.1.1'
retrofit2_version = '2.9.0'
rxjava_version = '3.0.0'
rxandroid_version = '3.0.0'
gson_version = '2.8.5'
glide_version = '4.9.0'
immersionbar_version = '3.0.0-beta05'
Expand All @@ -30,9 +30,18 @@ buildscript {
aspectj_version = '1.9.6'
auto_service_version = '1.0-rc6'
kotlinpoet_version = '1.4.0'
rxpermissions_version = "0.11"
rxpermissions_version = "0.12"
}
repositories {
maven{
url 'https://maven.aliyun.com/repository/public'
}
maven{
url 'https://maven.aliyun.com/repository/google'
}
maven{
url 'https://maven.aliyun.com/repository/gradle-plugin'
}
google()
jcenter()
maven { url 'https://jitpack.io' }
Expand Down
8 changes: 4 additions & 4 deletions mvp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ dependencies {

//retrofit2
api "com.squareup.retrofit2:retrofit:$retrofit2_version"
api "com.squareup.retrofit2:adapter-rxjava2:$retrofit2_version"
api "com.squareup.retrofit2:adapter-rxjava3:$retrofit2_version"
api "com.squareup.retrofit2:converter-gson:$retrofit2_version"

//rxjava
api "io.reactivex.rxjava2:rxjava:$rxjava_version"
api "io.reactivex.rxjava2:rxandroid:$rxandroid_version"
//rxjava3
api "io.reactivex.rxjava3:rxjava:$rxjava_version"
api "io.reactivex.rxjava3:rxandroid:$rxandroid_version"



Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.catchpig.mvp

import androidx.test.InstrumentationRegistry
import androidx.test.runner.AndroidJUnit4
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith

/**
* Instrumented test, which will execute on an Android device.
*
* @see [Testing documentation](http://d.android.com/tools/testing)
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getTargetContext()
Assert.assertEquals("com.catchpig.mvp.test", appContext.packageName)
}
}
6 changes: 3 additions & 3 deletions mvp/src/main/java/com/catchpig/mvp/base/BaseContract.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
import com.catchpig.mvp.base.activity.BaseActivity
import io.reactivex.Flowable
import io.reactivex.disposables.Disposable
import io.reactivex.subscribers.ResourceSubscriber
import io.reactivex.rxjava3.core.Flowable
import io.reactivex.rxjava3.disposables.Disposable
import io.reactivex.rxjava3.subscribers.ResourceSubscriber

/**
* @author catchpig
Expand Down
8 changes: 4 additions & 4 deletions mvp/src/main/java/com/catchpig/mvp/base/BasePresenter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package com.catchpig.mvp.base

import androidx.annotation.CallSuper
import com.catchpig.mvp.ext.io2main
import io.reactivex.Flowable
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.disposables.Disposable
import io.reactivex.subscribers.ResourceSubscriber
import io.reactivex.rxjava3.core.Flowable
import io.reactivex.rxjava3.disposables.CompositeDisposable
import io.reactivex.rxjava3.disposables.Disposable
import io.reactivex.rxjava3.subscribers.ResourceSubscriber


/**
Expand Down
6 changes: 3 additions & 3 deletions mvp/src/main/java/com/catchpig/mvp/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import org.koin.core.qualifier.named
import org.koin.dsl.bind
import org.koin.dsl.module
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import java.util.*
import java.util.concurrent.TimeUnit
Expand Down Expand Up @@ -55,7 +55,7 @@ val appModule = module {
factory {
Retrofit
.Builder()
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addCallAdapterFactory(RxJava3CallAdapterFactory.create())
.client(get())
}
}
Expand All @@ -79,7 +79,7 @@ val downloadModule = module {
Retrofit
.Builder()
.baseUrl(baseUrl)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addCallAdapterFactory(RxJava3CallAdapterFactory.create())
.client(get(named(DOWNLOAD_NAME)){ parametersOf(downloadProgressListener,timeout)})
.addConverterFactory(GsonConverterFactory.create())
.build()
Expand Down
7 changes: 4 additions & 3 deletions mvp/src/main/java/com/catchpig/mvp/ext/RxJavaExt.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.catchpig.mvp.ext

import io.reactivex.Flowable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.core.Flowable
import io.reactivex.rxjava3.schedulers.Schedulers


/**
* 被观察者在io线程中执行,观察者在主线程中执行
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import com.catchpig.mvp.di.DOWNLOAD_NAME
import com.catchpig.mvp.ext.io2main
import com.catchpig.mvp.network.listener.DownloadCallback
import com.catchpig.mvp.provider.KotlinMvpContentProvider
import io.reactivex.Flowable
import io.reactivex.schedulers.Schedulers
import io.reactivex.rxjava3.core.Flowable
import io.reactivex.rxjava3.schedulers.Schedulers
import okhttp3.ResponseBody
import org.koin.core.parameter.parametersOf
import org.koin.core.qualifier.named
Expand Down Expand Up @@ -61,6 +61,11 @@ class DownloadManager {
}.io2main().subscribeWith(downloadSubscriber)
}

/**
* 生成文件的地址
* @param downloadUrl String
* @return String
*/
private fun localFileName(downloadUrl:String):String{
val fileName = downloadUrl.replace("/","").replace("\\","")
var cashDir = if (Environment.MEDIA_MOUNTED == Environment.getExternalStorageState()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.catchpig.mvp.network.download

import io.reactivex.Flowable
import io.reactivex.rxjava3.core.Flowable
import okhttp3.ResponseBody
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.Streaming
import retrofit2.http.Url
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.catchpig.mvp.network.download
import com.catchpig.mvp.network.listener.DownloadCallback
import com.catchpig.mvp.network.listener.DownloadProgressListener
import com.catchpig.utils.ext.logd
import io.reactivex.subscribers.ResourceSubscriber
import io.reactivex.rxjava3.subscribers.ResourceSubscriber
import java.lang.ref.WeakReference
/**
* 下载观察者
Expand Down
17 changes: 0 additions & 17 deletions mvp/src/test/java/com/catchpig/mvp/ExampleUnitTest.java

This file was deleted.

16 changes: 16 additions & 0 deletions mvp/src/test/java/com/catchpig/mvp/ExampleUnitTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.catchpig.mvp

import org.junit.Assert
import org.junit.Test

/**
* Example local unit test, which will execute on the development machine (host).
*
* @see [Testing documentation](http://d.android.com/tools/testing)
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
Assert.assertEquals(4, 2 + 2.toLong())
}
}

0 comments on commit 78853b4

Please sign in to comment.