├── app ├── .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 │ │ │ └── layout │ │ │ │ ├── activity_dialog.xml │ │ │ │ └── activity_main.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── myapplication │ │ │ │ ├── ui │ │ │ │ ├── BaseView.java │ │ │ │ ├── IBaseView.java │ │ │ │ └── activity │ │ │ │ │ ├── BaseActivity.java │ │ │ │ │ ├── MainActivity.java │ │ │ │ │ └── DialogActivity.java │ │ │ │ ├── subscribe │ │ │ │ ├── ProgressCancelListener.java │ │ │ │ ├── ProgressDialogHandler.java │ │ │ │ └── ProgressSubscrible.java │ │ │ │ ├── dagger │ │ │ │ ├── ActivityScope.java │ │ │ │ ├── component │ │ │ │ │ └── MainactivityComponent.java │ │ │ │ └── module │ │ │ │ │ └── MainActivityModule.java │ │ │ │ ├── contacts │ │ │ │ └── MainActivityContact.java │ │ │ │ ├── AppComponent.java │ │ │ │ ├── network │ │ │ │ ├── RequestService.java │ │ │ │ ├── ApiException.java │ │ │ │ ├── RequestUtil.java │ │ │ │ └── OkhttpFactory.java │ │ │ │ ├── presenter │ │ │ │ ├── BasePresenter.java │ │ │ │ └── MainpresenterImpl.java │ │ │ │ ├── model │ │ │ │ ├── User.java │ │ │ │ └── HttpResult.java │ │ │ │ ├── MyApplication.java │ │ │ │ ├── utils │ │ │ │ ├── ToastUtis.java │ │ │ │ ├── NetWorkUtil.java │ │ │ │ └── SpUtils.java │ │ │ │ └── AppModule.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── myapplication │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── example │ │ └── myapplication │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── .idea ├── copyright │ └── profiles_settings.xml ├── markdown-navigator │ └── profiles_settings.xml ├── vcs.xml ├── modules.xml ├── runConfigurations.xml ├── gradle.xml ├── compiler.xml └── misc.xml ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ ├── gradle-wrapper.properties │ └── gradle-wrapper.properties.bak ├── .gitignore ├── gradle.properties ├── README.md ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | My Application 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengzhengbiao/EasyArchitechure/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /.idea/markdown-navigator/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengzhengbiao/EasyArchitechure/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengzhengbiao/EasyArchitechure/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengzhengbiao/EasyArchitechure/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengzhengbiao/EasyArchitechure/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengzhengbiao/EasyArchitechure/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengzhengbiao/EasyArchitechure/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengzhengbiao/EasyArchitechure/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengzhengbiao/EasyArchitechure/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengzhengbiao/EasyArchitechure/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengzhengbiao/EasyArchitechure/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.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 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/myapplication/ui/BaseView.java: -------------------------------------------------------------------------------- 1 | package com.example.myapplication.ui; 2 | 3 | /** 4 | * Created by JokerFish on 2017/8/17. 5 | */ 6 | 7 | public interface BaseView { 8 | } 9 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/myapplication/ui/IBaseView.java: -------------------------------------------------------------------------------- 1 | package com.example.myapplication.ui; 2 | 3 | /** 4 | * Created by JokerFish on 2017/8/17. 5 | */ 6 | 7 | public interface IBaseView { 8 | void showMessage(String msg); 9 | } 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/myapplication/subscribe/ProgressCancelListener.java: -------------------------------------------------------------------------------- 1 | package com.example.myapplication.subscribe; 2 | 3 | /** 4 | * Created by liukun on 16/3/10. 5 | */ 6 | public interface ProgressCancelListener { 7 | void onCancelProgress(); 8 | } 9 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/myapplication/dagger/ActivityScope.java: -------------------------------------------------------------------------------- 1 | package com.example.myapplication.dagger; 2 | 3 | import javax.inject.Scope; 4 | 5 | /** 6 | * Created by JokerFish on 2017/8/18. 7 | */ 8 | @Scope 9 | public @interface ActivityScope { 10 | } 11 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 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.0-all.zip 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties.bak: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 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-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/myapplication/contacts/MainActivityContact.java: -------------------------------------------------------------------------------- 1 | package com.example.myapplication.contacts; 2 | 3 | import com.example.myapplication.ui.IBaseView; 4 | 5 | /** 6 | * Created by JokerFish on 2017/8/18. 7 | */ 8 | 9 | public interface MainActivityContact { 10 | 11 | interface Presenter { 12 | 13 | void calculate(int num1, int num2); 14 | 15 | } 16 | 17 | interface View extends IBaseView { 18 | void signInSuccess(String knock); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/src/test/java/com/example/myapplication/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.example.myapplication; 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 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/myapplication/AppComponent.java: -------------------------------------------------------------------------------- 1 | package com.example.myapplication; 2 | 3 | import com.example.myapplication.presenter.BasePresenter; 4 | import com.example.myapplication.ui.activity.BaseActivity; 5 | 6 | import javax.inject.Singleton; 7 | 8 | import dagger.Component; 9 | 10 | /** 11 | * Created by JokerFish on 2017/8/17. 12 | */ 13 | @Singleton 14 | @Component(modules = {AppModule.class}) 15 | public interface AppComponent { 16 | 17 | void inject(BaseActivity baseActivity); 18 | 19 | void inject(BasePresenter basePresenter); 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/myapplication/network/RequestService.java: -------------------------------------------------------------------------------- 1 | package com.example.myapplication.network; 2 | 3 | import com.example.myapplication.model.HttpResult; 4 | 5 | import okhttp3.RequestBody; 6 | import retrofit2.http.Body; 7 | import retrofit2.http.POST; 8 | import rx.Observable; 9 | 10 | /** 11 | * @author: Administrator 12 | * @description: Retrofit 中的请求方法 13 | * @date: 2017-08-04 13:52 14 | */ 15 | public interface RequestService { 16 | 17 | @POST("user/login") 18 | Observable> login(@Body RequestBody requestBody); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/myapplication/presenter/BasePresenter.java: -------------------------------------------------------------------------------- 1 | package com.example.myapplication.presenter; 2 | 3 | import com.example.myapplication.MyApplication; 4 | import com.example.myapplication.network.RequestUtil; 5 | 6 | import javax.inject.Inject; 7 | 8 | /** 9 | * Created by JokerFish on 2017/8/17. 10 | */ 11 | 12 | public class BasePresenter { 13 | public static final String TAG = "Retrofit"; 14 | @Inject 15 | RequestUtil requestUtil; 16 | 17 | public BasePresenter() { 18 | MyApplication.getInstance().getAppComponent().inject(this); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/myapplication/dagger/component/MainactivityComponent.java: -------------------------------------------------------------------------------- 1 | package com.example.myapplication.dagger.component; 2 | 3 | import com.example.myapplication.AppComponent; 4 | import com.example.myapplication.dagger.ActivityScope; 5 | import com.example.myapplication.dagger.module.MainActivityModule; 6 | import com.example.myapplication.ui.activity.MainActivity; 7 | 8 | import dagger.Component; 9 | 10 | /** 11 | * Created by JokerFish on 2017/8/18. 12 | */ 13 | @ActivityScope 14 | @Component(modules = MainActivityModule.class, dependencies = AppComponent.class) 15 | public interface MainactivityComponent { 16 | void inject(MainActivity activity); 17 | } 18 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EasyArchitechure 2 | 一个适用于快速MVP项目开发的框架 3 | ##项目包含的内容 4 | * Retrolambda 5 | * Butterknife 6 | * Retrofit 7 | * RxJava 8 | * Okhttp 9 | * Logger 10 | * Dagger2 11 | ##编译JAVA版本 12 | JAVA_1.8 13 | ##项目特点 14 | * 对服务器返回的字段进行了统一处理 15 | * 对于网络请求封装了相应的对话框网络监听器,用户不用关心其等待对话框的显示和隐藏 16 | * 项目整体采用mvp构架,适合中型项目的开发 17 | ## 使用要点 18 | 1. 对于新开发的项目,直接改包名进行引用 19 | 2. 新建的activity直接继承BaseActivity即可 20 | 3. 对于需要网络请求的activity,需要重写setUpComponent(AppComponent appComponent)方法 21 | 5. 使用方式 22 | * 需要添加公共请求参数时候,可以在OkhhtpFactory中的requestInterceptor中添加公共请求参数 23 | * 对于服务器返回的数据需要处理的可以在responseInterceptor进行统一处理 24 | * 新增网络请求 25 | * 在RequestService添加请求方法 26 | * 在RequestUtil中新增方法,确定请求参数和返回值 27 | * 采用mvp方式组织代码时,新建对应activity的presenter继承自BasePresnter,在presenter中进行网络请求 28 | * 新建对应activity的MVP的Component和对应的Module,并在activity中注入 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/myapplication/dagger/module/MainActivityModule.java: -------------------------------------------------------------------------------- 1 | package com.example.myapplication.dagger.module; 2 | 3 | import com.example.myapplication.contacts.MainActivityContact; 4 | import com.example.myapplication.dagger.ActivityScope; 5 | import com.example.myapplication.presenter.MainpresenterImpl; 6 | 7 | import dagger.Module; 8 | import dagger.Provides; 9 | 10 | /** 11 | * Created by JokerFish on 2017/8/17. 12 | */ 13 | @Module 14 | public class MainActivityModule { 15 | private MainActivityContact.View mainView; 16 | 17 | public MainActivityModule(MainActivityContact.View mainView) { 18 | this.mainView = mainView; 19 | } 20 | 21 | @Provides 22 | @ActivityScope 23 | MainActivityContact.Presenter mainActivity() { 24 | return new MainpresenterImpl(mainView); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_dialog.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 12 | 13 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/example/myapplication/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.example.myapplication; 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.myapplication", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/myapplication/model/User.java: -------------------------------------------------------------------------------- 1 | package com.example.myapplication.model; 2 | 3 | /** 4 | * Created by JokerFish on 2017/7/18. 5 | */ 6 | 7 | public class User { 8 | private String mobile; 9 | private String password; 10 | private String captcha; 11 | 12 | public User(String mobile, String password) { 13 | this.mobile = mobile; 14 | this.captcha = password; 15 | } 16 | 17 | public String getPassword() { 18 | return password; 19 | } 20 | 21 | public void setPassword(String password) { 22 | this.password = password; 23 | } 24 | 25 | public String getMobile() { 26 | return mobile; 27 | } 28 | 29 | public void setMobile(String mobile) { 30 | this.mobile = mobile; 31 | } 32 | 33 | public String getCaptcha() { 34 | return captcha; 35 | } 36 | 37 | public void setCaptcha(String captcha) { 38 | this.captcha = captcha; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/myapplication/network/ApiException.java: -------------------------------------------------------------------------------- 1 | package com.example.myapplication.network; 2 | 3 | /** 4 | * Created by su on 2017/5/26. 5 | */ 6 | 7 | public class ApiException extends RuntimeException { 8 | public static final int USER_NOT_EXIST = 100; 9 | public static final int WRONG_PASSWORD = 101; 10 | 11 | public ApiException(String message) { 12 | super(message); 13 | } 14 | 15 | public ApiException(int code) { 16 | super(getApiExceptionMessage(code)); 17 | } 18 | 19 | private static String getApiExceptionMessage(int code) { 20 | String message = ""; 21 | switch (code) { 22 | case USER_NOT_EXIST: 23 | message = "该用户不存在"; 24 | break; 25 | case WRONG_PASSWORD: 26 | message = "密码错误"; 27 | break; 28 | default: 29 | message = "未知错误"; 30 | 31 | } 32 | return message; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /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 D:\Android\sdk/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 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | #配置混淆 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/myapplication/presenter/MainpresenterImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.myapplication.presenter; 2 | 3 | import android.util.Log; 4 | 5 | import com.example.myapplication.contacts.MainActivityContact; 6 | import com.example.myapplication.model.User; 7 | import com.example.myapplication.subscribe.ProgressSubscrible; 8 | 9 | /** 10 | * Created by JokerFish on 2017/8/17. 11 | */ 12 | 13 | public class MainpresenterImpl extends BasePresenter implements MainActivityContact.Presenter { 14 | 15 | private final MainActivityContact.View mainview; 16 | 17 | public MainpresenterImpl(MainActivityContact.View mainview) { 18 | this.mainview = mainview; 19 | } 20 | 21 | @Override 22 | public void calculate(int num1, int num2) { 23 | User user = new User("123456765432", "123456"); 24 | requestUtil.login(user, new ProgressSubscrible() { 25 | @Override 26 | public void onSuccess(String s) { 27 | Log.i(TAG, "onSuccess: "+s); 28 | mainview.signInSuccess(s); 29 | } 30 | }); 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/myapplication/subscribe/ProgressDialogHandler.java: -------------------------------------------------------------------------------- 1 | package com.example.myapplication.subscribe; 2 | 3 | import android.os.Handler; 4 | import android.os.Message; 5 | 6 | import com.example.myapplication.MyApplication; 7 | import com.example.myapplication.ui.activity.DialogActivity; 8 | 9 | /** 10 | * Created by su on 2017/5/26. 11 | */ 12 | 13 | public class ProgressDialogHandler extends Handler { 14 | public static final int SHOW_PROGRESS_DIALOG = 1; 15 | public static final int DISMISS_PROGRESS_DIALOG = 2; 16 | 17 | 18 | private boolean cancleable; 19 | 20 | 21 | public ProgressDialogHandler(boolean cancleable) { 22 | super(); 23 | this.cancleable = cancleable; 24 | } 25 | 26 | @Override 27 | public void handleMessage(Message msg) { 28 | switch (msg.what) { 29 | case SHOW_PROGRESS_DIALOG: 30 | DialogActivity.show(MyApplication.getInstance(), cancleable); 31 | break; 32 | case DISMISS_PROGRESS_DIALOG: 33 | DialogActivity.dismiss(MyApplication.getInstance()); 34 | break; 35 | } 36 | 37 | super.handleMessage(msg); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/myapplication/ui/activity/BaseActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.myapplication.ui.activity; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.app.AppCompatActivity; 6 | 7 | import com.example.myapplication.AppComponent; 8 | import com.example.myapplication.MyApplication; 9 | import com.example.myapplication.ui.IBaseView; 10 | import com.example.myapplication.utils.ToastUtis; 11 | 12 | import butterknife.ButterKnife; 13 | 14 | /** 15 | * Created by JokerFish on 2017/8/17. 16 | */ 17 | 18 | public abstract class BaseActivity extends AppCompatActivity implements IBaseView { 19 | 20 | 21 | @Override 22 | protected void onCreate(@Nullable Bundle savedInstanceState) { 23 | super.onCreate(savedInstanceState); 24 | setUpComponent(MyApplication.getInstance().getAppComponent()); 25 | setContentView(getLayoutResource()); 26 | ButterKnife.bind(this); 27 | } 28 | //使用mvp框架的activity需要重写该方法 29 | public void setUpComponent(AppComponent appComponent) { 30 | 31 | } 32 | 33 | @Override 34 | public void showMessage(String msg) { 35 | ToastUtis.showToast(this, msg); 36 | } 37 | 38 | public abstract int getLayoutResource(); 39 | } 40 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/myapplication/MyApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.myapplication; 2 | 3 | import android.app.Application; 4 | 5 | import com.example.myapplication.utils.SpUtils; 6 | import com.orhanobut.logger.LogLevel; 7 | import com.orhanobut.logger.Logger; 8 | 9 | /** 10 | * Created by JokerFish on 2017/8/17. 11 | */ 12 | 13 | public class MyApplication extends Application { 14 | private static MyApplication context; 15 | private AppComponent appComponent; 16 | 17 | @Override 18 | public void onCreate() { 19 | super.onCreate(); 20 | context = this; 21 | SpUtils.init(this); 22 | initLogger(); 23 | appComponent = DaggerAppComponent.builder().appModule(new AppModule(this)).build(); 24 | } 25 | 26 | private void initLogger() { 27 | Logger.init("Test") // default PRETTYLOGGER or use just init() 28 | .methodCount(2) // default 2 29 | .hideThreadInfo() // default shown 30 | .logLevel(BuildConfig.DEBUG ? LogLevel.FULL : LogLevel.NONE) // default LogLevel.FULL 31 | .methodOffset(2); // default 0 32 | 33 | } 34 | 35 | public AppComponent getAppComponent() { 36 | return appComponent; 37 | } 38 | 39 | public static MyApplication getInstance() { 40 | return context; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/myapplication/utils/ToastUtis.java: -------------------------------------------------------------------------------- 1 | package com.example.myapplication.utils; 2 | 3 | import android.content.Context; 4 | import android.support.annotation.StringRes; 5 | import android.view.Gravity; 6 | import android.widget.Toast; 7 | 8 | /** 9 | * Created by JokerFish on 2017/07/11. 10 | * 吐司工具类 11 | */ 12 | 13 | public class ToastUtis { 14 | private static Toast sToast; 15 | 16 | public static void showToast(Context context, String msg) { 17 | if (sToast == null) { 18 | sToast = Toast.makeText(context.getApplicationContext(), msg, Toast.LENGTH_SHORT); 19 | sToast.setGravity(Gravity.CENTER, 0, 0); 20 | } else { 21 | sToast.setText(msg); 22 | } 23 | sToast.show(); 24 | } 25 | 26 | public static void showToast(Context context, @StringRes int resId) { 27 | if (sToast == null) { 28 | sToast = Toast.makeText(context.getApplicationContext(), context.getResources().getString(resId), Toast.LENGTH_SHORT); 29 | sToast.setGravity(Gravity.CENTER, 0, 0); 30 | } else { 31 | sToast.setText(context.getResources().getString(resId)); 32 | } 33 | sToast.show(); 34 | } 35 | 36 | public static void cancleToast() { 37 | if (sToast != null) { 38 | sToast.cancel(); 39 | sToast = null; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/myapplication/model/HttpResult.java: -------------------------------------------------------------------------------- 1 | package com.example.myapplication.model; 2 | 3 | /** 4 | * Created by liukun on 16/3/5. 5 | */ 6 | public class HttpResult { 7 | 8 | public int code; 9 | public String message; 10 | public T data; 11 | private boolean canRetry; 12 | private String debugInfo; 13 | private boolean success; 14 | 15 | public int getCode() { 16 | return code; 17 | } 18 | 19 | public void setCode(int code) { 20 | this.code = code; 21 | } 22 | 23 | public String getMessage() { 24 | return message; 25 | } 26 | 27 | public void setMessage(String message) { 28 | this.message = message; 29 | } 30 | 31 | public T getData() { 32 | return data; 33 | } 34 | 35 | public void setData(T data) { 36 | this.data = data; 37 | } 38 | 39 | public boolean isCanRetry() { 40 | return canRetry; 41 | } 42 | 43 | public void setCanRetry(boolean canRetry) { 44 | this.canRetry = canRetry; 45 | } 46 | 47 | public String getDebugInfo() { 48 | return debugInfo; 49 | } 50 | 51 | public void setDebugInfo(String debugInfo) { 52 | this.debugInfo = debugInfo; 53 | } 54 | 55 | public boolean isSuccess() { 56 | return success; 57 | } 58 | 59 | public void setSuccess(boolean success) { 60 | this.success = success; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 15 | 20 | 21 | 26 | 27 | 32 | 33 | 37 | 38 |