├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ ├── dimens.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── values-w820dp │ │ │ │ └── dimens.xml │ │ │ └── layout │ │ │ │ └── activity_main.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── zhj │ │ │ │ └── retrofitwithrxjavademo │ │ │ │ ├── util │ │ │ │ ├── BuildConfig.java │ │ │ │ ├── APIException.java │ │ │ │ ├── Constant.java │ │ │ │ └── AppUtil.java │ │ │ │ ├── http │ │ │ │ ├── ProgressCancelListener.java │ │ │ │ ├── SubscriberOnNextListener.java │ │ │ │ ├── APIService.java │ │ │ │ ├── APIFactory.java │ │ │ │ ├── ProgressDialogHandler.java │ │ │ │ ├── ProgressSubscriber.java │ │ │ │ ├── RetrofitHttpUtil.java │ │ │ │ └── HttpLoggingInterceptor.java │ │ │ │ ├── entity │ │ │ │ ├── ListDayDiscount.java │ │ │ │ ├── HttpResult.java │ │ │ │ └── ProductBean.java │ │ │ │ ├── MyApplication.java │ │ │ │ ├── BaseActivity.java │ │ │ │ └── MainActivity.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── zhj │ │ │ └── retrofitwithrxjavademo │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── zhj │ │ └── retrofitwithrxjavademo │ │ └── ApplicationTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── README.md ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RetrofitWithRxJavaDemo 2 | Retrofit+Rxjava的封装使用 3 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | RetrofitWithRxJavaDemo 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuijilove/RetrofitWithRxJavaDemo/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuijilove/RetrofitWithRxJavaDemo/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuijilove/RetrofitWithRxJavaDemo/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuijilove/RetrofitWithRxJavaDemo/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuijilove/RetrofitWithRxJavaDemo/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuijilove/RetrofitWithRxJavaDemo/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/java/com/zhj/retrofitwithrxjavademo/util/BuildConfig.java: -------------------------------------------------------------------------------- 1 | package com.zhj.retrofitwithrxjavademo.util; 2 | 3 | /** 4 | * Created by hjzhang on 2016/7/26. 5 | */ 6 | public class BuildConfig { 7 | public static Boolean DEBUG = true; 8 | } 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/java/com/zhj/retrofitwithrxjavademo/http/ProgressCancelListener.java: -------------------------------------------------------------------------------- 1 | package com.zhj.retrofitwithrxjavademo.http; 2 | 3 | /** 4 | * Created by liukun on 16/3/10. 5 | */ 6 | public interface ProgressCancelListener { 7 | void onCancelProgress(); 8 | } 9 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/java/com/zhj/retrofitwithrxjavademo/http/SubscriberOnNextListener.java: -------------------------------------------------------------------------------- 1 | package com.zhj.retrofitwithrxjavademo.http; 2 | 3 | /** 4 | * Created by liukun on 16/3/10. 5 | */ 6 | public interface SubscriberOnNextListener { 7 | void onNext(T t); 8 | void onError(int code, String message); 9 | } 10 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/test/java/com/zhj/retrofitwithrxjavademo/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.zhj.retrofitwithrxjavademo; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/zhj/retrofitwithrxjavademo/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.zhj.retrofitwithrxjavademo; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/java/com/zhj/retrofitwithrxjavademo/entity/ListDayDiscount.java: -------------------------------------------------------------------------------- 1 | package com.zhj.retrofitwithrxjavademo.entity; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Created by hjzhang on 2016/7/27. 7 | */ 8 | public class ListDayDiscount { 9 | private List listDayDiscount; 10 | 11 | public List getListDayDiscount() { 12 | return listDayDiscount; 13 | } 14 | 15 | public void setListDayDiscount(List listDayDiscount) { 16 | this.listDayDiscount = listDayDiscount; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /app/src/main/java/com/zhj/retrofitwithrxjavademo/MyApplication.java: -------------------------------------------------------------------------------- 1 | package com.zhj.retrofitwithrxjavademo; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | 6 | import com.zhj.retrofitwithrxjavademo.http.APIFactory; 7 | 8 | /** 9 | * Created by hjzhang on 2016/7/27. 10 | */ 11 | public class MyApplication extends Application { 12 | public static Context aContext; 13 | @Override 14 | public void onCreate() { 15 | super.onCreate(); 16 | aContext = this; 17 | //初始化网络请求工具 18 | APIFactory.getInstance().init(this); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/zhj/retrofitwithrxjavademo/entity/HttpResult.java: -------------------------------------------------------------------------------- 1 | package com.zhj.retrofitwithrxjavademo.entity; 2 | 3 | import com.zhj.retrofitwithrxjavademo.util.Constant; 4 | 5 | public class HttpResult { 6 | 7 | public int code; 8 | public String desc; 9 | public T content; 10 | 11 | 12 | public boolean isSuccess() { 13 | return code == Constant.SUCCESS; 14 | } 15 | 16 | public boolean isEmpty() { 17 | return code == Constant.EMPTY; 18 | } 19 | 20 | public boolean isNoMore() { 21 | return code == Constant.NOMORE; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/zhj/retrofitwithrxjavademo/util/APIException.java: -------------------------------------------------------------------------------- 1 | package com.zhj.retrofitwithrxjavademo.util; 2 | 3 | /** 4 | * 自定义异常 5 | * Created by hjzhang on 2016/7/26. 6 | */ 7 | public class APIException extends RuntimeException{ 8 | public int code; 9 | public String message; 10 | 11 | public APIException(int code, String message) { 12 | this.code = code; 13 | this.message = message; 14 | } 15 | 16 | @Override 17 | public String getMessage() { 18 | return message; 19 | } 20 | 21 | public int getCode() { 22 | return code; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/zhj/retrofitwithrxjavademo/util/Constant.java: -------------------------------------------------------------------------------- 1 | package com.zhj.retrofitwithrxjavademo.util; 2 | 3 | /** 4 | * Created by Sunflower on 2016/1/11. 5 | */ 6 | public class Constant { 7 | /** 8 | * 成功 9 | */ 10 | public static final int SUCCESS = 0; 11 | /** 12 | * 没有数据 13 | */ 14 | public static final int EMPTY = -3; 15 | /** 16 | * 没有更多数据 17 | */ 18 | public static final int NOMORE= -4; 19 | 20 | /** 21 | * 网络中断,请检查您的网络状态 22 | */ 23 | public static final int NETERROR= -1000; 24 | /** 25 | * 未知错误 26 | */ 27 | public static final int UNKONWERROR= -1001; 28 | } 29 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\android\android_studio\android_studio_sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/zhj/retrofitwithrxjavademo/http/APIService.java: -------------------------------------------------------------------------------- 1 | package com.zhj.retrofitwithrxjavademo.http; 2 | 3 | import com.zhj.retrofitwithrxjavademo.entity.HttpResult; 4 | import com.zhj.retrofitwithrxjavademo.entity.ListDayDiscount; 5 | 6 | 7 | import retrofit2.http.Field; 8 | import retrofit2.http.FormUrlEncoded; 9 | import retrofit2.http.GET; 10 | import retrofit2.http.POST; 11 | import retrofit2.http.Part; 12 | import retrofit2.http.Query; 13 | import rx.Observable; 14 | 15 | /** 16 | * Created by hjzhang on 2016/7/26. 17 | */ 18 | public interface APIService { 19 | @GET("GetDayDiscountList") 20 | Observable> getDayDiscount(@Query("param") String param); 21 | 22 | @FormUrlEncoded 23 | @POST("GetDayDiscountList") 24 | Observable> getDayDiscountPost(@Field("param") String param); 25 | } 26 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "24.0.0" 6 | 7 | defaultConfig { 8 | applicationId "com.zhj.retrofitwithrxjavademo" 9 | minSdkVersion 14 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:23.3.0' 26 | compile 'io.reactivex:rxjava:1.1.8' 27 | compile 'io.reactivex:rxandroid:1.2.1' 28 | compile 'com.squareup.retrofit2:retrofit:2.1.0' 29 | compile 'com.squareup.retrofit2:converter-gson:2.1.0' 30 | compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0' 31 | compile 'com.google.code.gson:gson:2.6.2' 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/zhj/retrofitwithrxjavademo/http/APIFactory.java: -------------------------------------------------------------------------------- 1 | package com.zhj.retrofitwithrxjavademo.http; 2 | 3 | import com.zhj.retrofitwithrxjavademo.entity.ListDayDiscount; 4 | 5 | import rx.Observable; 6 | import rx.Subscriber; 7 | 8 | /** 9 | * Created by hjzhang on 2016/7/26. 10 | */ 11 | public class APIFactory extends RetrofitHttpUtil{ 12 | 13 | public static APIFactory getInstance() { 14 | return SingletonHolder.INSTANCE; 15 | } 16 | private static class SingletonHolder { 17 | private static final APIFactory INSTANCE = new APIFactory(); 18 | } 19 | 20 | public void getDayDiscount(Subscriber subscriber, String param){ 21 | Observable observable = apiService.getDayDiscount(param) 22 | .map(new HttpResultFunc()); 23 | toSubscribe(observable, subscriber); 24 | } 25 | public void getDayDiscountPost(Subscriber subscriber, String param){ 26 | Observable observable = apiService.getDayDiscountPost(param) 27 | .map(new HttpResultFunc()); 28 | toSubscribe(observable, subscriber); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 |