mirror of
https://github.com/WuXiaolong/AndroidMVPSample.git
synced 2025-06-06 13:24:03 +08:00
RxJava2
This commit is contained in:
parent
4ce68fb520
commit
4aab95e513
13
README.md
13
README.md
@ -1,4 +1,4 @@
|
|||||||
> MVP+Retrofit+RxJava实践小结,此Sample最初是Android MVP示例,后来融合Retrofit和RxJava,供参考。
|
> MVP + Retrofit + RxJava2 实践小结,此 Sample 最初是 Android MVP 示例,后来融合 Retrofit 和 RxJava2,供参考。
|
||||||
|
|
||||||
|
|
||||||
# 效果预览
|
# 效果预览
|
||||||
@ -19,17 +19,8 @@
|
|||||||
1. [RxBus](http://wuxiaolong.me/2016/04/07/rxbus/)
|
1. [RxBus](http://wuxiaolong.me/2016/04/07/rxbus/)
|
||||||
|
|
||||||
# 联系我
|
# 联系我
|
||||||
我的微信公众号:吴小龙同学,欢迎关注交流。
|
我的微信公众号:吴小龙同学,欢迎交流。
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|
||||||
# 更多交流
|
|
||||||
Android技术交流群-剩者为王⑤群:590967484
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 关于作者
|
|
||||||
[点击查看](http://wuxiaolong.me/about/)
|
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
apply plugin: 'com.android.application'
|
apply plugin: 'com.android.application'
|
||||||
apply plugin: 'com.jakewharton.butterknife'
|
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 27
|
compileSdkVersion 27
|
||||||
buildToolsVersion "27.0.3"
|
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "com.wuxiaolong.androidmvpsample"
|
applicationId "com.wuxiaolong.androidmvpsample"
|
||||||
@ -14,13 +12,11 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ext {
|
ext {
|
||||||
androidutilsVersion = '1.0.5'
|
androidutilsVersion = '1.0.6'
|
||||||
appcompatVersion = '27.1.0'
|
appcompatVersion = '27.1.0'
|
||||||
butterknifeVersion = '8.4.0'
|
butterknifeVersion = '8.4.0'
|
||||||
retrofitVersion = '2.3.0'
|
retrofitVersion = '2.3.0'
|
||||||
|
|
||||||
logginginterceptor = '3.9.1'
|
logginginterceptor = '3.9.1'
|
||||||
|
|
||||||
rxjavaVersion = '2.1.11'
|
rxjavaVersion = '2.1.11'
|
||||||
rxandroidVersion = "2.0.2"
|
rxandroidVersion = "2.0.2"
|
||||||
}
|
}
|
||||||
@ -28,16 +24,12 @@ ext {
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||||
implementation "com.wuxiaolong.androidutils:androidutils:$androidutilsVersion"
|
implementation "com.wuxiaolong.androidutils:androidutils:$androidutilsVersion"
|
||||||
|
|
||||||
implementation "com.android.support:appcompat-v7:$appcompatVersion"
|
implementation "com.android.support:appcompat-v7:$appcompatVersion"
|
||||||
// //butterknife
|
|
||||||
//noinspection GradleDependency
|
|
||||||
implementation "com.jakewharton:butterknife:$butterknifeVersion"
|
|
||||||
annotationProcessor "com.jakewharton:butterknife-compiler:$butterknifeVersion"
|
annotationProcessor "com.jakewharton:butterknife-compiler:$butterknifeVersion"
|
||||||
implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
|
implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
|
||||||
implementation "com.squareup.okhttp3:logging-interceptor:$logginginterceptor"
|
implementation "com.squareup.okhttp3:logging-interceptor:$logginginterceptor"
|
||||||
implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"
|
implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"
|
||||||
implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofitVersion"
|
implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofitVersion"
|
||||||
implementation "io.reactivex.rxjava2:rxandroid:$rxandroidVersion"
|
implementation "io.reactivex.rxjava2:rxandroid:$rxandroidVersion"
|
||||||
implementation "io.reactivex.rxjava2:rxjava:$rxjavaVersion"
|
implementation "io.reactivex.rxjava2:rxjava:$rxjavaVersion"
|
||||||
|
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
package com.wuxiaolong.androidmvpsample;
|
|
||||||
|
|
||||||
import android.app.Application;
|
|
||||||
import android.test.ApplicationTestCase;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
|
|
||||||
*/
|
|
||||||
public class ApplicationTest extends ApplicationTestCase<Application> {
|
|
||||||
public ApplicationTest() {
|
|
||||||
super(Application.class);
|
|
||||||
}
|
|
||||||
}
|
|
@ -10,7 +10,8 @@
|
|||||||
android:theme="@style/AppTheme">
|
android:theme="@style/AppTheme">
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.MainActivity"
|
android:name=".ui.MainActivity"
|
||||||
android:label="@string/app_name">
|
android:label="@string/app_name"
|
||||||
|
android:screenOrientation="portrait">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@ import com.wuxiaolong.androidutils.library.LogUtil;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import butterknife.ButterKnife;
|
|
||||||
import io.reactivex.Observable;
|
import io.reactivex.Observable;
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
import io.reactivex.disposables.CompositeDisposable;
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
@ -43,7 +42,6 @@ public abstract class BaseActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void setContentView(@LayoutRes int layoutResID) {
|
public void setContentView(@LayoutRes int layoutResID) {
|
||||||
super.setContentView(layoutResID);
|
super.setContentView(layoutResID);
|
||||||
ButterKnife.bind(this);
|
|
||||||
mActivity = this;
|
mActivity = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,14 +49,12 @@ public abstract class BaseActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void setContentView(View view) {
|
public void setContentView(View view) {
|
||||||
super.setContentView(view);
|
super.setContentView(view);
|
||||||
ButterKnife.bind(this);
|
|
||||||
mActivity = this;
|
mActivity = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setContentView(View view, ViewGroup.LayoutParams params) {
|
public void setContentView(View view, ViewGroup.LayoutParams params) {
|
||||||
super.setContentView(view, params);
|
super.setContentView(view, params);
|
||||||
ButterKnife.bind(this);
|
|
||||||
mActivity = this;
|
mActivity = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,9 +11,6 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
import com.wuxiaolong.androidmvpsample.R;
|
import com.wuxiaolong.androidmvpsample.R;
|
||||||
|
|
||||||
import org.reactivestreams.Subscription;
|
|
||||||
|
|
||||||
import butterknife.ButterKnife;
|
|
||||||
import io.reactivex.disposables.CompositeDisposable;
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
import io.reactivex.observers.DisposableObserver;
|
import io.reactivex.observers.DisposableObserver;
|
||||||
|
|
||||||
@ -30,7 +27,6 @@ public class BaseFragment extends Fragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
ButterKnife.bind(this, view);
|
|
||||||
mActivity = getActivity();
|
mActivity = getActivity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,8 +12,6 @@ import com.wuxiaolong.androidmvpsample.mvp.other.MvpActivity;
|
|||||||
import com.wuxiaolong.androidmvpsample.retrofit.ApiCallback;
|
import com.wuxiaolong.androidmvpsample.retrofit.ApiCallback;
|
||||||
import com.wuxiaolong.androidmvpsample.retrofit.RetrofitCallback;
|
import com.wuxiaolong.androidmvpsample.retrofit.RetrofitCallback;
|
||||||
|
|
||||||
import butterknife.BindView;
|
|
||||||
import butterknife.OnClick;
|
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -25,14 +23,14 @@ import retrofit2.Call;
|
|||||||
*/
|
*/
|
||||||
public class MainActivity extends MvpActivity<MainPresenter> implements MainView {
|
public class MainActivity extends MvpActivity<MainPresenter> implements MainView {
|
||||||
|
|
||||||
@BindView(R.id.text)
|
private TextView text;
|
||||||
TextView text;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
initToolBarAsHome("MVP+Retrofit+Rxjava");
|
text = findViewById(R.id.text);
|
||||||
|
initToolBarAsHome(getString(R.string.title));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -49,12 +47,11 @@ public class MainActivity extends MvpActivity<MainPresenter> implements MainView
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getDataFail(String msg) {
|
public void getDataFail(String msg) {
|
||||||
toastShow("网络不给力");
|
toastShow(getString(R.string.net_error));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@OnClick({R.id.button0, R.id.button1, R.id.button2})
|
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
switch (view.getId()) {
|
switch (view.getId()) {
|
||||||
case R.id.button0:
|
case R.id.button0:
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
<LinearLayout
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
tools:context=".ui.MainActivity">
|
tools:context=".ui.MainActivity">
|
||||||
|
|
||||||
<include layout="@layout/toolbar"/>
|
<include layout="@layout/toolbar" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/button0"
|
android:id="@+id/button0"
|
||||||
@ -15,7 +14,8 @@
|
|||||||
android:layout_marginLeft="10dp"
|
android:layout_marginLeft="10dp"
|
||||||
android:layout_marginRight="10dp"
|
android:layout_marginRight="10dp"
|
||||||
android:layout_marginTop="20dp"
|
android:layout_marginTop="20dp"
|
||||||
android:text="普通写法(Retrofit)"/>
|
android:onClick="onClick"
|
||||||
|
android:text="@string/text0" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/button1"
|
android:id="@+id/button1"
|
||||||
@ -24,7 +24,8 @@
|
|||||||
android:layout_marginLeft="10dp"
|
android:layout_marginLeft="10dp"
|
||||||
android:layout_marginRight="10dp"
|
android:layout_marginRight="10dp"
|
||||||
android:layout_marginTop="20dp"
|
android:layout_marginTop="20dp"
|
||||||
android:text="普通写法(Retrofit+Rxjava)"/>
|
android:onClick="onClick"
|
||||||
|
android:text="@string/text1" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/button2"
|
android:id="@+id/button2"
|
||||||
@ -33,12 +34,13 @@
|
|||||||
android:layout_marginLeft="10dp"
|
android:layout_marginLeft="10dp"
|
||||||
android:layout_marginRight="10dp"
|
android:layout_marginRight="10dp"
|
||||||
android:layout_marginTop="20dp"
|
android:layout_marginTop="20dp"
|
||||||
android:text="MVP+Retrofit+Rxjava"/>
|
android:onClick="onClick"
|
||||||
|
android:text="@string/text2" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/text"
|
android:id="@+id/text"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_margin="10dp"/>
|
android:layout_margin="10dp" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
@ -6,4 +6,9 @@
|
|||||||
<string name="wd">\n风向:</string>
|
<string name="wd">\n风向:</string>
|
||||||
<string name="ws">\n风级:</string>
|
<string name="ws">\n风级:</string>
|
||||||
<string name="time">\n发布时间:</string>
|
<string name="time">\n发布时间:</string>
|
||||||
|
<string name="net_error">网络不给力</string>
|
||||||
|
<string name="title">MVP+Retrofit+Rxjava2</string>
|
||||||
|
<string name="text0">普通写法(Retrofit)</string>
|
||||||
|
<string name="text1">普通写法(Retrofit+Rxjava)</string>
|
||||||
|
<string name="text2">MVP+Retrofit+Rxjava</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -7,7 +7,6 @@ buildscript {
|
|||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:3.0.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
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
// in the individual module build.gradle files
|
// in the individual module build.gradle files
|
||||||
|
Loading…
x
Reference in New Issue
Block a user