├── .gitignore ├── .idea ├── gradle.xml ├── markdown-navigator │ └── profiles_settings.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── Aac-data-module-coroutines ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── aac │ │ └── data │ │ └── coroutines │ │ ├── ColourisesDataAdapter.kt │ │ ├── CoroutinesExecute.kt │ │ └── ResultJava.kt │ └── res │ └── values │ └── strings.xml ├── Aac-data-module-http ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── aac │ │ └── data │ │ └── http │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── aac │ │ │ └── data │ │ │ └── http │ │ │ ├── converter │ │ │ ├── BeanConverter.java │ │ │ └── JsonObjectConverter.kt │ │ │ ├── live │ │ │ ├── CallExecuteLiveData.kt │ │ │ └── LiveDataAdapter.kt │ │ │ └── utils │ │ │ ├── SSS.java │ │ │ └── utils.kt │ └── res │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── aac │ └── data │ └── http │ └── ExampleUnitTest.java ├── Aac-data-module-rx2 ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── aac │ │ └── module │ │ └── rx2 │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── aac │ │ │ └── module │ │ │ └── rx2 │ │ │ └── presenter │ │ │ ├── AacRxFragmentPresenter.java │ │ │ ├── AacRxPresenter.java │ │ │ ├── data │ │ │ ├── AacRxDataAPresenter.java │ │ │ └── AacRxDataFPresenter.java │ │ │ └── list │ │ │ ├── AacRxListAPresenter.java │ │ │ ├── AacRxListFPresenter.java │ │ │ ├── AacRxMultiListAPresenter.java │ │ │ └── AacRxMultiListFPresenter.java │ └── res │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── aac │ └── module │ └── rx2 │ └── ExampleUnitTest.java ├── Aac-data-module ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── aac │ │ └── expansion │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── aac │ │ │ └── expansion │ │ │ ├── data │ │ │ ├── AacDataAPresenter.java │ │ │ ├── AacDataActivity.java │ │ │ ├── AacDataFPresenter.java │ │ │ └── AacDataFragment.java │ │ │ ├── ener │ │ │ ├── PostDataListener.java │ │ │ ├── ViewGetDataListener.java │ │ │ └── ViewGetListener.java │ │ │ └── list │ │ │ ├── AacListAPresenter.java │ │ │ ├── AacListActivity.java │ │ │ ├── AacListFPresenter.java │ │ │ ├── AacListFragment.java │ │ │ ├── AacMultiListAPresenter.java │ │ │ ├── AacMultiListActivity.java │ │ │ ├── AacMultiListFPresenter.java │ │ │ └── AacMultiListFragment.java │ └── res │ │ ├── drawable │ │ └── ic_chevron_left_black_24dp.xml │ │ ├── layout │ │ ├── aac_include_recycle_view.xml │ │ ├── aac_include_toolbar_view.xml │ │ ├── aac_recycle_view.xml │ │ └── aac_view_list_con_empty.xml │ │ └── values │ │ ├── ids.xml │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── aac │ └── expansion │ └── ExampleUnitTest.java ├── AacModule ├── .gitignore ├── build.gradle └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── aac │ │ └── module │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── aac │ │ │ └── module │ │ │ ├── callback │ │ │ └── ActivityLifecycleCallbacksWrapper.java │ │ │ ├── model │ │ │ ├── AacAndroidViewModel.java │ │ │ └── AacViewModel.java │ │ │ ├── pres │ │ │ └── RequiresPresenter.java │ │ │ ├── ui │ │ │ ├── AacActivity.java │ │ │ ├── AacFragment.java │ │ │ ├── AacFragmentPresenter.java │ │ │ ├── AacPresenter.java │ │ │ ├── AacService.java │ │ │ └── PresenterBuilder.java │ │ │ └── utils │ │ │ ├── ContentLayoutListener.java │ │ │ └── MyFragmentManager.java │ └── res │ │ └── values │ │ ├── ids.xml │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── aac │ └── module │ └── ExampleUnitTest.java ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── example │ │ └── aac │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── aac │ │ │ ├── ActivityCallback.java │ │ │ ├── App.java │ │ │ ├── java │ │ │ ├── MainActivity.java │ │ │ ├── TestPresenter.java │ │ │ ├── coroutines │ │ │ │ ├── CoroutinesActivity.kt │ │ │ │ └── DataBen.java │ │ │ ├── data │ │ │ │ ├── activity │ │ │ │ │ ├── TesDataPresenter.java │ │ │ │ │ ├── TestDataActivity.java │ │ │ │ │ ├── TestDataListActivity.java │ │ │ │ │ ├── TestDataListPresenter.java │ │ │ │ │ └── bean │ │ │ │ │ │ └── UserBean.java │ │ │ │ ├── fragment │ │ │ │ │ ├── TestFragmentActivity.java │ │ │ │ │ ├── data │ │ │ │ │ │ ├── Test2FragmentActivity.java │ │ │ │ │ │ ├── TestDataFragment.java │ │ │ │ │ │ └── TestDataFragmentPresenter.java │ │ │ │ │ └── list │ │ │ │ │ │ ├── TestDataFragmentActivity.java │ │ │ │ │ │ ├── TestFragmentPresenter.java │ │ │ │ │ │ └── TestListFragment.java │ │ │ │ ├── multi │ │ │ │ │ ├── adapter │ │ │ │ │ │ └── TestAdapter.kt │ │ │ │ │ ├── bean │ │ │ │ │ │ └── Multi.java │ │ │ │ │ ├── model │ │ │ │ │ │ └── MultiViewModel.java │ │ │ │ │ ├── presenter │ │ │ │ │ │ └── MultiPresenter.java │ │ │ │ │ └── ui │ │ │ │ │ │ └── MultiActivity.java │ │ │ │ ├── test │ │ │ │ │ ├── adapter │ │ │ │ │ │ └── TestAdapter.kt │ │ │ │ │ ├── bean │ │ │ │ │ │ └── Test.kt │ │ │ │ │ ├── model │ │ │ │ │ │ └── TestViewModel.kt │ │ │ │ │ ├── presenter │ │ │ │ │ │ └── TestPresenter.kt │ │ │ │ │ └── ui │ │ │ │ │ │ └── TestActivity.kt │ │ │ │ └── test4 │ │ │ │ │ ├── adapter │ │ │ │ │ └── Test4Adapter.kt │ │ │ │ │ ├── bean │ │ │ │ │ └── Test4.kt │ │ │ │ │ ├── model │ │ │ │ │ └── Test4ViewModel.kt │ │ │ │ │ ├── presenter │ │ │ │ │ └── Test4Presenter.kt │ │ │ │ │ └── ui │ │ │ │ │ └── Test4Fragment.kt │ │ │ └── model │ │ │ │ └── TestDataViewModel.java │ │ │ └── utils │ │ │ ├── JsonCallback.java │ │ │ ├── JsonCallbcakKotlin.kt │ │ │ └── rwar │ │ │ ├── model │ │ │ └── RwarViewModel.java │ │ │ ├── presenter │ │ │ └── RwarPresenter.java │ │ │ └── ui │ │ │ └── RwarActivity.java │ └── res │ │ ├── layout │ │ ├── activity_coroutines.xml │ │ ├── activity_main.xml │ │ ├── activity_multi.xml │ │ ├── activity_rwar.xml │ │ ├── activity_test.xml │ │ ├── activity_test1.xml │ │ ├── activity_test2.xml │ │ ├── activity_test23.xml │ │ ├── activity_test3.xml │ │ ├── activity_test4.xml │ │ ├── activity_test5.xml │ │ ├── activity_test77.xml │ │ ├── activity_testk.xml │ │ ├── activity_tets6.xml │ │ ├── fragment_test.xml │ │ ├── fragment_test1.xml │ │ ├── fragment_test2.xml │ │ ├── fragment_test3.xml │ │ ├── fragment_test4.xml │ │ ├── fragment_test44.xml │ │ ├── fragment_test5.xml │ │ ├── fragment_test6.xml │ │ ├── include_toolbar_view.xml │ │ ├── test__fragment_view.xml │ │ ├── test_cuutom_layout.xml │ │ ├── test_data1_views.xml │ │ ├── test_data_fragment_view.xml │ │ ├── test_data_list_actvity.xml │ │ ├── test_data_view.xml │ │ ├── test_fragmen_view.xml │ │ ├── test_list_custom_fragment_view.xml │ │ └── test_list_fragment_view.xml │ │ ├── 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-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── example │ └── aac │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /build 5 | /.idea 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 23 | -------------------------------------------------------------------------------- /.idea/markdown-navigator/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 27 | 28 | 29 | 30 | 31 | 32 | 34 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Aac-data-module-coroutines/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /Aac-data-module-coroutines/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | 5 | android { 6 | compileSdkVersion project.ext.compileSdkVersion 7 | buildToolsVersion project.ext.buildToolsVersion 8 | defaultConfig { 9 | minSdkVersion project.ext.minSdkVersion 10 | targetSdkVersion project.ext.targetSdkVersion 11 | versionCode project.ext.versionCode 12 | versionName project.ext.versionName 13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | lintOptions { 22 | abortOnError false 23 | } 24 | 25 | } 26 | 27 | dependencies { 28 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 29 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 30 | //网络请求 31 | compile 'com.lzy.net:okgo:3.0.4' 32 | compile 'com.lzy.net:okrx2:2.0.2' 33 | compile 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.0' 34 | compile 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.0' 35 | implementation project(':Aac-data-module-http') 36 | } 37 | kotlin { 38 | experimental { 39 | coroutines "error" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Aac-data-module-coroutines/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 | -------------------------------------------------------------------------------- /Aac-data-module-coroutines/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /Aac-data-module-coroutines/src/main/java/com/aac/data/coroutines/ColourisesDataAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.aac.data.coroutines 2 | 3 | import com.lzy.okgo.adapter.AdapterParam 4 | import com.lzy.okgo.adapter.Call 5 | import com.lzy.okgo.adapter.CallAdapter 6 | 7 | /** 8 | * author yangc 9 | * date 2017/12/17 10 | * E-Mail:yangchaojiang@outlook.com 11 | * Deprecated: 12 | */ 13 | 14 | class ColourisesDataAdapter : CallAdapter> { 15 | override fun adapt(call: Call, param: AdapterParam?): CoroutinesExecute?{ 16 | return CoroutinesExecute(call) 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Aac-data-module-coroutines/src/main/java/com/aac/data/coroutines/CoroutinesExecute.kt: -------------------------------------------------------------------------------- 1 | package com.aac.data.coroutines 2 | 3 | import com.lzy.okgo.adapter.Call 4 | import kotlinx.coroutines.* 5 | 6 | class CoroutinesExecute(private val call: Call)//订阅 7 | { 8 | 9 | fun onSubscribe(mSuccess: (mSuccess: T) -> Unit, mError: (mThrowable: Throwable?) -> Unit): Job { 10 | return GlobalScope.launch { 11 | val (ok, mError2) = onSubscribe().await() 12 | if (ok != null) { 13 | mSuccess(ok) 14 | } else { 15 | mError(mError2) 16 | } 17 | } 18 | 19 | } 20 | 21 | private fun onSubscribe() = GlobalScope.async(Dispatchers.IO) { 22 | try { 23 | if (this.isActive) { 24 | val mResponse = call.execute() 25 | if (!call.isCanceled && mResponse.isSuccessful && mResponse.body() != null) { 26 | ResultJava.of(mResponse.body()) 27 | } else { 28 | ResultJava.of(Throwable(mResponse.message())) 29 | } 30 | } else { 31 | ResultJava.of(Throwable("can")) 32 | } 33 | 34 | } catch (e: Exception) { 35 | ResultJava.of(Throwable(e.message)) 36 | } 37 | 38 | } 39 | } 40 | 41 | 42 | -------------------------------------------------------------------------------- /Aac-data-module-coroutines/src/main/java/com/aac/data/coroutines/ResultJava.kt: -------------------------------------------------------------------------------- 1 | package com.aac.data.coroutines 2 | 3 | /** 4 | * author yangc 5 | * date 2018/3/15 6 | * E-Mail:yangchaojiang@outlook.com 7 | * Deprecated: 8 | */ 9 | 10 | class ResultJava { 11 | 12 | var result: T? = null 13 | private set 14 | var error: Throwable? = null 15 | private set 16 | 17 | operator fun component1(): T? { 18 | return result 19 | } 20 | 21 | operator fun component2(): Throwable? { 22 | return error 23 | } 24 | 25 | companion object { 26 | fun of(error: Throwable): ResultJava { 27 | val bean = ResultJava() 28 | bean.error = error 29 | return bean 30 | } 31 | 32 | fun of(bean: T): ResultJava { 33 | val bean2 = ResultJava() 34 | bean2.result = bean 35 | return bean2 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Aac-data-module-coroutines/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Aac-data-module-coroutines 3 | 4 | -------------------------------------------------------------------------------- /Aac-data-module-http/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /Aac-data-module-http/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'kotlin-android' 3 | 4 | android { 5 | compileSdkVersion project.ext.compileSdkVersion 6 | buildToolsVersion project.ext.buildToolsVersion 7 | defaultConfig { 8 | minSdkVersion project.ext.minSdkVersion 9 | targetSdkVersion project.ext.targetSdkVersion 10 | versionCode project.ext.versionCode 11 | versionName project.ext.versionName 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | 14 | } 15 | 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | lintOptions { 23 | abortOnError false 24 | } 25 | 26 | } 27 | 28 | dependencies { 29 | implementation fileTree(include: ['*.jar'], dir: 'libs') 30 | testImplementation 'junit:junit:4.12' 31 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 32 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 33 | compile project(':Aac-data-module-rx2') 34 | //网络请求 35 | compile 'com.lzy.net:okgo:3.0.4' 36 | compile 'com.lzy.net:okrx2:2.0.2' 37 | implementation 'com.ycjiang:Yutils:1.2.4' 38 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 39 | } 40 | repositories { 41 | mavenCentral() 42 | } 43 | apply plugin: 'com.novoda.bintray-release' 44 | publish { 45 | userOrg = 'ycjiang' 46 | repoName="ycjiang" 47 | groupId = 'com.ycjiang' 48 | artifactId = 'AacHttpDataModule' 49 | publishVersion = project.ext.publishVersion 50 | desc = 'rapid development framework for data management Rx and http' 51 | website = 'https://github.com/yangchaojiang/AaComponents' 52 | } 53 | -------------------------------------------------------------------------------- /Aac-data-module-http/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 | -------------------------------------------------------------------------------- /Aac-data-module-http/src/androidTest/java/com/aac/data/http/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.aac.data.http; 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.aac.data.http.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Aac-data-module-http/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /Aac-data-module-http/src/main/java/com/aac/data/http/converter/BeanConverter.java: -------------------------------------------------------------------------------- 1 | package com.aac.data.http.converter; 2 | 3 | import android.support.annotation.NonNull; 4 | 5 | import com.alibaba.fastjson.JSONObject; 6 | import com.lzy.okgo.convert.Converter; 7 | import com.yutils.JsonManager; 8 | 9 | import java.lang.reflect.Type; 10 | 11 | import okhttp3.Response; 12 | import okhttp3.ResponseBody; 13 | 14 | /** 15 | * author yangc 16 | * date 2017/12/22 17 | * E-Mail:yangchaojiang@outlook.com 18 | * Deprecated: 19 | */ 20 | 21 | public class BeanConverter implements Converter { 22 | 23 | private Type type; 24 | private Class tClass; 25 | private final String key; 26 | 27 | /***** 28 | * @param tClass 返回实例对象类型 29 | * @param key 需要处理对象key 30 | */ 31 | public BeanConverter(@NonNull String key, @NonNull Class tClass) { 32 | this.key = key; 33 | this.tClass = tClass; 34 | 35 | } 36 | 37 | /***** 38 | * @param type 返回实例对象类型 39 | * @param key 需要处理对象key 40 | * set MYTypeReference typeReference = ic_new MYTypeReference>() {}; 41 | * set val typeReference =object: MYTypeReference>() { } 42 | */ 43 | public BeanConverter(@NonNull String key, @NonNull Type type) { 44 | this.key = key; 45 | this.type = type; 46 | } 47 | 48 | @Override 49 | public T convertResponse(Response response) throws Throwable { 50 | ResponseBody body = response.body(); 51 | if (body == null) { 52 | throw new Throwable(response.message()); 53 | } 54 | String data = body.string(); 55 | JSONObject jsonObject = JsonManager.parseJsonObject(data); 56 | if (jsonObject.getIntValue("errcode") == 0) { 57 | if (tClass != null) { 58 | if (key.equals("-1")) { 59 | return JsonManager.jsonToBean(data, tClass); 60 | } else { 61 | return jsonObject.getObject(key, tClass); 62 | } 63 | } else if (type != null) { 64 | return JsonManager.jsonToBean(key.equals("-1") ? data : jsonObject.get(key).toString(), type); 65 | } else { 66 | throw new Throwable(jsonObject.getString("errmsg")); 67 | } 68 | } else { 69 | throw new Throwable(jsonObject.getString("errmsg")); 70 | } 71 | 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Aac-data-module-http/src/main/java/com/aac/data/http/converter/JsonObjectConverter.kt: -------------------------------------------------------------------------------- 1 | package com.aac.data.http.converter 2 | 3 | 4 | import com.alibaba.fastjson.JSONObject 5 | import com.lzy.okgo.convert.Converter 6 | import com.yutils.JsonManager 7 | import okhttp3.Response 8 | 9 | /** 10 | * Created by yangc on 2017/10/7. 11 | * E-Mail:yangchaojiang@outlook.com 12 | * Deprecated: 13 | */ 14 | 15 | class JsonObjectConverter : Converter { 16 | /** 17 | * 该方法是子线程处理,不能做ui相关的工作 18 | * 主要作用是解析网络返回的 response 对象,生产onSuccess回调中需要的数据对象 19 | * 这里的解析工作不同的业务逻辑基本都不一样,所以需要自己实现,以下给出的时模板代码,实际使用根据需要修改 20 | */ 21 | @Throws(Throwable::class) 22 | override fun convertResponse(response: Response): com.alibaba.fastjson.JSONObject? { 23 | val body = response.body() 24 | if (body != null) { 25 | val s = JsonManager.parseJsonObject(body.string()) 26 | return if (s.getIntValue("errcode") == 0) { 27 | s 28 | } else { 29 | if (s.getIntValue("errcode") > 0) { 30 | throw IllegalStateException(s.getString("errmsg")) 31 | } else { 32 | throw IllegalStateException(response.message()) 33 | } 34 | } 35 | } else { 36 | throw IllegalStateException(response.message()) 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Aac-data-module-http/src/main/java/com/aac/data/http/live/CallExecuteLiveData.kt: -------------------------------------------------------------------------------- 1 | package com.aac.data.http 2 | 3 | import android.arch.lifecycle.MutableLiveData 4 | 5 | import com.lzy.okgo.adapter.Call 6 | import com.lzy.okgo.callback.Callback 7 | import com.lzy.okgo.model.Progress 8 | import com.lzy.okgo.model.Response 9 | import com.lzy.okgo.request.base.Request 10 | 11 | import io.reactivex.exceptions.CompositeException 12 | import io.reactivex.exceptions.Exceptions 13 | import io.reactivex.plugins.RxJavaPlugins 14 | 15 | /** 16 | * author yangc 17 | * date 2017/12/19 18 | * E-Mail:yangchaojiang@outlook.com 19 | * Deprecated: 20 | */ 21 | 22 | class CallExecuteLiveData (private val call: Call) : MutableLiveData(), Callback { 23 | private var terminated = false 24 | 25 | override fun onActive() { 26 | super.onActive() 27 | call.execute(this) 28 | } 29 | 30 | override fun onInactive() { 31 | super.onInactive() 32 | call.cancel() 33 | } 34 | 35 | override fun onStart(request: Request>) { 36 | 37 | } 38 | 39 | override fun onSuccess(response: Response) { 40 | if (call.isCanceled) return 41 | try { 42 | val data = response.body() 43 | postValue(data) 44 | } catch (e: Exception) { 45 | if (terminated) { 46 | RxJavaPlugins.onError(e) 47 | } else { 48 | onError(response) 49 | } 50 | } 51 | 52 | } 53 | 54 | override fun onCacheSuccess(response: Response) { 55 | onSuccess(response) 56 | } 57 | 58 | override fun onError(response: Response) { 59 | if (call.isCanceled) return 60 | 61 | val throwable = response.exception 62 | try { 63 | terminated = true 64 | postValue(null) 65 | } catch (inner: Throwable) { 66 | Exceptions.throwIfFatal(inner) 67 | RxJavaPlugins.onError(CompositeException(throwable, inner)) 68 | } 69 | 70 | } 71 | 72 | override fun onFinish() { 73 | if (call.isCanceled) return 74 | try { 75 | terminated = true 76 | } catch (inner: Throwable) { 77 | Exceptions.throwIfFatal(inner) 78 | RxJavaPlugins.onError(inner) 79 | } 80 | 81 | } 82 | 83 | override fun uploadProgress(progress: Progress) { 84 | 85 | } 86 | 87 | override fun downloadProgress(progress: Progress) { 88 | 89 | } 90 | 91 | @Throws(Throwable::class) 92 | override fun convertResponse(response: okhttp3.Response): T? { 93 | return null 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /Aac-data-module-http/src/main/java/com/aac/data/http/live/LiveDataAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.keba.utils 2 | 3 | 4 | import android.arch.lifecycle.MutableLiveData 5 | import com.aac.data.http.CallExecuteLiveData 6 | import com.lzy.okgo.adapter.AdapterParam 7 | import com.lzy.okgo.adapter.Call 8 | import com.lzy.okgo.adapter.CallAdapter 9 | 10 | /** 11 | * author yangc 12 | * date 2017/12/17 13 | * E-Mail:yangchaojiang@outlook.com 14 | * Deprecated: 15 | * try { 16 | val response = call.execute() 17 | if (!call.isCanceled) { 18 | it.onNext(response.body()) 19 | } 20 | if (!call.isCanceled) { 21 | it.onComplete() 22 | } 23 | } catch (e: Throwable) { 24 | it.onError(e) 25 | } 26 | */ 27 | 28 | 29 | class LiveDataAdapter : CallAdapter> { 30 | override fun adapt(call: Call, param: AdapterParam?): MutableLiveData? { 31 | return CallExecuteLiveData(call) 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Aac-data-module-http/src/main/java/com/aac/data/http/utils/SSS.java: -------------------------------------------------------------------------------- 1 | package com.aac.data.http.utils; 2 | 3 | import android.annotation.SuppressLint; 4 | 5 | import org.reactivestreams.Publisher; 6 | 7 | import io.reactivex.BackpressureStrategy; 8 | import io.reactivex.Flowable; 9 | import io.reactivex.FlowableEmitter; 10 | import io.reactivex.FlowableOnSubscribe; 11 | import io.reactivex.FlowableSubscriber; 12 | import io.reactivex.functions.Function; 13 | import io.reactivex.subjects.PublishSubject; 14 | 15 | /** 16 | * author yangc 17 | * date 2018/7/27 18 | * E-Mail:yangchaojiang@outlook.com 19 | * Deprecated: 20 | */ 21 | public class SSS { 22 | 23 | 24 | @SuppressLint("CheckResult") 25 | public void ssss(){ 26 | Flowable.just("12") 27 | .flatMap(new Function>() { 28 | @Override 29 | public Publisher apply(String s) throws Exception { 30 | return Flowable.just(true); 31 | } 32 | }); 33 | Flowable.create(new FlowableOnSubscribe() { 34 | @Override 35 | public void subscribe(FlowableEmitter emitter) throws Exception { 36 | 37 | } 38 | }, BackpressureStrategy.DROP); 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /Aac-data-module-http/src/main/java/com/aac/data/http/utils/utils.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("DEPRECATED_IDENTITY_EQUALS") 2 | 3 | @file:JvmName("AacUtils") 4 | @file:JvmMultifileClass 5 | 6 | 7 | package com.aac.data.http.utils 8 | 9 | import android.arch.lifecycle.LiveData 10 | import com.aac.data.http.converter.JsonObjectConverter 11 | import com.alibaba.fastjson.JSONObject 12 | import com.keba.utils.LiveDataAdapter 13 | import com.lzy.okgo.OkGo 14 | import com.lzy.okgo.convert.Converter 15 | import com.lzy.okgo.model.HttpParams 16 | import com.lzy.okgo.model.Response 17 | import com.lzy.okgo.request.GetRequest 18 | import com.lzy.okgo.request.PostRequest 19 | import com.lzy.okrx2.adapter.FlowableResponse 20 | import io.reactivex.BackpressureStrategy 21 | import io.reactivex.Flowable 22 | import io.reactivex.FlowableTransformer 23 | import io.reactivex.android.schedulers.AndroidSchedulers 24 | import io.reactivex.schedulers.Schedulers 25 | 26 | /** 27 | * author yangc 28 | * date 2018/5/2 29 | * E-Mail:yangchaojiang@outlook.com 30 | * Deprecated: 31 | */ 32 | 33 | /*** 34 | * Rx线程转换 35 | * ***/ 36 | fun defaultSchedulers(): FlowableTransformer { 37 | return FlowableTransformer { upstream -> upstream.observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()) } 38 | } 39 | 40 | /*** 41 | * @param response Response 42 | * ***/ 43 | private fun response(response: Response): Flowable { 44 | return Flowable.create({ 45 | val body = response.body() 46 | if (body != null) { 47 | it.onNext(body) 48 | } else { 49 | it.onError(Throwable("null")) 50 | } 51 | }, BackpressureStrategy.DROP) 52 | } 53 | 54 | /*** 55 | * @param url 请求地址 56 | * @param params 参数 57 | * @param converter 解析器 58 | * @return GetRequest 59 | * ***/ 60 | private fun httpGet(url: String, params: HttpParams?, converter: Converter): GetRequest { 61 | return OkGo.get(url).params(params).converter(converter) 62 | } 63 | 64 | /*** 65 | * @param url 请求地址 66 | * @param params 参数 67 | * @param converter 解析器 68 | * @return PostRequest 69 | * ***/ 70 | private fun httpPost(url: String, params: HttpParams?, converter: Converter): PostRequest { 71 | return OkGo.post(url).params(params).converter(converter) 72 | } 73 | 74 | /*** 75 | * @param url 请求地址 76 | * @param params 参数 77 | * @param converter 解析器 78 | * @return Flowable 79 | * ***/ 80 | fun httpRxGet(url: String, params: HttpParams, converter: Converter): Flowable { 81 | return httpGet(url, params, converter).adapt(FlowableResponse()) 82 | .flatMap { response(it) }.compose(defaultSchedulers()) 83 | } 84 | 85 | /*** 86 | * @param url 请求地址 87 | * @param params 参数 88 | * @param converter 解析器 89 | * @return Flowable 90 | * ***/ 91 | fun httpRxPost(url: String, params: HttpParams, converter: Converter): Flowable { 92 | return httpPost(url, params, converter).adapt(FlowableResponse()) 93 | .flatMap { response(it) }.compose(defaultSchedulers()) 94 | } 95 | 96 | /*** 97 | * @param url 请求地址 98 | * @param key 参数key 99 | * @param value value 100 | * @param converter 解析器 101 | * @return Flowable 102 | * ***/ 103 | fun httpRxget2(url: String, key: String, value: Any ,converter: Converter): Flowable { 104 | val params = HttpParams() 105 | params.put(key, value.toString()) 106 | return httpGet(url, params, converter).adapt(FlowableResponse()) 107 | .flatMap { response(it) }.compose(defaultSchedulers()) 108 | } 109 | 110 | /*** 111 | * @param url 请求地址 112 | * @param key 参数key 113 | * @param value value 114 | * @param converter 解析器 115 | * @return Flowable 116 | * ***/ 117 | fun httpRxPost(url: String, key: String, value: Any, converter: Converter): Flowable { 118 | val params = HttpParams() 119 | params.put(key, value.toString()) 120 | return httpPost(url, params, converter).adapt(FlowableResponse()) 121 | .flatMap { response(it) }.compose(defaultSchedulers()) 122 | } 123 | 124 | /*** 125 | * @param url 请求地址 126 | * @param params 参数 127 | * @return Flowable 128 | * ***/ 129 | fun httpRxGetJson(url: String, params: HttpParams): Flowable { 130 | return httpRxGet(url, params, JsonObjectConverter()).compose(defaultSchedulers()) 131 | } 132 | 133 | /*** 134 | * @param url 请求地址 135 | * @param params 参数 136 | * @return Flowable 137 | * ***/ 138 | fun httpRxPostJson(url: String, params: HttpParams): Flowable { 139 | return httpRxPost(url, params, JsonObjectConverter()).compose(defaultSchedulers()) 140 | } 141 | 142 | /*** 143 | * @param url 请求地址 144 | * @param params 参数 145 | * @param converter 解析器 146 | * @return LiveData 147 | * ***/ 148 | fun httpLivePost(url: String, params: HttpParams, converter: Converter): LiveData { 149 | return httpPost(url, params, converter).adapt(LiveDataAdapter()) 150 | } 151 | 152 | /*** 153 | * @param url 请求地址 154 | * @param params 参数 155 | * @param converter 解析器 156 | * @return LiveData 157 | * ***/ 158 | fun httpLiveGet(url: String, params: HttpParams, converter: Converter): LiveData { 159 | return httpGet(url, params, converter).adapt(LiveDataAdapter()) 160 | } 161 | /*** 162 | * @param url 请求地址 163 | * @param key 参数key 164 | * @param value value 165 | * @param converter 解析器 166 | * @return LiveData 167 | * ***/ 168 | fun httpLivePost(url: String,key: String, value: Any, converter: Converter): LiveData { 169 | val params = HttpParams() 170 | params.put(key, value.toString()) 171 | return httpPost(url, params, converter).adapt(LiveDataAdapter()) 172 | } 173 | 174 | /*** 175 | * @param url 请求地址 176 | * @param key 参数key 177 | * @param value value 178 | * @param converter 解析器 179 | * @return LiveData 180 | * ***/ 181 | fun httpLiveGet(url: String, key: String, value: Any, converter: Converter): LiveData { 182 | val params = HttpParams() 183 | params.put(key, value.toString()) 184 | return httpGet(url, params, converter).adapt(LiveDataAdapter()) 185 | } -------------------------------------------------------------------------------- /Aac-data-module-http/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Aac-data-module-http 3 | 4 | -------------------------------------------------------------------------------- /Aac-data-module-http/src/test/java/com/aac/data/http/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.aac.data.http; 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 | } -------------------------------------------------------------------------------- /Aac-data-module-rx2/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /Aac-data-module-rx2/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion project.ext.compileSdkVersion 5 | buildToolsVersion project.ext.buildToolsVersion 6 | defaultConfig { 7 | minSdkVersion project.ext.minSdkVersion 8 | targetSdkVersion project.ext.targetSdkVersion 9 | versionCode project.ext.versionCode 10 | versionName project.ext.versionName 11 | 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | //设置JDK1.8 22 | compileOptions { 23 | sourceCompatibility JavaVersion.VERSION_1_8 24 | targetCompatibility JavaVersion.VERSION_1_8 25 | } 26 | lintOptions { 27 | abortOnError false 28 | } 29 | 30 | buildTypes { 31 | release { 32 | minifyEnabled false 33 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 34 | } 35 | } 36 | lintOptions { 37 | abortOnError false 38 | } 39 | } 40 | 41 | dependencies { 42 | implementation fileTree(dir: 'libs', include: ['*.jar']) 43 | 44 | testImplementation 'junit:junit:4.12' 45 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 46 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 47 | implementation 'com.android.support:appcompat-v7:'+libSversion 48 | compile 'io.reactivex.rxjava2:rxjava:2.1.12' 49 | compile 'io.reactivex.rxjava2:rxandroid:2.0.2' 50 | compile project(':Aac-data-module') 51 | 52 | } 53 | apply plugin: 'com.novoda.bintray-release' 54 | publish { 55 | userOrg = 'ycjiang' 56 | repoName="ycjiang" 57 | groupId = 'com.ycjiang' 58 | artifactId = 'AacRxDataModule' 59 | publishVersion = project.ext.publishVersion 60 | desc = 'Based on google Android Architecture Components package to achieve MVP rapid development framework for data management Rx' 61 | website = 'https://github.com/yangchaojiang/AaComponents' 62 | } -------------------------------------------------------------------------------- /Aac-data-module-rx2/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 | -------------------------------------------------------------------------------- /Aac-data-module-rx2/src/androidTest/java/com/aac/module/rx2/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.aac.module.rx2; 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.aac.module.rx2.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Aac-data-module-rx2/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /Aac-data-module-rx2/src/main/java/com/aac/module/rx2/presenter/AacRxFragmentPresenter.java: -------------------------------------------------------------------------------- 1 | package com.aac.module.rx2.presenter; 2 | 3 | import android.support.annotation.CallSuper; 4 | 5 | import com.aac.module.ui.AacFragment; 6 | import com.aac.module.ui.AacFragmentPresenter; 7 | import com.aac.module.ui.AacPresenter; 8 | 9 | import io.reactivex.disposables.CompositeDisposable; 10 | import io.reactivex.disposables.Disposable; 11 | 12 | /** 13 | * author yangc 14 | * date 2017/12/18 15 | * E-Mail:yangchaojiang@outlook.com 16 | * Deprecated: 17 | */ 18 | 19 | public class AacRxFragmentPresenter extends AacFragmentPresenter { 20 | private CompositeDisposable compositeDisposable; 21 | 22 | public void addDisposable(Disposable disposable) { 23 | if (compositeDisposable == null) { 24 | compositeDisposable = new CompositeDisposable(); 25 | } 26 | compositeDisposable.add(disposable); 27 | } 28 | 29 | 30 | @CallSuper 31 | @Override 32 | protected void onDestroy() { 33 | //Activity销毁时,取消网络请求 34 | if (compositeDisposable != null) { 35 | compositeDisposable.dispose(); 36 | compositeDisposable.clear(); 37 | } 38 | super.onDestroy(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Aac-data-module-rx2/src/main/java/com/aac/module/rx2/presenter/AacRxPresenter.java: -------------------------------------------------------------------------------- 1 | package com.aac.module.rx2.presenter; 2 | 3 | import android.support.annotation.CallSuper; 4 | 5 | import com.aac.module.ui.AacPresenter; 6 | 7 | import io.reactivex.disposables.CompositeDisposable; 8 | import io.reactivex.disposables.Disposable; 9 | 10 | /** 11 | * author yangc 12 | * date 2017/12/18 13 | * E-Mail:yangchaojiang@outlook.com 14 | * Deprecated: 15 | */ 16 | 17 | public class AacRxPresenter extends AacPresenter { 18 | private CompositeDisposable compositeDisposable; 19 | 20 | public void addDisposable(Disposable disposable) { 21 | if (compositeDisposable == null) { 22 | compositeDisposable = new CompositeDisposable(); 23 | } 24 | compositeDisposable.add(disposable); 25 | } 26 | 27 | 28 | @CallSuper 29 | @Override 30 | protected void onDestroy() { 31 | //Activity销毁时,取消网络请求 32 | if (compositeDisposable != null) { 33 | compositeDisposable.dispose(); 34 | compositeDisposable.clear(); 35 | } 36 | super.onDestroy(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Aac-data-module-rx2/src/main/java/com/aac/module/rx2/presenter/data/AacRxDataAPresenter.java: -------------------------------------------------------------------------------- 1 | package com.aac.module.rx2.presenter.data; 2 | 3 | 4 | import android.support.annotation.CallSuper; 5 | import android.support.annotation.NonNull; 6 | 7 | import com.aac.expansion.data.AacDataAPresenter; 8 | import com.aac.expansion.data.AacDataActivity; 9 | import org.reactivestreams.Subscriber; 10 | import org.reactivestreams.Subscription; 11 | 12 | import io.reactivex.disposables.CompositeDisposable; 13 | import io.reactivex.disposables.Disposable; 14 | import io.reactivex.subjects.BehaviorSubject; 15 | 16 | /** 17 | * Created by yangc on 2017/8/14. 18 | * E-Mail:yangchaojiang@outlook.com 19 | * Deprecated: 数据业务 20 | */ 21 | 22 | public abstract class AacRxDataAPresenter extends AacDataAPresenter { 23 | //View的订阅关系,View被销毁时自动取消订阅。 24 | private Subscription mSubscription; 25 | private CompositeDisposable compositeDisposable; 26 | //用于缓存数据的Subscriber 27 | private BehaviorSubject mData = BehaviorSubject.create(); 28 | private Subscriber subscriber = new Subscriber() { 29 | @Override 30 | public void onSubscribe(Subscription s) { 31 | mSubscription = s; 32 | } 33 | 34 | @Override 35 | public void onNext(M m) { 36 | mData.onNext(m); 37 | } 38 | 39 | @Override 40 | public void onError(Throwable t) { 41 | mData.onError(t); 42 | } 43 | 44 | @Override 45 | public void onComplete() { 46 | 47 | } 48 | }; 49 | 50 | @CallSuper 51 | @Override 52 | protected void onCreate() { 53 | super.onCreate(); 54 | addDisposable(mData.subscribe(this::postData, this::postError)); 55 | } 56 | 57 | 58 | /*** 59 | * 手动发布数据 60 | * @param data 数据 61 | * 62 | **/ 63 | protected void postRxData(@NonNull M data) { 64 | mData.onNext(data); 65 | } 66 | 67 | /** 68 | * 手动发布错误 69 | * 70 | * @param e e 71 | */ 72 | public void postRxError(Throwable e) { 73 | mData.onError(e); 74 | } 75 | 76 | /** 77 | * 订阅 78 | * 79 | * @return Subscriber 80 | ***/ 81 | public Subscriber getDataRxSubscriber() { 82 | return subscriber; 83 | } 84 | 85 | /** 86 | * 获取缓存数据的Subscriber 87 | * 可以通过 `getDataSubject().getValue();` 获取缓存数据。 88 | * 89 | * @return BehaviorSubject 90 | */ 91 | public BehaviorSubject getDataSubject() { 92 | return mData; 93 | } 94 | 95 | public void addDisposable(Disposable disposable) { 96 | if (compositeDisposable == null) { 97 | compositeDisposable = new CompositeDisposable(); 98 | } 99 | compositeDisposable.add(disposable); 100 | } 101 | 102 | @CallSuper 103 | @Override 104 | protected void onDestroy() { 105 | //Activity销毁时,取消网络请求 106 | if (compositeDisposable != null) { 107 | compositeDisposable.dispose(); 108 | compositeDisposable.clear(); 109 | } 110 | if (mSubscription != null) { 111 | mSubscription.cancel(); 112 | } 113 | super.onDestroy(); 114 | } 115 | 116 | } 117 | -------------------------------------------------------------------------------- /Aac-data-module-rx2/src/main/java/com/aac/module/rx2/presenter/data/AacRxDataFPresenter.java: -------------------------------------------------------------------------------- 1 | package com.aac.module.rx2.presenter.data; 2 | 3 | 4 | import android.support.annotation.CallSuper; 5 | import android.support.annotation.NonNull; 6 | 7 | import com.aac.expansion.data.AacDataFPresenter; 8 | import com.aac.expansion.data.AacDataFragment; 9 | 10 | import org.reactivestreams.Subscriber; 11 | import org.reactivestreams.Subscription; 12 | 13 | import io.reactivex.disposables.CompositeDisposable; 14 | import io.reactivex.disposables.Disposable; 15 | import io.reactivex.subjects.BehaviorSubject; 16 | 17 | /** 18 | * author yangc 19 | * date 2017/8/14 20 | * E-Mail:yangchaojiang@outlook.com 21 | * Deprecated: Fragment数据业务 22 | */ 23 | 24 | public abstract class AacRxDataFPresenter extends AacDataFPresenter { 25 | 26 | //View的订阅关系,View被销毁时自动取消订阅。 27 | private Subscription mSubscription; 28 | //订阅类管理类 29 | private CompositeDisposable compositeDisposable; 30 | //用于缓存数据的Subscriber 31 | private BehaviorSubject mData = BehaviorSubject.create(); 32 | private Subscriber subscriber = new Subscriber() { 33 | @Override 34 | public void onSubscribe(Subscription s) { 35 | mSubscription = s; 36 | } 37 | 38 | @Override 39 | public void onNext(M m) { 40 | mData.onNext(m); 41 | } 42 | 43 | @Override 44 | public void onError(Throwable t) { 45 | mData.onError(t); 46 | } 47 | 48 | @Override 49 | public void onComplete() { 50 | 51 | } 52 | }; 53 | 54 | @CallSuper 55 | @Override 56 | protected void onCreate() { 57 | super.onCreate(); 58 | addDisposable(mData.subscribe(this::postData, this::postError)); 59 | 60 | } 61 | /** 62 | * 获取缓存数据的Subscriber 63 | * 可以通过 `getDataSubject().getValue();` 获取缓存数据。 64 | * 65 | * @return BehaviorSubject 66 | */ 67 | public BehaviorSubject getDataSubject() { 68 | return mData; 69 | } 70 | /*** 71 | * 手动发布数据 72 | * @param data 数据 73 | * 74 | **/ 75 | protected void postRxData(@NonNull M data) { 76 | mData.onNext(data); 77 | } 78 | 79 | /** 80 | * 订阅 81 | * 82 | * @return Subscriber 83 | ***/ 84 | public Subscriber getDataRxSubscriber() { 85 | return subscriber; 86 | } 87 | 88 | 89 | public void addDisposable(Disposable disposable) { 90 | if (compositeDisposable == null) { 91 | compositeDisposable = new CompositeDisposable(); 92 | } 93 | compositeDisposable.add(disposable); 94 | } 95 | @CallSuper 96 | @Override 97 | protected void onDestroy() { 98 | if (mSubscription != null) { 99 | mSubscription.cancel(); 100 | } 101 | //Activity销毁时,取消网络请求 102 | if (compositeDisposable != null) { 103 | compositeDisposable.dispose(); 104 | compositeDisposable.clear(); 105 | } 106 | super.onDestroy(); 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /Aac-data-module-rx2/src/main/java/com/aac/module/rx2/presenter/list/AacRxListAPresenter.java: -------------------------------------------------------------------------------- 1 | package com.aac.module.rx2.presenter.list; 2 | 3 | 4 | 5 | 6 | import com.aac.expansion.list.AacListActivity; 7 | import com.aac.module.rx2.presenter.data.AacRxDataAPresenter; 8 | 9 | import java.util.List; 10 | 11 | 12 | 13 | /** 14 | * Created by yangc on 2017/8/14. 15 | * E-Mail:yangchaojiang@outlook.com 16 | * Deprecated: 数据业务 17 | * 18 | */ 19 | 20 | public abstract class AacRxListAPresenter extends AacRxDataAPresenter> { 21 | 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Aac-data-module-rx2/src/main/java/com/aac/module/rx2/presenter/list/AacRxListFPresenter.java: -------------------------------------------------------------------------------- 1 | package com.aac.module.rx2.presenter.list; 2 | 3 | import com.aac.expansion.list.AacListFragment; 4 | import com.aac.module.rx2.presenter.data.AacRxDataFPresenter; 5 | 6 | import java.util.List; 7 | 8 | 9 | /** 10 | * author yangc 11 | * date 2017/8/14 12 | * E-Mail:yangchaojiang@outlook.com 13 | * Deprecated: Fragment数据业务 14 | */ 15 | 16 | public abstract class AacRxListFPresenter extends AacRxDataFPresenter> { 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Aac-data-module-rx2/src/main/java/com/aac/module/rx2/presenter/list/AacRxMultiListAPresenter.java: -------------------------------------------------------------------------------- 1 | package com.aac.module.rx2.presenter.list; 2 | 3 | import com.aac.expansion.list.AacMultiListFragment; 4 | import com.aac.module.rx2.presenter.data.AacRxDataFPresenter; 5 | 6 | import java.util.List; 7 | 8 | 9 | /** 10 | * author yangc 11 | * date 2017/8/14 12 | * E-Mail:yangchaojiang@outlook.com 13 | * Deprecated: Fragment数据业务 14 | */ 15 | 16 | public abstract class AacRxMultiListAPresenter extends AacRxDataFPresenter> { 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Aac-data-module-rx2/src/main/java/com/aac/module/rx2/presenter/list/AacRxMultiListFPresenter.java: -------------------------------------------------------------------------------- 1 | package com.aac.module.rx2.presenter.list; 2 | 3 | import com.aac.expansion.list.AacMultiListFragment; 4 | import com.aac.module.rx2.presenter.data.AacRxDataFPresenter; 5 | 6 | import java.util.List; 7 | 8 | 9 | /** 10 | * author yangc 11 | * date 2017/8/14 12 | * E-Mail:yangchaojiang@outlook.com 13 | * Deprecated: Fragment数据业务 14 | */ 15 | 16 | public abstract class AacRxMultiListFPresenter extends AacRxDataFPresenter> { 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Aac-data-module-rx2/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Aac-data-module-rx2 3 | 4 | -------------------------------------------------------------------------------- /Aac-data-module-rx2/src/test/java/com/aac/module/rx2/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.aac.module.rx2; 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 | } -------------------------------------------------------------------------------- /Aac-data-module/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /Aac-data-module/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'me.tatarka.retrolambda' 3 | android { 4 | compileSdkVersion project.ext.compileSdkVersion 5 | buildToolsVersion project.ext.buildToolsVersion 6 | defaultConfig { 7 | minSdkVersion project.ext.minSdkVersion 8 | targetSdkVersion project.ext.targetSdkVersion 9 | versionCode project.ext.versionCode 10 | versionName project.ext.versionName 11 | 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | //设置JDK1.8 22 | compileOptions { 23 | sourceCompatibility JavaVersion.VERSION_1_8 24 | targetCompatibility JavaVersion.VERSION_1_8 25 | } 26 | lintOptions { 27 | abortOnError false 28 | } 29 | } 30 | 31 | dependencies { 32 | compile fileTree(include: ['*.jar'], dir: 'libs') 33 | androidTestCompile('com.android.support.test.espresso:espresso-core:3.0.2', { 34 | exclude group: 'com.android.support', module: 'support-annotations' 35 | }) 36 | testCompile 'junit:junit:4.12' 37 | compile 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.40' 38 | compile "com.android.support:recyclerview-v7:${libSversion}" 39 | compile 'com.ycjiang:center-toolbar:1.0.6' 40 | compile 'com.ycjiang:loadviewhelper:1.1.6' 41 | compile project(':AacModule') 42 | 43 | } 44 | 45 | 46 | apply plugin: 'com.novoda.bintray-release' 47 | //上传到jcenter 48 | publish { 49 | userOrg = 'ycjiang' 50 | repoName="ycjiang" 51 | groupId = 'com.ycjiang' 52 | artifactId = 'AacDataModule' 53 | publishVersion = project.ext.publishVersion 54 | desc = 'Based on google Android Architecture Components package to achieve MVP rapid development framework for data management' 55 | website = 'https://github.com/yangchaojiang/AaComponents' 56 | } 57 | 58 | 59 | -------------------------------------------------------------------------------- /Aac-data-module/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:\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 | -keep class com.chad.library.adapter.** { 19 | *; 20 | } 21 | -keep public class * extends com.chad.library.adapter.base.BaseQuickAdapter 22 | -keep public class * extends com.chad.library.adapter.base.BaseViewHolder 23 | -keepclassmembers public class * extends com.chad.library.adapter.base.BaseViewHolder { 24 | (android.view.View); 25 | } 26 | -------------------------------------------------------------------------------- /Aac-data-module/src/androidTest/java/com/aac/expansion/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.aac.expansion; 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.acc.given.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Aac-data-module/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Aac-data-module/src/main/java/com/aac/expansion/data/AacDataAPresenter.java: -------------------------------------------------------------------------------- 1 | package com.aac.expansion.data; 2 | 3 | 4 | import android.arch.lifecycle.Observer; 5 | import android.support.annotation.NonNull; 6 | 7 | import com.aac.expansion.ener.PostDataListener; 8 | import com.aac.module.ui.AacPresenter; 9 | 10 | /** 11 | * Created by yangc on 2017/8/14. 12 | * E-Mail:yangchaojiang@outlook.com 13 | * Deprecated: 数据业务 14 | */ 15 | 16 | public abstract class AacDataAPresenter extends AacPresenter implements PostDataListener { 17 | private Observer observeForever = m -> { 18 | if (m != null) { 19 | postData(m); 20 | } else { 21 | postError(new Throwable(new NullPointerException())); 22 | } 23 | }; 24 | 25 | @Override 26 | public void postData(@NonNull M m) { 27 | getView().setBaseData(m); 28 | } 29 | 30 | @Override 31 | public void postError(Throwable e) { 32 | getView().setError(new Throwable(new NullPointerException())); 33 | } 34 | 35 | /** 36 | * 订阅 37 | * 38 | * @return Observer 39 | ***/ 40 | public Observer getDataSubscriber() { 41 | return observeForever; 42 | } 43 | 44 | @Override 45 | public void retryData() { 46 | setLoadData(1); 47 | } 48 | 49 | /*** 50 | * 列表加载分页数据 51 | * 52 | * @param pager 分页 等于1 刷新 53 | ***/ 54 | public void setLoadData(int pager) { 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Aac-data-module/src/main/java/com/aac/expansion/data/AacDataActivity.java: -------------------------------------------------------------------------------- 1 | package com.aac.expansion.data; 2 | 3 | 4 | import android.support.annotation.CallSuper; 5 | import android.support.annotation.NonNull; 6 | import android.view.View; 7 | import com.aac.expansion.ener.ViewGetDataListener; 8 | import com.aac.module.ui.AacActivity; 9 | import com.helper.loadviewhelper.load.LoadViewHelper; 10 | 11 | /** 12 | * author yangc 13 | * date 2017/8/14 14 | * E-Mail:yangchaojiang@outlook.com 15 | * Deprecated: Activity数据父类 16 | */ 17 | 18 | public abstract class AacDataActivity

extends AacActivity

implements ViewGetDataListener { 19 | private LoadViewHelper helper; 20 | 21 | @CallSuper 22 | @Override 23 | public void onDestroy() { 24 | super.onDestroy(); 25 | if (helper != null) { 26 | helper.onDestroy(); 27 | } 28 | } 29 | 30 | /*** 31 | *父类调用方法,用于切换 32 | * **/ 33 | void setBaseData(@NonNull M data) { 34 | if (helper != null) { 35 | helper.showContent(); 36 | } 37 | setData(data); 38 | } 39 | 40 | 41 | /*** 42 | *父类调用方法,用于切换 43 | * **/ 44 | @Override 45 | public void setError(Throwable e) { 46 | if (helper != null) { 47 | helper.showError(); 48 | } 49 | } 50 | 51 | @Override 52 | public LoadViewHelper getViewLoadHelper() { 53 | return helper; 54 | } 55 | 56 | @Override 57 | public void showLoadView() { 58 | if (helper != null) { 59 | helper.showLoading(); 60 | } 61 | } 62 | 63 | @Override 64 | public void initLoadHelper(@NonNull View view) { 65 | helper = new LoadViewHelper(view); 66 | helper.showLoading(); 67 | helper.setListener(() -> getPresenter().retryData()); 68 | } 69 | 70 | @Override 71 | public void showErrorView() { 72 | if (helper != null) { 73 | helper.showError(); 74 | } 75 | } 76 | 77 | @Override 78 | public void showContentView() { 79 | if (helper != null) { 80 | helper.showContent(); 81 | } 82 | } 83 | /*** 84 | * 数据返回 85 | * @param data data 86 | * **/ 87 | public abstract void setData(@NonNull M data); 88 | 89 | } 90 | -------------------------------------------------------------------------------- /Aac-data-module/src/main/java/com/aac/expansion/data/AacDataFPresenter.java: -------------------------------------------------------------------------------- 1 | package com.aac.expansion.data; 2 | 3 | 4 | import android.arch.lifecycle.Observer; 5 | import android.support.annotation.NonNull; 6 | 7 | import com.aac.expansion.ener.PostDataListener; 8 | import com.aac.module.ui.AacFragmentPresenter; 9 | 10 | /** 11 | * author yangc 12 | * date 2017/8/14 13 | * E-Mail:yangchaojiang@outlook.com 14 | * Deprecated: Fragment数据业务 15 | */ 16 | 17 | public abstract class AacDataFPresenter extends AacFragmentPresenter implements PostDataListener { 18 | 19 | private Observer observeForever = m -> { 20 | if (m != null) { 21 | postData(m); 22 | } else { 23 | postError(new Throwable(new NullPointerException())); 24 | } 25 | }; 26 | 27 | @Override 28 | public void postData(@NonNull M m) { 29 | getView().setBaseData(m); 30 | } 31 | 32 | @Override 33 | public void postError(Throwable e) { 34 | getView().setError(e); 35 | 36 | } 37 | 38 | @Override 39 | public void retryData() { 40 | 41 | } 42 | /** 43 | * 返回订阅数据 44 | * 45 | * @return Observer 46 | ***/ 47 | public Observer getDataSubscriber() { 48 | return observeForever; 49 | } 50 | 51 | /** 52 | * 当视图初始化并且对用户可见的时候去真正的加载数据 53 | */ 54 | protected abstract void lazyLoad(); 55 | 56 | /** 57 | * 当视图已经对用户不可见并且加载过数据,如果需要在切换到其他页面时停止加载数据,可以覆写此方法 58 | */ 59 | protected void stopLoad() { 60 | } 61 | /*** 62 | * 列表加载分页数据 63 | * 64 | * @param pager 分页 等于1 刷新 65 | ***/ 66 | public void setLoadData(int pager){} 67 | 68 | } 69 | -------------------------------------------------------------------------------- /Aac-data-module/src/main/java/com/aac/expansion/data/AacDataFragment.java: -------------------------------------------------------------------------------- 1 | package com.aac.expansion.data; 2 | 3 | import android.support.annotation.CallSuper; 4 | import android.support.annotation.NonNull; 5 | import android.view.View; 6 | 7 | import com.aac.expansion.ener.ViewGetDataListener; 8 | import com.aac.module.ui.AacFragment; 9 | import com.helper.loadviewhelper.load.LoadViewHelper; 10 | 11 | /** 12 | * Created by yangc on 2017/8/14. 13 | * E-Mail:yangchaojiang@outlook.com 14 | * Deprecated: Fragment 数据view 15 | */ 16 | 17 | public abstract class AacDataFragment

extends AacFragment

implements ViewGetDataListener { 18 | private LoadViewHelper helper; 19 | private boolean isInit = false; 20 | private boolean isLoad = false; 21 | 22 | @CallSuper 23 | @Override 24 | public void onDestroy() { 25 | super.onDestroy(); 26 | if (helper != null) { 27 | helper.onDestroy(); 28 | } 29 | } 30 | 31 | /*** 32 | * 父类调用方法,用于切换 33 | **/ 34 | void setBaseData(@NonNull M data) { 35 | showContentView(); 36 | setData(data); 37 | } 38 | 39 | @Override 40 | public void setError(Throwable e) { 41 | showErrorView(); 42 | } 43 | 44 | /** 45 | * 视图是否已经对用户可见,系统的方法 46 | */ 47 | @CallSuper 48 | @Override 49 | public void setUserVisibleHint(boolean isVisibleToUser) { 50 | super.setUserVisibleHint(isVisibleToUser); 51 | if (setOpenLazyLoad()) { 52 | isCanLoadData(); 53 | } 54 | } 55 | 56 | /** 57 | * 是否可以加载数据 58 | * 可以加载数据的条件: 59 | * 1.视图已经初始化 60 | * 2.视图对用户可见 61 | */ 62 | protected void isCanLoadData() { 63 | if (!isInit) { 64 | return; 65 | } 66 | if (getUserVisibleHint()) { 67 | if (!isLoad) { 68 | isLoad = true; 69 | getPresenter().lazyLoad(); 70 | }else { 71 | showContentView(); 72 | } 73 | } else { 74 | if (isLoad) { 75 | getPresenter().stopLoad(); 76 | } 77 | } 78 | } 79 | 80 | /** 81 | * 开启懒加载 82 | * 83 | * @return setOpenLazyLoad true 开启 false 84 | **/ 85 | protected boolean setOpenLazyLoad() { 86 | return false; 87 | } 88 | 89 | @Override 90 | public LoadViewHelper getViewLoadHelper() { 91 | return helper; 92 | } 93 | 94 | @Override 95 | public void initLoadHelper(@NonNull View view) { 96 | if (!isInit) { 97 | helper = new LoadViewHelper(view); 98 | helper.showLoading(); 99 | helper.setListener(() -> { 100 | getViewLoadHelper().showLoading(); 101 | getPresenter().retryData(); 102 | }); 103 | } 104 | } 105 | 106 | @Override 107 | public void showErrorView() { 108 | 109 | if (helper != null) { 110 | helper.showError(); 111 | } 112 | } 113 | 114 | @Override 115 | public void showContentView() { 116 | if (helper != null) { 117 | helper.showContent(); 118 | } 119 | } 120 | 121 | @Override 122 | public void showLoadView() { 123 | if (helper != null) { 124 | helper.showLoading(); 125 | } 126 | } 127 | 128 | /*** 129 | * 数据返回 130 | * @param data data 131 | * **/ 132 | protected abstract void setData(@NonNull M data); 133 | } 134 | -------------------------------------------------------------------------------- /Aac-data-module/src/main/java/com/aac/expansion/ener/PostDataListener.java: -------------------------------------------------------------------------------- 1 | package com.aac.expansion.ener; 2 | 3 | import android.support.annotation.NonNull; 4 | 5 | 6 | /** 7 | * author yangc 8 | * date 2017/12/28 9 | * E-Mail:yangchaojiang@outlook.com 10 | * Deprecated: 11 | */ 12 | 13 | public interface PostDataListener { 14 | 15 | /*** 16 | * 手动发布数据 17 | * @param m 数据 18 | * 19 | **/ 20 | void postData(@NonNull M m); 21 | /** 22 | * 手动发布错误 23 | * 24 | * @param e e 25 | */ 26 | void postError(Throwable e); 27 | /** 28 | * 点击重试加载 29 | **/ 30 | void retryData(); 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Aac-data-module/src/main/java/com/aac/expansion/ener/ViewGetDataListener.java: -------------------------------------------------------------------------------- 1 | package com.aac.expansion.ener; 2 | 3 | import android.support.annotation.NonNull; 4 | import android.view.View; 5 | 6 | import com.helper.loadviewhelper.load.LoadViewHelper; 7 | 8 | /** 9 | * Created by yangc on 2017/9/15. 10 | * E-Mail:yangchaojiang@outlook.com 11 | * Deprecated: 数据view 接口 12 | */ 13 | 14 | 15 | public interface ViewGetDataListener { 16 | 17 | LoadViewHelper getViewLoadHelper(); 18 | 19 | /*** 20 | * 错误处理 21 | * 22 | * @param e 错误 23 | **/ 24 | void setError(Throwable e); 25 | 26 | /*** 27 | * 显示加载中布局 28 | * @param contentView 内容布局 29 | * ***/ 30 | void initLoadHelper(@NonNull View contentView); 31 | 32 | /*** 33 | * 显示加载中布局 34 | * ***/ 35 | void showLoadView(); 36 | 37 | /*** 38 | * 显示错误布局 39 | * ***/ 40 | void showErrorView(); 41 | 42 | /*** 43 | * 显示内容布局 44 | * ***/ 45 | void showContentView(); 46 | } 47 | -------------------------------------------------------------------------------- /Aac-data-module/src/main/java/com/aac/expansion/ener/ViewGetListener.java: -------------------------------------------------------------------------------- 1 | package com.aac.expansion.ener; 2 | 3 | import android.support.annotation.LayoutRes; 4 | import android.support.v7.widget.RecyclerView; 5 | 6 | import com.chad.library.adapter.base.BaseQuickAdapter; 7 | import com.chad.library.adapter.base.BaseViewHolder; 8 | 9 | /** 10 | * Created by yangc on 2017/9/15. 11 | * E-Mail:yangchaojiang@outlook.com 12 | * Deprecated: 列表数据view 接口 13 | */ 14 | 15 | 16 | public interface ViewGetListener extends ViewGetDataListener{ 17 | /*** 18 | * 获取当前的分页数 19 | * @return int 20 | ***/ 21 | int getCurPage(); 22 | /** 23 | * 获取获取最后一个示例 24 | * @return BaseQuickAdapter 25 | **/ 26 | M getLastItem(); 27 | /** 28 | * 获取RecyclerView 29 | * @return RecyclerView 30 | **/ 31 | RecyclerView getRecyclerView(); 32 | 33 | /** 34 | * 获取数据适配器实例 35 | * @return BaseQuickAdapter 36 | **/ 37 | BaseQuickAdapter getAdapter(); 38 | 39 | /*** 40 | * 设置网格中的列数 41 | * 子类重写该方法 大于1 使用网格布局 否则L是list 42 | * @return int 43 | */ 44 | int setGridSpanCount(); 45 | 46 | /*** 47 | * 获取item数据layoutId 48 | * @return int 49 | **/ 50 | @LayoutRes 51 | int getItemLayout(); 52 | 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /Aac-data-module/src/main/java/com/aac/expansion/list/AacListAPresenter.java: -------------------------------------------------------------------------------- 1 | package com.aac.expansion.list; 2 | 3 | 4 | 5 | import com.aac.expansion.data.AacDataAPresenter; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Created by yangc on 2017/8/14. 11 | * E-Mail:yangchaojiang@outlook.com 12 | * Deprecated: 列表数据业务 13 | */ 14 | 15 | public abstract class AacListAPresenter extends AacDataAPresenter>{ 16 | 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Aac-data-module/src/main/java/com/aac/expansion/list/AacListFPresenter.java: -------------------------------------------------------------------------------- 1 | package com.aac.expansion.list; 2 | 3 | import com.aac.expansion.data.AacDataFPresenter; 4 | import java.util.List; 5 | 6 | /** 7 | * Created by yangc on 2017/8/14. 8 | * E-Mail:yangchaojiang@outlook.com 9 | * Deprecated: Fragment 列表数据理处理 10 | */ 11 | 12 | public abstract class AacListFPresenter extends AacDataFPresenter> { 13 | 14 | 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Aac-data-module/src/main/java/com/aac/expansion/list/AacListFragment.java: -------------------------------------------------------------------------------- 1 | package com.aac.expansion.list; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.CallSuper; 5 | import android.support.annotation.NonNull; 6 | import android.support.annotation.Nullable; 7 | import android.support.v4.widget.SwipeRefreshLayout; 8 | import android.support.v7.widget.GridLayoutManager; 9 | import android.support.v7.widget.LinearLayoutManager; 10 | import android.support.v7.widget.RecyclerView; 11 | import android.view.View; 12 | 13 | import com.aac.expansion.R; 14 | import com.aac.expansion.data.AacDataFPresenter; 15 | import com.aac.expansion.data.AacDataFragment; 16 | import com.aac.expansion.ener.ViewGetListener; 17 | import com.chad.library.adapter.base.BaseQuickAdapter; 18 | import com.chad.library.adapter.base.BaseViewHolder; 19 | 20 | import java.lang.ref.WeakReference; 21 | import java.util.List; 22 | 23 | /** 24 | * author yangc 25 | * date 2017/8/14 26 | * E-Mail:yangchaojiang@outlook.com 27 | * Deprecated: 列表Fragment 支持懒加载, 子类重写setOpenLazyLoad方法,开启懒加载 28 | */ 29 | 30 | public abstract class AacListFragment

extends AacDataFragment> 31 | implements SwipeRefreshLayout.OnRefreshListener, BaseQuickAdapter.RequestLoadMoreListener, ViewGetListener { 32 | private RecyclerView recyclerView; 33 | protected SwipeRefreshLayout swipeRefresh; 34 | private int daraPage = 1; 35 | private AacBaseQuickAdapter adapter; 36 | 37 | @CallSuper 38 | @Override 39 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 40 | super.onViewCreated(view, savedInstanceState); 41 | swipeRefresh = view.findViewById(R.id.swipeRefresh); 42 | recyclerView = view.findViewById(R.id.recyclerView); 43 | if (setGridSpanCount() <= 1) { 44 | recyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false)); 45 | } else { 46 | recyclerView.setLayoutManager(new GridLayoutManager(getActivity(), setGridSpanCount())); 47 | } 48 | // recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL)); 49 | swipeRefresh.setOnRefreshListener(this); 50 | swipeRefresh.setRefreshing(false); 51 | adapter = new AacBaseQuickAdapter(this); 52 | adapter.bindToRecyclerView(recyclerView); 53 | } 54 | 55 | @Override 56 | public void initLoadHelper(@NonNull View view) { 57 | super.initLoadHelper(view); 58 | adapter.setEmptyView(getViewLoadHelper().getEmptyLayoutId(),recyclerView); 59 | } 60 | 61 | @CallSuper 62 | @Override 63 | public void onDestroy() { 64 | super.onDestroy(); 65 | if (adapter != null) { 66 | adapter.getData().clear(); 67 | adapter.setOnLoadMoreListener(null, recyclerView); 68 | 69 | } 70 | if (swipeRefresh != null) { 71 | swipeRefresh.setRefreshing(false); 72 | swipeRefresh.setOnRefreshListener(null); 73 | } 74 | } 75 | 76 | /*** 77 | * 设置数据 78 | * @param data data 79 | * **/ 80 | public void setData(@NonNull List data) { 81 | if (daraPage < 2) { 82 | if (swipeRefresh.isRefreshing()) { 83 | setRefreshing(false); 84 | } 85 | adapter.getData().clear(); 86 | adapter.notifyDataSetChanged(); 87 | adapter.addData(data); 88 | 89 | } else { 90 | if (data.isEmpty()) { 91 | adapter.loadMoreEnd(); 92 | } else { 93 | adapter.loadMoreComplete(); 94 | } 95 | adapter.addData(data); 96 | } 97 | 98 | } 99 | 100 | @Override 101 | public void setError(Throwable e) { 102 | if (daraPage < 2) { 103 | if (swipeRefresh.isRefreshing()) { 104 | setRefreshing(false); 105 | } 106 | showErrorView(); 107 | } else { 108 | adapter.loadMoreFail(); 109 | } 110 | } 111 | 112 | public void setDaraPage(int daraPage) { 113 | this.daraPage = daraPage; 114 | } 115 | 116 | @Override 117 | public int getContentLayoutId() { 118 | return R.layout.aac_include_recycle_view; 119 | } 120 | 121 | 122 | @Override 123 | public void onRefresh() { 124 | daraPage = 1; 125 | getPresenter().setLoadData(daraPage); 126 | } 127 | 128 | @Override 129 | public void onLoadMoreRequested() { 130 | daraPage += 1; 131 | getPresenter().setLoadData(daraPage); 132 | } 133 | 134 | 135 | @Override 136 | public int getCurPage() { 137 | return daraPage; 138 | } 139 | @Nullable 140 | @Override 141 | public M getLastItem() { 142 | if (adapter.getData().isEmpty()){ 143 | return null; 144 | } 145 | return adapter.getItem(adapter.getData().size()-1); 146 | } 147 | /** 148 | * 获取RecyclerView 149 | **/ 150 | @Override 151 | public RecyclerView getRecyclerView() { 152 | return recyclerView; 153 | } 154 | 155 | /** 156 | * 获取数据适配器实例 157 | **/ 158 | @Override 159 | public BaseQuickAdapter getAdapter() { 160 | return adapter; 161 | } 162 | 163 | 164 | /*** 165 | * @param setRefreshing 是否刷新 true false 则停止 166 | **/ 167 | public void setRefreshing(boolean setRefreshing) { 168 | showContentView(); 169 | swipeRefresh.postDelayed(() -> { 170 | if (swipeRefresh == null) return; 171 | swipeRefresh.setRefreshing(setRefreshing); 172 | if (setRefreshing) { 173 | onRefresh(); 174 | } 175 | }, 200); 176 | } 177 | 178 | /** 179 | * 是否启用分页 默认不启用 180 | * 181 | * @param enable true 启用 false 不启用 182 | */ 183 | public void setStartLoadMore(boolean enable) { 184 | if (enable) { 185 | adapter.setOnLoadMoreListener(this, recyclerView); 186 | } 187 | } 188 | /**** 189 | * BaseViewHolder 实现item 布局内容 190 | * 191 | * @param helper BaseViewHolder 192 | * @param item 数据 193 | **/ 194 | protected abstract void convertViewHolder(BaseViewHolder helper, M item); 195 | /*** 196 | * 数据式适配器 197 | ****/ 198 | private class AacBaseQuickAdapter extends BaseQuickAdapter { 199 | private WeakReference weakReference; 200 | 201 | private AacBaseQuickAdapter(AacListFragment aacListFragment) { 202 | super(getItemLayout()); 203 | weakReference = new WeakReference<>(aacListFragment); 204 | 205 | } 206 | 207 | @Override 208 | protected void convert(BaseViewHolder helper, M item) { 209 | if (weakReference.get() == null) return; 210 | convertViewHolder(helper, item); 211 | } 212 | } 213 | 214 | 215 | } 216 | 217 | -------------------------------------------------------------------------------- /Aac-data-module/src/main/java/com/aac/expansion/list/AacMultiListAPresenter.java: -------------------------------------------------------------------------------- 1 | package com.aac.expansion.list; 2 | 3 | 4 | 5 | import com.aac.expansion.data.AacDataAPresenter; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Created by yangc on 2017/8/14. 11 | * E-Mail:yangchaojiang@outlook.com 12 | * Deprecated: 列表数据业务 13 | */ 14 | 15 | public abstract class AacMultiListAPresenter extends AacDataAPresenter>{ 16 | 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Aac-data-module/src/main/java/com/aac/expansion/list/AacMultiListActivity.java: -------------------------------------------------------------------------------- 1 | package com.aac.expansion.list; 2 | 3 | 4 | import android.os.Bundle; 5 | import android.support.annotation.CallSuper; 6 | import android.support.annotation.NonNull; 7 | import android.support.annotation.Nullable; 8 | import android.support.v4.widget.SwipeRefreshLayout; 9 | import android.support.v7.widget.GridLayoutManager; 10 | import android.support.v7.widget.LinearLayoutManager; 11 | import android.support.v7.widget.RecyclerView; 12 | import android.view.View; 13 | import com.aac.expansion.R; 14 | import com.aac.expansion.data.AacDataAPresenter; 15 | import com.aac.expansion.data.AacDataActivity; 16 | import com.chad.library.adapter.base.BaseMultiItemQuickAdapter; 17 | import com.chad.library.adapter.base.BaseQuickAdapter; 18 | import java.util.List; 19 | 20 | /** 21 | * Created by yangc on 2017/8/14. 22 | * E-Mail:yangchaojiang@outlook.com 23 | * Deprecated: 数据父类 24 | */ 25 | 26 | public abstract class AacMultiListActivity

extends AacDataActivity> 27 | implements SwipeRefreshLayout.OnRefreshListener, BaseQuickAdapter.RequestLoadMoreListener { 28 | protected RecyclerView recyclerView; 29 | protected SwipeRefreshLayout swipeRefresh; 30 | private BaseMultiItemQuickAdapter adapter; 31 | private int daraPage = 1; 32 | 33 | @CallSuper 34 | @Override 35 | protected void onCreate(@Nullable Bundle savedInstanceState) { 36 | super.onCreate(savedInstanceState); 37 | swipeRefresh = findViewById(R.id.swipeRefresh); 38 | recyclerView = findViewById(R.id.recyclerView); 39 | if (setGridSpanCount() <= 1) { 40 | recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)); 41 | } else { 42 | recyclerView.setLayoutManager(new GridLayoutManager(this, setGridSpanCount())); 43 | } 44 | // recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL)); 45 | swipeRefresh.setOnRefreshListener(this); 46 | adapter =getMultiAdapter(); 47 | adapter.bindToRecyclerView(recyclerView); 48 | //检查是否满一屏,如果不满足关闭loadMore 49 | initLoadHelper(swipeRefresh); 50 | adapter.disableLoadMoreIfNotFullPage(); 51 | 52 | } 53 | 54 | @CallSuper 55 | @Override 56 | public void onDestroy() { 57 | super.onDestroy(); 58 | if (adapter != null) { 59 | adapter.getData().clear(); 60 | adapter.setOnLoadMoreListener(null, recyclerView); 61 | } 62 | if (swipeRefresh != null) { 63 | swipeRefresh.setRefreshing(false); 64 | swipeRefresh.setOnRefreshListener(null); 65 | } 66 | } 67 | 68 | @Override 69 | public void initLoadHelper(@NonNull View view) { 70 | super.initLoadHelper(view); 71 | adapter.setEmptyView(getViewLoadHelper().getEmptyLayoutId()); 72 | } 73 | 74 | @Override 75 | public void onRefresh() { 76 | daraPage = 1; 77 | getPresenter().setLoadData(daraPage); 78 | } 79 | 80 | @Override 81 | public void onLoadMoreRequested() { 82 | daraPage += 1; 83 | getPresenter().setLoadData(daraPage); 84 | } 85 | 86 | /*** 87 | * 设置数据 88 | * @param data data 89 | * **/ 90 | @Override 91 | public void setData(@NonNull List data) { 92 | if (daraPage < 2) { 93 | if (swipeRefresh.isRefreshing()) { 94 | setRefreshing(false); 95 | } 96 | adapter.getData().clear(); 97 | adapter.notifyDataSetChanged(); 98 | adapter.addData(data); 99 | 100 | } else { 101 | if (data.isEmpty()) { 102 | adapter.loadMoreEnd(); 103 | } else { 104 | adapter.loadMoreComplete(); 105 | } 106 | adapter.addData(data); 107 | } 108 | 109 | } 110 | 111 | /*** 112 | * 错误 113 | * @param e 错误 114 | **/ 115 | @Override 116 | public void setError(Throwable e) { 117 | if (daraPage < 2) { 118 | if (swipeRefresh.isRefreshing()) { 119 | setRefreshing(false); 120 | } 121 | showErrorView(); 122 | } else { 123 | adapter.loadMoreFail(); 124 | } 125 | } 126 | 127 | @Override 128 | public int getContentLayoutId() { 129 | return R.layout.aac_recycle_view; 130 | } 131 | 132 | public void setDaraPage(int daraPage) { 133 | this.daraPage = daraPage; 134 | } 135 | 136 | public int getCurPage() { 137 | return daraPage; 138 | } 139 | 140 | /** 141 | * 获取RecyclerView 142 | **/ 143 | public RecyclerView getRecyclerView() { 144 | return recyclerView; 145 | } 146 | 147 | /*** 148 | * 进入页面开启是否下拉刷新 149 | * 150 | * @param setRefreshing true 开始刷新 false 停滞 151 | **/ 152 | public void setRefreshing(final boolean setRefreshing) { 153 | showContentView(); 154 | swipeRefresh.postDelayed(() -> { 155 | if (swipeRefresh == null) return; 156 | swipeRefresh.setRefreshing(setRefreshing); 157 | if (setRefreshing) { 158 | onRefresh(); 159 | } 160 | }, 200); 161 | 162 | } 163 | /*** 164 | * 设置网格中的列数 165 | * 子类重写该方法 大于1 使用网格布局 否则L是list 166 | */ 167 | public int setGridSpanCount() { 168 | return 1; 169 | } 170 | 171 | /** 172 | * 是否启用分页 默认不启用 173 | * 174 | * @param enable true 启用 false 不启用 175 | */ 176 | public void setLoadMore(boolean enable) { 177 | if (enable) { 178 | adapter.setOnLoadMoreListener(this, recyclerView); 179 | } 180 | } 181 | @NonNull 182 | public abstract BaseMultiItemQuickAdapter getMultiAdapter(); 183 | 184 | } 185 | -------------------------------------------------------------------------------- /Aac-data-module/src/main/java/com/aac/expansion/list/AacMultiListFPresenter.java: -------------------------------------------------------------------------------- 1 | package com.aac.expansion.list; 2 | 3 | import com.aac.expansion.data.AacDataFPresenter; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * Created by yangc on 2017/8/14. 9 | * E-Mail:yangchaojiang@outlook.com 10 | * Deprecated: Fragment 列表数据理处理 11 | */ 12 | 13 | public abstract class AacMultiListFPresenter extends AacDataFPresenter> { 14 | 15 | 16 | 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Aac-data-module/src/main/java/com/aac/expansion/list/AacMultiListFragment.java: -------------------------------------------------------------------------------- 1 | package com.aac.expansion.list; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.CallSuper; 5 | import android.support.annotation.NonNull; 6 | import android.support.annotation.Nullable; 7 | import android.support.v4.widget.SwipeRefreshLayout; 8 | import android.support.v7.widget.GridLayoutManager; 9 | import android.support.v7.widget.LinearLayoutManager; 10 | import android.support.v7.widget.RecyclerView; 11 | import android.view.View; 12 | import com.aac.expansion.R; 13 | import com.aac.expansion.data.AacDataFPresenter; 14 | import com.aac.expansion.data.AacDataFragment; 15 | import com.chad.library.adapter.base.BaseMultiItemQuickAdapter; 16 | import com.chad.library.adapter.base.BaseQuickAdapter; 17 | import com.chad.library.adapter.base.entity.MultiItemEntity; 18 | import java.util.List; 19 | 20 | /** 21 | * author yangc 22 | * date 2017/8/14 23 | * E-Mail:yangchaojiang@outlook.com 24 | * Deprecated: 列表Fragment 支持懒加载, 子类重写setOpenLazyLoad方法,开启懒加载 25 | */ 26 | 27 | public abstract class AacMultiListFragment

extends AacDataFragment> 28 | implements SwipeRefreshLayout.OnRefreshListener, BaseQuickAdapter.RequestLoadMoreListener{ 29 | private RecyclerView recyclerView; 30 | protected SwipeRefreshLayout swipeRefresh; 31 | private int daraPage = 1; 32 | private BaseMultiItemQuickAdapter adapter; 33 | 34 | @CallSuper 35 | @Override 36 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 37 | super.onViewCreated(view, savedInstanceState); 38 | swipeRefresh = view.findViewById(R.id.swipeRefresh); 39 | recyclerView = view.findViewById(R.id.recyclerView); 40 | if (setGridSpanCount() <= 1) { 41 | recyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false)); 42 | } else { 43 | recyclerView.setLayoutManager(new GridLayoutManager(getActivity(), setGridSpanCount())); 44 | } 45 | // recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL)); 46 | swipeRefresh.setOnRefreshListener(this); 47 | swipeRefresh.setRefreshing(false); 48 | adapter = getMultiAdapter(); 49 | adapter.bindToRecyclerView(recyclerView); 50 | } 51 | 52 | @Override 53 | public void initLoadHelper(@NonNull View view) { 54 | super.initLoadHelper(view); 55 | adapter.setEmptyView(getViewLoadHelper().getEmptyLayoutId(), recyclerView); 56 | } 57 | 58 | @CallSuper 59 | @Override 60 | public void onDestroy() { 61 | super.onDestroy(); 62 | if (adapter != null) { 63 | adapter.getData().clear(); 64 | adapter.setOnLoadMoreListener(null, recyclerView); 65 | 66 | } 67 | if (swipeRefresh != null) { 68 | swipeRefresh.setRefreshing(false); 69 | swipeRefresh.setOnRefreshListener(null); 70 | } 71 | } 72 | 73 | /*** 74 | * 设置数据 75 | * @param data data 76 | * **/ 77 | public void setData(@NonNull List data) { 78 | if (daraPage < 2) { 79 | if (swipeRefresh.isRefreshing()) { 80 | setRefreshing(false); 81 | } 82 | adapter.getData().clear(); 83 | adapter.notifyDataSetChanged(); 84 | adapter.addData(data); 85 | 86 | } else { 87 | if (data.isEmpty()) { 88 | adapter.loadMoreEnd(); 89 | } else { 90 | adapter.loadMoreComplete(); 91 | } 92 | adapter.addData(data); 93 | } 94 | 95 | } 96 | 97 | @Override 98 | public void setError(Throwable e) { 99 | if (daraPage < 2) { 100 | if (swipeRefresh.isRefreshing()) { 101 | setRefreshing(false); 102 | } 103 | showErrorView(); 104 | } else { 105 | adapter.loadMoreFail(); 106 | } 107 | } 108 | 109 | public void setDaraPage(int daraPage) { 110 | this.daraPage = daraPage; 111 | } 112 | /*** 113 | * @param setRefreshing 是否刷新 true false 则停止 114 | **/ 115 | public void setRefreshing(boolean setRefreshing) { 116 | showContentView(); 117 | swipeRefresh.postDelayed(() -> { 118 | if (swipeRefresh == null) return; 119 | swipeRefresh.setRefreshing(setRefreshing); 120 | if (setRefreshing) { 121 | onRefresh(); 122 | } 123 | }, 200); 124 | } 125 | 126 | /** 127 | * 是否启用分页 默认不启用 128 | * 129 | * @param enable true 启用 false 不启用 130 | */ 131 | public void setStartLoadMore(boolean enable) { 132 | if (enable) { 133 | adapter.setOnLoadMoreListener(this, recyclerView); 134 | } 135 | } 136 | @Override 137 | public int getContentLayoutId() { 138 | return R.layout.aac_include_recycle_view; 139 | } 140 | 141 | 142 | @Override 143 | public void onRefresh() { 144 | daraPage = 1; 145 | getPresenter().setLoadData(daraPage); 146 | } 147 | 148 | @Override 149 | public void onLoadMoreRequested() { 150 | daraPage += 1; 151 | getPresenter().setLoadData(daraPage); 152 | } 153 | 154 | public int getCurPage() { 155 | return daraPage; 156 | } 157 | 158 | @Nullable 159 | public M getLastItem() { 160 | if (adapter.getData().isEmpty()) { 161 | return null; 162 | } 163 | return (M) adapter.getItem(adapter.getData().size() - 1); 164 | } 165 | /** 166 | * 获取RecyclerView 167 | **/ 168 | public RecyclerView getRecyclerView() { 169 | return recyclerView; 170 | } 171 | /*** 172 | * 设置网格中的列数 173 | * 子类重写该方法 大于1 使用网格布局 否则L是list 174 | */ 175 | public int setGridSpanCount() { 176 | return 1; 177 | } 178 | 179 | @NonNull 180 | public abstract BaseMultiItemQuickAdapter getMultiAdapter(); 181 | 182 | } 183 | 184 | -------------------------------------------------------------------------------- /Aac-data-module/src/main/res/drawable/ic_chevron_left_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /Aac-data-module/src/main/res/layout/aac_include_recycle_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 11 | 15 | 16 | -------------------------------------------------------------------------------- /Aac-data-module/src/main/res/layout/aac_include_toolbar_view.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Aac-data-module/src/main/res/layout/aac_recycle_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Aac-data-module/src/main/res/layout/aac_view_list_con_empty.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 14 | -------------------------------------------------------------------------------- /Aac-data-module/src/main/res/values/ids.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Aac-data-module/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | AccDataModule 3 | 暂无数据 4 | 5 | -------------------------------------------------------------------------------- /Aac-data-module/src/test/java/com/aac/expansion/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.aac.expansion; 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 | } -------------------------------------------------------------------------------- /AacModule/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /AacModule/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'me.tatarka.retrolambda' 3 | android { 4 | compileSdkVersion project.ext.compileSdkVersion 5 | buildToolsVersion project.ext.buildToolsVersion 6 | defaultConfig { 7 | minSdkVersion project.ext.minSdkVersion 8 | targetSdkVersion project.ext.targetSdkVersion 9 | versionCode project.ext.versionCode 10 | versionName project.ext.versionName 11 | 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | 22 | lintOptions { 23 | abortOnError false 24 | } 25 | //设置JDK1.8 26 | compileOptions { 27 | sourceCompatibility JavaVersion.VERSION_1_8 28 | targetCompatibility JavaVersion.VERSION_1_8 29 | } 30 | lintOptions { 31 | abortOnError false 32 | } 33 | 34 | } 35 | 36 | dependencies { 37 | compile fileTree(include: ['*.jar'], dir: 'libs') 38 | androidTestCompile('com.android.support.test.espresso:espresso-core:3.0.2', { 39 | exclude group: 'com.android.support', module: 'support-annotations' 40 | }) 41 | testCompile 'junit:junit:4.12' 42 | def lifecycle_version = "1.1.1" 43 | // alternatively, just LiveData 44 | compile "com.android.support:appcompat-v7:${libSversion}" 45 | compile "android.arch.lifecycle:extensions:$lifecycle_version" 46 | // alternatively - just ViewModel 47 | compile "android.arch.lifecycle:viewmodel:$lifecycle_version" // use -ktx for Kotlin 48 | // alternatively - just LiveData 49 | compile "android.arch.lifecycle:livedata:$lifecycle_version" 50 | // alternatively - Lifecycles only (no ViewModel or LiveData). 51 | // Support library depends on this lightweight import 52 | compile "android.arch.lifecycle:runtime:$lifecycle_version" 53 | 54 | annotationProcessor "android.arch.lifecycle:compiler:$lifecycle_version" 55 | } 56 | 57 | apply plugin: 'com.novoda.bintray-release' 58 | ////上传到jcenter 59 | // 60 | publish { 61 | repoName="ycjiang"//仓库名 62 | userOrg = 'ycjiang' 63 | groupId = 'com.ycjiang' 64 | artifactId = 'AacModule' 65 | publishVersion = project.ext.publishVersion 66 | desc = 'Based on google Android Architecture Components package to achieve MVP rapid development framework' 67 | website = 'https://github.com/yangchaojiang/AaComponents' 68 | dryRun = false 69 | } 70 | -------------------------------------------------------------------------------- /AacModule/src/androidTest/java/com/aac/module/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.aac.module; 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.acc.module.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /AacModule/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /AacModule/src/main/java/com/aac/module/callback/ActivityLifecycleCallbacksWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2013 Benoit 'BoD' Lubek (BoD@JRAF.org) 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | package com.aac.module.callback; 25 | 26 | import android.annotation.TargetApi; 27 | import android.app.Activity; 28 | import android.app.Application.ActivityLifecycleCallbacks; 29 | import android.os.Build; 30 | import android.os.Bundle; 31 | 32 | /** 33 | * Wraps into an {@link ActivityLifecycleCallbacks}. 34 | */ 35 | @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) 36 | public abstract class ActivityLifecycleCallbacksWrapper implements ActivityLifecycleCallbacks { 37 | 38 | 39 | @Override 40 | public void onActivityCreated(Activity activity, Bundle savedInstanceState) { 41 | } 42 | 43 | @Override 44 | public void onActivityStarted(Activity activity) { 45 | } 46 | 47 | @Override 48 | public void onActivityResumed(Activity activity) { 49 | } 50 | 51 | @Override 52 | public void onActivityPaused(Activity activity) { 53 | } 54 | 55 | @Override 56 | public void onActivityStopped(Activity activity) { 57 | } 58 | 59 | @Override 60 | public void onActivitySaveInstanceState(Activity activity, Bundle outState) { 61 | } 62 | 63 | @Override 64 | public void onActivityDestroyed(Activity activity) { 65 | } 66 | 67 | @Override 68 | public boolean equals(Object o) { 69 | return this==o; 70 | } 71 | 72 | 73 | @Override 74 | public int hashCode() { 75 | return this.hashCode(); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /AacModule/src/main/java/com/aac/module/model/AacAndroidViewModel.java: -------------------------------------------------------------------------------- 1 | package com.aac.module.model; 2 | 3 | import android.app.Application; 4 | import android.arch.lifecycle.AndroidViewModel; 5 | 6 | /** 7 | * Created by yangc on 2017/8/27. 8 | * E-Mail:yangchaojiang@outlook.com 9 | * Deprecated:父类view模型 10 | */ 11 | 12 | public abstract class AacAndroidViewModel extends AndroidViewModel { 13 | 14 | public AacAndroidViewModel(Application application) { 15 | super(application); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /AacModule/src/main/java/com/aac/module/model/AacViewModel.java: -------------------------------------------------------------------------------- 1 | package com.aac.module.model; 2 | 3 | import android.arch.lifecycle.ViewModel; 4 | 5 | /** 6 | * Created by yangc on 2017/8/27. 7 | * E-Mail:yangchaojiang@outlook.com 8 | * Deprecated: 父类view模型 9 | */ 10 | 11 | public abstract class AacViewModel extends ViewModel { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /AacModule/src/main/java/com/aac/module/pres/RequiresPresenter.java: -------------------------------------------------------------------------------- 1 | package com.aac.module.pres; 2 | 3 | import com.aac.module.ui.AacPresenter; 4 | 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Inherited; 7 | import java.lang.annotation.Retention; 8 | import java.lang.annotation.RetentionPolicy; 9 | import java.lang.annotation.Target; 10 | 11 | 12 | @Inherited 13 | @Retention(RetentionPolicy.RUNTIME) 14 | @Target(ElementType.TYPE) 15 | public @interface RequiresPresenter { 16 | Class value(); 17 | } 18 | -------------------------------------------------------------------------------- /AacModule/src/main/java/com/aac/module/ui/AacActivity.java: -------------------------------------------------------------------------------- 1 | package com.aac.module.ui; 2 | 3 | import android.arch.lifecycle.Lifecycle; 4 | import android.arch.lifecycle.LifecycleRegistry; 5 | import android.content.Intent; 6 | import android.os.Bundle; 7 | import android.os.PersistableBundle; 8 | import android.support.annotation.CallSuper; 9 | import android.support.annotation.NonNull; 10 | import android.support.annotation.Nullable; 11 | import android.support.v7.app.AppCompatActivity; 12 | import android.support.v7.widget.Toolbar; 13 | 14 | import com.aac.module.R; 15 | import com.aac.module.utils.ContentLayoutListener; 16 | 17 | /** 18 | * Created by yangc on 2017/8/13. 19 | * E-Mail:yangchaojiang@outlook.com 20 | * Deprecated: 控制activity 控制类 21 | * 22 | * @param

与activity 订阅{@link AacPresenter }类 23 | * @see AacActivity 24 | */ 25 | 26 | public abstract class AacActivity

extends AppCompatActivity implements ContentLayoutListener { 27 | private LifecycleRegistry lifecycleRegistry = new LifecycleRegistry(this); 28 | private P t = PresenterBuilder.fromViewClass(this); 29 | @CallSuper 30 | @Override 31 | protected void onCreate(@Nullable Bundle savedInstanceState) { 32 | super.onCreate(savedInstanceState); 33 | if (getContentLayoutId() == 0) { 34 | throw new NullPointerException(getString(R.string.aac_layout_error_hint)); 35 | } 36 | setContentView(getContentLayoutId()); 37 | Toolbar toolbar = findViewById(R.id.toolbar); 38 | if (toolbar != null) { 39 | onSetToolbar(toolbar); 40 | } 41 | if (t != null) { 42 | lifecycleRegistry.addObserver(t); 43 | t.onCreateView(); 44 | } 45 | 46 | } 47 | @CallSuper 48 | @Override 49 | protected void onDestroy() { 50 | super.onDestroy(); 51 | lifecycleRegistry.removeObserver(t); 52 | lifecycleRegistry = null; 53 | t = null; 54 | } 55 | 56 | @CallSuper 57 | @Override 58 | public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) { 59 | super.onSaveInstanceState(outState, outPersistentState); 60 | t.onSave(outState); 61 | } 62 | 63 | @NonNull 64 | @CallSuper 65 | @Override 66 | public LifecycleRegistry getLifecycle() { 67 | return lifecycleRegistry; 68 | } 69 | 70 | @CallSuper 71 | @Override 72 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 73 | t.onResult(requestCode, resultCode, data); 74 | super.onActivityResult(requestCode, resultCode, data); 75 | } 76 | 77 | /** 78 | * 设置Toolbar如果使用了ToolBar则自动部署。没有则无影响。 79 | * 80 | * @param toolbar toolbar 81 | **/ 82 | public void onSetToolbar(Toolbar toolbar) { 83 | setSupportActionBar(toolbar); 84 | toolbar.setNavigationOnClickListener((view) -> finish()); 85 | assert getSupportActionBar() != null; 86 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 87 | } 88 | 89 | @Override 90 | public void setTitle(CharSequence title) { 91 | if (getSupportActionBar() != null) { 92 | getSupportActionBar().setTitle(title); 93 | } 94 | } 95 | 96 | /*** 97 | * 得到对应业务处理类 98 | * 99 | * @return L 100 | **/ 101 | public P getPresenter() { 102 | return t; 103 | } 104 | /** 105 | * 返回当前生命中周期状态 106 | * 107 | * @param state Lifecycle.State 108 | * @return boolean 109 | **/ 110 | public boolean getState(Lifecycle.State state) { 111 | return lifecycleRegistry.getCurrentState().isAtLeast(state); 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /AacModule/src/main/java/com/aac/module/ui/AacFragment.java: -------------------------------------------------------------------------------- 1 | package com.aac.module.ui; 2 | 3 | import android.arch.lifecycle.Lifecycle; 4 | import android.arch.lifecycle.LifecycleRegistry; 5 | import android.os.Bundle; 6 | import android.support.annotation.CallSuper; 7 | import android.support.annotation.NonNull; 8 | import android.support.annotation.Nullable; 9 | import android.support.v4.app.Fragment; 10 | import android.view.LayoutInflater; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | 14 | import com.aac.module.R; 15 | import com.aac.module.utils.ContentLayoutListener; 16 | 17 | /** 18 | * Created by yangc on 2017/8/13. 19 | * E-Mail:yangchaojiang@outlook.com 20 | * Deprecated: 21 | * 22 | * @param

AacFragment 订阅{@link AacFragmentPresenter }类 23 | * @see AacFragment 24 | */ 25 | 26 | public abstract class AacFragment

extends Fragment implements ContentLayoutListener { 27 | private LifecycleRegistry lifecycleRegistry = new LifecycleRegistry(this); 28 | private P t = PresenterBuilder.fromViewClass(this); 29 | 30 | @CallSuper 31 | @Override 32 | public void onCreate(@Nullable Bundle savedInstanceState) { 33 | super.onCreate(savedInstanceState); 34 | lifecycleRegistry.addObserver(t); 35 | lifecycleRegistry.markState(Lifecycle.State.CREATED); 36 | } 37 | 38 | @Nullable 39 | @Override 40 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 41 | if (getContentLayoutId() == 0) { 42 | throw new NullPointerException(getString(R.string.aac_layout_error_hint)); 43 | } 44 | return inflater.inflate(getContentLayoutId(), container, false); 45 | } 46 | 47 | @CallSuper 48 | @Override 49 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 50 | t.onCreateView(); 51 | super.onViewCreated(view, savedInstanceState); 52 | t.onViewCreated(); 53 | } 54 | 55 | @CallSuper 56 | @Override 57 | public void onStart() { 58 | super.onStart(); 59 | lifecycleRegistry.markState(Lifecycle.State.STARTED); 60 | } 61 | 62 | @CallSuper 63 | @Override 64 | public void onResume() { 65 | super.onResume(); 66 | lifecycleRegistry.markState(Lifecycle.State.RESUMED); 67 | } 68 | 69 | @CallSuper 70 | @Override 71 | public void onDestroyView() { 72 | super.onDestroyView(); 73 | t.onDestroyView(); 74 | } 75 | 76 | @CallSuper 77 | @Override 78 | public void onDestroy() { 79 | super.onDestroy(); 80 | lifecycleRegistry.markState(Lifecycle.State.DESTROYED); 81 | lifecycleRegistry.removeObserver(t); 82 | lifecycleRegistry = null; 83 | t = null; 84 | } 85 | 86 | 87 | 88 | @NonNull 89 | @Override 90 | public LifecycleRegistry getLifecycle() { 91 | return lifecycleRegistry; 92 | } 93 | 94 | /*** 95 | * 得到对应业务处理类 96 | * 97 | * @return R 98 | **/ 99 | public P getPresenter() { 100 | return t; 101 | } 102 | 103 | /** 104 | * 返回是否当前生命中周期状态 105 | * 106 | * @param state Lifecycle.State 107 | * @return boolean 108 | **/ 109 | public boolean getState(Lifecycle.State state) { 110 | return lifecycleRegistry.getCurrentState().isAtLeast(state); 111 | } 112 | 113 | } 114 | -------------------------------------------------------------------------------- /AacModule/src/main/java/com/aac/module/ui/AacFragmentPresenter.java: -------------------------------------------------------------------------------- 1 | package com.aac.module.ui; 2 | 3 | 4 | /** 5 | * Created by yangc on 2017/8/13. 6 | * E-Mail:yangchaojiang@outlook.com 7 | * Deprecated: Fragment业务处理控制类 8 | * 9 | * @param AacFragmentPresenter 订阅{@link AacFragment}类 10 | * @see AacFragmentPresenter 11 | */ 12 | 13 | 14 | public abstract class AacFragmentPresenter extends AacPresenter { 15 | 16 | 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /AacModule/src/main/java/com/aac/module/ui/AacPresenter.java: -------------------------------------------------------------------------------- 1 | package com.aac.module.ui; 2 | 3 | import android.app.Activity; 4 | import android.arch.lifecycle.Lifecycle; 5 | import android.arch.lifecycle.LifecycleObserver; 6 | import android.arch.lifecycle.OnLifecycleEvent; 7 | import android.arch.lifecycle.ViewModel; 8 | import android.arch.lifecycle.ViewModelProvider; 9 | import android.arch.lifecycle.ViewModelProviders; 10 | import android.content.Intent; 11 | import android.os.Bundle; 12 | import android.support.annotation.NonNull; 13 | import android.support.v4.app.Fragment; 14 | import android.support.v4.app.FragmentActivity; 15 | 16 | /** 17 | * author yangc 18 | * date 2017/8/13 19 | * E-Mail:yangchaojiang@outlook.com 20 | * Deprecated: 业务处理控制类 21 | * 22 | * @param 与AacPresenter建立订阅View 23 | * @see AacPresenter 24 | */ 25 | 26 | public abstract class AacPresenter implements LifecycleObserver { 27 | private Lifecycle lifecycle; 28 | private ActivityType view; 29 | 30 | @OnLifecycleEvent(Lifecycle.Event.ON_CREATE) 31 | protected void onCreate() { 32 | 33 | } 34 | 35 | @OnLifecycleEvent(Lifecycle.Event.ON_START) 36 | protected void onStart() { 37 | } 38 | 39 | @OnLifecycleEvent(Lifecycle.Event.ON_RESUME) 40 | protected void onResume() { 41 | } 42 | 43 | @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE) 44 | protected void onPause() { 45 | } 46 | 47 | @OnLifecycleEvent(Lifecycle.Event.ON_STOP) 48 | protected void onStop() { 49 | } 50 | 51 | @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) 52 | protected void onDestroy() { 53 | view = null; 54 | lifecycle = null; 55 | } 56 | protected void onCreateView() { 57 | 58 | } 59 | 60 | public void onDestroyView() { 61 | 62 | } 63 | 64 | public void onViewCreated() { 65 | } 66 | protected void onResult(int requestCode, int resultCode, Intent data) { 67 | 68 | } 69 | 70 | protected void onSave(Bundle state) { 71 | 72 | } 73 | 74 | @NonNull 75 | public final ActivityType getView() { 76 | return view; 77 | } 78 | 79 | /*** 80 | * 单例获取viewModel方式类型实例 81 | * 82 | * @param modelClass modelClass类型 83 | *@param ViewModelType 84 | * @return ViewModelType 85 | **/ 86 | public ViewModelType getInstanceViewModel(Class modelClass) { 87 | return new ViewModelProvider.NewInstanceFactory().create(modelClass); 88 | } 89 | 90 | /*** 91 | * 获取数据viewModel方式类型实例 92 | * 93 | * @param modelClass modelClass类型 94 | *@param ViewModelType 95 | * @return ViewModelType 96 | **/ 97 | public ViewModelType getViewActivityModel(Class modelClass) { 98 | 99 | if (view instanceof Fragment) { 100 | return ViewModelProviders.of(((Fragment) view).getActivity()).get(modelClass); 101 | } else if (view instanceof FragmentActivity) { 102 | return ViewModelProviders.of((FragmentActivity) view).get(modelClass); 103 | } else { 104 | return getInstanceViewModel(modelClass); 105 | } 106 | } 107 | 108 | /*** 109 | * 获取数据viewModel方式类型实例 110 | * 111 | * @param modelClass modelClass类型 112 | *@param ViewModelType 113 | * @return ViewModelType 114 | **/ 115 | public ViewModelType getViewModel(Class modelClass) { 116 | 117 | if (view instanceof Fragment) { 118 | return ViewModelProviders.of((Fragment) view).get(modelClass); 119 | } else if (view instanceof FragmentActivity) { 120 | return ViewModelProviders.of((FragmentActivity) view).get(modelClass); 121 | } else { 122 | return getInstanceViewModel(modelClass); 123 | } 124 | } 125 | 126 | /*** 127 | * 获取数据viewModel方式类型实例 128 | * 129 | * @param modelClass modelClass类型 130 | *@param ViewModelType 131 | * @return ViewModelType 132 | **/ 133 | public ViewModelType getApplicationViewModel(Class modelClass) { 134 | 135 | if (view instanceof Fragment) { 136 | return new ViewModelProvider.AndroidViewModelFactory(((Fragment) view).getActivity().getApplication()).create(modelClass); 137 | } else if (view instanceof FragmentActivity) { 138 | return new ViewModelProvider.AndroidViewModelFactory(((Activity) view).getApplication()).create(modelClass); 139 | } else { 140 | return getInstanceViewModel(modelClass); 141 | 142 | } 143 | } 144 | /** 145 | * 返回是否当前生命中周期状态 146 | * 147 | * @param state Lifecycle.State 148 | * @return boolean 149 | **/ 150 | public boolean isAtLeast(Lifecycle.State state) { 151 | return lifecycle.getCurrentState().isAtLeast(state); 152 | } 153 | 154 | void create(@NonNull ActivityType view) { 155 | this.view = view; 156 | } 157 | 158 | 159 | } 160 | -------------------------------------------------------------------------------- /AacModule/src/main/java/com/aac/module/ui/AacService.java: -------------------------------------------------------------------------------- 1 | package com.aac.module.ui; 2 | 3 | import android.arch.lifecycle.LifecycleService; 4 | import android.content.Intent; 5 | 6 | /** 7 | * Created by yangc on 2017/8/13. 8 | * E-Mail:yangchaojiang@outlook.com 9 | * Deprecated: 10 | * 11 | * @see AacService 12 | */ 13 | 14 | 15 | public abstract class AacService

extends LifecycleService { 16 | private P t = PresenterBuilder.fromViewClass(this); 17 | @Override 18 | public void onCreate() { 19 | super.onCreate(); 20 | getLifecycle().addObserver(t); 21 | } 22 | @Override 23 | public int onStartCommand(Intent intent, int flags, int startId) { 24 | return super.onStartCommand(intent, flags, startId); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /AacModule/src/main/java/com/aac/module/ui/PresenterBuilder.java: -------------------------------------------------------------------------------- 1 | package com.aac.module.ui; 2 | 3 | 4 | import android.arch.lifecycle.LifecycleOwner; 5 | import android.support.annotation.NonNull; 6 | 7 | import com.aac.module.pres.RequiresPresenter; 8 | 9 | /** 10 | * Created by yangc on 2017/8/13. 11 | * E-Mail:yangchaojiang@outlook.com 12 | * Deprecated: java反射当前类 13 | */ 14 | public class PresenterBuilder { 15 | 16 | public static PresenterType fromViewClass(@NonNull LifecycleOwner viewClass) { 17 | RequiresPresenter annotation = viewClass.getClass().getAnnotation(RequiresPresenter.class); 18 | //noinspection unchecked 19 | if (annotation == null) { 20 | return null; 21 | //throw new RuntimeException("You must declaration @RequiresPresenter for your Activity"); 22 | } 23 | Class presenterClass = (Class) annotation.value(); 24 | PresenterType presenter; 25 | try { 26 | presenter = presenterClass.newInstance(); 27 | presenter.create(viewClass); 28 | } catch (InstantiationException e) { 29 | throw new RuntimeException("PresenterBuilder Find generic failed:"+e); 30 | } catch (IllegalAccessException e) { 31 | throw new RuntimeException("PresenterBuilder Find generic failed:"+e); 32 | } 33 | return presenter; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /AacModule/src/main/java/com/aac/module/utils/ContentLayoutListener.java: -------------------------------------------------------------------------------- 1 | package com.aac.module.utils; 2 | 3 | import android.support.annotation.LayoutRes; 4 | 5 | /** 6 | * Created by yangc on 2017/12/2 7 | * E-Mail:yangchaojiang@outlook.com 8 | * Deprecated: 9 | */ 10 | 11 | public interface ContentLayoutListener { 12 | 13 | /*** 14 | * 内容布局id 15 | * @return int 16 | ***/ 17 | @LayoutRes 18 | int getContentLayoutId(); 19 | } 20 | -------------------------------------------------------------------------------- /AacModule/src/main/java/com/aac/module/utils/MyFragmentManager.java: -------------------------------------------------------------------------------- 1 | package com.aac.module.utils; 2 | 3 | import android.support.annotation.IdRes; 4 | import android.support.annotation.NonNull; 5 | import android.support.v4.app.Fragment; 6 | import android.support.v4.app.FragmentManager; 7 | import android.support.v4.app.FragmentTransaction; 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | /** 11 | * Created by yangc on 2017/9/11. 12 | * E-Mail:yangchaojiang@outlook.com 13 | * Deprecated: fragment 管里类 14 | */ 15 | 16 | public class MyFragmentManager { 17 | private List fragmentList; 18 | private FragmentManager fragmentManager; 19 | private int resId; 20 | /**** 21 | * 初始化 22 | * 23 | * @param fragmentManager fragment 容器 24 | * @param resId 容器布局 25 | * @param data list列表数据 26 | **/ 27 | public MyFragmentManager(@NonNull List data,@NonNull FragmentManager fragmentManager, @IdRes int resId) { 28 | fragmentList = new ArrayList<>(); 29 | this.fragmentManager = fragmentManager; 30 | this.resId = resId; 31 | addAll(data); 32 | } 33 | 34 | /**** 35 | * 初始化 36 | * 37 | * @param fragmentManager fragment 容器 38 | * @param resId 容器布局 39 | **/ 40 | public MyFragmentManager(@NonNull FragmentManager fragmentManager, @IdRes int resId) { 41 | fragmentList = new ArrayList<>(); 42 | this.fragmentManager = fragmentManager; 43 | this.resId = resId; 44 | } 45 | 46 | /**** 47 | * 添加列表 48 | * 49 | * @param data list列表数据 50 | ***/ 51 | private void addAll(List data) { 52 | fragmentList.addAll(data); 53 | FragmentTransaction b = fragmentManager.beginTransaction(); 54 | for (Fragment item : fragmentList) { 55 | b.add(resId, item); 56 | } 57 | for (Fragment item : fragmentList) { 58 | b.hide(item); 59 | } 60 | b.show(fragmentList.get(0)); 61 | b.commitAllowingStateLoss(); 62 | } 63 | /**** 64 | * 添加item 65 | * 66 | * @param fragment 添加单个 67 | ***/ 68 | public void add(Fragment fragment) { 69 | fragmentList.add(fragment); 70 | } 71 | /**** 72 | * 插入item 73 | * 74 | * @param index 插入索引 75 | * @param fragment item 76 | ***/ 77 | public void install(int index,Fragment fragment) { 78 | fragmentList.set(index,fragment); 79 | } 80 | 81 | /*** 82 | * 显示当前fragment 其他隐藏 83 | * 84 | * @param index 索引 85 | **/ 86 | public void show(int index) { 87 | FragmentTransaction b = fragmentManager.beginTransaction(); 88 | b.show(fragmentList.get(index)); 89 | b.commitAllowingStateLoss(); 90 | } 91 | /*** 92 | * 显示当前fragment 其他隐藏 93 | * 94 | * @param index 索引 95 | **/ 96 | public void updateShow(int index) { 97 | FragmentTransaction b = fragmentManager.beginTransaction(); 98 | for (Fragment item : fragmentList) { 99 | b.hide(item); 100 | } 101 | b.show(fragmentList.get(index)); 102 | b.commitAllowingStateLoss(); 103 | } 104 | 105 | /*** 106 | * 隐藏当前fragment 107 | * 108 | * @param index 索引 109 | **/ 110 | public void hide(int index) { 111 | FragmentTransaction b = fragmentManager.beginTransaction(); 112 | b.show(fragmentList.get(index)); 113 | b.commitAllowingStateLoss(); 114 | } 115 | /*** 116 | * 隐藏当前fragment 117 | * 118 | * @param index 索引 119 | **/ 120 | public void replace(int index) { 121 | FragmentTransaction b = fragmentManager.beginTransaction(); 122 | b.replace(resId,fragmentList.get(index)); 123 | b.commitAllowingStateLoss(); 124 | } 125 | /*** 126 | *获取当前Fragment 实例 127 | * 128 | *@param T 129 | * @param index 索引 130 | * @return T 131 | **/ 132 | public T getItem(int index) { 133 | return (T) fragmentList.get(index); 134 | } 135 | 136 | 137 | /*** 138 | * 全部隐藏当前fragment 139 | **/ 140 | public void hideAll() { 141 | FragmentTransaction b = fragmentManager.beginTransaction(); 142 | for (Fragment item : fragmentList) { 143 | b.hide(item); 144 | } 145 | b.commitAllowingStateLoss(); 146 | } 147 | 148 | /*** 149 | * 释放资源 150 | * **/ 151 | public void onDestroy() { 152 | if (fragmentList != null) { 153 | fragmentList.clear(); 154 | fragmentList = null; 155 | } 156 | fragmentManager = null; 157 | } 158 | 159 | } 160 | -------------------------------------------------------------------------------- /AacModule/src/main/res/values/ids.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /AacModule/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | AccModule 3 | 没有布局文件id 4 | 5 | -------------------------------------------------------------------------------- /AacModule/src/test/java/com/aac/module/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.aac.module; 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 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AaComponents 2 | 3 | [ ![Download](https://api.bintray.com/packages/ycjiang/ycjiang/AacHttpDataModule/images/download.svg) ](https://bintray.com/ycjiang/ycjiang/AacHttpDataModule/_latestVersion) 4 | 5 | 基于google Android Architecture Components 封装实现MVP快速开发框架 6 | 7 | AaComponents 是一套基于MVP模式的快速开发框架。定义了一套开发规范。 8 | 并提供了基于这套规范的Activity,Fragment,Presenter,Model等父类及控件和API等, 9 | 完成APP开发过程中大量繁琐工作。 10 | 11 | ##依赖 12 | * 1 compile 'com.ycjiang:AacDataModule:2.5.3' 13 | * 2 compile 'com.ycjiang:AacModule:2.5.3' 14 | * 3 compile 'com.ycjiang:AacRxDataModule:2.5.3' 15 | * 4 compile 'com.ycjiang:AacHttpDataModule:2.5.3' 16 | >> 注意 引用 AaDataModule 默认引用 AacModule 包, 不需要在引用在AaDataModule 17 | 18 | ``` 19 | repositories { 20 | jcenter() 21 | maven { url "https://jitpack.io" }//BaseRecyclerViewAdapterHelper框架需要 22 | //3.0以下as的版本 23 | maven { url 'https://maven.google.com' } 24 | 或者 //3.0以上as的版本。下面的 25 | google(); 26 | 27 | 28 | } 29 | ``` 30 | ### 使用插件快速生成aac模板代码[戳我](https://github.com/yangchaojiang/AAcHelper) 31 | 32 | #### More 33 | Find more details about Matisse in [wiki](https://github.com/yangchaojiang/AaComponents/wiki) 34 | 35 | ##重复依赖 36 | 本库已经依赖了下面的库,请注意重复依赖的问题 37 | 38 | compile 'android.arch.lifecycle:extensions:1.0.0' 39 | annotationProcessor "android.arch.lifecycle:compiler:1.0.0" 40 | compile "com.android.support:appcompat-v7:${libSversion}" 41 | compile 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34' 42 | compile "com.android.support:recyclerview-v7:${libSversion}" 43 | compile 'com.ycjiang:loadviewhelper:1.1.0' 44 | compile 'com.ycjiang:center-toolbar:1.0.0' 45 | // 46 | // AacHttpDataModule 内部引用 47 | compile 'com.lzy.net:okgo:3.0.4' 48 | compile 'com.lzy.net:okrx2:2.0.2' -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android-extensions' 3 | apply plugin: 'kotlin-android' 4 | apply plugin: 'kotlin-kapt' 5 | android { 6 | compileSdkVersion project.ext.compileSdkVersion 7 | buildToolsVersion project.ext.buildToolsVersion 8 | defaultConfig { 9 | minSdkVersion project.ext.minSdkVersion 10 | targetSdkVersion project.ext.targetSdkVersion 11 | versionCode project.ext.versionCode 12 | versionName project.ext.versionName 13 | applicationId "com.example.aac" 14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 15 | } 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | dataBinding { 23 | enabled = true 24 | } 25 | compileOptions { 26 | sourceCompatibility JavaVersion.VERSION_1_8 27 | targetCompatibility JavaVersion.VERSION_1_8 28 | } 29 | lintOptions { 30 | abortOnError false 31 | } 32 | } 33 | 34 | dependencies { 35 | implementation 'com.android.support.constraint:constraint-layout:1.1.2' 36 | compile fileTree(include: ['*.jar'], dir: 'libs') 37 | androidTestCompile('com.android.support.test.espresso:espresso-core:3.0.2', { 38 | exclude group: 'com.android.support', module: 'support-annotations' 39 | }) 40 | compile('com.android.support:appcompat-v7:' + libSversion, { 41 | exclude group: 'com.android.support', module: 'appcompat-v7' 42 | }) 43 | compile('com.android.support:support-v4:' + libSversion, { 44 | exclude group: 'com.android.support', module: 'support-v4' 45 | }) 46 | compile 'com.baoyz.pullrefreshlayout:library:1.2.0' 47 | compile 'com.ycjiang:Yutils:1.2.4' 48 | testCompile 'junit:junit:4.12' 49 | compile 'com.coolerfall:android-app-daemon:1.2.0' 50 | compile 'android.arch.lifecycle:reactivestreams:1.1.1' 51 | compile 'com.lzy.net:okgo:3.0.4' 52 | compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 53 | // compile 'com.ycjiang:AacHttpDataModule:2.4.8' 54 | implementation project(':Aac-data-module-http') 55 | implementation project(':Aac-data-module-coroutines') 56 | } 57 | -------------------------------------------------------------------------------- /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:\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 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/example/aac/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.example.aac; 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.aac", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/ActivityCallback.java: -------------------------------------------------------------------------------- 1 | package com.example.aac; 2 | 3 | import android.app.Activity; 4 | import android.content.res.Configuration; 5 | import android.content.res.Resources; 6 | import android.os.Bundle; 7 | import android.support.v7.app.AppCompatDelegate; 8 | 9 | import com.aac.module.callback.ActivityLifecycleCallbacksWrapper; 10 | 11 | /** 12 | * Created by yangc on 2017/8/17. 13 | * E-Mail:yangchaojiang@outlook.com 14 | * Deprecated: 周期回调 15 | */ 16 | public class ActivityCallback extends ActivityLifecycleCallbacksWrapper { 17 | 18 | @Override 19 | public void onActivityCreated(Activity activity, Bundle savedInstanceState) { 20 | super.onActivityCreated(activity, savedInstanceState); 21 | AppCompatDelegate.setCompatVectorFromResourcesEnabled(false); 22 | 23 | } 24 | 25 | @Override 26 | public void onActivityResumed(Activity activity) { 27 | super.onActivityResumed(activity); 28 | } 29 | @Override 30 | public void onActivitySaveInstanceState(Activity activity, Bundle outState) { 31 | super.onActivitySaveInstanceState(activity, outState); 32 | } 33 | 34 | @Override 35 | public void onActivityDestroyed(Activity activity) { 36 | super.onActivityDestroyed(activity); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/App.java: -------------------------------------------------------------------------------- 1 | package com.example.aac; 2 | 3 | import android.app.Application; 4 | 5 | 6 | /** 7 | * Created by yangc on 2017/8/17. 8 | * E-Mail:yangchaojiang@outlook.com 9 | * Deprecated: 10 | */ 11 | public class App extends Application { 12 | 13 | 14 | @Override 15 | public void onCreate() { 16 | super.onCreate(); 17 | registerActivityLifecycleCallbacks(new ActivityCallback()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/java/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.aac.java; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v7.app.ActionBar; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.view.View; 9 | 10 | import com.center.toolbar.TitleToolbar; 11 | import com.example.aac.R; 12 | import com.example.aac.java.coroutines.CoroutinesActivity; 13 | import com.example.aac.java.data.activity.TestDataActivity; 14 | import com.example.aac.java.data.activity.TestDataListActivity; 15 | import com.example.aac.java.data.fragment.TestFragmentActivity; 16 | 17 | public class MainActivity extends AppCompatActivity { 18 | private TitleToolbar titleToolbar; 19 | @Override 20 | protected void onCreate(Bundle savedInstanceState) { 21 | super.onCreate(savedInstanceState); 22 | setContentView(R.layout.activity_main); 23 | this.titleToolbar = findViewById(R.id.toolbar); 24 | setSupportActionBar(titleToolbar); 25 | ActionBar mActionBar = getSupportActionBar(); 26 | mActionBar.setDisplayOptions(mActionBar.getDisplayOptions() | ActionBar.DISPLAY_HOME_AS_UP); 27 | titleToolbar.setTitle("我的"); 28 | findViewById(R.id.button).setOnClickListener(new View.OnClickListener() { 29 | @Override 30 | public void onClick(View v) { 31 | Intent intent = new Intent(MainActivity.this, TestDataActivity.class); 32 | startActivity(intent); 33 | } 34 | }); 35 | findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() { 36 | @Override 37 | public void onClick(View v) { 38 | Intent intent = new Intent(MainActivity.this, TestDataListActivity.class); 39 | startActivity(intent); 40 | } 41 | }); 42 | findViewById(R.id.button3).setOnClickListener(new View.OnClickListener() { 43 | @Override 44 | public void onClick(View v) { 45 | Intent intent = new Intent(MainActivity.this, TestFragmentActivity.class); 46 | startActivity(intent); 47 | } 48 | }); 49 | findViewById(R.id.button4).setOnClickListener(new View.OnClickListener() { 50 | @Override 51 | public void onClick(View v) { 52 | Intent intent = new Intent(MainActivity.this, CoroutinesActivity.class); 53 | startActivity(intent); 54 | } 55 | }); 56 | } 57 | 58 | @Override 59 | protected void onPostCreate(@Nullable Bundle savedInstanceState) { 60 | super.onPostCreate(savedInstanceState); 61 | 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/java/TestPresenter.java: -------------------------------------------------------------------------------- 1 | package com.example.aac.java; 2 | 3 | import android.arch.lifecycle.LiveData; 4 | import android.util.Log; 5 | 6 | import com.aac.data.http.converter.BeanConverter; 7 | import com.aac.data.http.utils.AacUtils; 8 | import com.aac.module.ui.AacPresenter; 9 | import com.alibaba.fastjson.TypeReference; 10 | import com.lzy.okgo.model.HttpParams; 11 | 12 | import java.lang.reflect.Type; 13 | import java.util.List; 14 | 15 | import io.reactivex.Flowable; 16 | 17 | /** 18 | * Created by yangc on 2017/8/13. 19 | * E-Mail:yangchaojiang@outlook.com 20 | * Deprecated: 21 | */ 22 | 23 | public class TestPresenter extends AacPresenter { 24 | public static final String TAG = "TestPresenter"; 25 | 26 | 27 | @Override 28 | protected void onCreateView() { 29 | super.onCreateView(); 30 | Log.d(TAG, "onCreateView"); 31 | } 32 | 33 | public LiveData sss() { 34 | HttpParams httpParams = new HttpParams(); 35 | return AacUtils.httpLiveGet("sss" 36 | , httpParams 37 | , new BeanConverter("-1", String.class)); 38 | } 39 | 40 | public Flowable> sss2() { 41 | HttpParams params = new HttpParams(); 42 | TypeReference typeReference = new TypeReference>(){}; 43 | return AacUtils.httpRxGet("sss" 44 | , params 45 | , new BeanConverter<>("-1",typeReference.getType())); 46 | } 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/java/coroutines/CoroutinesActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.aac.java.coroutines 2 | 3 | import android.arch.lifecycle.LiveData 4 | import android.os.Bundle 5 | import android.support.v7.app.AppCompatActivity 6 | import android.util.Log 7 | import com.aac.data.coroutines.ColourisesDataAdapter 8 | import com.aac.data.http.converter.BeanConverter 9 | import com.aac.data.http.utils.httpLivePost 10 | import com.aac.data.http.utils.httpRxGet 11 | import com.aac.data.http.utils.httpRxPost 12 | import com.example.aac.R 13 | import com.lzy.okgo.OkGo 14 | import com.lzy.okgo.model.HttpParams 15 | import com.yutils.YUtils 16 | import io.reactivex.Flowable 17 | 18 | class CoroutinesActivity : AppCompatActivity() { 19 | 20 | override fun onCreate(savedInstanceState: Bundle?){ 21 | super.onCreate(savedInstanceState) 22 | YUtils.initialize(application) 23 | val data = HttpParams() 24 | data.put("test", "1233") 25 | setContentView(R.layout.activity_coroutines) 26 | /* httpRxGet("http://www.kuaidi.com/index-ajaxselectcourierinfo-1202247993797-yunda.html", data, 27 | BeanConverter("-1", DataBen::class.java)) 28 | .subscribe({ 29 | YUtils.Toast(it.timeused + "222222222222") 30 | }, { 31 | Log.d("CoroutinesActivity", it.message) 32 | }) 33 | */ 34 | OkGo.get("https://gamazavr.ru/json/search/?query=call%20of") 35 | .converter(BeanConverter("-1", DataBen::class.java)) 36 | .adapt(ColourisesDataAdapter()) 37 | .onSubscribe({ 38 | YUtils.Toast(it.timeused + "222222222222") 39 | },{ 40 | Log.d("CoroutinesActivity", it?.message) 41 | }) 42 | 43 | 44 | } 45 | fun ssss(): Flowable { 46 | val data = HttpParams() 47 | return httpRxGet("http://www.kuaidi.com/index-ajaxselectcourierinfo-1202247993797-yunda.html", 48 | data, 49 | BeanConverter("-1", DataBen::class.java)) 50 | } 51 | 52 | fun sssss(): LiveData { 53 | val data = HttpParams() 54 | return httpLivePost("http://www.kuaidi.com/index-ajaxselectcourierinfo-1202247993797-yunda.html", 55 | data, 56 | BeanConverter("-1", DataBen::class.java)) 57 | } 58 | 59 | fun DataBean(string: String): Flowable { 60 | val params = HttpParams() 61 | params.put("string", string) 62 | return httpRxPost("sss" 63 | , params, 64 | BeanConverter("-1", DataBen::class.java)) 65 | 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/java/coroutines/DataBen.java: -------------------------------------------------------------------------------- 1 | package com.example.aac.java.coroutines; 2 | 3 | /** 4 | * author yangc 5 | * date 2018/7/5 6 | * E-Mail:yangchaojiang@outlook.com 7 | * Deprecated: 8 | */ 9 | public class DataBen { 10 | private Boolean success; 11 | private String time; 12 | private String timeused; 13 | 14 | public Boolean getSuccess() { 15 | return success; 16 | } 17 | 18 | public void setSuccess(Boolean success) { 19 | this.success = success; 20 | } 21 | 22 | public String getTime() { 23 | return time; 24 | } 25 | 26 | public void setTime(String time) { 27 | this.time = time; 28 | } 29 | 30 | public String getTimeused() { 31 | return timeused; 32 | } 33 | 34 | public void setTimeused(String timeused) { 35 | this.timeused = timeused; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/java/data/activity/TesDataPresenter.java: -------------------------------------------------------------------------------- 1 | package com.example.aac.java.data.activity; 2 | 3 | import android.util.Log; 4 | 5 | import com.aac.expansion.data.AacDataAPresenter; 6 | import com.aac.module.rx2.presenter.data.AacRxDataAPresenter; 7 | import com.example.aac.java.data.activity.bean.UserBean; 8 | import com.example.aac.java.model.TestDataViewModel; 9 | 10 | 11 | /** 12 | * Created by yangc on 2017/8/13. 13 | * E-Mail:yangchaojiang@outlook.com 14 | * Deprecated: 15 | */ 16 | 17 | public class TesDataPresenter extends AacRxDataAPresenter { 18 | public static final String TAG = TesDataPresenter.class.getName(); 19 | private TestDataViewModel dataViewModel; 20 | 21 | @Override 22 | public void onCreate() { 23 | super.onCreate(); 24 | Log.d(TAG, "onCreate"); 25 | dataViewModel = getApplicationViewModel(TestDataViewModel.class); 26 | getData(); 27 | } 28 | 29 | 30 | @Override 31 | public void retryData() { 32 | getData(); 33 | } 34 | 35 | public void getData() { 36 | dataViewModel.getData().observe(getView(), getDataSubscriber()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/java/data/activity/TestDataActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.aac.java.data.activity; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.NonNull; 5 | import android.support.annotation.Nullable; 6 | import android.widget.TextView; 7 | 8 | import com.aac.expansion.data.AacDataActivity; 9 | import com.aac.module.pres.RequiresPresenter; 10 | import com.example.aac.R; 11 | 12 | /** 13 | * Created by yangc on 2017/8/14. 14 | * E-Mail:yangchaojiang@outlook.com 15 | * Deprecated: 16 | */ 17 | 18 | @RequiresPresenter(TesDataPresenter.class) 19 | public class TestDataActivity extends AacDataActivity { 20 | TextView te; 21 | 22 | @Override 23 | protected void onCreate(@Nullable Bundle savedInstanceState) { 24 | super.onCreate(savedInstanceState); 25 | te = findViewById(R.id.textView2); 26 | initLoadHelper(findViewById(R.id.root)); 27 | getSupportActionBar().setTitle("测试"); 28 | } 29 | 30 | 31 | @Override 32 | public void setData(@NonNull String data) { 33 | te.setText(data); 34 | } 35 | 36 | @Override 37 | public int getContentLayoutId() { 38 | return R.layout.test_data1_views; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/java/data/activity/TestDataListActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.aac.java.data.activity; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | 6 | import com.aac.expansion.list.AacListActivity; 7 | import com.aac.module.pres.RequiresPresenter; 8 | import com.chad.library.adapter.base.BaseViewHolder; 9 | 10 | /** 11 | * Created by yangc on 2017/8/14. 12 | * E-Mail:yangchaojiang@outlook.com 13 | * Deprecated: 14 | */ 15 | 16 | @RequiresPresenter(TestDataListPresenter.class) 17 | public class TestDataListActivity extends AacListActivity { 18 | 19 | @Override 20 | protected void onCreate(@Nullable Bundle savedInstanceState) { 21 | super.onCreate(savedInstanceState); 22 | setLoadMore(true); 23 | setRefreshing(true); 24 | setTitle("测试数据"); 25 | } 26 | 27 | @Override 28 | public int getItemLayout() { return android.R.layout.simple_list_item_2; } 29 | @Override 30 | public void convertViewHolder(BaseViewHolder helper, String item) { 31 | helper.setText(android.R.id.text1, item); 32 | helper.setText(android.R.id.text2, item); 33 | } 34 | 35 | 36 | 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/java/data/activity/TestDataListPresenter.java: -------------------------------------------------------------------------------- 1 | package com.example.aac.java.data.activity; 2 | 3 | 4 | import com.aac.module.rx2.presenter.list.AacRxListAPresenter; 5 | import com.example.aac.java.model.TestDataViewModel; 6 | 7 | /** 8 | * Created by yangc on 2017/8/14. 9 | * E-Mail:yangchaojiang@outlook.com 10 | * Deprecated: 11 | */ 12 | 13 | public class TestDataListPresenter extends AacRxListAPresenter { 14 | private TestDataViewModel viewModel; 15 | @Override 16 | public void onCreate() { 17 | super.onCreate(); 18 | viewModel = getViewModel(TestDataViewModel.class); 19 | setLoadData(1); 20 | } 21 | 22 | /*** 23 | * 没有进入页面没有开启刷新需要说手动调用 24 | * **/ 25 | @Override 26 | public void setLoadData(int pager) { 27 | super.setLoadData(pager); 28 | viewModel.getListData(pager).observe(getView(), getDataSubscriber()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/java/data/activity/bean/UserBean.java: -------------------------------------------------------------------------------- 1 | package com.example.aac.java.data.activity.bean; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | /** 7 | * Created by yangc on 2017/9/25. 8 | * E-Mail:yangchaojiang@outlook.com 9 | * Deprecated: 10 | */ 11 | 12 | public class UserBean implements Parcelable { 13 | 14 | private String test; 15 | 16 | public String getTest() { 17 | return test; 18 | } 19 | 20 | public void setTest(String test) { 21 | this.test = test; 22 | } 23 | 24 | @Override 25 | public int describeContents() { 26 | return 0; 27 | } 28 | 29 | @Override 30 | public void writeToParcel(Parcel dest, int flags) { 31 | dest.writeString(this.test); 32 | } 33 | 34 | public UserBean() { 35 | } 36 | 37 | protected UserBean(Parcel in) { 38 | this.test = in.readString(); 39 | } 40 | 41 | public static final Creator CREATOR = new Creator() { 42 | @Override 43 | public UserBean createFromParcel(Parcel source) { 44 | return new UserBean(source); 45 | } 46 | 47 | @Override 48 | public UserBean[] newArray(int size) { 49 | return new UserBean[size]; 50 | } 51 | }; 52 | } 53 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/java/data/fragment/TestFragmentActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.aac.java.data.fragment; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.view.View; 7 | 8 | import com.aac.module.ui.AacActivity; 9 | import com.example.aac.R; 10 | import com.example.aac.java.data.fragment.data.Test2FragmentActivity; 11 | import com.example.aac.java.data.fragment.list.TestDataFragmentActivity; 12 | 13 | /** 14 | * Created by yangc on 2017/8/27. 15 | * E-Mail:yangchaojiang@outlook.com 16 | * Deprecated: 17 | */ 18 | 19 | public class TestFragmentActivity extends AacActivity { 20 | public static final String TAG = "TestDataFragmentActivity"; 21 | @Override 22 | protected void onCreate(@Nullable Bundle savedInstanceState) { 23 | super.onCreate(savedInstanceState); 24 | findViewById(R.id.button5).setOnClickListener(new View.OnClickListener() { 25 | @Override 26 | public void onClick(View v) { 27 | Intent intent = new Intent(TestFragmentActivity.this, Test2FragmentActivity.class); 28 | startActivity(intent); 29 | 30 | } 31 | }); 32 | findViewById(R.id.button6).setOnClickListener(new View.OnClickListener() { 33 | @Override 34 | public void onClick(View v) { 35 | Intent intent = new Intent(TestFragmentActivity.this, TestDataFragmentActivity.class); 36 | startActivity(intent); 37 | 38 | } 39 | }); 40 | 41 | } 42 | 43 | @Override 44 | public int getContentLayoutId() { 45 | return R.layout.test_fragmen_view; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/java/data/fragment/data/Test2FragmentActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.aac.java.data.fragment.data; 2 | 3 | import com.aac.module.ui.AacActivity; 4 | import com.example.aac.R; 5 | 6 | /** 7 | * Created by yangc on 2017/8/15. 8 | * E-Mail:yangchaojiang@outlook.com 9 | * Deprecated: fragment 详细数据demo 10 | */ 11 | 12 | public class Test2FragmentActivity extends AacActivity { 13 | 14 | @Override 15 | public int getContentLayoutId() { 16 | return R.layout.test__fragment_view; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/java/data/fragment/data/TestDataFragment.java: -------------------------------------------------------------------------------- 1 | package com.example.aac.java.data.fragment.data; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.NonNull; 5 | import android.support.annotation.Nullable; 6 | import android.view.View; 7 | import android.widget.TextView; 8 | 9 | import com.aac.expansion.data.AacDataFragment; 10 | import com.aac.module.pres.RequiresPresenter; 11 | import com.example.aac.R; 12 | 13 | /** 14 | * Created by yangc on 2017/8/15. 15 | * E-Mail:yangchaojiang@outlook.com 16 | * Deprecated: fragment 详细数据demo 17 | */ 18 | @RequiresPresenter(TestDataFragmentPresenter.class) 19 | public class TestDataFragment extends AacDataFragment { 20 | 21 | private TextView textView2; 22 | 23 | @Override 24 | public int getContentLayoutId() { 25 | return R.layout.test_data_fragment_view; 26 | } 27 | @Override 28 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 29 | super.onViewCreated(view, savedInstanceState); 30 | textView2 = view.findViewById( R.id.textView); 31 | initLoadHelper(view.findViewById(R.id.textViewlayout)); 32 | } 33 | @Override 34 | public void setData(@NonNull String data) { 35 | textView2.setText(data); 36 | } 37 | @Override 38 | public void setError(Throwable e) { 39 | 40 | } 41 | 42 | @Override 43 | public void onDestroy() { 44 | super.onDestroy(); 45 | } 46 | 47 | @Override 48 | protected boolean setOpenLazyLoad() { 49 | return true; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/java/data/fragment/data/TestDataFragmentPresenter.java: -------------------------------------------------------------------------------- 1 | package com.example.aac.java.data.fragment.data; 2 | 3 | 4 | import android.util.Log; 5 | 6 | import com.aac.expansion.data.AacDataFPresenter; 7 | import com.example.aac.java.model.TestDataViewModel; 8 | 9 | /** 10 | * Created by yangc on 2017/8/15. 11 | * E-Mail:yangchaojiang@outlook.com 12 | * Deprecated: 13 | */ 14 | 15 | public class TestDataFragmentPresenter extends AacDataFPresenter { 16 | public static final String TAG = "TestFragmentPresenter"; 17 | private TestDataViewModel viewModel; 18 | 19 | @Override 20 | protected void onCreateView() { 21 | super.onCreateView(); 22 | viewModel=getViewModel(TestDataViewModel.class); 23 | Log.d(TAG,"onCreateView"); 24 | 25 | } 26 | 27 | @Override 28 | protected void lazyLoad() { 29 | Log.d(TAG,"lazyLoad"); 30 | viewModel.getData().observe(getView(),getDataSubscriber()); 31 | 32 | } 33 | 34 | @Override 35 | public void retryData() { 36 | lazyLoad(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/java/data/fragment/list/TestDataFragmentActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.aac.java.data.fragment.list; 2 | 3 | import com.aac.module.ui.AacActivity; 4 | import com.example.aac.R; 5 | 6 | /** 7 | * Created by yangc on 2017/8/15. 8 | * E-Mail:yangchaojiang@outlook.com 9 | * Deprecated: 10 | */ 11 | 12 | public class TestDataFragmentActivity extends AacActivity { 13 | 14 | 15 | @Override 16 | public int getContentLayoutId() { 17 | return R.layout.test_list_fragment_view; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/java/data/fragment/list/TestFragmentPresenter.java: -------------------------------------------------------------------------------- 1 | package com.example.aac.java.data.fragment.list; 2 | 3 | import com.aac.expansion.list.AacListFPresenter; 4 | import com.example.aac.java.model.TestDataViewModel; 5 | 6 | /** 7 | * Created by yangc on 2017/8/15. 8 | * E-Mail:yangchaojiang@outlook.com 9 | * Deprecated: 10 | */ 11 | 12 | public class TestFragmentPresenter extends AacListFPresenter { 13 | 14 | private TestDataViewModel viewModel; 15 | @Override 16 | protected void onCreateView() { 17 | super.onCreateView(); 18 | viewModel = getViewModel(TestDataViewModel.class); 19 | } 20 | /** 21 | * 是否可以加载数据 22 | * 可以加载数据的条件: 23 | */ 24 | @Override 25 | protected void lazyLoad() { 26 | viewModel.getListData(1).observe(getView(), getDataSubscriber()); 27 | } 28 | 29 | @Override 30 | public void setLoadData(int pager) { 31 | viewModel.getListData(pager).observe(getView(), getDataSubscriber()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/java/data/fragment/list/TestListFragment.java: -------------------------------------------------------------------------------- 1 | package com.example.aac.java.data.fragment.list; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.view.View; 6 | import com.aac.expansion.list.AacListFragment; 7 | import com.aac.module.pres.RequiresPresenter; 8 | import com.chad.library.adapter.base.BaseViewHolder; 9 | 10 | /** 11 | * Created by yangc on 2017/8/15. 12 | * E-Mail:yangchaojiang@outlook.com 13 | * Deprecated: 14 | */ 15 | @RequiresPresenter(TestFragmentPresenter.class) 16 | public class TestListFragment extends AacListFragment { 17 | 18 | /*** 19 | * 等于1 list 大于1 GridS 20 | * **/ 21 | @Override 22 | public int setGridSpanCount() { 23 | return 3; 24 | } 25 | @Override 26 | public int getItemLayout() { 27 | return android.R.layout.simple_list_item_2; 28 | } 29 | @Override 30 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 31 | super.onViewCreated(view, savedInstanceState); 32 | setStartLoadMore(true); 33 | setRefreshing(true); 34 | } 35 | 36 | @Override 37 | public void convertViewHolder(BaseViewHolder helper, String item) { 38 | helper.setText(android.R.id.text1, item); 39 | helper.setText(android.R.id.text2, item); 40 | } 41 | @Override 42 | protected boolean setOpenLazyLoad() { 43 | return false; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/java/data/multi/adapter/TestAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.example.aac.java.data.multi.adapter 2 | 3 | import com.chad.library.adapter.base.BaseMultiItemQuickAdapter 4 | import com.chad.library.adapter.base.BaseViewHolder 5 | import com.example.aac.java.data.multi.bean.Multi 6 | 7 | import java.util.ArrayList 8 | 9 | /** 10 | * Same as QuickAdapter#QuickAdapter(Context,int) but with 11 | * some initialization data. 12 | * 13 | * @param data A new list is created out of this one to avoid mutable list 14 | */ 15 | class TestAdapter : BaseMultiItemQuickAdapter(ArrayList()) { 16 | 17 | init { 18 | //addItemType(); 19 | } 20 | override fun convert(helper: BaseViewHolder, item: Multi) { 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/java/data/multi/bean/Multi.java: -------------------------------------------------------------------------------- 1 | package com.example.aac.java.data.multi.bean; 2 | 3 | 4 | import android.os.Parcel; 5 | import android.os.Parcelable; 6 | 7 | import com.chad.library.adapter.base.entity.MultiItemEntity; 8 | 9 | /** 10 | * Created by yangc on 2018/10/15 11:08:53 11 | * E-Mail:yangchaojiang@outlook.com 12 | * Deprecated: 13 | **/ 14 | public class Multi implements Parcelable,MultiItemEntity { 15 | 16 | 17 | protected Multi(Parcel in) { 18 | } 19 | 20 | @Override 21 | public void writeToParcel(Parcel dest, int flags) { 22 | } 23 | @Override 24 | public int describeContents() { 25 | return 0; 26 | } 27 | 28 | public static final Creator CREATOR = new Creator() { 29 | @Override 30 | public Multi createFromParcel(Parcel in) { 31 | return new Multi(in); 32 | } 33 | 34 | @Override 35 | public Multi[] newArray(int size) { 36 | return new Multi[size]; 37 | } 38 | }; 39 | 40 | @Override 41 | public int getItemType() { 42 | return 0; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/java/data/multi/model/MultiViewModel.java: -------------------------------------------------------------------------------- 1 | package com.example.aac.java.data.multi.model; 2 | 3 | import com.aac.module.model.AacViewModel; 4 | /** 5 | * Created by yangc on 2018/10/15 11:08:53 6 | * E-Mail:yangchaojiang@outlook.com 7 | * Deprecated: 8 | **/ 9 | public class MultiViewModel extends AacViewModel { 10 | @Override 11 | protected void onCleared() { 12 | super.onCleared(); 13 | } 14 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/java/data/multi/presenter/MultiPresenter.java: -------------------------------------------------------------------------------- 1 | package com.example.aac.java.data.multi.presenter; 2 | 3 | import com.aac.expansion.list.AacListAPresenter; 4 | import com.aac.expansion.list.AacMultiListAPresenter; 5 | import com.example.aac.java.data.multi.model.MultiViewModel; 6 | import com.example.aac.java.data.multi.ui.MultiActivity; 7 | import com.example.aac.java.data.multi.bean.Multi; 8 | 9 | /** 10 | * Created by yangc on 2018/10/15 11:08:53 11 | * E-Mail:yangchaojiang@outlook.com 12 | * Deprecated: 13 | **/ 14 | public class MultiPresenter extends AacMultiListAPresenter { 15 | public static final String TAG = MultiPresenter.class.getName(); 16 | private MultiViewModel mMulti; 17 | @Override 18 | public void onCreate() { 19 | super.onCreate(); 20 | mMulti = getViewModel(MultiViewModel.class); 21 | } 22 | 23 | @Override 24 | public void setLoadData(int pager) { 25 | // mMulti.getListData(getView(),"id").observe(getView(),getDataSubscriber()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/java/data/multi/ui/MultiActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.aac.java.data.multi.ui; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import com.aac.expansion.list.AacListActivity; 7 | import android.os.Bundle; 8 | import android.support.annotation.NonNull; 9 | import android.support.annotation.Nullable; 10 | 11 | import com.aac.expansion.list.AacMultiListActivity; 12 | import com.chad.library.adapter.base.BaseMultiItemQuickAdapter; 13 | import com.chad.library.adapter.base.BaseQuickAdapter; 14 | import com.chad.library.adapter.base.BaseViewHolder; 15 | import com.aac.module.pres.RequiresPresenter; 16 | import com.example.aac.R; 17 | import com.example.aac.java.data.multi.adapter.TestAdapter; 18 | import com.example.aac.java.data.multi.presenter.MultiPresenter; 19 | import com.example.aac.java.data.multi.bean.Multi; 20 | 21 | /** 22 | * Created by yangc on 2018/10/15 11:08:53 23 | * E-Mail:yangchaojiang@outlook.com 24 | * Deprecated: 25 | **/ 26 | @RequiresPresenter(MultiPresenter.class) 27 | public class MultiActivity extends AacMultiListActivity { 28 | private TestAdapter mTestAdapter; 29 | 30 | public static void startActivity(Activity activity) { 31 | Intent intent = new Intent(activity,MultiActivity.class); 32 | activity.startActivity(intent); 33 | } 34 | @Override 35 | protected void onCreate(@Nullable Bundle savedInstanceState) { 36 | super.onCreate(savedInstanceState); 37 | setLoadMore(true); 38 | } 39 | 40 | 41 | @Override 42 | public int setGridSpanCount() { 43 | return 3; 44 | } 45 | 46 | @NonNull 47 | @Override 48 | public TestAdapter getMultiAdapter() { 49 | return mTestAdapter; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/java/data/test/adapter/TestAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.example.aac.java.data.test.adapter 2 | import com.chad.library.adapter.base.BaseMultiItemQuickAdapter 3 | import com.chad.library.adapter.base.BaseViewHolder 4 | import com.example.aac.java.data.test.bean.Test 5 | 6 | import java.util.ArrayList 7 | 8 | /** 9 | * Same as QuickAdapter#QuickAdapter(Context,int) but with 10 | * some initialization data. 11 | * 12 | */ 13 | class TestAdapter : BaseMultiItemQuickAdapter(ArrayList()) { 14 | 15 | init { 16 | //addItemType(); 17 | } 18 | 19 | override fun convert(helper: BaseViewHolder, item: Test) { 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/java/data/test/bean/Test.kt: -------------------------------------------------------------------------------- 1 | package com.example.aac.java.data.test.bean 2 | import java.io.Serializable 3 | import com.chad.library.adapter.base.entity.MultiItemEntity; 4 | /** 5 | * Created by yangc on 2018/10/15 18:14:55 6 | * E-Mail:yangchaojiang@outlook.com 7 | * Deprecated: 8 | **/ 9 | class Test :Serializable,MultiItemEntity { 10 | var test:String?=null 11 | 12 | 13 | override fun getItemType(): Int = 0 14 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/java/data/test/model/TestViewModel.kt: -------------------------------------------------------------------------------- 1 | package com.example.aac.java.data.test.model 2 | import com.aac.module.model.AacViewModel 3 | 4 | /** 5 | * Created by yangc on 2018/10/15 18:14:55 6 | * E-Mail:yangchaojiang@outlook.com 7 | * Deprecated: 8 | **/ 9 | class TestViewModel : AacViewModel() { 10 | override fun onCleared() { 11 | super.onCleared() 12 | } 13 | 14 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/java/data/test/presenter/TestPresenter.kt: -------------------------------------------------------------------------------- 1 | package com.example.aac.java.data.test.presenter 2 | 3 | import com.aac.expansion.list.AacMultiListAPresenter 4 | 5 | import com.example.aac.java.data.test.model.TestViewModel 6 | import com.example.aac.java.data.test.ui.TestActivity 7 | import com.example.aac.java.data.test.bean.Test; 8 | 9 | 10 | /** 11 | * Created by yangc on 2018/10/15 18:14:55 12 | * E-Mail:yangchaojiang@outlook.com 13 | * Deprecated: 14 | **/ 15 | class TestPresenter : AacMultiListAPresenter (){ 16 | private lateinit var mTest: TestViewModel 17 | public override fun onCreate() { 18 | super.onCreate() 19 | mTest = getViewModel(TestViewModel::class.java) 20 | } 21 | 22 | fun lazyLoad() { 23 | } 24 | companion object { 25 | val TAG = TestPresenter::class.java.name 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/java/data/test/ui/TestActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.aac.java.data.test.ui 2 | import android.app.Activity 3 | import android.content.Intent 4 | import android.os.Bundle 5 | import com.aac.expansion.list.AacMultiListActivity 6 | 7 | import com.chad.library.adapter.base.BaseViewHolder 8 | import com.aac.module.pres.RequiresPresenter 9 | import com.chad.library.adapter.base.BaseMultiItemQuickAdapter 10 | import com.example.aac.R 11 | import com.example.aac.java.data.test.presenter.TestPresenter 12 | import com.example.aac.java.data.test.bean.Test 13 | import com.example.aac.java.data.test.adapter.TestAdapter 14 | 15 | /** 16 | * Created by yangc on 2018/10/15 18:14:55 17 | * E-Mail:yangchaojiang@outlook.com 18 | * Deprecated: 19 | **/ 20 | @RequiresPresenter(TestPresenter::class) 21 | class TestActivity : AacMultiListActivity() { 22 | 23 | private val mTestAdapter : TestAdapter = TestAdapter() 24 | 25 | override fun getMultiAdapter(): BaseMultiItemQuickAdapter = mTestAdapter 26 | 27 | override fun onCreate(savedInstanceState: Bundle?) { 28 | super.onCreate(savedInstanceState) 29 | // setLoadMore(true) 30 | } 31 | 32 | companion object { 33 | fun startActivity(activity: Activity) { 34 | val intent = Intent(activity, TestActivity::class.java) 35 | activity.startActivity(intent) 36 | } 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/java/data/test4/adapter/Test4Adapter.kt: -------------------------------------------------------------------------------- 1 | package com.example.aac.java.data.test4.adapter 2 | import com.chad.library.adapter.base.BaseMultiItemQuickAdapter 3 | import com.chad.library.adapter.base.BaseViewHolder 4 | import com.example.aac.java.data.test4.bean.Test4 5 | 6 | import java.util.ArrayList 7 | 8 | /** 9 | * Same as QuickAdapter#QuickAdapter(Context,int) but with 10 | * some initialization data. 11 | * 12 | */ 13 | class Test4Adapter : BaseMultiItemQuickAdapter(ArrayList()) { 14 | 15 | init { 16 | //addItemType(); 17 | } 18 | 19 | override fun convert(helper: BaseViewHolder, item: Test4) { 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/java/data/test4/bean/Test4.kt: -------------------------------------------------------------------------------- 1 | package com.example.aac.java.data.test4.bean 2 | import java.io.Serializable 3 | import com.chad.library.adapter.base.entity.MultiItemEntity; 4 | /** 5 | * Created by yangc on 2018/10/15 18:15:15 6 | * E-Mail:yangchaojiang@outlook.com 7 | * Deprecated: 8 | **/ 9 | class Test4 :Serializable,MultiItemEntity { 10 | var test:String?=null 11 | 12 | 13 | override fun getItemType(): Int = 0 14 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/java/data/test4/model/Test4ViewModel.kt: -------------------------------------------------------------------------------- 1 | package com.example.aac.java.data.test4.model 2 | import com.aac.module.model.AacViewModel 3 | 4 | /** 5 | * Created by yangc on 2018/10/15 18:15:15 6 | * E-Mail:yangchaojiang@outlook.com 7 | * Deprecated: 8 | **/ 9 | class Test4ViewModel : AacViewModel() { 10 | override fun onCleared() { 11 | super.onCleared() 12 | } 13 | 14 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/java/data/test4/presenter/Test4Presenter.kt: -------------------------------------------------------------------------------- 1 | package com.example.aac.java.data.test4.presenter 2 | 3 | import com.aac.expansion.list.AacMultiListFPresenter 4 | import com.example.aac.java.data.test4.model.Test4ViewModel 5 | import com.example.aac.java.data.test4.ui.Test4Fragment 6 | import com.example.aac.java.data.test4.bean.Test4; 7 | 8 | 9 | /** 10 | * Created by yangc on 2018/10/15 18:15:15 11 | * E-Mail:yangchaojiang@outlook.com 12 | * Deprecated: 13 | **/ 14 | class Test4Presenter : AacMultiListFPresenter (){ 15 | private lateinit var mTest4: Test4ViewModel 16 | public override fun onCreate() { 17 | super.onCreate() 18 | mTest4 = getViewModel(Test4ViewModel::class.java) 19 | } 20 | 21 | override fun lazyLoad() { 22 | } 23 | companion object { 24 | val TAG = Test4Presenter::class.java.name 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/java/data/test4/ui/Test4Fragment.kt: -------------------------------------------------------------------------------- 1 | package com.example.aac.java.data.test4.ui 2 | import android.os.Bundle 3 | import android.view.View 4 | import com.aac.expansion.list.AacMultiListFragment 5 | import com.chad.library.adapter.base.BaseViewHolder 6 | import com.aac.module.pres.RequiresPresenter 7 | import com.chad.library.adapter.base.BaseMultiItemQuickAdapter 8 | import com.example.aac.R 9 | import com.example.aac.java.data.test4.presenter.Test4Presenter 10 | import com.example.aac.java.data.test4.bean.Test4 11 | import com.example.aac.java.data.test4.adapter.Test4Adapter 12 | 13 | /** 14 | * Created by yangc on 2018/10/15 18:15:14 15 | * E-Mail:yangchaojiang@outlook.com 16 | * Deprecated: 17 | **/ 18 | @RequiresPresenter(Test4Presenter::class) 19 | class Test4Fragment : AacMultiListFragment() { 20 | 21 | private val mTest4Adapter : Test4Adapter = Test4Adapter() 22 | 23 | override fun getMultiAdapter(): BaseMultiItemQuickAdapter = mTest4Adapter 24 | 25 | override fun setOpenLazyLoad(): Boolean = true 26 | 27 | override fun setGridSpanCount(): Int = 1 28 | 29 | override fun onViewCreated(view: View?, savedInstanceState: Bundle?) { 30 | super.onViewCreated(view, savedInstanceState) 31 | //setStartLoadMore(true); 32 | } 33 | 34 | companion object { 35 | fun getInstance(param: String): Test4Fragment { 36 | val fragment = Test4Fragment() 37 | val bundle = Bundle() 38 | bundle.putString("param", param) 39 | fragment.arguments = bundle 40 | return fragment 41 | } 42 | } 43 | 44 | } 45 | 46 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/java/model/TestDataViewModel.java: -------------------------------------------------------------------------------- 1 | package com.example.aac.java.model; 2 | 3 | import android.app.Application; 4 | import android.arch.lifecycle.AndroidViewModel; 5 | import android.arch.lifecycle.LiveData; 6 | import android.arch.lifecycle.MutableLiveData; 7 | import android.content.Context; 8 | import android.os.SystemClock; 9 | import android.util.Log; 10 | 11 | 12 | import com.alibaba.fastjson.TypeReference; 13 | import com.example.aac.java.data.activity.bean.UserBean; 14 | import com.example.aac.utils.JsonCallback; 15 | import com.lzy.okgo.OkGo; 16 | import com.lzy.okgo.callback.StringCallback; 17 | import com.lzy.okgo.model.Response; 18 | 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | /** 23 | * Created by yangc on 2017/8/14. 24 | * E-Mail:yangchaojiang@outlook.com 25 | * Deprecated: 26 | */ 27 | 28 | public class TestDataViewModel extends AndroidViewModel { 29 | private MutableLiveData data = new MutableLiveData<>(); 30 | private MutableLiveData> listData = new MutableLiveData<>(); 31 | private MutableLiveData liveData = new MutableLiveData<>(); 32 | public TestDataViewModel(Application application) { 33 | super(application); 34 | Log.d("TestDataViewModel", "TestDataViewModel"); 35 | 36 | } 37 | 38 | public LiveData getData() { 39 | Log.d("TestDataViewModel", data.getValue() + ""); 40 | Thread s = new Thread(new Runnable() { 41 | @Override 42 | public void run() { 43 | SystemClock.sleep(1000); 44 | data.postValue(null); 45 | //data.postValue("获取数据"); 46 | } 47 | }); 48 | s.start(); 49 | return data; 50 | } 51 | 52 | 53 | @Override 54 | protected void onCleared() { 55 | super.onCleared(); 56 | Log.d("TestDataViewModel", "onCleared"); 57 | } 58 | 59 | public LiveData> getListData(final int page) { 60 | Thread s = new Thread(new Runnable() { 61 | @Override 62 | public void run() { 63 | SystemClock.sleep(2000); 64 | int s = (page - 1) * 40; 65 | List list = new ArrayList<>(); 66 | for (int i = s; i < 40 * page; i++) { 67 | list.add("数据:" + i); 68 | } 69 | listData.postValue(list); 70 | } 71 | }); 72 | s.start(); 73 | return listData; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/utils/JsonCallback.java: -------------------------------------------------------------------------------- 1 | package com.example.aac.utils; 2 | 3 | 4 | import com.alibaba.fastjson.JSONObject; 5 | import com.alibaba.fastjson.TypeReference; 6 | import com.lzy.okgo.callback.AbsCallback; 7 | import com.lzy.okgo.request.base.Request; 8 | import com.yutils.JsonManager; 9 | 10 | import java.lang.reflect.Type; 11 | 12 | import okhttp3.Response; 13 | import okhttp3.ResponseBody; 14 | 15 | /** 16 | * Created by yangc on 2017/10/7. 17 | * E-Mail:yangchaojiang@outlook.com 18 | * Deprecated: 19 | */ 20 | 21 | public abstract class JsonCallback extends AbsCallback { 22 | private Type type; 23 | private Class clazz; 24 | private String key; 25 | 26 | public JsonCallback(String key, Class clazz) { 27 | this.clazz = clazz; 28 | this.key = key; 29 | } 30 | public JsonCallback(String key, Type type) { 31 | this.type = type; 32 | this.key = key; 33 | } 34 | private JsonCallback(){ 35 | 36 | } 37 | /** 38 | * 该方法是子线程处理,不能做ui相关的工作 39 | * 主要作用是解析网络返回的 response 对象,生产onSuccess回调中需要的数据对象 40 | * 这里的解析工作不同的业务逻辑基本都不一样,所以需要自己实现,以下给出的时模板代码,实际使用根据需要修改 41 | */ 42 | @Override 43 | public T convertResponse(Response response) throws Throwable { 44 | // 重要的事情说三遍,不同的业务,这里的代码逻辑都不一样,如果你不修改,那么基本不可用 45 | // 重要的事情说三遍,不同的业务,这里的代码逻辑都不一样,如果你不修改,那么基本不可用 46 | // 重要的事情说三遍,不同的业务,这里的代码逻辑都不一样,如果你不修改,那么基本不可用 47 | //详细自定义的原理和文档,看这里: https://github.com/jeasonlzy/okhttp-OkGo/wiki/JsonCallback 48 | ResponseBody body = response.body(); 49 | if (body == null) { 50 | return null; 51 | } 52 | JSONObject s = JsonManager.parseJsonObject(body.string()); 53 | if (s.getBoolean("success")) { 54 | if (clazz!=null){ 55 | return JsonManager.jsonToBean(s.get(key).toString(),clazz); 56 | }else if (type!=null){ 57 | return JsonManager.jsonToBean(s.get(key).toString(),type); 58 | }else { 59 | return JsonManager.jsonToBean(body.bytes()); 60 | } 61 | } else { 62 | throw new IllegalStateException(response.message()); 63 | } 64 | } 65 | 66 | 67 | } 68 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/utils/JsonCallbcakKotlin.kt: -------------------------------------------------------------------------------- 1 | package com.keba.utils 2 | 3 | 4 | import android.support.annotation.AnyThread 5 | import android.support.annotation.NonNull 6 | import com.alibaba.fastjson.JSONObject 7 | import com.lzy.okgo.callback.AbsCallback 8 | import com.yutils.JsonManager 9 | import java.lang.reflect.Type 10 | import okhttp3.Response 11 | 12 | /** 13 | * Created by yangc on 2017/10/7. 14 | * E-Mail:yangchaojiang@outlook.com 15 | * Deprecated: 16 | */ 17 | 18 | abstract class JsonCallbcakKotlin : AbsCallback { 19 | private var type: Type? = null 20 | private var clazz: Class? = null 21 | private var key: String? = null 22 | 23 | constructor(@NonNull key: String, clazz: Class) { 24 | this.clazz = clazz 25 | this.key = key 26 | } 27 | 28 | constructor(@NonNull key: String, type: Type) { 29 | this.type = type 30 | this.key = key 31 | } 32 | 33 | override fun onStart(request: com.lzy.okgo.request.base.Request>?) { 34 | super.onStart(request) 35 | } 36 | 37 | /** 38 | * 该方法是子线程处理,不能做ui相关的工作 39 | * 主要作用是解析网络返回的 response 对象,生产onSuccess回调中需要的数据对象 40 | * 这里的解析工作不同的业务逻辑基本都不一样,所以需要自己实现,以下给出的时模板代码,实际使用根据需要修改 41 | */ 42 | @Throws(Throwable::class) 43 | override fun convertResponse(response: Response): T? { 44 | // 重要的事情说三遍,不同的业务,这里的代码逻辑都不一样,如果你不修改,那么基本不可用 45 | // 重要的事情说三遍,不同的业务,这里的代码逻辑都不一样,如果你不修改,那么基本不可用 46 | // 重要的事情说三遍,不同的业务,这里的代码逻辑都不一样,如果你不修改,那么基本不可用 47 | //详细自定义的原理和文档,看这里: https://github.com/jeasonlzy/okhttp-OkGo/wiki/JsonCallback 48 | val body = response.body() ?: return null 49 | val s = JsonManager.parseJsonObject(body.string()) 50 | return if (s.getBoolean("success")!!) { 51 | when { 52 | clazz != null -> JsonManager.jsonToBean(s[key].toString(), clazz!!) 53 | type != null -> JsonManager.jsonToBean(s[key].toString(), type!!) 54 | else -> JsonManager.jsonToBean(body.bytes()) 55 | } 56 | } else { 57 | throw IllegalStateException(response.message()) 58 | } 59 | } 60 | 61 | companion object { 62 | /***** 63 | * @param response 請求對象 64 | * @param type 返回实例对象类型 65 | * @param key 需要处理对象key 66 | * @return T 67 | * set TypeReference typeReference = new TypeReference() {}; 68 | */ 69 | @AnyThread 70 | @Throws(Exception::class) 71 | fun getBean(response: Response, type: Type, key: String): T? { 72 | val body = response.body() ?: return null 73 | val s = JsonManager.parseJsonObject(body.string()) 74 | return if (s.getBoolean("success")!!) { 75 | JsonManager.jsonToBean(s?.get(key).toString(), type) 76 | } else if (!s.getBoolean("success")!!) { 77 | JsonManager.jsonToBean(body.bytes()) 78 | } else { 79 | throw IllegalStateException(response.message()) 80 | } 81 | } 82 | 83 | /***** 84 | * @param response 請求對象 85 | * @param clazz 返回实例对象类型 86 | * @param key 需要处理对象key 87 | * @return T 88 | */ 89 | @AnyThread 90 | @Throws(Exception::class) 91 | fun getBean(response: Response, clazz: Class, key: String): T? { 92 | val body = response.body() ?: return null 93 | val s = JsonManager.parseJsonObject(body.string()) 94 | return if (s.getBoolean("success")!!) { 95 | JsonManager.jsonToBean(s?.get(key).toString(), clazz) 96 | } else if (!s.getBoolean("success")!!) { 97 | JsonManager.jsonToBean(body.bytes()) 98 | } else { 99 | throw IllegalStateException(response.message()) 100 | } 101 | } 102 | 103 | /***** 104 | * @param response 請求對象 105 | * @param clazz 返回实例对象类型 106 | * @param key 需要处理对象key 107 | * @return T 108 | */ 109 | @AnyThread 110 | @Throws(Exception::class) 111 | fun getBean(response: Response): JSONObject? { 112 | val body = response.body() ?: return null 113 | return JsonManager.parseJsonObject(body.string()) 114 | 115 | } 116 | 117 | /***** 118 | * @param response 請求對象 119 | * @param clazz 返回实例对象类型 120 | * @param key 需要处理对象key 121 | * @return T 122 | */ 123 | @AnyThread 124 | @Throws(Exception::class) 125 | fun getListBean(response: Response, clazz: Class, key: String): List? { 126 | val body = response.body() ?: return null 127 | val s = JsonManager.parseJsonObject(body.string()) 128 | if (s.getBoolean("success")!!) { 129 | return JsonManager.jsonToList(s?.get(key).toString(), clazz) 130 | } else { 131 | throw IllegalStateException(response.message()) 132 | } 133 | } 134 | } 135 | 136 | } 137 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/utils/rwar/model/RwarViewModel.java: -------------------------------------------------------------------------------- 1 | package com.example.aac.utils.rwar.model; 2 | 3 | import com.aac.module.model.AacViewModel; 4 | /** 5 | * Created by yangc on 2018/11/27 17:29:05 6 | * E-Mail:yangchaojiang@outlook.com 7 | * Deprecated: 8 | **/ 9 | public class RwarViewModel extends AacViewModel { 10 | @Override 11 | protected void onCleared() { 12 | super.onCleared(); 13 | } 14 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/utils/rwar/presenter/RwarPresenter.java: -------------------------------------------------------------------------------- 1 | package com.example.aac.utils.rwar.presenter; 2 | 3 | 4 | import com.aac.module.ui.AacPresenter; 5 | import com.example.aac.utils.rwar.model.RwarViewModel; 6 | import com.example.aac.utils.rwar.ui.RwarActivity; 7 | 8 | /** 9 | * Created by yangc on 2018/11/27 17:29:04 10 | * E-Mail:yangchaojiang@outlook.com 11 | * Deprecated: 12 | **/public class RwarPresenter extends AacPresenter { 13 | 14 | public static final String TAG = RwarPresenter.class.getName(); 15 | private RwarViewModel mRwar; 16 | @Override 17 | public void onCreate() { 18 | super.onCreate(); 19 | mRwar = getViewModel(RwarViewModel.class); 20 | } 21 | 22 | 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/aac/utils/rwar/ui/RwarActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.aac.utils.rwar.ui; 2 | 3 | 4 | import android.app.Activity; 5 | import android.content.Intent; 6 | import android.os.Bundle; 7 | import android.support.annotation.Nullable; 8 | import com.aac.module.ui.AacActivity; 9 | import com.aac.module.pres.RequiresPresenter; 10 | import com.example.aac.R; 11 | import com.example.aac.utils.rwar.presenter.RwarPresenter; 12 | 13 | 14 | 15 | /** 16 | * Created by yangc on 2018/11/27 17:29:04 17 | * E-Mail:yangchaojiang@outlook.com 18 | * Deprecated: 19 | **/ 20 | @RequiresPresenter(RwarPresenter.class) 21 | public class RwarActivity extends AacActivity { 22 | 23 | public static void startActivity(Activity activity) { 24 | Intent intent = new Intent(activity,RwarActivity.class); 25 | activity.startActivity(intent); 26 | } 27 | @Override 28 | public int getContentLayoutId() { return R.layout.activity_rwar; } 29 | 30 | @Override 31 | protected void onCreate(@Nullable Bundle savedInstanceState) { 32 | super.onCreate(savedInstanceState); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_coroutines.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 |