Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
升级 rxjava2 为 rxjava3
Browse files Browse the repository at this point in the history
  • Loading branch information
z-chu committed Jul 31, 2020
1 parent 1b58b1b commit c548092
Show file tree
Hide file tree
Showing 23 changed files with 139 additions and 198 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.21'
ext.kotlin_version = '1.3.72'
repositories {
jcenter()
maven {
Expand All @@ -11,9 +11,9 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.android.tools.build:gradle:4.2.0-alpha02'

classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath "guru.stefma.bintrayrelease:bintrayrelease:1.1.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
Expand Down
6 changes: 2 additions & 4 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#Fri Feb 15 13:36:39 SGT 2019
#Thu Jul 30 18:08:36 CST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
org.gradle.daemon=true
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
org.gradle.parallel=true
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-rc-1-all.zip
8 changes: 6 additions & 2 deletions rxcache-kotlin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ android {
abortOnError false
checkReleaseBuilds false
}
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
compileOnly 'com.google.code.gson:gson:2.8.5'
compileOnly 'io.reactivex.rxjava2:rxjava:2.2.0'
compileOnly 'com.google.code.gson:gson:2.8.6'
implementation "io.reactivex.rxjava3:rxjava:3.0.4"
compileOnly project(':rxcache')
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.zchu.rxcache.RxCache
import com.zchu.rxcache.data.CacheResult
import com.zchu.rxcache.stategy.IFlowableStrategy
import com.zchu.rxcache.stategy.IObservableStrategy
import io.reactivex.*
import io.reactivex.rxjava3.core.*

inline fun <reified T> RxCache.load(key: String): Observable<CacheResult<T>> {
return load<T>(key, object : TypeToken<T>() {}.type)
Expand Down
11 changes: 8 additions & 3 deletions rxcache/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ android {
abortOnError false
}

compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}

}

dependencies {
compileOnly 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'io.reactivex.rxjava2:rxjava:2.2.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
implementation 'com.google.code.gson:gson:2.8.5'
implementation "io.reactivex.rxjava3:rxjava:3.0.4"
implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.jakewharton:disklrucache:2.0.2'
}

Expand Down
23 changes: 12 additions & 11 deletions rxcache/src/main/java/com/zchu/rxcache/RxCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import android.os.Environment;
import android.os.StatFs;

import androidx.annotation.NonNull;

import com.zchu.rxcache.data.CacheResult;
import com.zchu.rxcache.diskconverter.IDiskConverter;
import com.zchu.rxcache.diskconverter.SerializableDiskConverter;
Expand All @@ -17,17 +19,16 @@
import java.lang.reflect.Type;
import java.security.MessageDigest;

import androidx.annotation.NonNull;
import io.reactivex.BackpressureStrategy;
import io.reactivex.Flowable;
import io.reactivex.FlowableEmitter;
import io.reactivex.FlowableOnSubscribe;
import io.reactivex.FlowableTransformer;
import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.ObservableSource;
import io.reactivex.ObservableTransformer;
import io.reactivex.rxjava3.core.BackpressureStrategy;
import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.core.FlowableEmitter;
import io.reactivex.rxjava3.core.FlowableOnSubscribe;
import io.reactivex.rxjava3.core.FlowableTransformer;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.ObservableEmitter;
import io.reactivex.rxjava3.core.ObservableOnSubscribe;
import io.reactivex.rxjava3.core.ObservableSource;
import io.reactivex.rxjava3.core.ObservableTransformer;


/**
Expand Down
16 changes: 9 additions & 7 deletions rxcache/src/main/java/com/zchu/rxcache/RxCacheHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import android.annotation.SuppressLint;

import androidx.annotation.NonNull;

import com.zchu.rxcache.data.CacheResult;
import com.zchu.rxcache.data.ResultFrom;
import com.zchu.rxcache.utils.LogUtils;
Expand All @@ -11,13 +13,13 @@
import java.lang.reflect.Type;
import java.util.ConcurrentModificationException;

import io.reactivex.Flowable;
import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.ObservableSource;
import io.reactivex.rxjava3.functions.Consumer;
import io.reactivex.rxjava3.functions.Function;
import io.reactivex.rxjava3.schedulers.Schedulers;


/**
* author : zchu
Expand Down
3 changes: 2 additions & 1 deletion rxcache/src/main/java/com/zchu/rxcache/data/CacheResult.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.zchu.rxcache.data;

import io.reactivex.functions.Function;

import io.reactivex.rxjava3.functions.Function;

/**
* 数据
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

public class GsonDiskConverter implements IDiskConverter {

private Gson mGson = new Gson();
private final Gson mGson;


public GsonDiskConverter() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.zchu.rxcache.stategy;

import androidx.annotation.NonNull;

import com.zchu.rxcache.CacheTarget;
import com.zchu.rxcache.RxCache;
import com.zchu.rxcache.RxCacheHelper;
Expand All @@ -10,10 +12,10 @@
import java.lang.reflect.Type;
import java.util.Arrays;

import io.reactivex.Flowable;
import io.reactivex.Observable;
import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Predicate;
import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.functions.Predicate;


/**
* 先缓存,后网络
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

import java.lang.reflect.Type;

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

/**
* 优先缓存
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@

import java.lang.reflect.Type;

import io.reactivex.Flowable;
import io.reactivex.Observable;
import io.reactivex.functions.Predicate;
import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.functions.Predicate;


/**
* 优先缓存并可设置超时时间
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
import java.lang.reflect.Type;
import java.util.Arrays;

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


/**
* 优先网络
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import java.lang.reflect.Type;

import io.reactivex.Flowable;
import io.reactivex.rxjava3.core.Flowable;


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

import java.lang.reflect.Type;

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


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

import java.lang.reflect.Type;

import io.reactivex.Flowable;
import io.reactivex.Observable;
import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Function;
import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.functions.Function;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

import java.lang.reflect.Type;

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


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

import java.lang.reflect.Type;

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


/**
Expand Down
25 changes: 16 additions & 9 deletions rxcache/src/main/java/com/zchu/rxcache/utils/LogUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,45 @@ private LogUtils() {

public static void log(Object message) {
StackTraceElement element = new Throwable().getStackTrace()[1];
print(element, message, null);
print(false, element, message, null);
}
public static void log(Object message, Throwable error) {
StackTraceElement element = new Throwable().getStackTrace()[1];
print(element, message, error);
print(false, element, message, error);
}

public static void debug(Object message) {
if (DEBUG) {
StackTraceElement element = new Throwable().getStackTrace()[1];
print(element, message, null);
print(true, element, message, null);
}
}
public static void debug(Object message, Throwable error) {
if (DEBUG) {
StackTraceElement element = new Throwable().getStackTrace()[1];
print(element, message, error);
print(true, element, message, error);
}
}



private static void print(StackTraceElement element, Object message, Throwable error) {
private static void print(boolean isDebug, StackTraceElement element, Object message, Throwable error) {
String className = element.getClassName();
className = className.substring(className.lastIndexOf('.') + 1);
String tag = className+'.'+element.getMethodName()+'('+element.getFileName()+':'+element.getLineNumber()+')';
String tag = className + '.' + element.getMethodName() + '(' + element.getFileName() + ':' + element.getLineNumber() + ')';
String text = toString(message);

if (error != null) {
Log.e("[RxCache]", tag + "\n\t" + text, error);
if (isDebug) {
Log.d("[RxCache]", tag + "\n\t" + text, error);
} else {
Log.e("[RxCache]", tag + "\n\t" + text, error);
}
} else {
Log.e("[RxCache]", tag + "\n\t" + text);
if (isDebug) {
Log.d("[RxCache]", tag + "\n\t" + text);
} else {
Log.e("[RxCache]", tag + "\n\t" + text);
}
}
}

Expand Down
29 changes: 18 additions & 11 deletions sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
android {
compileSdkVersion 28
compileSdkVersion 29

defaultConfig {
applicationId "com.zchu.sample"
minSdkVersion 14
targetSdkVersion 28
targetSdkVersion 29
versionCode 1
versionName "1.0"

Expand All @@ -23,22 +23,29 @@ android {
abortOnError false
}

compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.1', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
testImplementation 'junit:junit:4.12'
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
implementation 'io.reactivex.rxjava2:rxjava:2.2.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
implementation 'com.squareup.okio:okio:1.15.0'
implementation 'com.squareup.okhttp3:okhttp:3.12.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
testImplementation 'junit:junit:4.13'


implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.9.0'
implementation 'com.squareup.retrofit2:adapter-rxjava3:2.9.0'
implementation "io.reactivex.rxjava3:rxjava:3.0.4"
implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'

implementation 'com.squareup.okio:okio:2.2.2'
implementation 'com.squareup.okhttp3:okhttp:3.14.9'
implementation 'com.zchu:zlog:1.0.1'

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Expand Down
Loading

0 comments on commit c548092

Please sign in to comment.