├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── 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 │ │ │ │ ├── colors.xml │ │ │ │ ├── dimens.xml │ │ │ │ ├── styles.xml │ │ │ │ └── strings.xml │ │ │ ├── values-w820dp │ │ │ │ └── dimens.xml │ │ │ └── layout │ │ │ │ ├── activity_login.xml │ │ │ │ └── fragment_login.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── comtesting │ │ │ │ └── atomtry │ │ │ │ ├── base │ │ │ │ ├── BaseView.java │ │ │ │ ├── BaseActivity.java │ │ │ │ ├── BasePresenter.java │ │ │ │ └── BaseFragment.java │ │ │ │ ├── request │ │ │ │ ├── mCallBack.java │ │ │ │ ├── mHttpRequest.java │ │ │ │ ├── RetrofitApi.java │ │ │ │ ├── HttpRequestFactory.java │ │ │ │ ├── parameter │ │ │ │ │ ├── userParameter.java │ │ │ │ │ └── HttpParameter.java │ │ │ │ ├── HttpResult.java │ │ │ │ └── retrofitHttpRequest.java │ │ │ │ ├── home │ │ │ │ └── homeActivity.java │ │ │ │ ├── register │ │ │ │ └── RegisterActivity.java │ │ │ │ ├── scope │ │ │ │ └── fragmentScoped.java │ │ │ │ ├── login │ │ │ │ ├── LoginComponent.java │ │ │ │ ├── LoginContract.java │ │ │ │ ├── LoginModule.java │ │ │ │ ├── LoginActivity.java │ │ │ │ ├── LoginPresenter.java │ │ │ │ └── LoginFragment.java │ │ │ │ ├── mAppComponent.java │ │ │ │ ├── utils │ │ │ │ ├── ActivityUtils.java │ │ │ │ ├── ciPherUtils.java │ │ │ │ ├── ExceptionUtils.java │ │ │ │ └── RxjavaFactory.java │ │ │ │ ├── mAppModule.java │ │ │ │ ├── mApplication.java │ │ │ │ ├── data │ │ │ │ ├── greendao │ │ │ │ │ └── userLogin.java │ │ │ │ ├── repository │ │ │ │ │ └── UserRepository.java │ │ │ │ └── bean │ │ │ │ │ └── UserLoginBean.java │ │ │ │ └── rxbus │ │ │ │ └── RxBus.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── comtesting │ │ │ └── atomtry │ │ │ ├── myRobolectricTestRunner.java │ │ │ └── login │ │ │ ├── loginPresenterTest.java │ │ │ └── LoginScreenTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── example │ │ └── comtesting │ │ └── atomtry │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── README.md ├── .idea ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── kotlinc.xml ├── modules.xml ├── runConfigurations.xml ├── gradle.xml ├── compiler.xml ├── inspectionProfiles │ └── Project_Default.xml └── misc.xml ├── 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 | # atomRXDT-MVP 2 | retrofit2+rxjava2+dagger2+greenDao3+mvp+test 3 | 4 | just a practice project 5 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrqatom/atomRXDT-MVP/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrqatom/atomRXDT-MVP/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrqatom/atomRXDT-MVP/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrqatom/atomRXDT-MVP/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrqatom/atomRXDT-MVP/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrqatom/atomRXDT-MVP/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /.idea/kotlinc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Mar 13 14:20:23 CST 2017 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-3.3-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/comtesting/atomtry/base/BaseView.java: -------------------------------------------------------------------------------- 1 | package com.example.comtesting.atomtry.base; 2 | 3 | 4 | /** 5 | * Created by atom on 2017/2/24. 6 | * view层基础接口 7 | */ 8 | 9 | public interface BaseView

{ 10 | void setPresenter(P presenter); 11 | } 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/comtesting/atomtry/request/mCallBack.java: -------------------------------------------------------------------------------- 1 | package com.example.comtesting.atomtry.request; 2 | 3 | /** 4 | * Created by atom on 2017/2/24. 5 | * 请求返回 6 | */ 7 | 8 | public interface mCallBack { 9 | void success(T response); 10 | 11 | void fail(String message); 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/comtesting/atomtry/base/BaseActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.comtesting.atomtry.base; 2 | 3 | import com.trello.rxlifecycle2.components.support.RxAppCompatActivity; 4 | 5 | /** 6 | * Created by atom on 2017/3/23. 7 | * 基础activity 8 | */ 9 | 10 | public class BaseActivity extends RxAppCompatActivity { 11 | } 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/comtesting/atomtry/home/homeActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.comtesting.atomtry.home; 2 | 3 | 4 | import com.trello.rxlifecycle2.components.support.RxAppCompatActivity; 5 | 6 | /** 7 | * Created by atom on 2017/3/16. 8 | * 主页 9 | */ 10 | 11 | public class homeActivity extends RxAppCompatActivity{ 12 | 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/comtesting/atomtry/register/RegisterActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.comtesting.atomtry.register; 2 | 3 | 4 | import com.example.comtesting.atomtry.base.BaseActivity; 5 | 6 | /** 7 | * Created by atom on 2017/2/27. 8 | * 注册activity 9 | */ 10 | 11 | public class RegisterActivity extends BaseActivity { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/comtesting/atomtry/scope/fragmentScoped.java: -------------------------------------------------------------------------------- 1 | package com.example.comtesting.atomtry.scope; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | 7 | import javax.inject.Scope; 8 | 9 | /** 10 | * Created by atom on 2017/4/13. 11 | */ 12 | @Documented 13 | @Scope 14 | @Retention(RetentionPolicy.RUNTIME) 15 | public @interface fragmentScoped { 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/comtesting/atomtry/login/LoginComponent.java: -------------------------------------------------------------------------------- 1 | package com.example.comtesting.atomtry.login; 2 | 3 | import com.example.comtesting.atomtry.mAppComponent; 4 | import com.example.comtesting.atomtry.scope.fragmentScoped; 5 | 6 | import dagger.Component; 7 | 8 | /** 9 | * Created by atom on 2017/2/24. 10 | * dagger的登录component 11 | */ 12 | @fragmentScoped 13 | @Component(dependencies = mAppComponent.class,modules = LoginModule.class) 14 | public interface LoginComponent { 15 | void inject(LoginActivity loginActivity); 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/comtesting/atomtry/request/mHttpRequest.java: -------------------------------------------------------------------------------- 1 | package com.example.comtesting.atomtry.request; 2 | 3 | import com.example.comtesting.atomtry.request.parameter.HttpParameter; 4 | import com.example.comtesting.atomtry.request.parameter.userParameter; 5 | 6 | /** 7 | * Created by atom on 2017/2/24. 8 | * 网络请求 9 | */ 10 | 11 | public interface mHttpRequest { 12 | void request(String url, Class clazz, mCallBack callBack); 13 | 14 | void request(String url, HttpParameter param, mCallBack callBack); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | AtomTry 3 | 用户名 4 | 密码 5 | 登录 6 | 注册 7 | 手机号 8 | 验证码 9 | 获取验证码 10 | 确认 11 | 取消 12 | 记住密码 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/comtesting/atomtry/mAppComponent.java: -------------------------------------------------------------------------------- 1 | package com.example.comtesting.atomtry; 2 | 3 | import android.content.Context; 4 | 5 | import com.example.comtesting.atomtry.request.mHttpRequest; 6 | import com.example.comtesting.atomtry.request.retrofitHttpRequest; 7 | 8 | import javax.inject.Singleton; 9 | 10 | import dagger.Component; 11 | 12 | /** 13 | * Created by atom on 2017/2/24. 14 | * 全局component 15 | */ 16 | @Singleton 17 | @Component(modules = mAppModule.class) 18 | public interface mAppComponent { 19 | mHttpRequest getMHttpRequest(); 20 | } 21 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/comtesting/atomtry/request/RetrofitApi.java: -------------------------------------------------------------------------------- 1 | package com.example.comtesting.atomtry.request; 2 | 3 | import java.util.Map; 4 | 5 | import io.reactivex.Observable; 6 | import retrofit2.http.Body; 7 | import retrofit2.http.POST; 8 | import retrofit2.http.Url; 9 | 10 | /** 11 | * 12 | * @author atom 13 | * @date 2017/3/14 14 | * Retrofit API 15 | */ 16 | 17 | public interface RetrofitApi { 18 | 19 | @POST 20 | Observable getResponse(@Url String url, @Body Map parameter); 21 | 22 | //这里踩坑记录:retrofit不支持:type泛型 23 | @POST 24 | Observable getResponse(@Url String url); 25 | } 26 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/comtesting/atomtry/request/HttpRequestFactory.java: -------------------------------------------------------------------------------- 1 | package com.example.comtesting.atomtry.request; 2 | 3 | /** 4 | * Created by atom on 2017/2/24. 5 | * 获得请求实例的工厂,实现可替换原则 6 | */ 7 | 8 | public class HttpRequestFactory { 9 | private static mHttpRequest mHttpRequest; 10 | 11 | public static mHttpRequest getRetrofitHttpRequest() { 12 | if (mHttpRequest == null) { 13 | synchronized (HttpRequestFactory.class) { 14 | if (mHttpRequest == null) { 15 | mHttpRequest = new retrofitHttpRequest(); 16 | } 17 | } 18 | } 19 | return mHttpRequest; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /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 F:\AndroidSDK/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/example/comtesting/atomtry/utils/ActivityUtils.java: -------------------------------------------------------------------------------- 1 | package com.example.comtesting.atomtry.utils; 2 | 3 | import android.support.v4.app.Fragment; 4 | import android.support.v4.app.FragmentManager; 5 | 6 | import java.util.List; 7 | 8 | import static com.google.common.base.Preconditions.checkNotNull; 9 | 10 | /** 11 | * Created by atom on 2017/2/24. 12 | * activity工具包 13 | */ 14 | 15 | public class ActivityUtils { 16 | 17 | /** 18 | * 添加fragment 19 | */ 20 | public static void addFragment(FragmentManager manager, Fragment fragment, int layoutId) { 21 | checkNotNull(manager); 22 | checkNotNull(fragment); 23 | manager.beginTransaction().add(layoutId, fragment).commit(); 24 | } 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 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/comtesting/atomtry/request/parameter/userParameter.java: -------------------------------------------------------------------------------- 1 | package com.example.comtesting.atomtry.request.parameter; 2 | 3 | /** 4 | * Created by atom on 2017/3/19. 5 | */ 6 | @Deprecated 7 | public class userParameter{ 8 | private String phone; 9 | private String psw; 10 | 11 | public String getPsw() { 12 | return psw; 13 | } 14 | 15 | public void setPsw(String psw) { 16 | this.psw = psw; 17 | } 18 | 19 | public String getPhone() { 20 | 21 | return phone; 22 | } 23 | 24 | public void setPhone(String phone) { 25 | this.phone = phone; 26 | } 27 | 28 | // @Override 29 | // public void setParameterToField() { 30 | // phone = parameters.get("phone"); 31 | // psw = parameters.get("psw"); 32 | // } 33 | } 34 | -------------------------------------------------------------------------------- /app/src/test/java/com/example/comtesting/atomtry/myRobolectricTestRunner.java: -------------------------------------------------------------------------------- 1 | package com.example.comtesting.atomtry; 2 | 3 | 4 | import org.junit.runners.model.InitializationError; 5 | import org.robolectric.RoboSettings; 6 | import org.robolectric.RobolectricTestRunner; 7 | 8 | /** 9 | * 继承RobolectricTestRunner改变下载路径,加快Robolectric的下载 10 | */ 11 | public class myRobolectricTestRunner extends RobolectricTestRunner { 12 | public myRobolectricTestRunner(Class testClass) throws InitializationError { 13 | super(testClass); 14 | 15 | // 从源码知道MavenDependencyResolver默认以RoboSettings的repositoryUrl和repositoryId为默认值,因此只需要对RoboSetting进行赋值即可 16 | RoboSettings.setMavenRepositoryId("alimaven"); 17 | RoboSettings.setMavenRepositoryUrl("http://maven.aliyun.com/nexus/content/groups/public/"); 18 | } 19 | } -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/comtesting/atomtry/request/parameter/HttpParameter.java: -------------------------------------------------------------------------------- 1 | package com.example.comtesting.atomtry.request.parameter; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * Created by atom on 2017/3/15. 8 | */ 9 | 10 | public class HttpParameter { 11 | public Map parameters; 12 | public Class clazz; 13 | 14 | public Class getClazz() { 15 | return clazz; 16 | } 17 | 18 | public void setClazz(Class clazz) { 19 | this.clazz = clazz; 20 | } 21 | 22 | public HttpParameter() { 23 | parameters = new HashMap<>(); 24 | } 25 | 26 | public Map getParameters() { 27 | return parameters; 28 | } 29 | public void addParameter(String key,String parameter){ 30 | parameters.put(key,parameter); 31 | } 32 | // public abstract void setParameterToField(); 33 | } 34 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/example/comtesting/atomtry/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.example.comtesting.atomtry; 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 | * Instrumentation 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.comtesting.atomtry", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/comtesting/atomtry/base/BasePresenter.java: -------------------------------------------------------------------------------- 1 | package com.example.comtesting.atomtry.base; 2 | 3 | import com.example.comtesting.atomtry.data.repository.UserRepository; 4 | import com.example.comtesting.atomtry.request.mHttpRequest; 5 | 6 | import javax.inject.Inject; 7 | 8 | /** 9 | * Created by atom on 2017/2/24. 10 | * presenter层 11 | */ 12 | 13 | public class BasePresenter{ 14 | public final V mView; 15 | public final UserRepository mUserRepository; 16 | public final mHttpRequest mHttpRequest; 17 | 18 | public BasePresenter(V mView, UserRepository mUserRepository, com.example.comtesting.atomtry.request.mHttpRequest mHttpRequest) { 19 | this.mView = mView; 20 | this.mUserRepository = mUserRepository; 21 | this.mHttpRequest = mHttpRequest; 22 | } 23 | 24 | @Inject 25 | void setupListeners() { 26 | mView.setPresenter(this); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/comtesting/atomtry/login/LoginContract.java: -------------------------------------------------------------------------------- 1 | package com.example.comtesting.atomtry.login; 2 | 3 | import com.example.comtesting.atomtry.base.BasePresenter; 4 | import com.example.comtesting.atomtry.base.BaseView; 5 | import com.example.comtesting.atomtry.data.bean.UserLoginBean; 6 | import com.example.comtesting.atomtry.data.greendao.userLogin; 7 | 8 | /** 9 | * Created by atom on 2017/2/24. 10 | * login的view、presenter接口 11 | */ 12 | 13 | public interface LoginContract { 14 | interface View extends BaseView { 15 | void showLoginDialog(); 16 | 17 | void showLoginSuccess(UserLoginBean bean); 18 | 19 | void showLoginFail(String message); 20 | 21 | boolean isActive(); 22 | 23 | boolean isRemember(); 24 | 25 | void initUser(userLogin user); 26 | } 27 | 28 | interface presenter{ 29 | void login(String userName, String password); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/comtesting/atomtry/mAppModule.java: -------------------------------------------------------------------------------- 1 | package com.example.comtesting.atomtry; 2 | 3 | import android.content.Context; 4 | 5 | import com.example.comtesting.atomtry.request.HttpRequestFactory; 6 | import com.example.comtesting.atomtry.request.mHttpRequest; 7 | 8 | import java.util.concurrent.TimeUnit; 9 | 10 | import javax.inject.Singleton; 11 | 12 | import dagger.Module; 13 | import dagger.Provides; 14 | import okhttp3.OkHttpClient; 15 | import retrofit2.Retrofit; 16 | import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; 17 | import retrofit2.converter.gson.GsonConverterFactory; 18 | 19 | /** 20 | * Created by atom on 2017/2/24. 21 | * 全局module 22 | */ 23 | @Module 24 | public class mAppModule { 25 | private Context mContext; 26 | 27 | public mAppModule(Context mContext) { 28 | this.mContext = mContext; 29 | } 30 | 31 | @Singleton 32 | @Provides 33 | public mHttpRequest provideHttpRequest() { 34 | return HttpRequestFactory.getRetrofitHttpRequest(); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/comtesting/atomtry/login/LoginModule.java: -------------------------------------------------------------------------------- 1 | package com.example.comtesting.atomtry.login; 2 | 3 | 4 | import com.example.comtesting.atomtry.data.repository.UserRepository; 5 | import com.example.comtesting.atomtry.request.HttpRequestFactory; 6 | import com.example.comtesting.atomtry.request.mHttpRequest; 7 | 8 | import javax.inject.Singleton; 9 | 10 | import dagger.Module; 11 | import dagger.Provides; 12 | 13 | /** 14 | * Created by atom on 2017/2/24. 15 | * dagger的登录module 16 | */ 17 | @Module 18 | public class LoginModule { 19 | private LoginContract.View mView; 20 | 21 | public LoginModule(LoginContract.View mView) { 22 | this.mView = mView; 23 | } 24 | 25 | @Provides 26 | LoginContract.View provideView(){ 27 | return mView; 28 | } 29 | @Provides 30 | UserRepository provideUserRepository(){ 31 | return new UserRepository(); 32 | } 33 | // @Provides 34 | // mHttpRequest provideRequest(){ 35 | // return HttpRequestFactory.getRetrofitHttpRequest(); 36 | // } 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/comtesting/atomtry/request/HttpResult.java: -------------------------------------------------------------------------------- 1 | package com.example.comtesting.atomtry.request; 2 | 3 | /** 4 | * Created by atom on 2017/3/15. 5 | * 网络请求返回 6 | */ 7 | 8 | public class HttpResult { 9 | public String statusCode; 10 | public boolean status; 11 | public String message; 12 | public T data; 13 | 14 | public String getMessage() { 15 | return message; 16 | } 17 | 18 | public void setMessage(String message) { 19 | this.message = message; 20 | } 21 | 22 | public String getStatusCode() { 23 | return statusCode; 24 | } 25 | 26 | public void setStatusCode(String statusCode) { 27 | this.statusCode = statusCode; 28 | } 29 | 30 | public boolean isStatus() { 31 | return status; 32 | } 33 | 34 | public void setStatus(boolean status) { 35 | this.status = status; 36 | } 37 | 38 | public T getData() { 39 | return data; 40 | } 41 | 42 | public void setData(T data) { 43 | this.data = data; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 24 | 27 | 28 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_login.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 12 | 18 | 19 | 20 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/comtesting/atomtry/base/BaseFragment.java: -------------------------------------------------------------------------------- 1 | package com.example.comtesting.atomtry.base; 2 | 3 | import android.app.ProgressDialog; 4 | import android.content.Context; 5 | import android.os.Bundle; 6 | import android.support.annotation.Nullable; 7 | import android.widget.Toast; 8 | 9 | import com.example.comtesting.atomtry.login.LoginPresenter; 10 | import com.trello.rxlifecycle2.components.support.RxFragment; 11 | 12 | /** 13 | * 14 | * @author atom 15 | * @date 2017/3/16 16 | */ 17 | 18 | public class BaseFragment

extends RxFragment{ 19 | public ProgressDialog progressDialog; 20 | Context mContext; 21 | 22 | @Override 23 | public void onCreate(@Nullable Bundle savedInstanceState) { 24 | super.onCreate(savedInstanceState); 25 | mContext = getActivity(); 26 | } 27 | 28 | public void showProgressDialog(String content){ 29 | if (progressDialog==null){ 30 | progressDialog=new ProgressDialog(mContext); 31 | } 32 | progressDialog.setMessage(content); 33 | progressDialog.show(); 34 | } 35 | public void disMissProgressDialog(){ 36 | if (progressDialog==null){ 37 | return; 38 | } 39 | progressDialog.dismiss(); 40 | } 41 | 42 | public void showToast(String content){ 43 | Toast.makeText(mContext,content,Toast.LENGTH_SHORT).show(); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/comtesting/atomtry/utils/ciPherUtils.java: -------------------------------------------------------------------------------- 1 | package com.example.comtesting.atomtry.utils; 2 | 3 | import android.support.annotation.NonNull; 4 | 5 | import java.io.UnsupportedEncodingException; 6 | import java.security.MessageDigest; 7 | import java.security.NoSuchAlgorithmException; 8 | 9 | /** 10 | * Created by atom on 2017/3/16. 11 | * 12 | */ 13 | 14 | public class ciPherUtils { 15 | /** 16 | * 进行MD5加密(小写) 17 | */ 18 | public static String Str2MD5LowCase(@NonNull String str) { 19 | return Str2MD5UpCase(str).toLowerCase(); 20 | } 21 | 22 | /** 23 | * 进行MD5加密MD5加密 24 | */ 25 | public static String Str2MD5UpCase(@NonNull String str) { 26 | byte[] hash; 27 | try { 28 | hash = MessageDigest.getInstance("MD5").digest( 29 | str.getBytes("UTF-8")); 30 | } catch (NoSuchAlgorithmException e) { 31 | throw new RuntimeException("Huh, MD5 should be supported?", e); 32 | } catch (UnsupportedEncodingException e) { 33 | throw new RuntimeException("Huh, UTF-8 should be supported?", e); 34 | } 35 | StringBuilder hex = new StringBuilder(hash.length * 2); 36 | for (byte b : hash) { 37 | if ((b & 0xFF) < 0x10) 38 | hex.append("0"); 39 | hex.append(Integer.toHexString(b & 0xFF)); 40 | } 41 | return hex.toString(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 36 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/comtesting/atomtry/login/LoginActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.comtesting.atomtry.login; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | import android.support.v7.widget.Toolbar; 6 | 7 | import com.example.comtesting.atomtry.R; 8 | import com.example.comtesting.atomtry.base.BaseActivity; 9 | import com.example.comtesting.atomtry.mApplication; 10 | import com.example.comtesting.atomtry.utils.ActivityUtils; 11 | 12 | import javax.inject.Inject; 13 | 14 | /** 15 | * @author atom 16 | * 登录activity 17 | */ 18 | public class LoginActivity extends BaseActivity { 19 | @Inject 20 | LoginPresenter presenter; 21 | @Override 22 | protected void onCreate(Bundle savedInstanceState) { 23 | super.onCreate(savedInstanceState); 24 | setContentView(R.layout.activity_login); 25 | initView(); 26 | } 27 | private void initView(){ 28 | Toolbar toolbar = (Toolbar) findViewById(R.id.login_title); 29 | setSupportActionBar(toolbar); 30 | toolbar.setTitle(R.string.login); 31 | 32 | LoginFragment fragment= 33 | (LoginFragment) getSupportFragmentManager().findFragmentById(R.id.login_content); 34 | if (fragment==null){ 35 | fragment=LoginFragment.newInstance(); 36 | ActivityUtils.addFragment(getSupportFragmentManager(),fragment,R.id.login_content); 37 | } 38 | DaggerLoginComponent.builder() 39 | .mAppComponent(mApplication.getAppComponent()) 40 | .loginModule(new LoginModule(fragment)).build().inject(this); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/comtesting/atomtry/mApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.comtesting.atomtry; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.app.Application; 5 | import android.content.Context; 6 | 7 | import com.example.comtesting.atomtry.greendao.gen.DaoMaster; 8 | import com.example.comtesting.atomtry.greendao.gen.DaoSession; 9 | import com.example.comtesting.atomtry.request.retrofitHttpRequest; 10 | 11 | import org.greenrobot.greendao.database.Database; 12 | 13 | 14 | /** 15 | * Created by atom on 2017/2/24. 16 | */ 17 | 18 | public class mApplication extends Application { 19 | private static mAppComponent mAppComponent; 20 | 21 | private DaoSession daoSession; 22 | @SuppressLint("StaticFieldLeak") 23 | private static Context mContext; 24 | @Override 25 | public void onCreate() { 26 | super.onCreate(); 27 | mContext=this; 28 | initGreenDao(); 29 | retrofitHttpRequest.init(); 30 | mAppComponent = DaggermAppComponent.builder() 31 | .mAppModule(new mAppModule(mContext)).build(); 32 | } 33 | 34 | public static Context getmContext() { 35 | return mContext; 36 | } 37 | 38 | public static mAppComponent getAppComponent() { 39 | return mAppComponent; 40 | } 41 | 42 | private void initGreenDao(){ 43 | DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "atom_db" ); 44 | Database db = helper.getReadableDb(); 45 | daoSession = new DaoMaster(db).newSession(); 46 | } 47 | 48 | public DaoSession getDaoSession() { 49 | return daoSession; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/comtesting/atomtry/data/greendao/userLogin.java: -------------------------------------------------------------------------------- 1 | package com.example.comtesting.atomtry.data.greendao; 2 | 3 | import org.greenrobot.greendao.annotation.Entity; 4 | import org.greenrobot.greendao.annotation.Id; 5 | import org.greenrobot.greendao.annotation.Generated; 6 | 7 | /** 8 | * Created by atom on 2017/4/6. 9 | */ 10 | @Entity 11 | public class userLogin { 12 | @Id(autoincrement = true) 13 | private Long id; 14 | private String userName; 15 | private String password; 16 | private boolean isRemember; 17 | 18 | public String getPassword() { 19 | return this.password; 20 | } 21 | 22 | public void setPassword(String password) { 23 | this.password = password; 24 | } 25 | 26 | public String getUserName() { 27 | return this.userName; 28 | } 29 | 30 | public void setUserName(String userName) { 31 | this.userName = userName; 32 | } 33 | 34 | public Long getId() { 35 | return this.id; 36 | } 37 | 38 | public void setId(Long id) { 39 | this.id = id; 40 | } 41 | 42 | public boolean getIsRemember() { 43 | return this.isRemember; 44 | } 45 | 46 | public void setIsRemember(boolean isRemember) { 47 | this.isRemember = isRemember; 48 | } 49 | 50 | @Generated(hash = 1270635441) 51 | public userLogin(Long id, String userName, String password, boolean isRemember) { 52 | this.id = id; 53 | this.userName = userName; 54 | this.password = password; 55 | this.isRemember = isRemember; 56 | } 57 | 58 | @Generated(hash = 1680734102) 59 | public userLogin() { 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/comtesting/atomtry/rxbus/RxBus.java: -------------------------------------------------------------------------------- 1 | package com.example.comtesting.atomtry.rxbus; 2 | 3 | import io.reactivex.Observable; 4 | import io.reactivex.android.schedulers.AndroidSchedulers; 5 | import io.reactivex.disposables.Disposable; 6 | import io.reactivex.functions.Consumer; 7 | import io.reactivex.subjects.PublishSubject; 8 | import io.reactivex.subjects.Subject; 9 | 10 | /** 11 | * Created by atom on 2017/3/23. 12 | * 自定义事件总线eventbus 13 | */ 14 | 15 | public class RxBus { 16 | 17 | private static volatile RxBus instance; 18 | private final Subject subject; 19 | 20 | private RxBus() { 21 | //rxjava2里subject已经可以直接toSerialized(),使得线程安全 22 | subject = PublishSubject.create().toSerialized(); 23 | //rxjava1 SerializedSubject是线程安全的 24 | // subject = new SerializedSubject<>(PublishSubject.create()); 25 | } 26 | 27 | public static RxBus getInstance() { 28 | if (instance == null) { 29 | synchronized (RxBus.class) { 30 | if (instance == null) { 31 | instance = new RxBus(); 32 | } 33 | } 34 | } 35 | return instance; 36 | } 37 | //发送消息 38 | public void post(Object object) { 39 | subject.onNext(object); 40 | } 41 | 42 | private Observable toObservable(final Class type) { 43 | return subject.ofType(type); 44 | } 45 | 46 | public Disposable toDisposable(Class type, Consumer consumer) { 47 | return RxBus.getInstance() 48 | .toObservable(type) 49 | .observeOn(AndroidSchedulers.mainThread()) 50 | .subscribe(consumer); 51 | } 52 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/comtesting/atomtry/data/repository/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.example.comtesting.atomtry.data.repository; 2 | 3 | 4 | import android.support.annotation.Nullable; 5 | 6 | import com.example.comtesting.atomtry.data.greendao.userLogin; 7 | import com.example.comtesting.atomtry.greendao.gen.userLoginDao; 8 | import com.example.comtesting.atomtry.mApplication; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * Created by atom on 2017/2/24. 14 | */ 15 | 16 | public class UserRepository { 17 | private userLoginDao daoSession; 18 | 19 | public UserRepository() { 20 | daoSession = ((mApplication) mApplication.getmContext()).getDaoSession().getUserLoginDao(); 21 | } 22 | 23 | /** 24 | * 数据库:增 25 | * 26 | * @param bean 27 | */ 28 | public void insertUser(userLogin bean) { 29 | daoSession.insert(bean); 30 | } 31 | 32 | /** 33 | * 数据库:删 34 | * 35 | * @param id 36 | */ 37 | public void deleteUser(Long id) { 38 | daoSession.deleteByKey(id); 39 | } 40 | 41 | public void deleteUser(userLogin bean) { 42 | deleteUser(bean.getId()); 43 | } 44 | 45 | /** 46 | * 数据库:改 47 | * 48 | * @param id 修改前的ID 49 | * @param bean 修改后的Data 50 | */ 51 | public void upDataUser(userLogin bean, @Nullable Long id) { 52 | if (id != null) bean.setId(id); 53 | daoSession.update(bean); 54 | } 55 | 56 | /** 57 | * 数据库:查 58 | * 59 | * @param id 60 | */ 61 | public userLogin queryUser(Long id) { 62 | return daoSession.load(id); 63 | } 64 | public List queryAllUser() { 65 | return daoSession.loadAll(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/comtesting/atomtry/utils/ExceptionUtils.java: -------------------------------------------------------------------------------- 1 | package com.example.comtesting.atomtry.utils; 2 | 3 | /** 4 | * Created by atom on 2017/3/22. 5 | * 异常处理 6 | */ 7 | 8 | import android.net.ParseException; 9 | 10 | import com.google.gson.JsonParseException; 11 | 12 | import org.json.JSONException; 13 | 14 | import java.net.ConnectException; 15 | 16 | import retrofit2.HttpException; 17 | 18 | 19 | public class ExceptionUtils { 20 | //对应HTTP的状态码 21 | private static final int UNAUTHORIZED = 401; 22 | private static final int FORBIDDEN = 403; 23 | private static final int NOT_FOUND = 404; 24 | private static final int REQUEST_TIMEOUT = 408; 25 | private static final int INTERNAL_SERVER_ERROR = 500; 26 | private static final int BAD_GATEWAY = 502; 27 | private static final int SERVICE_UNAVAILABLE = 503; 28 | private static final int GATEWAY_TIMEOUT = 504; 29 | 30 | public static Exception handleException(Throwable e) { 31 | String ex; 32 | if (e instanceof HttpException) { //HTTP错误 33 | HttpException httpException = (HttpException) e; 34 | switch (httpException.code()) { 35 | case UNAUTHORIZED: 36 | case FORBIDDEN: 37 | case NOT_FOUND: 38 | case REQUEST_TIMEOUT: 39 | case GATEWAY_TIMEOUT: 40 | case INTERNAL_SERVER_ERROR: 41 | case BAD_GATEWAY: 42 | case SERVICE_UNAVAILABLE: 43 | default: 44 | ex = "网络出错了"; //均视为网络错误 45 | break; 46 | } 47 | } else if (e instanceof JsonParseException 48 | || e instanceof JSONException 49 | || e instanceof ParseException) { 50 | ex = "数据解析错误"; //均视为解析错误 51 | } else if (e instanceof ConnectException) { 52 | ex = "网络连接失败"; //均视为网络错误 53 | } else { 54 | ex = e.getMessage(); //未知错误或服务器返回 55 | } 56 | return new Exception(ex); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/comtesting/atomtry/utils/RxjavaFactory.java: -------------------------------------------------------------------------------- 1 | package com.example.comtesting.atomtry.utils; 2 | 3 | import java.util.concurrent.Callable; 4 | 5 | import javax.xml.transform.Transformer; 6 | 7 | import io.reactivex.Observable; 8 | import io.reactivex.ObservableSource; 9 | import io.reactivex.ObservableTransformer; 10 | import io.reactivex.Scheduler; 11 | import io.reactivex.android.plugins.RxAndroidPlugins; 12 | import io.reactivex.android.schedulers.AndroidSchedulers; 13 | import io.reactivex.functions.Function; 14 | import io.reactivex.plugins.RxJavaPlugins; 15 | import io.reactivex.schedulers.Schedulers; 16 | import io.reactivex.schedulers.TestScheduler; 17 | import retrofit2.Response; 18 | 19 | /** 20 | * Created by atom on 2017/3/22. 21 | * Rxjava工具类 22 | */ 23 | 24 | public class RxjavaFactory { 25 | /** 26 | * 优雅的处理Rx的异常并返回 27 | * @param 28 | */ 29 | public static class HttpResponseFunc implements Function> { 30 | @Override 31 | public Observable apply(Throwable throwable) throws Exception { 32 | return Observable.error(ExceptionUtils.handleException(throwable)); 33 | } 34 | } 35 | 36 | /** 37 | * 简化的操作,发布者IO线程,订阅者UI线程 38 | * @param 39 | * @return 40 | */ 41 | public static ObservableTransformer io_main_trasformer(){ 42 | return new ObservableTransformer() { 43 | @Override 44 | public ObservableSource apply(Observable upstream) { 45 | return upstream.subscribeOn(Schedulers.io()) 46 | .observeOn(AndroidSchedulers.mainThread()); 47 | } 48 | }; 49 | } 50 | 51 | /** 52 | * 单元测试的时候,利用RxJavaPlugins将io线程转换为trampoline 53 | * trampoline应该是立即执行的意思(待商榷),替代了Rx1的immediate。 54 | */ 55 | public static void asyncToSync() { 56 | RxJavaPlugins.reset(); 57 | RxJavaPlugins.setIoSchedulerHandler(new Function() { 58 | @Override 59 | public Scheduler apply(Scheduler scheduler) throws Exception { 60 | return Schedulers.trampoline(); 61 | } 62 | }); 63 | // RxAndroidPlugins.reset(); 64 | // RxAndroidPlugins.setInitMainThreadSchedulerHandler(new Function, Scheduler>() { 65 | // @Override 66 | // public Scheduler apply(Callable schedulerCallable) throws Exception { 67 | // return Schedulers.trampoline(); 68 | // } 69 | // }); 70 | } 71 | 72 | 73 | 74 | } 75 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/comtesting/atomtry/login/LoginPresenter.java: -------------------------------------------------------------------------------- 1 | package com.example.comtesting.atomtry.login; 2 | 3 | import com.example.comtesting.atomtry.base.BasePresenter; 4 | import com.example.comtesting.atomtry.data.bean.UserLoginBean; 5 | import com.example.comtesting.atomtry.data.greendao.userLogin; 6 | import com.example.comtesting.atomtry.data.repository.UserRepository; 7 | import com.example.comtesting.atomtry.request.mHttpRequest; 8 | import com.example.comtesting.atomtry.request.parameter.HttpParameter; 9 | import com.example.comtesting.atomtry.request.mCallBack; 10 | import com.example.comtesting.atomtry.utils.ciPherUtils; 11 | 12 | import javax.inject.Inject; 13 | 14 | 15 | /** 16 | * 17 | * @author atom 18 | * @date 2017/2/24 19 | */ 20 | 21 | public class LoginPresenter extends BasePresenter implements LoginContract.presenter { 22 | @SuppressWarnings("FieldCanBeLocal") 23 | private final String loginUrl = "Home/User/login"; 24 | 25 | @Inject 26 | public LoginPresenter(LoginContract.View mView, UserRepository mUserRepository, mHttpRequest mHttpRequest) { 27 | super(mView,mUserRepository,mHttpRequest); 28 | } 29 | 30 | public void init() { 31 | userLogin user = mUserRepository.queryUser(1L); 32 | if (user != null) { 33 | mView.initUser(user); 34 | } 35 | } 36 | 37 | @Override 38 | public void login(final String userName, final String password) { 39 | mView.showLoginDialog(); 40 | HttpParameter parameter = new HttpParameter(); 41 | parameter.addParameter("phone", userName); 42 | parameter.addParameter("psw", ciPherUtils.Str2MD5LowCase(password)); 43 | parameter.setClazz(UserLoginBean.class); 44 | mHttpRequest.request(loginUrl, parameter, new mCallBack() { 45 | @Override 46 | public void success(UserLoginBean response) { 47 | if (!mView.isActive()) return; 48 | mView.showLoginSuccess(response); 49 | if (mUserRepository.queryUser(1L) != null) { 50 | mUserRepository.upDataUser(new userLogin(1L, userName, password, mView.isRemember()), null); 51 | } else { 52 | mUserRepository.insertUser(new userLogin(1L, userName, password, mView.isRemember())); 53 | } 54 | } 55 | 56 | @Override 57 | public void fail(String message) { 58 | if (!mView.isActive()) return; 59 | mView.showLoginFail(message); 60 | } 61 | }); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /app/src/test/java/com/example/comtesting/atomtry/login/loginPresenterTest.java: -------------------------------------------------------------------------------- 1 | package com.example.comtesting.atomtry.login; 2 | 3 | import com.example.comtesting.atomtry.data.bean.UserLoginBean; 4 | import com.example.comtesting.atomtry.data.greendao.userLogin; 5 | import com.example.comtesting.atomtry.data.repository.UserRepository; 6 | import com.example.comtesting.atomtry.request.mCallBack; 7 | import com.example.comtesting.atomtry.request.mHttpRequest; 8 | import com.example.comtesting.atomtry.request.parameter.HttpParameter; 9 | 10 | import org.junit.Before; 11 | import org.junit.Test; 12 | import org.mockito.ArgumentCaptor; 13 | import org.mockito.Captor; 14 | import org.mockito.Mock; 15 | import org.mockito.MockitoAnnotations; 16 | 17 | import static junit.framework.Assert.*; 18 | import static org.mockito.Matchers.*; 19 | import static org.mockito.Mockito.*; 20 | 21 | /** 22 | * Created by atom on 2017/4/8. 23 | * 测试 24 | */ 25 | 26 | public class loginPresenterTest { 27 | public static final String USER_NAME = "userName"; 28 | public static final String PASSWORD = "password"; 29 | @Mock 30 | private LoginContract.View mView; 31 | @Mock 32 | private UserRepository mUserRepository; 33 | @Mock 34 | private mHttpRequest mHttpRequest; 35 | 36 | @Captor 37 | private ArgumentCaptor mCallbackCaptor; 38 | 39 | private LoginPresenter mLoginPresenter; 40 | 41 | @Before 42 | public void setUp() { 43 | MockitoAnnotations.initMocks(this); 44 | mLoginPresenter = new LoginPresenter(mView, mUserRepository, mHttpRequest); 45 | when(mView.isActive()).thenReturn(true); 46 | } 47 | 48 | @SuppressWarnings("unchecked") 49 | @Test 50 | public void testLogin() { 51 | when(mUserRepository.queryUser(anyLong())).thenReturn(any(userLogin.class)); 52 | // doNothing().when(mHttpRequest) 53 | // .request(anyString(),any(HttpParameter.class),mCallbackCaptor.capture()); 54 | mLoginPresenter.login(USER_NAME, PASSWORD); 55 | 56 | verify(mView).showLoginDialog(); 57 | verify(mHttpRequest).request(anyString(), any(HttpParameter.class), mCallbackCaptor.capture()); 58 | mCallbackCaptor.getValue().success(any(UserLoginBean.class)); 59 | verify(mView).showLoginSuccess(any(UserLoginBean.class)); 60 | verify(mUserRepository).queryUser(anyLong()); 61 | 62 | ArgumentCaptor userLoginCaptor = ArgumentCaptor.forClass(userLogin.class); 63 | verify(mUserRepository).upDataUser(userLoginCaptor.capture(), anyLong()); 64 | assertEquals(USER_NAME, userLoginCaptor.getValue().getUserName()); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_login.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 14 | 15 | 22 | 23 | 32 | 33 | 41 | 42 | 51 | 52 | 56 | 57 |