├── mvp ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── layout │ │ │ │ └── activity_login.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ └── drawable │ │ │ │ └── ic_launcher_background.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── mvp │ │ │ │ ├── base │ │ │ │ ├── BaseMvpView.java │ │ │ │ ├── BaseMvpPresenter.java │ │ │ │ ├── BaseObserver.java │ │ │ │ └── BaseMvpActivity.java │ │ │ │ ├── entity │ │ │ │ ├── LoginInfo.java │ │ │ │ └── UserInfo.java │ │ │ │ ├── api │ │ │ │ └── LoginApi.java │ │ │ │ ├── contract │ │ │ │ └── LoginContract.java │ │ │ │ ├── app │ │ │ │ └── App.java │ │ │ │ ├── util │ │ │ │ ├── ToastUtil.java │ │ │ │ └── TUtil.java │ │ │ │ ├── rx │ │ │ │ └── RxTransformerHelper.java │ │ │ │ ├── ui │ │ │ │ └── login │ │ │ │ │ ├── LoginPresenter.java │ │ │ │ │ └── LoginActivity.java │ │ │ │ └── helper │ │ │ │ └── RetrofitCreateHelper.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── mvp │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── example │ │ └── mvp │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── myrxjava ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── layout │ │ │ │ └── activity_main.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ └── drawable │ │ │ │ └── ic_launcher_background.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── myrxjava │ │ │ │ ├── base │ │ │ │ ├── BasePresenter.java │ │ │ │ ├── BaseMvpView.java │ │ │ │ └── BaseActivity.java │ │ │ │ ├── entity │ │ │ │ ├── LoginInfo.java │ │ │ │ └── UserInfo.java │ │ │ │ ├── scope │ │ │ │ └── LoginSingleton.java │ │ │ │ ├── ui │ │ │ │ └── login │ │ │ │ │ ├── LoginModule.java │ │ │ │ │ ├── LoginPresenter.java │ │ │ │ │ └── LoginActivity.java │ │ │ │ ├── api │ │ │ │ └── LoginApi.java │ │ │ │ ├── inject │ │ │ │ ├── component │ │ │ │ │ ├── LoginActivityComponent.java │ │ │ │ │ └── AppComponent.java │ │ │ │ └── module │ │ │ │ │ ├── AppModule.java │ │ │ │ │ └── ApiModule.java │ │ │ │ ├── constract │ │ │ │ └── LoginContract.java │ │ │ │ ├── app │ │ │ │ └── App.java │ │ │ │ └── util │ │ │ │ └── TUtil.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── myrxjava │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── example │ │ └── myrxjava │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── README.md ├── gradle.properties ├── gradlew.bat └── gradlew /mvp/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /myrxjava/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':myrxjava', ':mvp' -------------------------------------------------------------------------------- /mvp/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | mvp 3 | 4 | -------------------------------------------------------------------------------- /myrxjava/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | MyRxJava 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makeloveandroid/dagger2/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dagger2 2 | Dagger2+RxJava+Retrofit+OkHttp+MVP 3 | 4 | 博客地址: 5 | https://blog.csdn.net/wenyingzhi/article/details/80077318 6 | -------------------------------------------------------------------------------- /mvp/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makeloveandroid/dagger2/HEAD/mvp/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /mvp/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makeloveandroid/dagger2/HEAD/mvp/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /mvp/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makeloveandroid/dagger2/HEAD/mvp/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /mvp/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makeloveandroid/dagger2/HEAD/mvp/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /mvp/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makeloveandroid/dagger2/HEAD/mvp/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /myrxjava/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makeloveandroid/dagger2/HEAD/myrxjava/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /myrxjava/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makeloveandroid/dagger2/HEAD/myrxjava/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /mvp/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makeloveandroid/dagger2/HEAD/mvp/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /mvp/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makeloveandroid/dagger2/HEAD/mvp/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /mvp/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makeloveandroid/dagger2/HEAD/mvp/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /mvp/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makeloveandroid/dagger2/HEAD/mvp/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /myrxjava/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makeloveandroid/dagger2/HEAD/myrxjava/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /myrxjava/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makeloveandroid/dagger2/HEAD/myrxjava/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /myrxjava/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makeloveandroid/dagger2/HEAD/myrxjava/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /mvp/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makeloveandroid/dagger2/HEAD/mvp/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /myrxjava/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makeloveandroid/dagger2/HEAD/myrxjava/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /myrxjava/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makeloveandroid/dagger2/HEAD/myrxjava/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /myrxjava/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makeloveandroid/dagger2/HEAD/myrxjava/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /myrxjava/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makeloveandroid/dagger2/HEAD/myrxjava/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /myrxjava/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makeloveandroid/dagger2/HEAD/myrxjava/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /mvp/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /mvp/src/main/java/com/example/mvp/base/BaseMvpView.java: -------------------------------------------------------------------------------- 1 | package com.example.mvp.base; 2 | 3 | public interface BaseMvpView { 4 | void showLoadDialog(); 5 | void showErrorMsg(String msg); 6 | void showToastMsg(String msg); 7 | void hideDialog(); 8 | } 9 | -------------------------------------------------------------------------------- /myrxjava/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Apr 20 17:15:04 CST 2018 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-4.1-all.zip 7 | -------------------------------------------------------------------------------- /myrxjava/src/main/java/com/example/myrxjava/base/BasePresenter.java: -------------------------------------------------------------------------------- 1 | package com.example.myrxjava.base; 2 | 3 | /** 4 | * 一个MVP的Presenter的抽取 5 | */ 6 | 7 | public class BasePresenter { 8 | public T mView; 9 | 10 | public void setMvpView(T view) { 11 | mView = view; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /mvp/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /myrxjava/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /mvp/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /myrxjava/src/main/java/com/example/myrxjava/base/BaseMvpView.java: -------------------------------------------------------------------------------- 1 | package com.example.myrxjava.base; 2 | 3 | /** 4 | * Mvp中的view接口的,公用方法抽取 5 | */ 6 | 7 | public interface BaseMvpView { 8 | void showLoadDialog(); 9 | void showErrorMsg(String msg); 10 | void showToastMsg(String msg); 11 | void hideDialog(); 12 | } 13 | -------------------------------------------------------------------------------- /myrxjava/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /mvp/src/main/java/com/example/mvp/entity/LoginInfo.java: -------------------------------------------------------------------------------- 1 | package com.example.mvp.entity; 2 | 3 | /** 4 | * Created by wenyingzhi on 2018/4/23. 5 | */ 6 | 7 | public class LoginInfo { 8 | private String user; 9 | private String pass; 10 | 11 | public LoginInfo(String user, String pass) { 12 | this.user = user; 13 | this.pass = pass; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /myrxjava/src/main/java/com/example/myrxjava/entity/LoginInfo.java: -------------------------------------------------------------------------------- 1 | package com.example.myrxjava.entity; 2 | 3 | /** 4 | * Created by wenyingzhi on 2018/4/23. 5 | */ 6 | 7 | public class LoginInfo { 8 | private String user; 9 | private String pass; 10 | 11 | public LoginInfo(String user, String pass) { 12 | this.user = user; 13 | this.pass = pass; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /mvp/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /myrxjava/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /myrxjava/src/main/java/com/example/myrxjava/scope/LoginSingleton.java: -------------------------------------------------------------------------------- 1 | package com.example.myrxjava.scope; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.Retention; 5 | 6 | import javax.inject.Scope; 7 | 8 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 9 | 10 | /** 11 | * Created by wenyingzhi on 2018/4/23. 12 | */ 13 | 14 | @Scope 15 | @Documented 16 | @Retention(RUNTIME) 17 | public @interface LoginSingleton {} 18 | -------------------------------------------------------------------------------- /mvp/src/test/java/com/example/mvp/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.example.mvp; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /mvp/src/main/java/com/example/mvp/base/BaseMvpPresenter.java: -------------------------------------------------------------------------------- 1 | package com.example.mvp.base; 2 | 3 | import io.reactivex.disposables.CompositeDisposable; 4 | 5 | public abstract class BaseMvpPresenter { 6 | public CompositeDisposable mCompositeDisposable = new CompositeDisposable(); 7 | public V mView; 8 | 9 | public void setView(V view){ 10 | mView=view; 11 | } 12 | 13 | public void unSubscription(){ 14 | mCompositeDisposable.clear(); 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /mvp/src/main/java/com/example/mvp/base/BaseObserver.java: -------------------------------------------------------------------------------- 1 | package com.example.mvp.base; 2 | 3 | import io.reactivex.Observer; 4 | import io.reactivex.disposables.CompositeDisposable; 5 | import io.reactivex.disposables.Disposable; 6 | import io.reactivex.observers.DisposableObserver; 7 | 8 | public abstract class BaseObserver extends DisposableObserver { 9 | 10 | public BaseObserver(CompositeDisposable compositeDisposable) { 11 | compositeDisposable.add(this); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /myrxjava/src/test/java/com/example/myrxjava/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.example.myrxjava; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /myrxjava/src/main/java/com/example/myrxjava/ui/login/LoginModule.java: -------------------------------------------------------------------------------- 1 | package com.example.myrxjava.ui.login; 2 | 3 | import com.example.myrxjava.api.LoginApi; 4 | 5 | import dagger.Module; 6 | import dagger.Provides; 7 | import retrofit2.Retrofit; 8 | 9 | @Module 10 | public class LoginModule { 11 | /** 12 | * 提供登陆的api的请求对象 13 | * @param retrofit 14 | * @return 15 | */ 16 | @Provides 17 | public LoginApi providesLoginApi(Retrofit retrofit){ 18 | return retrofit.create(LoginApi.class); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /mvp/src/main/java/com/example/mvp/api/LoginApi.java: -------------------------------------------------------------------------------- 1 | package com.example.mvp.api; 2 | 3 | 4 | import com.example.mvp.entity.UserInfo; 5 | 6 | import java.util.Map; 7 | 8 | import io.reactivex.Observable; 9 | import retrofit2.http.FieldMap; 10 | import retrofit2.http.FormUrlEncoded; 11 | import retrofit2.http.POST; 12 | 13 | /** 14 | * Created by wenyingzhi on 2018/4/23. 15 | */ 16 | 17 | //登陆请求的API 18 | public interface LoginApi { 19 | @FormUrlEncoded 20 | @POST("/e/member/ajaxlogin/") 21 | Observable login(@FieldMap Map parameters); 22 | } 23 | -------------------------------------------------------------------------------- /myrxjava/src/main/java/com/example/myrxjava/api/LoginApi.java: -------------------------------------------------------------------------------- 1 | package com.example.myrxjava.api; 2 | 3 | import com.example.myrxjava.entity.UserInfo; 4 | 5 | import java.util.Map; 6 | 7 | 8 | import retrofit2.http.FieldMap; 9 | import retrofit2.http.FormUrlEncoded; 10 | import retrofit2.http.POST; 11 | import rx.Observable; 12 | 13 | /** 14 | * Created by wenyingzhi on 2018/4/23. 15 | */ 16 | 17 | //登陆请求的API 18 | public interface LoginApi { 19 | @FormUrlEncoded 20 | @POST("/e/member/ajaxlogin/") 21 | Observable login(@FieldMap Map parameters); 22 | } 23 | -------------------------------------------------------------------------------- /myrxjava/src/main/java/com/example/myrxjava/inject/component/LoginActivityComponent.java: -------------------------------------------------------------------------------- 1 | package com.example.myrxjava.inject.component; 2 | 3 | import com.example.myrxjava.scope.LoginSingleton; 4 | import com.example.myrxjava.ui.login.LoginActivity; 5 | import com.example.myrxjava.ui.login.LoginModule; 6 | 7 | import dagger.Component; 8 | 9 | /** 10 | * Created by wenyingzhi on 2018/4/23. 11 | */ 12 | @LoginSingleton 13 | @Component(modules = {LoginModule.class},dependencies = {AppComponent.class}) 14 | public interface LoginActivityComponent { 15 | void inject(LoginActivity activity); 16 | } 17 | -------------------------------------------------------------------------------- /mvp/src/main/java/com/example/mvp/contract/LoginContract.java: -------------------------------------------------------------------------------- 1 | package com.example.mvp.contract; 2 | 3 | import com.example.mvp.base.BaseMvpPresenter; 4 | import com.example.mvp.base.BaseMvpView; 5 | import com.example.mvp.entity.UserInfo; 6 | 7 | public interface LoginContract { 8 | interface LoginView extends BaseMvpView{ 9 | String getUser(); 10 | String getPass(); 11 | void loginSucccess(UserInfo userInfo); 12 | void loginError(String msg); 13 | } 14 | 15 | abstract class LoginPresenter extends BaseMvpPresenter{ 16 | public abstract void login(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /mvp/src/main/java/com/example/mvp/app/App.java: -------------------------------------------------------------------------------- 1 | package com.example.mvp.app; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | import android.view.View; 6 | 7 | 8 | /** 9 | * Created by wenyingzhi on 2018/4/23. 10 | */ 11 | 12 | public class App extends Application { 13 | private static Application app; 14 | @Override 15 | public void onCreate() { 16 | super.onCreate(); 17 | app=this; 18 | } 19 | 20 | public static Application getApplication(){ 21 | return app; 22 | } 23 | 24 | public static Context getAppContext(){ 25 | return app.getApplicationContext(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /myrxjava/src/main/java/com/example/myrxjava/constract/LoginContract.java: -------------------------------------------------------------------------------- 1 | package com.example.myrxjava.constract; 2 | 3 | import com.example.myrxjava.base.BaseMvpView; 4 | import com.example.myrxjava.base.BasePresenter; 5 | import com.example.myrxjava.entity.LoginInfo; 6 | import com.example.myrxjava.entity.UserInfo; 7 | 8 | 9 | /** 10 | * Created by wenyingzhi on 2018/4/23. 11 | */ 12 | 13 | public interface LoginContract { 14 | interface LoginMvpView extends BaseMvpView{ 15 | void loginSuccess(UserInfo userInfo); 16 | String getUser(); 17 | String getPass(); 18 | } 19 | 20 | abstract class LoginBasePresenter extends BasePresenter{ 21 | public abstract void login(); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /mvp/src/main/java/com/example/mvp/util/ToastUtil.java: -------------------------------------------------------------------------------- 1 | package com.example.mvp.util; 2 | 3 | import android.widget.Toast; 4 | 5 | import com.example.mvp.app.App; 6 | 7 | //还是dagger2方便点 8 | public class ToastUtil { 9 | 10 | private final Toast toast; 11 | 12 | public static Toast getToast(){ 13 | return Hodler.holder.toast; 14 | } 15 | 16 | public static void showToast(String msg){ 17 | Toast toast = getToast(); 18 | toast.setText(msg); 19 | toast.show(); 20 | } 21 | 22 | private ToastUtil(){ 23 | toast = Toast.makeText(App.getAppContext(), "", Toast.LENGTH_SHORT); 24 | } 25 | private static class Hodler{ 26 | public static ToastUtil holder=new ToastUtil(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /myrxjava/src/main/java/com/example/myrxjava/inject/component/AppComponent.java: -------------------------------------------------------------------------------- 1 | package com.example.myrxjava.inject.component; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | import android.widget.Toast; 6 | 7 | import com.example.myrxjava.inject.module.ApiModule; 8 | import com.example.myrxjava.inject.module.AppModule; 9 | 10 | import javax.inject.Singleton; 11 | 12 | import dagger.Component; 13 | import retrofit2.Retrofit; 14 | 15 | /** 16 | * Created by wenyingzhi on 2018/4/23. 17 | */ 18 | @Singleton 19 | @Component(modules = {AppModule.class, ApiModule.class}) 20 | public interface AppComponent { 21 | Context getContext(); 22 | Application getApplication(); 23 | Retrofit getRetrofit(); 24 | Toast getToast(); 25 | } 26 | -------------------------------------------------------------------------------- /mvp/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /myrxjava/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /mvp/src/androidTest/java/com/example/mvp/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.example.mvp; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.example.mvp", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /mvp/src/main/java/com/example/mvp/rx/RxTransformerHelper.java: -------------------------------------------------------------------------------- 1 | package com.example.mvp.rx; 2 | 3 | 4 | import io.reactivex.ObservableSource; 5 | import io.reactivex.ObservableTransformer; 6 | import io.reactivex.android.schedulers.AndroidSchedulers; 7 | import io.reactivex.schedulers.Schedulers; 8 | 9 | public class RxTransformerHelper { 10 | 11 | /** 12 | * 切换线程 13 | * 14 | * @param 15 | * @return 16 | */ 17 | public static ObservableTransformer schedulerTransf() { 18 | return new ObservableTransformer() { 19 | @Override 20 | public ObservableSource apply(io.reactivex.Observable upstream) { 21 | return upstream 22 | .subscribeOn(Schedulers.io()) 23 | .observeOn(AndroidSchedulers.mainThread()); 24 | } 25 | }; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /mvp/src/main/java/com/example/mvp/entity/UserInfo.java: -------------------------------------------------------------------------------- 1 | package com.example.mvp.entity; 2 | 3 | /** 4 | * Created by wenyingzhi on 2018/4/23. 5 | */ 6 | 7 | public class UserInfo { 8 | 9 | /** 10 | * status : error 11 | * msg : failuserid 12 | */ 13 | 14 | private String status; 15 | private String msg; 16 | 17 | public String getStatus() { 18 | return status; 19 | } 20 | 21 | public void setStatus(String status) { 22 | this.status = status; 23 | } 24 | 25 | public String getMsg() { 26 | return msg; 27 | } 28 | 29 | public void setMsg(String msg) { 30 | this.msg = msg; 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return "UserInfo{" + 36 | "status='" + status + '\'' + 37 | ", msg='" + msg + '\'' + 38 | '}'; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /myrxjava/src/main/java/com/example/myrxjava/entity/UserInfo.java: -------------------------------------------------------------------------------- 1 | package com.example.myrxjava.entity; 2 | 3 | /** 4 | * Created by wenyingzhi on 2018/4/23. 5 | */ 6 | 7 | public class UserInfo { 8 | 9 | /** 10 | * status : error 11 | * msg : failuserid 12 | */ 13 | 14 | private String status; 15 | private String msg; 16 | 17 | public String getStatus() { 18 | return status; 19 | } 20 | 21 | public void setStatus(String status) { 22 | this.status = status; 23 | } 24 | 25 | public String getMsg() { 26 | return msg; 27 | } 28 | 29 | public void setMsg(String msg) { 30 | this.msg = msg; 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return "UserInfo{" + 36 | "status='" + status + '\'' + 37 | ", msg='" + msg + '\'' + 38 | '}'; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /myrxjava/src/androidTest/java/com/example/myrxjava/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.example.myrxjava; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.example.myrxjava", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /mvp/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /myrxjava/src/main/java/com/example/myrxjava/inject/module/AppModule.java: -------------------------------------------------------------------------------- 1 | package com.example.myrxjava.inject.module; 2 | 3 | import android.app.Application; 4 | import android.app.ProgressDialog; 5 | import android.content.Context; 6 | import android.widget.Toast; 7 | 8 | import com.example.myrxjava.app.App; 9 | 10 | import javax.inject.Inject; 11 | import javax.inject.Singleton; 12 | 13 | import dagger.Module; 14 | import dagger.Provides; 15 | 16 | /** 17 | * 全局APP 18 | */ 19 | @Module 20 | public class AppModule { 21 | @Provides 22 | public Context procideContext(){ 23 | return App.getAppContext(); 24 | } 25 | 26 | @Provides 27 | public Application provideApplication(){ 28 | return App.getApplication(); 29 | } 30 | 31 | @Singleton 32 | @Provides 33 | public Toast providesToast(Context context){ 34 | return Toast.makeText(context,"",Toast.LENGTH_SHORT); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /myrxjava/src/main/java/com/example/myrxjava/app/App.java: -------------------------------------------------------------------------------- 1 | package com.example.myrxjava.app; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | 6 | import com.example.myrxjava.inject.component.AppComponent; 7 | import com.example.myrxjava.inject.component.DaggerAppComponent; 8 | 9 | import javax.inject.Inject; 10 | 11 | /** 12 | * Created by wenyingzhi on 2018/4/23. 13 | */ 14 | 15 | public class App extends Application { 16 | private static Application app; 17 | public static AppComponent appComponent; 18 | @Override 19 | public void onCreate() { 20 | super.onCreate(); 21 | app=this; 22 | //初始化全局AppComponent,主要对module里面单利和app处于一个生命周期 23 | appComponent = DaggerAppComponent.create(); 24 | } 25 | 26 | public static Application getApplication(){ 27 | return app; 28 | } 29 | 30 | public static Context getAppContext(){ 31 | return app.getApplicationContext(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /mvp/src/main/res/layout/activity_login.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 14 | 19 | 20 |