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/)
|
||||
|
||||
# 联系我
|
||||
我的微信公众号:吴小龙同学,欢迎关注交流。
|
||||
我的微信公众号:吴小龙同学,欢迎交流。
|
||||
|
||||

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

|
||||
|
||||
|
||||
|
||||
# 关于作者
|
||||
[点击查看](http://wuxiaolong.me/about/)
|
||||
|
@ -1,9 +1,7 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'com.jakewharton.butterknife'
|
||||
|
||||
android {
|
||||
compileSdkVersion 27
|
||||
buildToolsVersion "27.0.3"
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.wuxiaolong.androidmvpsample"
|
||||
@ -14,13 +12,11 @@ android {
|
||||
}
|
||||
|
||||
ext {
|
||||
androidutilsVersion = '1.0.5'
|
||||
androidutilsVersion = '1.0.6'
|
||||
appcompatVersion = '27.1.0'
|
||||
butterknifeVersion = '8.4.0'
|
||||
retrofitVersion = '2.3.0'
|
||||
|
||||
logginginterceptor = '3.9.1'
|
||||
|
||||
rxjavaVersion = '2.1.11'
|
||||
rxandroidVersion = "2.0.2"
|
||||
}
|
||||
@ -28,11 +24,7 @@ ext {
|
||||
dependencies {
|
||||
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"
|
||||
|
@ -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">
|
||||
<activity
|
||||
android:name=".ui.MainActivity"
|
||||
android:label="@string/app_name">
|
||||
android:label="@string/app_name"
|
||||
android:screenOrientation="portrait">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
|
@ -20,7 +20,6 @@ import com.wuxiaolong.androidutils.library.LogUtil;
|
||||
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;
|
||||
@ -43,7 +42,6 @@ public abstract class BaseActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void setContentView(@LayoutRes int layoutResID) {
|
||||
super.setContentView(layoutResID);
|
||||
ButterKnife.bind(this);
|
||||
mActivity = this;
|
||||
}
|
||||
|
||||
@ -51,14 +49,12 @@ public abstract class BaseActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void setContentView(View view) {
|
||||
super.setContentView(view);
|
||||
ButterKnife.bind(this);
|
||||
mActivity = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentView(View view, ViewGroup.LayoutParams params) {
|
||||
super.setContentView(view, params);
|
||||
ButterKnife.bind(this);
|
||||
mActivity = this;
|
||||
}
|
||||
|
||||
|
@ -11,9 +11,6 @@ import android.widget.Toast;
|
||||
|
||||
import com.wuxiaolong.androidmvpsample.R;
|
||||
|
||||
import org.reactivestreams.Subscription;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.observers.DisposableObserver;
|
||||
|
||||
@ -30,7 +27,6 @@ public class BaseFragment extends Fragment {
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
ButterKnife.bind(this, view);
|
||||
mActivity = getActivity();
|
||||
}
|
||||
|
||||
|
@ -12,8 +12,6 @@ import com.wuxiaolong.androidmvpsample.mvp.other.MvpActivity;
|
||||
import com.wuxiaolong.androidmvpsample.retrofit.ApiCallback;
|
||||
import com.wuxiaolong.androidmvpsample.retrofit.RetrofitCallback;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
import retrofit2.Call;
|
||||
|
||||
/**
|
||||
@ -25,14 +23,14 @@ import retrofit2.Call;
|
||||
*/
|
||||
public class MainActivity extends MvpActivity<MainPresenter> implements MainView {
|
||||
|
||||
@BindView(R.id.text)
|
||||
TextView text;
|
||||
private TextView text;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
initToolBarAsHome("MVP+Retrofit+Rxjava");
|
||||
text = findViewById(R.id.text);
|
||||
initToolBarAsHome(getString(R.string.title));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -49,12 +47,11 @@ public class MainActivity extends MvpActivity<MainPresenter> implements MainView
|
||||
|
||||
@Override
|
||||
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) {
|
||||
switch (view.getId()) {
|
||||
case R.id.button0:
|
||||
|
@ -1,12 +1,11 @@
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:context=".ui.MainActivity">
|
||||
|
||||
<include layout="@layout/toolbar"/>
|
||||
<include layout="@layout/toolbar" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button0"
|
||||
@ -15,7 +14,8 @@
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="普通写法(Retrofit)"/>
|
||||
android:onClick="onClick"
|
||||
android:text="@string/text0" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button1"
|
||||
@ -24,7 +24,8 @@
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="普通写法(Retrofit+Rxjava)"/>
|
||||
android:onClick="onClick"
|
||||
android:text="@string/text1" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button2"
|
||||
@ -33,12 +34,13 @@
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="MVP+Retrofit+Rxjava"/>
|
||||
android:onClick="onClick"
|
||||
android:text="@string/text2" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp"/>
|
||||
android:layout_margin="10dp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
@ -6,4 +6,9 @@
|
||||
<string name="wd">\n风向:</string>
|
||||
<string name="ws">\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>
|
||||
|
@ -7,7 +7,6 @@ buildscript {
|
||||
}
|
||||
dependencies {
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user