mirror of
https://github.com/WuXiaolong/AndroidMVPSample.git
synced 2025-06-06 13:24:03 +08:00
1. rxjava1.0 -> rxjava2.0
2. png -> webp
This commit is contained in:
parent
6d23bebca7
commit
4aa23833a6
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,3 +6,4 @@
|
||||
.DS_Store
|
||||
/build
|
||||
/captures
|
||||
.idea
|
22
.idea/compiler.xml
generated
22
.idea/compiler.xml
generated
@ -1,22 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<resourceExtensions />
|
||||
<wildcardResourcePatterns>
|
||||
<entry name="!?*.java" />
|
||||
<entry name="!?*.form" />
|
||||
<entry name="!?*.class" />
|
||||
<entry name="!?*.groovy" />
|
||||
<entry name="!?*.scala" />
|
||||
<entry name="!?*.flex" />
|
||||
<entry name="!?*.kt" />
|
||||
<entry name="!?*.clj" />
|
||||
<entry name="!?*.aj" />
|
||||
</wildcardResourcePatterns>
|
||||
<annotationProcessing>
|
||||
<profile default="true" name="Default" enabled="false">
|
||||
<processorPath useClasspath="true" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</project>
|
3
.idea/copyright/profiles_settings.xml
generated
3
.idea/copyright/profiles_settings.xml
generated
@ -1,3 +0,0 @@
|
||||
<component name="CopyrightManager">
|
||||
<settings default="" />
|
||||
</component>
|
6
.idea/encodings.xml
generated
6
.idea/encodings.xml
generated
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="PROJECT" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
18
.idea/gradle.xml
generated
18
.idea/gradle.xml
generated
@ -1,18 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveModulePerSourceSet" value="false" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
65
.idea/misc.xml
generated
65
.idea/misc.xml
generated
@ -1,65 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="EntryPointsManager">
|
||||
<entry_points version="2.0" />
|
||||
</component>
|
||||
<component name="NullableNotNullManager">
|
||||
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
|
||||
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
|
||||
<option name="myNullables">
|
||||
<value>
|
||||
<list size="4">
|
||||
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
|
||||
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
|
||||
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
|
||||
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
<option name="myNotNulls">
|
||||
<value>
|
||||
<list size="4">
|
||||
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
|
||||
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
|
||||
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
|
||||
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
|
||||
<OptionsSetting value="true" id="Add" />
|
||||
<OptionsSetting value="true" id="Remove" />
|
||||
<OptionsSetting value="true" id="Checkout" />
|
||||
<OptionsSetting value="true" id="Update" />
|
||||
<OptionsSetting value="true" id="Status" />
|
||||
<OptionsSetting value="true" id="Edit" />
|
||||
<ConfirmationsSetting value="0" id="Add" />
|
||||
<ConfirmationsSetting value="0" id="Remove" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
<option name="id" value="Android" />
|
||||
</component>
|
||||
<component name="SvnConfiguration">
|
||||
<configuration>C:\Users\WuXiaolong\AppData\Roaming\Subversion</configuration>
|
||||
</component>
|
||||
<component name="masterDetails">
|
||||
<states>
|
||||
<state key="ProjectJDKs.UI">
|
||||
<settings>
|
||||
<last-edited>1.8</last-edited>
|
||||
<splitter-proportions>
|
||||
<option name="proportions">
|
||||
<list>
|
||||
<option value="0.2" />
|
||||
</list>
|
||||
</option>
|
||||
</splitter-proportions>
|
||||
</settings>
|
||||
</state>
|
||||
</states>
|
||||
</component>
|
||||
</project>
|
9
.idea/modules.xml
generated
9
.idea/modules.xml
generated
@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/AndroidMVPSample.iml" filepath="$PROJECT_DIR$/AndroidMVPSample.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
12
.idea/runConfigurations.xml
generated
12
.idea/runConfigurations.xml
generated
@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RunConfigurationProducerService">
|
||||
<option name="ignoredProducers">
|
||||
<set>
|
||||
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
|
||||
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
|
||||
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
6
.idea/vcs.xml
generated
6
.idea/vcs.xml
generated
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
1
app/.gitignore
vendored
1
app/.gitignore
vendored
@ -1 +1,2 @@
|
||||
/build
|
||||
*.iml
|
92
app/app.iml
92
app/app.iml
@ -1,92 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="AndroidMVPSample" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="android-gradle" name="Android-Gradle">
|
||||
<configuration>
|
||||
<option name="GRADLE_PROJECT_PATH" value=":app" />
|
||||
</configuration>
|
||||
</facet>
|
||||
<facet type="android" name="Android">
|
||||
<configuration>
|
||||
<option name="SELECTED_BUILD_VARIANT" value="debug" />
|
||||
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
|
||||
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
|
||||
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
|
||||
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
|
||||
<option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugAndroidTestSources" />
|
||||
<afterSyncTasks>
|
||||
<task>generateDebugAndroidTestSources</task>
|
||||
<task>generateDebugSources</task>
|
||||
</afterSyncTasks>
|
||||
<option name="ALLOW_USER_CONFIGURATION" value="false" />
|
||||
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
|
||||
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
|
||||
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
|
||||
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
|
||||
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
|
||||
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/androidTest/debug" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/debug" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.0.1/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.0.1/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/tmp" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" exported="" name="httpclient-4.3.6" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-v4-23.0.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="android-async-http-1.4.9" level="project" />
|
||||
<orderEntry type="library" exported="" name="appcompat-v7-23.0.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-annotations-23.0.1" level="project" />
|
||||
</component>
|
||||
</module>
|
@ -1,34 +1,44 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'com.jakewharton.butterknife'
|
||||
|
||||
android {
|
||||
compileSdkVersion 25
|
||||
buildToolsVersion "25.0.3"
|
||||
compileSdkVersion 27
|
||||
buildToolsVersion "27.0.3"
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.wuxiaolong.androidmvpsample"
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 22
|
||||
versionCode 20
|
||||
versionName "2.0"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
targetSdkVersion 27
|
||||
versionCode 1
|
||||
}
|
||||
}
|
||||
|
||||
ext {
|
||||
androidutilsVersion = '1.0.5'
|
||||
appcompatVersion = '27.1.0'
|
||||
butterknifeVersion = '8.4.0'
|
||||
retrofitVersion = '2.3.0'
|
||||
|
||||
logginginterceptor = '3.9.1'
|
||||
|
||||
rxjavaVersion = '2.1.11'
|
||||
rxandroidVersion = "2.0.2"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile fileTree(include: ['*.jar'], dir: 'libs')
|
||||
compile 'com.android.support:appcompat-v7:25.3.1'
|
||||
compile 'com.wuxiaolong.androidutils:androidutils:1.0.5'
|
||||
compile 'com.jakewharton:butterknife:7.0.1'
|
||||
compile 'com.squareup.retrofit2:retrofit:2.0.2'
|
||||
compile 'com.squareup.okhttp3:logging-interceptor:3.1.2'
|
||||
compile 'com.squareup.retrofit2:converter-gson:2.0.2'
|
||||
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2'
|
||||
compile 'io.reactivex:rxandroid:1.1.0'
|
||||
compile 'io.reactivex:rxjava:1.1.0'
|
||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||
implementation "com.wuxiaolong.androidutils:androidutils:$androidutilsVersion"
|
||||
|
||||
implementation "com.android.support:appcompat-v7:$appcompatVersion"
|
||||
// //butterknife
|
||||
//noinspection GradleDependency
|
||||
implementation "com.jakewharton:butterknife:$butterknifeVersion"
|
||||
annotationProcessor "com.jakewharton:butterknife-compiler:$butterknifeVersion"
|
||||
implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
|
||||
implementation "com.squareup.okhttp3:logging-interceptor:$logginginterceptor"
|
||||
implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"
|
||||
implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofitVersion"
|
||||
implementation "io.reactivex.rxjava2:rxandroid:$rxandroidVersion"
|
||||
implementation "io.reactivex.rxjava2:rxjava:$rxjavaVersion"
|
||||
|
||||
}
|
||||
|
@ -3,11 +3,11 @@ package com.wuxiaolong.androidmvpsample.mvp.other;
|
||||
import com.wuxiaolong.androidmvpsample.retrofit.ApiStores;
|
||||
import com.wuxiaolong.androidmvpsample.retrofit.ApiClient;
|
||||
|
||||
import rx.Observable;
|
||||
import rx.Subscriber;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
import rx.subscriptions.CompositeSubscription;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.observers.DisposableObserver;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
|
||||
/**
|
||||
@ -19,7 +19,7 @@ import rx.subscriptions.CompositeSubscription;
|
||||
public class BasePresenter<V> {
|
||||
public V mvpView;
|
||||
protected ApiStores apiStores;
|
||||
private CompositeSubscription mCompositeSubscription;
|
||||
private CompositeDisposable mCompositeDisposable;
|
||||
|
||||
public void attachView(V mvpView) {
|
||||
this.mvpView = mvpView;
|
||||
@ -29,25 +29,27 @@ public class BasePresenter<V> {
|
||||
|
||||
public void detachView() {
|
||||
this.mvpView = null;
|
||||
onUnsubscribe();
|
||||
onUnSubscribe();
|
||||
}
|
||||
|
||||
|
||||
//RXjava取消注册,以避免内存泄露
|
||||
public void onUnsubscribe() {
|
||||
if (mCompositeSubscription != null && mCompositeSubscription.hasSubscriptions()) {
|
||||
mCompositeSubscription.unsubscribe();
|
||||
//RxJava取消注册,以避免内存泄露
|
||||
public void onUnSubscribe() {
|
||||
if (mCompositeDisposable != null) {
|
||||
mCompositeDisposable.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void addSubscription(Observable observable, Subscriber subscriber) {
|
||||
if (mCompositeSubscription == null) {
|
||||
mCompositeSubscription = new CompositeSubscription();
|
||||
public void addSubscription(Observable observable, DisposableObserver observer) {
|
||||
if (mCompositeDisposable == null) {
|
||||
mCompositeDisposable = new CompositeDisposable();
|
||||
}
|
||||
mCompositeSubscription.add(observable
|
||||
.subscribeOn(Schedulers.io())
|
||||
|
||||
mCompositeDisposable.add(observer);
|
||||
|
||||
observable.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(subscriber));
|
||||
.subscribeWith(observer);
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,10 @@ package com.wuxiaolong.androidmvpsample.retrofit;
|
||||
|
||||
import com.wuxiaolong.androidutils.library.LogUtil;
|
||||
|
||||
import retrofit2.adapter.rxjava.HttpException;
|
||||
import rx.Subscriber;
|
||||
|
||||
import io.reactivex.observers.DisposableObserver;
|
||||
import retrofit2.HttpException;
|
||||
|
||||
|
||||
/**
|
||||
* Created by WuXiaolong on 2016/9/22.
|
||||
@ -12,7 +14,7 @@ import rx.Subscriber;
|
||||
* 微信公众号:吴小龙同学
|
||||
* 个人博客:http://wuxiaolong.me/
|
||||
*/
|
||||
public abstract class ApiCallback<M> extends Subscriber<M> {
|
||||
public abstract class ApiCallback<M> extends DisposableObserver<M> {
|
||||
|
||||
public abstract void onSuccess(M model);
|
||||
|
||||
@ -50,7 +52,7 @@ public abstract class ApiCallback<M> extends Subscriber<M> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCompleted() {
|
||||
public void onComplete() {
|
||||
onFinish();
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import com.wuxiaolong.androidmvpsample.BuildConfig;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.logging.HttpLoggingInterceptor;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
|
||||
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
/**
|
||||
@ -32,7 +32,7 @@ public class ApiClient {
|
||||
mRetrofit = new Retrofit.Builder()
|
||||
.baseUrl(ApiStores.API_SERVER_URL)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
|
||||
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
|
||||
.client(okHttpClient)
|
||||
.build();
|
||||
}
|
||||
|
@ -2,10 +2,10 @@ package com.wuxiaolong.androidmvpsample.retrofit;
|
||||
|
||||
import com.wuxiaolong.androidmvpsample.mvp.main.MainModel;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Path;
|
||||
import rx.Observable;
|
||||
|
||||
/**
|
||||
* Created by WuXiaolong on 2016/3/24.
|
||||
|
@ -21,13 +21,13 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.observers.DisposableObserver;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import retrofit2.Call;
|
||||
import rx.Observable;
|
||||
import rx.Subscriber;
|
||||
import rx.Subscription;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
import rx.subscriptions.CompositeSubscription;
|
||||
|
||||
/**
|
||||
* Created by WuXiaolong on 2015/9/23.
|
||||
@ -35,9 +35,9 @@ import rx.subscriptions.CompositeSubscription;
|
||||
* 微信公众号:吴小龙同学
|
||||
* 个人博客:http://wuxiaolong.me/
|
||||
*/
|
||||
public class BaseActivity extends AppCompatActivity {
|
||||
public abstract class BaseActivity extends AppCompatActivity {
|
||||
public Activity mActivity;
|
||||
private CompositeSubscription mCompositeSubscription;
|
||||
private CompositeDisposable mCompositeDisposable;
|
||||
private List<Call> calls;
|
||||
|
||||
@Override
|
||||
@ -60,7 +60,6 @@ public class BaseActivity extends AppCompatActivity {
|
||||
super.setContentView(view, params);
|
||||
ButterKnife.bind(this);
|
||||
mActivity = this;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -93,36 +92,37 @@ public class BaseActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
|
||||
public void addSubscription(Observable observable, Subscriber subscriber) {
|
||||
if (mCompositeSubscription == null) {
|
||||
mCompositeSubscription = new CompositeSubscription();
|
||||
public <T> void addSubscription(Observable<T> observable, DisposableObserver<T> observer) {
|
||||
if (mCompositeDisposable == null) {
|
||||
mCompositeDisposable = new CompositeDisposable();
|
||||
}
|
||||
mCompositeSubscription.add(observable
|
||||
.subscribeOn(Schedulers.io())
|
||||
mCompositeDisposable.add(observer);
|
||||
|
||||
observable.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(subscriber));
|
||||
.subscribe(observer);
|
||||
}
|
||||
|
||||
public void addSubscription(Subscription subscription) {
|
||||
if (mCompositeSubscription == null) {
|
||||
mCompositeSubscription = new CompositeSubscription();
|
||||
public void addSubscription(Disposable disposable) {
|
||||
if (mCompositeDisposable == null) {
|
||||
mCompositeDisposable = new CompositeDisposable();
|
||||
}
|
||||
mCompositeSubscription.add(subscription);
|
||||
mCompositeDisposable.add(disposable);
|
||||
}
|
||||
|
||||
public void onUnsubscribe() {
|
||||
LogUtil.d("onUnsubscribe");
|
||||
LogUtil.d("onUnSubscribe");
|
||||
//取消注册,以避免内存泄露
|
||||
if (mCompositeSubscription != null && mCompositeSubscription.hasSubscriptions())
|
||||
mCompositeSubscription.unsubscribe();
|
||||
if (mCompositeDisposable != null)
|
||||
mCompositeDisposable.dispose();
|
||||
}
|
||||
|
||||
public Toolbar initToolBar(String title) {
|
||||
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
if (toolbar != null) {
|
||||
setSupportActionBar(toolbar);
|
||||
TextView toolbaTitle = (TextView) toolbar.findViewById(R.id.toolbar_title);
|
||||
TextView toolbaTitle = toolbar.findViewById(R.id.toolbar_title);
|
||||
toolbaTitle.setText(title);
|
||||
}
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
|
@ -11,9 +11,11 @@ import android.widget.Toast;
|
||||
|
||||
import com.wuxiaolong.androidmvpsample.R;
|
||||
|
||||
import org.reactivestreams.Subscription;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import rx.Subscription;
|
||||
import rx.subscriptions.CompositeSubscription;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.observers.DisposableObserver;
|
||||
|
||||
/**
|
||||
* Created by WuXiaolong on 2015/9/23.
|
||||
@ -55,19 +57,19 @@ public class BaseFragment extends Fragment {
|
||||
onUnsubscribe();
|
||||
}
|
||||
|
||||
private CompositeSubscription mCompositeSubscription;
|
||||
private CompositeDisposable mCompositeDisposable;
|
||||
|
||||
public void onUnsubscribe() {
|
||||
//取消注册,以避免内存泄露
|
||||
if (mCompositeSubscription != null) {
|
||||
mCompositeSubscription.unsubscribe();
|
||||
if (mCompositeDisposable != null) {
|
||||
mCompositeDisposable.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public void addSubscription(Subscription subscription) {
|
||||
// if (mCompositeSubscription == null) {
|
||||
mCompositeSubscription = new CompositeSubscription();
|
||||
public void addSubscription(DisposableObserver observer) {
|
||||
// if (mCompositeDisposable == null) {
|
||||
mCompositeDisposable = new CompositeDisposable();
|
||||
// }
|
||||
mCompositeSubscription.add(subscription);
|
||||
mCompositeDisposable.add(observer);
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import com.wuxiaolong.androidmvpsample.mvp.other.MvpActivity;
|
||||
import com.wuxiaolong.androidmvpsample.retrofit.ApiCallback;
|
||||
import com.wuxiaolong.androidmvpsample.retrofit.RetrofitCallback;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import retrofit2.Call;
|
||||
@ -26,16 +26,14 @@ import retrofit2.Call;
|
||||
*/
|
||||
public class MainActivity extends MvpActivity<MainPresenter> implements MainView {
|
||||
|
||||
@Bind(R.id.text)
|
||||
@BindView(R.id.text)
|
||||
TextView text;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
ButterKnife.bind(this);
|
||||
initToolBarAsHome("MVP+Retrofit+Rxjava");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -64,7 +62,7 @@ public class MainActivity extends MvpActivity<MainPresenter> implements MainView
|
||||
loadDataByRetrofit();
|
||||
break;
|
||||
case R.id.button1:
|
||||
loadDataByRetrofitRxjava();
|
||||
loadDataByRetrofitRxJava();
|
||||
break;
|
||||
case R.id.button2:
|
||||
//请求接口
|
||||
@ -101,10 +99,12 @@ public class MainActivity extends MvpActivity<MainPresenter> implements MainView
|
||||
}
|
||||
|
||||
//全国+国外主要城市代码http://mobile.weather.com.cn/js/citylist.xml
|
||||
private void loadDataByRetrofitRxjava() {
|
||||
private void loadDataByRetrofitRxJava() {
|
||||
showProgressDialog();
|
||||
addSubscription(apiStores().loadDataByRetrofitRxjava("101220602"),
|
||||
addSubscription(
|
||||
apiStores().loadDataByRetrofitRxjava("101220602"),
|
||||
new ApiCallback<MainModel>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(MainModel model) {
|
||||
dataSuccess(model);
|
||||
@ -113,7 +113,6 @@ public class MainActivity extends MvpActivity<MainPresenter> implements MainView
|
||||
@Override
|
||||
public void onFailure(String msg) {
|
||||
toastShow(msg);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,9 +3,11 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
google()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:2.3.1'
|
||||
classpath 'com.android.tools.build:gradle:3.0.1'
|
||||
classpath 'com.jakewharton:butterknife-gradle-plugin:8.4.0'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
@ -15,5 +17,6 @@ buildscript {
|
||||
allprojects {
|
||||
repositories {
|
||||
jcenter()
|
||||
google()
|
||||
}
|
||||
}
|
||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
|
||||
|
BIN
screenshots.png
BIN
screenshots.png
Binary file not shown.
Before Width: | Height: | Size: 43 KiB |
BIN
screenshots.webp
Normal file
BIN
screenshots.webp
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
Loading…
x
Reference in New Issue
Block a user