diff --git a/app/build.gradle b/app/build.gradle index c011dd2..2bfe04c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,7 +1,6 @@ import com.zwh.plugin.AspectjPlugin apply plugin: 'com.android.application' -apply plugin: 'me.tatarka.retrolambda' apply from: 'tinkerpatch.gradle' apply from: 'tinkerpatch.gradle' @@ -28,6 +27,7 @@ android { targetSdkVersion rootProject.ext.android["targetSdkVersion"] versionCode rootProject.ext.android["versionCode"] versionName rootProject.ext.android["versionName"] + flavorDimensions "versionCode" testInstrumentationRunner rootProject.ext.dependencies["androidJUnitRunner"] vectorDrawables.useSupportLibrary = true manifestPlaceholders = [BUGLY_APP_CHANNEL_VALUE:"other"] @@ -45,6 +45,7 @@ android { buildConfigField "boolean", "LOG_DEBUG", "true" buildConfigField "boolean", "USE_CANARY", "true" minifyEnabled false + multiDexEnabled true multiDexKeepProguard file('multiDexKeep.pro') proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' ndk { @@ -62,6 +63,7 @@ android { shrinkResources true zipAlignEnabled true signingConfig signingConfigs.release + multiDexEnabled true multiDexKeepProguard file('multiDexKeep.pro') proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' ndk { @@ -71,19 +73,31 @@ android { } } productFlavors { - baidu {manifestPlaceholders = [BUGLY_APP_CHANNEL_VALUE:"baidu"]} - fir {manifestPlaceholders = [BUGLY_APP_CHANNEL_VALUE:"fir"]} - xiaomi {manifestPlaceholders = [BUGLY_APP_CHANNEL_VALUE:"xiaomi"]} + baidu { + + manifestPlaceholders = [BUGLY_APP_CHANNEL_VALUE:"baidu"] + + } + fir { + + manifestPlaceholders = [BUGLY_APP_CHANNEL_VALUE:"fir"] + + } + xiaomi { + + manifestPlaceholders = [BUGLY_APP_CHANNEL_VALUE:"xiaomi"] + + } } applicationVariants.all { variant -> - variant.outputs.each { output -> + variant.outputs.all { output -> def outputFile = output.outputFile if (variant.buildType.name.equals('release')) { //生成apk名字的格式:Channel1.0.0_2016-06-22_baidu.apk //可自定义自己想要生成的格式 def fileName = "Channel${defaultConfig.versionName}_${releaseTime()}_${variant.productFlavors[0].name}.apk" - output.outputFile = new File(outputFile.parent, fileName) + outputFileName = new File(outputFile.parent, fileName) } } } @@ -118,9 +132,9 @@ def releaseTime() { dependencies { - compile fileTree(include: ['*.jar'], dir: 'libs') + implementation fileTree(include: ['*.jar'], dir: 'libs') //support - compile(rootProject.ext.dependencies["cardview-v7"]) { + implementation(rootProject.ext.dependencies["cardview-v7"]) { exclude module: 'support-annotations' } //tools @@ -129,46 +143,45 @@ dependencies { //view annotationProcessor(rootProject.ext.dependencies["butterknife-compiler"]) { exclude module: 'support-annotations' - exclude module: 'butterknife-annotations' } - compile rootProject.ext.dependencies["paginate"] + implementation rootProject.ext.dependencies["paginate"] //arms - compile project(':arms') + implementation project(':arms') // compile 'me.jessyan:arms:2.1.5' - compile rootProject.ext.dependencies["multidex"] - testCompile rootProject.ext.dependencies["junit"] - testCompile rootProject.ext.dependencies["mockito-core"] - testCompile rootProject.ext.dependencies["robolectric"] - testCompile rootProject.ext.dependencies["DaggerMock"] - androidTestCompile rootProject.ext.dependencies["robolectric"] - debugCompile rootProject.ext.dependencies["canary-debug"] - releaseCompile rootProject.ext.dependencies["canary-release"] - testCompile rootProject.ext.dependencies["canary-release"] + implementation rootProject.ext.dependencies["multidex"] + testImplementation rootProject.ext.dependencies["junit"] + testImplementation rootProject.ext.dependencies["mockito-core"] + testImplementation rootProject.ext.dependencies["robolectric"] + testImplementation rootProject.ext.dependencies["DaggerMock"] + androidTestImplementation rootProject.ext.dependencies["robolectric"] + debugImplementation rootProject.ext.dependencies["canary-debug"] + releaseImplementation rootProject.ext.dependencies["canary-release"] + testImplementation rootProject.ext.dependencies["canary-release"] annotationProcessor project(':apt') - compile project(':apt-lib') - compile rootProject.ext.dependencies["constraint-layout"] - compile rootProject.ext.dependencies["aspectjrt"] - compile rootProject.ext.dependencies["appbarspring"] - compile rootProject.ext.dependencies["BaseRecyclerViewAdapterHelper"] - compile rootProject.ext.dependencies["gsyVideoPlayer-java"] - compile rootProject.ext.dependencies["gsyVideoPlayer-armv7a"] - compile rootProject.ext.dependencies["gsyVideoPlayer-x86"] - compile rootProject.ext.dependencies["gsyVideoPlayer-arm64"] - compile(rootProject.ext.dependencies["bmob-sdk"]) { + implementation project(':apt-lib') + implementation rootProject.ext.dependencies["constraint-layout"] + implementation rootProject.ext.dependencies["aspectjrt"] + implementation rootProject.ext.dependencies["appbarspring"] + implementation rootProject.ext.dependencies["BaseRecyclerViewAdapterHelper"] + implementation rootProject.ext.dependencies["gsyVideoPlayer-java"] + implementation rootProject.ext.dependencies["gsyVideoPlayer-armv7a"] + implementation rootProject.ext.dependencies["gsyVideoPlayer-x86"] + implementation rootProject.ext.dependencies["gsyVideoPlayer-arm64"] + implementation(rootProject.ext.dependencies["bmob-sdk"]) { exclude group: 'com.squareup.okhttp3' exclude module: 'com.squareup.okio' } - compile rootProject.ext.dependencies["http-legacy"] - compile rootProject.ext.dependencies["bmob-sms"] - compile rootProject.ext.dependencies["ucrop"] - compile rootProject.ext.dependencies["greendao"] - compile rootProject.ext.dependencies["materialprogressbar"] - compile rootProject.ext.dependencies["filedownloader"] - compile rootProject.ext.dependencies["crashreport_upgrade"] + implementation rootProject.ext.dependencies["http-legacy"] + implementation rootProject.ext.dependencies["bmob-sms"] + implementation rootProject.ext.dependencies["ucrop"] + implementation rootProject.ext.dependencies["greendao"] + implementation rootProject.ext.dependencies["materialprogressbar"] + implementation rootProject.ext.dependencies["filedownloader"] + implementation rootProject.ext.dependencies["crashreport_upgrade"] // compile rootProject.ext.dependencies["tinkerpatch-android-sdk"] // provided rootProject.ext.dependencies["tinker-android-anno"] - compile(name: 'matisse_ucrop_1.0.0', ext: 'aar') - compile(name: 'progress-release', ext: 'aar') + implementation(name: 'matisse_ucrop_1.0.0', ext: 'aar') + implementation(name: 'progress-release', ext: 'aar') } apply plugin: AspectjPlugin diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/app/utils/RxUtils.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/app/utils/RxUtils.java index c11b19e..2a6745c 100644 --- a/app/src/main/java/com/zwh/mvparms/eyepetizer/app/utils/RxUtils.java +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/app/utils/RxUtils.java @@ -1,7 +1,7 @@ package com.zwh.mvparms.eyepetizer.app.utils; import com.jess.arms.mvp.IView; -import com.trello.rxlifecycle2.LifecycleProvider; +import com.jess.arms.utils.RxLifecycleUtils; import com.trello.rxlifecycle2.LifecycleTransformer; import io.reactivex.Observable; @@ -44,7 +44,7 @@ public void accept(@NonNull Disposable disposable) throws Exception { public void run() { view.hideLoading();//隐藏进度条 } - }).compose(RxUtils.bindToLifecycle(view)); + }).compose(RxLifecycleUtils.bindToLifecycle(view)); } }; } @@ -60,7 +60,7 @@ public void run() { view.hideLoading();//隐藏进度条 } }) - .compose(RxUtils.bindToLifecycle(view)); + .compose(RxLifecycleUtils.bindToLifecycle(view)); } }; } @@ -76,11 +76,7 @@ public Observable apply(Observable observable) { public static LifecycleTransformer bindToLifecycle(IView view) { - if (view instanceof LifecycleProvider){ - return ((LifecycleProvider)view).bindToLifecycle(); - }else { - throw new IllegalArgumentException("view isn't activity or fragment"); - } + return RxLifecycleUtils.bindToLifecycle(view); } diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/app/utils/UUIDS.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/app/utils/UUIDS.java new file mode 100644 index 0000000..586a51d --- /dev/null +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/app/utils/UUIDS.java @@ -0,0 +1,163 @@ +package com.zwh.mvparms.eyepetizer.app.utils; + +import android.content.Context; +import android.content.SharedPreferences; +import android.os.Environment; +import android.util.Log; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; + +/** + * Created by Administrator on 2017\12\15 0015. + * 设备唯一表示ID + */ + +public class UUIDS { + + private static final String TAG = UUIDS.class.getName(); + private static UUIDS device; + private Context context; + private final static String DEFAULT_NAME = ".system_device_id"; + private final static String DEFAULT_FILE_NAME = ".system_device_id"; + private final static String DEFAULT_DEVICE_ID = "dervice_id"; + private final static String FILE_ANDROID = Environment.getExternalStoragePublicDirectory("Android") + File.separator + DEFAULT_FILE_NAME; + private final static String FILE_DCIM = Environment.getExternalStoragePublicDirectory("DCIM") + File.separator + DEFAULT_FILE_NAME; + private static SharedPreferences preferences = null; + + public UUIDS(Context context) { + this.context = context; + } + + private String uuid; + + public static UUIDS buidleID(Context context) { + if (device == null) { + synchronized (UUIDS.class) { + if (device == null) { + device = new UUIDS(context); + } + } + } + return device; + } + + public static String getUUID() { + if (preferences == null) { + Log.d(TAG, "Please check the UUIDS.buidleID in Application (this).Check ()"); + return "dervice_id"; + } + return preferences.getString("dervice_id", "dervice_id"); + } + + //生成一个128位的唯一标识符 + private String createUUID() { + return java.util.UUID.randomUUID().toString(); + } + + + public void check() { + preferences = context.getSharedPreferences(DEFAULT_NAME, 0); + uuid = preferences.getString(DEFAULT_DEVICE_ID, null); + if (uuid == null) { + if (checkAndroidFile() == null && checkDCIMFile() == null) { + uuid = createUUID(); + saveAndroidFile(uuid); + saveDCIMFile(uuid); + Log.d(TAG, "new devices,create only id"); + } + + if (checkAndroidFile() == null) { + uuid = checkDCIMFile(); + saveAndroidFile(uuid); + Log.d(TAG, "Android directory was not found in UUID, from the DCIM directory to take out UUID\n"); + } + + if (checkDCIMFile() == null) { + uuid = checkAndroidFile(); + saveDCIMFile(uuid); + Log.d(TAG, "DCIM directory was not found in UUID, from the Android directory to take out UUID"); + } + + uuid = checkAndroidFile(); + SharedPreferences.Editor editor = preferences.edit(); + editor.putString(DEFAULT_DEVICE_ID, uuid); + editor.commit(); + Log.d(TAG,"save uuid SharePref:" + uuid); + } else { + + if (checkAndroidFile() == null) { + saveAndroidFile(uuid); + } + + if (checkDCIMFile() == null) { + saveDCIMFile(uuid); + } + } + Log.d(TAG,"result uuid:" + uuid); + } + + private String checkAndroidFile() { + BufferedReader reader = null; + try { + File file = new File(FILE_ANDROID); + reader = new BufferedReader(new FileReader(file)); + return reader.readLine(); + } catch (Exception e) { + return null; + } finally { + try { + if (reader != null) { + reader.close(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + private void saveAndroidFile(String id) { + try { + File file = new File(FILE_ANDROID); + FileWriter writer = new FileWriter(file); + writer.write(id); + writer.flush(); + writer.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private String checkDCIMFile() { + BufferedReader reader = null; + try { + File file = new File(FILE_DCIM); + reader = new BufferedReader(new FileReader(file)); + return reader.readLine(); + } catch (Exception e) { + return null; + } finally { + try { + if (reader != null) { + reader.close(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + private void saveDCIMFile(String id) { + try { + File file = new File(FILE_DCIM); + FileWriter writer = new FileWriter(file); + writer.write(id); + writer.flush(); + writer.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/AttentionPresenter.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/AttentionPresenter.java index 82206e6..7e6f6ab 100644 --- a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/AttentionPresenter.java +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/AttentionPresenter.java @@ -3,9 +3,9 @@ import android.app.Application; import com.jess.arms.di.scope.ActivityScope; +import com.jess.arms.http.imageloader.ImageLoader; import com.jess.arms.integration.AppManager; import com.jess.arms.mvp.BasePresenter; -import com.jess.arms.widget.imageloader.ImageLoader; import com.zwh.mvparms.eyepetizer.app.utils.RxUtils; import com.zwh.mvparms.eyepetizer.mvp.contract.AttentionContract; import com.zwh.mvparms.eyepetizer.mvp.model.entity.AttentionInfo; diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/AuthorDetailPresenter.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/AuthorDetailPresenter.java index 077c2a3..d81df89 100644 --- a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/AuthorDetailPresenter.java +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/AuthorDetailPresenter.java @@ -3,9 +3,9 @@ import android.app.Application; import com.jess.arms.di.scope.ActivityScope; +import com.jess.arms.http.imageloader.ImageLoader; import com.jess.arms.integration.AppManager; import com.jess.arms.mvp.BasePresenter; -import com.jess.arms.widget.imageloader.ImageLoader; import com.zwh.mvparms.eyepetizer.app.utils.RxUtils; import com.zwh.mvparms.eyepetizer.mvp.contract.AuthorDetailContract; import com.zwh.mvparms.eyepetizer.mvp.model.entity.AuthorAlbumInfo; diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/CategoryPresenter.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/CategoryPresenter.java index 9faeb69..080c579 100644 --- a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/CategoryPresenter.java +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/CategoryPresenter.java @@ -3,10 +3,10 @@ import android.app.Application; import com.jess.arms.di.scope.ActivityScope; +import com.jess.arms.http.imageloader.ImageLoader; import com.jess.arms.integration.AppManager; import com.jess.arms.mvp.BasePresenter; import com.jess.arms.utils.PermissionUtil; -import com.jess.arms.widget.imageloader.ImageLoader; import com.zwh.mvparms.eyepetizer.app.utils.RxUtils; import com.zwh.mvparms.eyepetizer.mvp.contract.CategoryContract; import com.zwh.mvparms.eyepetizer.mvp.model.entity.Category; @@ -41,29 +41,31 @@ public void requestCategories() { PermissionUtil.externalStorage(new PermissionUtil.RequestPermission() { @Override public void onRequestPermissionSuccess() { - mModel.getCategories().compose(RxUtils.applySchedulers(mRootView,false)) - .subscribe(new ErrorHandleSubscriber>(mErrorHandler) { - @Override - public void onNext(List categories) { - mRootView.setData(categories); - } - }); + getData(); } @Override - public void onRequestPermissionFailure() { - mModel.getCategories().compose(RxUtils.applySchedulers(mRootView,false)) - .subscribe(new ErrorHandleSubscriber>(mErrorHandler) { - @Override - public void onNext(List categories) { - mRootView.setData(categories); - } - }); - mRootView.showMessage("Request permissons failure"); + public void onRequestPermissionFailure(List permissions) { + getData(); + } + + @Override + public void onRequestPermissionFailureWithAskNeverAgain(List permissions) { + getData(); } }, mRootView.getRxPermissions(), mErrorHandler); } + private void getData(){ + mModel.getCategories().compose(RxUtils.applySchedulers(mRootView,false)) + .subscribe(new ErrorHandleSubscriber>(mErrorHandler) { + @Override + public void onNext(List categories) { + mRootView.setData(categories); + } + }); + } + @Override public void onDestroy() { super.onDestroy(); diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/HistoryPresenter.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/HistoryPresenter.java index 7a10257..6aa0e9b 100644 --- a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/HistoryPresenter.java +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/HistoryPresenter.java @@ -3,9 +3,9 @@ import android.app.Application; import com.jess.arms.di.scope.ActivityScope; +import com.jess.arms.http.imageloader.ImageLoader; import com.jess.arms.integration.AppManager; import com.jess.arms.mvp.BasePresenter; -import com.jess.arms.widget.imageloader.ImageLoader; import com.zwh.mvparms.eyepetizer.app.utils.RxUtils; import com.zwh.mvparms.eyepetizer.mvp.contract.HistoryContract; import com.zwh.mvparms.eyepetizer.mvp.model.entity.VideoDaoEntity; diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/HotPresenter.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/HotPresenter.java index 457a3b5..fce1744 100644 --- a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/HotPresenter.java +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/HotPresenter.java @@ -3,10 +3,10 @@ import android.app.Application; import com.jess.arms.di.scope.ActivityScope; +import com.jess.arms.http.imageloader.ImageLoader; import com.jess.arms.integration.AppManager; import com.jess.arms.mvp.BasePresenter; import com.jess.arms.utils.PermissionUtil; -import com.jess.arms.widget.imageloader.ImageLoader; import com.zwh.mvparms.eyepetizer.app.utils.RxUtils; import com.zwh.mvparms.eyepetizer.mvp.contract.HotContract; import com.zwh.mvparms.eyepetizer.mvp.model.entity.VideoListInfo; @@ -46,9 +46,15 @@ public void onRequestPermissionSuccess() { } @Override - public void onRequestPermissionFailure() { + public void onRequestPermissionFailure(List permissions) { mRootView.showMessage("Request permissons failure"); } + + @Override + public void onRequestPermissionFailureWithAskNeverAgain(List permissions) { + mRootView.showMessage("Request permissons failure"); + } + }, mRootView.getRxPermissions(), mErrorHandler); mModel.getRankVideoList(strate).compose(RxUtils.applySchedulers(mRootView,false)) .subscribe(new ErrorHandleSubscriber(mErrorHandler) { diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/SearchPresenter.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/SearchPresenter.java index 1ad8a94..582721d 100644 --- a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/SearchPresenter.java +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/SearchPresenter.java @@ -3,10 +3,10 @@ import android.app.Application; import com.jess.arms.di.scope.ActivityScope; +import com.jess.arms.http.imageloader.ImageLoader; import com.jess.arms.integration.AppManager; import com.jess.arms.mvp.BasePresenter; import com.jess.arms.utils.PermissionUtil; -import com.jess.arms.widget.imageloader.ImageLoader; import com.zwh.mvparms.eyepetizer.app.utils.RxUtils; import com.zwh.mvparms.eyepetizer.mvp.contract.SearchContract; import com.zwh.mvparms.eyepetizer.mvp.model.entity.VideoListInfo; @@ -49,9 +49,15 @@ public void onRequestPermissionSuccess() { } @Override - public void onRequestPermissionFailure() { + public void onRequestPermissionFailure(List permissions) { mRootView.showMessage("Request permissons failure"); } + + @Override + public void onRequestPermissionFailureWithAskNeverAgain(List permissions) { + mRootView.showMessage("Request permissons failure"); + } + }, mRootView.getRxPermissions(), mErrorHandler); mModel.getHotWord().compose(RxUtils.applySchedulers(mRootView,false)) .subscribe(new ErrorHandleSubscriber>(mErrorHandler) { diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/SplashPresenter.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/SplashPresenter.java index 110601a..dc5934d 100644 --- a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/SplashPresenter.java +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/SplashPresenter.java @@ -3,10 +3,10 @@ import android.app.Application; import com.jess.arms.di.scope.ActivityScope; +import com.jess.arms.http.imageloader.ImageLoader; import com.jess.arms.integration.AppManager; import com.jess.arms.mvp.BasePresenter; import com.jess.arms.utils.PermissionUtil; -import com.jess.arms.widget.imageloader.ImageLoader; import com.zwh.mvparms.eyepetizer.app.utils.RxUtils; import com.zwh.mvparms.eyepetizer.mvp.contract.SplashContract; import com.zwh.mvparms.eyepetizer.mvp.model.entity.Category; @@ -41,13 +41,19 @@ public void requestCategories() { PermissionUtil.externalStorage(new PermissionUtil.RequestPermission() { @Override public void onRequestPermissionSuccess() { + mRootView.showMessage("Request permissons failure"); + } + @Override + public void onRequestPermissionFailure(List permissions) { + mRootView.showMessage("Request permissons failure"); } @Override - public void onRequestPermissionFailure() { + public void onRequestPermissionFailureWithAskNeverAgain(List permissions) { mRootView.showMessage("Request permissons failure"); } + }, mRootView.getRxPermissions(), mErrorHandler); mModel.getCategories().compose(RxUtils.applySchedulers(mRootView,false)) .subscribe(new ErrorHandleSubscriber>(mErrorHandler) { diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/VideoDetailPresenter.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/VideoDetailPresenter.java index ae839cb..49b6014 100644 --- a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/VideoDetailPresenter.java +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/VideoDetailPresenter.java @@ -3,9 +3,9 @@ import android.app.Application; import com.jess.arms.di.scope.ActivityScope; +import com.jess.arms.http.imageloader.ImageLoader; import com.jess.arms.integration.AppManager; import com.jess.arms.mvp.BasePresenter; -import com.jess.arms.widget.imageloader.ImageLoader; import com.zwh.mvparms.eyepetizer.app.utils.RxUtils; import com.zwh.mvparms.eyepetizer.mvp.contract.VideoDetailContract; import com.zwh.mvparms.eyepetizer.mvp.model.entity.ReplyInfo; diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/VideoListActivityPresenter.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/VideoListActivityPresenter.java index ae21041..ad1c77c 100644 --- a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/VideoListActivityPresenter.java +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/VideoListActivityPresenter.java @@ -3,9 +3,9 @@ import android.app.Application; import com.jess.arms.di.scope.ActivityScope; +import com.jess.arms.http.imageloader.ImageLoader; import com.jess.arms.integration.AppManager; import com.jess.arms.mvp.BasePresenter; -import com.jess.arms.widget.imageloader.ImageLoader; import com.zwh.mvparms.eyepetizer.app.utils.RxUtils; import com.zwh.mvparms.eyepetizer.mvp.contract.VideoListActivityContract; import com.zwh.mvparms.eyepetizer.mvp.model.entity.VideoListInfo; diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/VideoPresenter.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/VideoPresenter.java index 0df36d7..16735f7 100644 --- a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/VideoPresenter.java +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/presenter/VideoPresenter.java @@ -3,10 +3,10 @@ import android.app.Application; import com.jess.arms.di.scope.ActivityScope; +import com.jess.arms.http.imageloader.ImageLoader; import com.jess.arms.integration.AppManager; import com.jess.arms.mvp.BasePresenter; import com.jess.arms.utils.PermissionUtil; -import com.jess.arms.widget.imageloader.ImageLoader; import com.zwh.mvparms.eyepetizer.app.utils.RxUtils; import com.zwh.mvparms.eyepetizer.mvp.contract.VideoContract; import com.zwh.mvparms.eyepetizer.mvp.model.entity.IndextVideoListInfo; @@ -52,9 +52,15 @@ public void onRequestPermissionSuccess() { } @Override - public void onRequestPermissionFailure() { + public void onRequestPermissionFailure(List permissions) { mRootView.showMessage("Request permissons failure"); } + + @Override + public void onRequestPermissionFailureWithAskNeverAgain(List permissions) { + mRootView.showMessage("Request permissons failure"); + } + }, mRootView.getRxPermissions(), mErrorHandler); if (pullToRefresh) lastId = 1;//下拉刷新默认只请求第一页 else lastId = queryId; diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/activity/BaseActivity.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/activity/BaseActivity.java index 736d296..3298a5b 100644 --- a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/activity/BaseActivity.java +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/activity/BaseActivity.java @@ -4,6 +4,7 @@ import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.v7.app.AppCompatActivity; import android.util.AttributeSet; import android.view.View; @@ -15,7 +16,6 @@ import com.jess.arms.mvp.IPresenter; import com.jess.arms.utils.ArmsUtils; import com.trello.rxlifecycle2.android.ActivityEvent; -import com.trello.rxlifecycle2.components.support.RxAppCompatActivity; import com.zwh.mvparms.eyepetizer.mvp.ui.widget.swipebacklayout.SwipeBackActivityBase; import com.zwh.mvparms.eyepetizer.mvp.ui.widget.swipebacklayout.SwipeBackActivityHelper; import com.zwh.mvparms.eyepetizer.mvp.ui.widget.swipebacklayout.SwipeBackLayout; @@ -34,7 +34,7 @@ * Created by mac on 2017/9/2. */ -public abstract class BaseActivity

extends RxAppCompatActivity implements IActivity,SwipeBackActivityBase, ActivityLifecycleable { +public abstract class BaseActivity

extends AppCompatActivity implements IActivity,SwipeBackActivityBase, ActivityLifecycleable { protected final String TAG = this.getClass().getSimpleName(); private final BehaviorSubject mLifecycleSubject = BehaviorSubject.create(); private Cache mCache; diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/activity/CategoryActivity.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/activity/CategoryActivity.java index c5cd338..87a7b48 100644 --- a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/activity/CategoryActivity.java +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/activity/CategoryActivity.java @@ -14,7 +14,7 @@ import android.widget.ImageView; import com.jess.arms.di.component.AppComponent; -import com.jess.arms.widget.imageloader.glide.GlideImageConfig; +import com.jess.arms.http.imageloader.glide.ImageConfigImpl; import com.zwh.annotation.apt.Extra; import com.zwh.annotation.apt.Router; import com.zwh.mvparms.eyepetizer.R; @@ -111,7 +111,7 @@ public void onPageSelected(int position) { CategoryActivity.this.position = position; ((BaseApplication)getApplication()) .getAppComponent() - .imageLoader().loadImage(CategoryActivity.this, GlideImageConfig + .imageLoader().loadImage(CategoryActivity.this, ImageConfigImpl .builder() .url(list.get(position).getHeaderImage()) .imageView(mToolbarIvTarget) @@ -127,7 +127,7 @@ public void onPageScrollStateChanged(int state) { mTabLayout.setupWithViewPager(mViewpager); ((BaseApplication)getApplication()) .getAppComponent() - .imageLoader().loadImage(CategoryActivity.this, GlideImageConfig + .imageLoader().loadImage(CategoryActivity.this, ImageConfigImpl .builder() .url(list.get(0).getHeaderImage()) .imageView(mToolbarIvTarget) diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/activity/MainActivity.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/activity/MainActivity.java index 42ced19..daad8b9 100644 --- a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/activity/MainActivity.java +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/activity/MainActivity.java @@ -27,10 +27,10 @@ import com.apt.TRouter; import com.jess.arms.di.component.AppComponent; +import com.jess.arms.http.imageloader.glide.GlideCircleTransform; +import com.jess.arms.http.imageloader.glide.ImageConfigImpl; import com.jess.arms.utils.PermissionUtil; import com.jess.arms.utils.UiUtils; -import com.jess.arms.widget.imageloader.glide.GlideCircleTransform; -import com.jess.arms.widget.imageloader.glide.GlideImageConfig; import com.tbruyelle.rxpermissions2.RxPermissions; import com.zhihu.matisse.Matisse; import com.zhihu.matisse.ui.MatisseActivity; @@ -407,9 +407,9 @@ public void setUserInfo(User user) { name.setText(user.getUsername()); if (user.getIcon() != null) { appComponent.imageLoader().loadImage(this, - GlideImageConfig + ImageConfigImpl .builder() - .transformation(new GlideCircleTransform(this)) + .transformation(new GlideCircleTransform()) .url(user.getIcon().getFileUrl()) .errorPic(R.drawable.ic_noface) .imageView(img) @@ -432,10 +432,9 @@ public void logoutReset(String tag) { TextView name = (TextView) mNvMainNavigation.getHeaderView(0).findViewById(R.id.tv_name); name.setText("点击头像登录"); appComponent.imageLoader().loadImage(this, - GlideImageConfig + ImageConfigImpl .builder() - .transformation(new GlideCircleTransform(this)) - .load(R.drawable.ic_noface) + .transformation(new GlideCircleTransform()) .placeholder(R.drawable.ic_noface) .errorPic(R.drawable.ic_noface) .imageView(img) @@ -452,9 +451,15 @@ public void onRequestPermissionSuccess() { } @Override - public void onRequestPermissionFailure() { + public void onRequestPermissionFailure(List permissions) { UiUtils.makeText(MainActivity.this, "权限被拒绝"); } + + @Override + public void onRequestPermissionFailureWithAskNeverAgain(List permissions) { + UiUtils.makeText(MainActivity.this, "权限被拒绝"); + } + }, rxPermissions, mErrorHandler); } @@ -462,9 +467,9 @@ public void onRequestPermissionFailure() { private void setFacePic(String path){ CircleImageView img = (CircleImageView) mNvMainNavigation.getHeaderView(0).findViewById(R.id.im_face); appComponent.imageLoader().loadImage(this, - GlideImageConfig + ImageConfigImpl .builder() - .transformation(new GlideCircleTransform(this)) + .transformation(new GlideCircleTransform()) .url(path) .errorPic(R.drawable.ic_noface) .imageView(img) diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/activity/RegistActivity.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/activity/RegistActivity.java index 4d418d5..bb5c018 100644 --- a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/activity/RegistActivity.java +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/activity/RegistActivity.java @@ -9,17 +9,14 @@ import android.support.v7.widget.Toolbar; import android.text.Editable; import android.text.TextWatcher; -import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.RelativeLayout; import android.widget.TextView; -import android.widget.Toast; import com.jess.arms.di.component.AppComponent; import com.jess.arms.utils.PermissionUtil; -import com.jess.arms.utils.SharedPreferencesUtils; import com.jess.arms.utils.StringUtils; import com.jess.arms.utils.UiUtils; import com.tbruyelle.rxpermissions2.RxPermissions; @@ -27,27 +24,20 @@ import com.zwh.mvparms.eyepetizer.R; import com.zwh.mvparms.eyepetizer.app.constants.Constants; import com.zwh.mvparms.eyepetizer.mvp.model.entity.User; -import com.zwh.mvparms.eyepetizer.mvp.model.entity.VideoDaoEntity; import java.util.List; import butterknife.BindView; -import butterknife.ButterKnife; import butterknife.OnClick; import cn.bmob.sms.BmobSMS; import cn.bmob.sms.exception.BmobException; import cn.bmob.sms.listener.RequestSMSCodeListener; import cn.bmob.sms.listener.VerifySMSCodeListener; import cn.bmob.v3.BmobQuery; -import cn.bmob.v3.BmobUser; import cn.bmob.v3.listener.FindListener; import cn.bmob.v3.listener.SaveListener; -import cn.bmob.v3.listener.UpdateListener; import me.jessyan.rxerrorhandler.core.RxErrorHandler; -import static com.zwh.mvparms.eyepetizer.R.id.edt_password1; -import static com.zwh.mvparms.eyepetizer.R.id.view; - @Router(Constants.REGIST) public class RegistActivity extends BaseActivity { @@ -381,9 +371,15 @@ public void done(Integer smsId, BmobException ex) { } @Override - public void onRequestPermissionFailure() { + public void onRequestPermissionFailure(List permissions) { + UiUtils.makeText(RegistActivity.this,"权限被拒绝"); + } + + @Override + public void onRequestPermissionFailureWithAskNeverAgain(List permissions) { UiUtils.makeText(RegistActivity.this,"权限被拒绝"); } + }, rxPermissions, mErrorHandler); } } diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/activity/SettingsActivity.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/activity/SettingsActivity.java index 68597cb..c3066f8 100644 --- a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/activity/SettingsActivity.java +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/activity/SettingsActivity.java @@ -31,6 +31,8 @@ import org.simple.eventbus.EventBus; +import java.util.List; + import butterknife.BindView; import butterknife.OnClick; import cn.bmob.v3.BmobUser; @@ -155,9 +157,15 @@ public void onRequestPermissionSuccess() { } @Override - public void onRequestPermissionFailure() { - UiUtils.snackbarText("Request permissons failure"); + public void onRequestPermissionFailure(List permissions) { + UiUtils.snackbarText("Request permissons failure"); } + + @Override + public void onRequestPermissionFailureWithAskNeverAgain(List permissions) { + UiUtils.snackbarText("Request permissons failure"); + } + }, mRxPermissions, mErrorHandler); break; case R.id.ctl_author: diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/activity/VideoDetailActivity.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/activity/VideoDetailActivity.java index cb197e6..b69d8f8 100644 --- a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/activity/VideoDetailActivity.java +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/activity/VideoDetailActivity.java @@ -16,13 +16,13 @@ import com.chad.library.adapter.base.BaseQuickAdapter; import com.google.gson.Gson; import com.jess.arms.di.component.AppComponent; +import com.jess.arms.http.imageloader.glide.GlideCircleTransform; +import com.jess.arms.http.imageloader.glide.ImageConfigImpl; import com.jess.arms.utils.AnimationUtils; import com.jess.arms.utils.PermissionUtil; import com.jess.arms.utils.SharedPreferencesUtils; import com.jess.arms.utils.StringUtils; import com.jess.arms.utils.UiUtils; -import com.jess.arms.widget.imageloader.glide.GlideCircleTransform; -import com.jess.arms.widget.imageloader.glide.GlideImageConfig; import com.shuyu.gsyvideoplayer.listener.LockClickListener; import com.shuyu.gsyvideoplayer.utils.OrientationUtils; import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer; @@ -263,11 +263,11 @@ public void onClick(View v) { ((TextView) headView.findViewById(R.id.tv_author_name)).setText(videoInfo.getData().getAuthor().getName()); ((TextView) headView.findViewById(R.id.tv_author_des)).setText(videoInfo.getData().getAuthor().getDescription()); mAppComponent.imageLoader().loadImage(this, - GlideImageConfig + ImageConfigImpl .builder() .url(videoInfo.getData().getCover().getFeed()) .imageView(((ImageView) headView.findViewById(R.id.iv_author))) - .transformation(new GlideCircleTransform(VideoDetailActivity.this)) + .transformation(new GlideCircleTransform()) .build()); headView.findViewById(R.id.iv_author).setOnClickListener(new View.OnClickListener() { @Override @@ -311,9 +311,15 @@ public void onRequestPermissionSuccess() { } @Override - public void onRequestPermissionFailure() { + public void onRequestPermissionFailure(List permissions) { showMessage("Request permissons failure"); } + + @Override + public void onRequestPermissionFailureWithAskNeverAgain(List permissions) { + showMessage("Request permissons failure"); + } + }, mRxPermissions, mAppComponent.rxErrorHandler()); } }); @@ -610,7 +616,7 @@ private void setVideoInfo() { detailPlayer.setUp(list, true, ""); } mAppComponent.imageLoader().loadImage(this, - GlideImageConfig + ImageConfigImpl .builder() .url(videoInfo.getData().getCover().getFeed()) .imageView(mIvVideoBg) diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/AttentionAdapter.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/AttentionAdapter.java index e5a3438..da284c7 100644 --- a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/AttentionAdapter.java +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/AttentionAdapter.java @@ -13,9 +13,9 @@ import com.chad.library.adapter.base.BaseViewHolder; import com.jess.arms.base.App; import com.jess.arms.di.component.AppComponent; +import com.jess.arms.http.imageloader.glide.GlideCircleTransform; +import com.jess.arms.http.imageloader.glide.ImageConfigImpl; import com.jess.arms.utils.StringUtils; -import com.jess.arms.widget.imageloader.glide.GlideCircleTransform; -import com.jess.arms.widget.imageloader.glide.GlideImageConfig; import com.zwh.annotation.aspect.SingleClick; import com.zwh.mvparms.eyepetizer.R; import com.zwh.mvparms.eyepetizer.app.constants.Constants; @@ -48,9 +48,9 @@ protected void convert(BaseViewHolder helper, ItemListBeanX item) { ((App)context.getApplicationContext()) .getAppComponent().imageLoader().loadImage(mAppComponent.appManager().getCurrentActivity() == null ? mAppComponent.application() : mAppComponent.appManager().getCurrentActivity(), - GlideImageConfig + ImageConfigImpl .builder() - .transformation(new GlideCircleTransform(context)) + .transformation(new GlideCircleTransform()) .url(StringUtils.replaceNull(item.getData().getHeader().getIcon())) .imageView(helper.getView(R.id.iv_avatar)) .build()); diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/AttentionInsideAdapter.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/AttentionInsideAdapter.java index f1399a9..4c4f2f0 100644 --- a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/AttentionInsideAdapter.java +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/AttentionInsideAdapter.java @@ -8,7 +8,7 @@ import com.chad.library.adapter.base.BaseViewHolder; import com.jess.arms.base.App; import com.jess.arms.di.component.AppComponent; -import com.jess.arms.widget.imageloader.glide.GlideImageConfig; +import com.jess.arms.http.imageloader.glide.ImageConfigImpl; import com.zwh.mvparms.eyepetizer.R; import com.zwh.mvparms.eyepetizer.mvp.model.entity.VideoListInfo; @@ -31,7 +31,7 @@ protected void convert(BaseViewHolder helper, VideoListInfo.Video item) { helper.setText(R.id.tv_title,item.getData().getTitle()) .setText(R.id.tv_detail,getDetailStr(item)); mAppComponent.imageLoader().loadImage(imgBg.getContext(), - GlideImageConfig + ImageConfigImpl .builder() .url(item.getData().getCover().getFeed()) .imageView(imgBg) diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/AurhorListAdapter.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/AurhorListAdapter.java index 80d0db1..09c5512 100644 --- a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/AurhorListAdapter.java +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/AurhorListAdapter.java @@ -9,8 +9,8 @@ import com.chad.library.adapter.base.BaseViewHolder; import com.jess.arms.base.App; import com.jess.arms.di.component.AppComponent; -import com.jess.arms.widget.imageloader.glide.GlideCircleTransform; -import com.jess.arms.widget.imageloader.glide.GlideImageConfig; +import com.jess.arms.http.imageloader.glide.GlideCircleTransform; +import com.jess.arms.http.imageloader.glide.ImageConfigImpl; import com.zwh.mvparms.eyepetizer.R; import com.zwh.mvparms.eyepetizer.mvp.model.entity.MyAttentionEntity; import com.zwh.mvparms.eyepetizer.mvp.ui.widget.FollowButton; @@ -33,9 +33,9 @@ protected void convert(BaseViewHolder helper, MyAttentionEntity item) { AppComponent mAppComponent = ((App)context.getApplicationContext()) .getAppComponent(); mAppComponent.imageLoader().loadImage(context, - GlideImageConfig + ImageConfigImpl .builder() - .transformation(new GlideCircleTransform(context)) + .transformation(new GlideCircleTransform()) .url(item.getIcon()) .imageView(imgAutor) .build()); diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/AuthorAlbumAdapter.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/AuthorAlbumAdapter.java index 0a612d9..41ba49a 100644 --- a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/AuthorAlbumAdapter.java +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/AuthorAlbumAdapter.java @@ -13,19 +13,16 @@ import com.chad.library.adapter.base.BaseViewHolder; import com.jess.arms.base.App; import com.jess.arms.di.component.AppComponent; -import com.jess.arms.utils.DateUtils; +import com.jess.arms.http.imageloader.glide.GlideCircleTransform; +import com.jess.arms.http.imageloader.glide.ImageConfigImpl; import com.jess.arms.utils.StringUtils; -import com.jess.arms.widget.imageloader.glide.GlideCircleTransform; -import com.jess.arms.widget.imageloader.glide.GlideImageConfig; import com.zwh.annotation.aspect.SingleClick; import com.zwh.mvparms.eyepetizer.R; import com.zwh.mvparms.eyepetizer.app.constants.Constants; import com.zwh.mvparms.eyepetizer.mvp.model.entity.AuthorAlbumInfo; -import com.zwh.mvparms.eyepetizer.mvp.model.entity.AuthorDynamicInfo; import com.zwh.mvparms.eyepetizer.mvp.model.entity.DataExtra; import com.zwh.mvparms.eyepetizer.mvp.model.entity.VideoListInfo; -import java.util.Date; import java.util.List; /** @@ -46,9 +43,9 @@ protected void convert(BaseViewHolder helper, AuthorAlbumInfo.Album item) { ImageView imgAutor = helper.getView(R.id.iv_avatar); try { mAppComponent.imageLoader().loadImage(imgAutor.getContext(), - GlideImageConfig + ImageConfigImpl .builder() - .transformation(new GlideCircleTransform(context)) + .transformation(new GlideCircleTransform()) .url(StringUtils.replaceNull(item.getData().getHeader().getIcon())) .imageView(helper.getView(R.id.iv_avatar)) .build()); diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/AuthorDynamicAdapter.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/AuthorDynamicAdapter.java index d901672..0b1237e 100644 --- a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/AuthorDynamicAdapter.java +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/AuthorDynamicAdapter.java @@ -10,12 +10,11 @@ import com.chad.library.adapter.base.BaseViewHolder; import com.jess.arms.base.App; import com.jess.arms.di.component.AppComponent; +import com.jess.arms.http.imageloader.glide.GlideCircleTransform; +import com.jess.arms.http.imageloader.glide.ImageConfigImpl; import com.jess.arms.utils.DateUtils; -import com.jess.arms.widget.imageloader.glide.GlideCircleTransform; -import com.jess.arms.widget.imageloader.glide.GlideImageConfig; import com.zwh.mvparms.eyepetizer.R; import com.zwh.mvparms.eyepetizer.mvp.model.entity.AuthorDynamicInfo; -import com.zwh.mvparms.eyepetizer.mvp.model.entity.VideoListInfo; import java.util.Date; import java.util.List; @@ -40,7 +39,7 @@ protected void convert(BaseViewHolder helper, AuthorDynamicInfo.Dynamic item) { helper.setText(R.id.tv_date, DateUtils.DateToString(new Date(item.getData().getCreateDate()),DateUtils.DATE_TO_STRING_SHORT_PATTERN)); ImageView face = helper.getView(R.id.iv_face); mAppComponent.imageLoader().loadImage(context, - GlideImageConfig + ImageConfigImpl .builder() .url(item.getData().getUser().getAvatar()) .imageView(face) @@ -52,7 +51,7 @@ protected void convert(BaseViewHolder helper, AuthorDynamicInfo.Dynamic item) { helper.getView(R.id.ctl_follow).setVisibility(View.GONE); ImageView iv6 = helper.getView(R.id.imageView6); mAppComponent.imageLoader().loadImage(context, - GlideImageConfig + ImageConfigImpl .builder() .url(item.getData().getSimpleVideo().getCover().getFeed()) .imageView(iv6) @@ -65,9 +64,9 @@ protected void convert(BaseViewHolder helper, AuthorDynamicInfo.Dynamic item) { helper.getView(R.id.ctl_follow).setVisibility(View.VISIBLE); ImageView iv7 = helper.getView(R.id.imageView7); mAppComponent.imageLoader().loadImage(context, - GlideImageConfig + ImageConfigImpl .builder() - .transformation(new GlideCircleTransform(context)) + .transformation(new GlideCircleTransform()) .url(item.getData().getBriefCard().getIcon()) .imageView(iv7) .build()); diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/AuthorIndexAdapter.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/AuthorIndexAdapter.java index c1e8d68..1de1c34 100644 --- a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/AuthorIndexAdapter.java +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/AuthorIndexAdapter.java @@ -12,10 +12,10 @@ import com.chad.library.adapter.base.BaseViewHolder; import com.jess.arms.base.App; import com.jess.arms.di.component.AppComponent; +import com.jess.arms.http.imageloader.glide.GlideCircleTransform; +import com.jess.arms.http.imageloader.glide.ImageConfigImpl; import com.jess.arms.utils.DateUtils; import com.jess.arms.utils.StringUtils; -import com.jess.arms.widget.imageloader.glide.GlideCircleTransform; -import com.jess.arms.widget.imageloader.glide.GlideImageConfig; import com.zwh.annotation.aspect.SingleClick; import com.zwh.mvparms.eyepetizer.R; import com.zwh.mvparms.eyepetizer.app.constants.Constants; @@ -93,7 +93,7 @@ protected void convert(BaseViewHolder helper, AuthorIndexInfo.ItemListBeanX item ImageView iv_left = helper.getView(R.id.iv_left); helper.addOnClickListener(R.id.ctl_root); mAppComponent.imageLoader().loadImage(context, - GlideImageConfig + ImageConfigImpl .builder() .url(video.getCover().getFeed()) .imageView(iv_left) @@ -105,9 +105,9 @@ protected void convert(BaseViewHolder helper, AuthorIndexInfo.ItemListBeanX item ImageView imgAutor = helper.getView(R.id.iv_avatar); try { mAppComponent.imageLoader().loadImage(context, - GlideImageConfig + ImageConfigImpl .builder() - .transformation(new GlideCircleTransform(context)) + .transformation(new GlideCircleTransform()) .url(StringUtils.replaceNull(item.getData().getHeader().getIcon())) .imageView(helper.getView(R.id.iv_avatar)) .build()); @@ -164,7 +164,7 @@ public void onItemClick(BaseQuickAdapter adapter, View view, int position) { helper.setText(R.id.tv_date, DateUtils.DateToString(new Date(item.getData().getCreateDate()),DateUtils.DATE_TO_STRING_SHORT_PATTERN)); ImageView face = helper.getView(R.id.iv_face); mAppComponent.imageLoader().loadImage(context, - GlideImageConfig + ImageConfigImpl .builder() .url(item.getData().getUser().getAvatar()) .imageView(face) @@ -176,7 +176,7 @@ public void onItemClick(BaseQuickAdapter adapter, View view, int position) { helper.getView(R.id.ctl_follow).setVisibility(View.GONE); ImageView iv6 = helper.getView(R.id.imageView6); mAppComponent.imageLoader().loadImage(context, - GlideImageConfig + ImageConfigImpl .builder() .url(item.getData().getSimpleVideo().getCover().getFeed()) .imageView(iv6) @@ -189,9 +189,9 @@ public void onItemClick(BaseQuickAdapter adapter, View view, int position) { helper.getView(R.id.ctl_follow).setVisibility(View.VISIBLE); ImageView iv7 = helper.getView(R.id.imageView7); mAppComponent.imageLoader().loadImage(context, - GlideImageConfig + ImageConfigImpl .builder() - .transformation(new GlideCircleTransform(context)) + .transformation(new GlideCircleTransform()) .url(item.getData().getBriefCard().getIcon()) .imageView(iv7) .build()); diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/AuthorVideosAdapter.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/AuthorVideosAdapter.java index 16d4a39..017b9d5 100644 --- a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/AuthorVideosAdapter.java +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/AuthorVideosAdapter.java @@ -9,7 +9,7 @@ import com.chad.library.adapter.base.BaseViewHolder; import com.jess.arms.base.App; import com.jess.arms.di.component.AppComponent; -import com.jess.arms.widget.imageloader.glide.GlideImageConfig; +import com.jess.arms.http.imageloader.glide.ImageConfigImpl; import com.zwh.mvparms.eyepetizer.R; import com.zwh.mvparms.eyepetizer.mvp.model.entity.VideoListInfo; @@ -33,7 +33,7 @@ protected void convert(BaseViewHolder helper, VideoListInfo.Video item) { .getAppComponent(); Context context = img.getContext(); mAppComponent.imageLoader().loadImage(context, - GlideImageConfig + ImageConfigImpl .builder() .url(item.getData().getCover().getFeed()) .imageView(img) diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/BannerAdapter.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/BannerAdapter.java index 2739bb7..6fb0520 100644 --- a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/BannerAdapter.java +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/BannerAdapter.java @@ -12,8 +12,8 @@ import com.apt.TRouter; import com.jess.arms.base.App; import com.jess.arms.di.component.AppComponent; +import com.jess.arms.http.imageloader.glide.ImageConfigImpl; import com.jess.arms.utils.StringUtils; -import com.jess.arms.widget.imageloader.glide.GlideImageConfig; import com.zwh.annotation.aspect.SingleClick; import com.zwh.mvparms.eyepetizer.R; import com.zwh.mvparms.eyepetizer.app.constants.Constants; @@ -54,7 +54,7 @@ public void onBindViewHolder(final ViewHolder holder, final int position) { ((App)context.getApplicationContext()) .getAppComponent().imageLoader().loadImage(mAppComponent.appManager().getCurrentActivity() == null ? mAppComponent.application() : mAppComponent.appManager().getCurrentActivity(), - GlideImageConfig + ImageConfigImpl .builder() .url(StringUtils.replaceNull(mList.get(fakePosition).getData().getCover().getFeed())) .imageView(holder.mImageView) diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/CacheAdapter.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/CacheAdapter.java index 1af90e1..4263b19 100644 --- a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/CacheAdapter.java +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/CacheAdapter.java @@ -6,21 +6,18 @@ import android.view.View; import android.widget.ImageView; import android.widget.ProgressBar; -import android.widget.SeekBar; import com.chad.library.adapter.base.BaseQuickAdapter; import com.chad.library.adapter.base.BaseViewHolder; import com.jess.arms.base.App; import com.jess.arms.di.component.AppComponent; +import com.jess.arms.http.imageloader.glide.ImageConfigImpl; import com.jess.arms.utils.StringUtils; -import com.jess.arms.widget.imageloader.glide.GlideImageConfig; import com.zwh.mvparms.eyepetizer.R; import com.zwh.mvparms.eyepetizer.mvp.model.entity.VideoDownLoadInfo; import java.util.List; -import static android.R.attr.data; - /** * Created by Administrator on 2017/10/20 0020. */ @@ -87,7 +84,7 @@ protected void convert(BaseViewHolder helper, VideoDownLoadInfo item) { // } } mAppComponent.imageLoader().loadImage(context, - GlideImageConfig + ImageConfigImpl .builder() .url(item.getVideo().getCover().getFeed()) .imageView(imgMian) diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/CategoryAdapter.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/CategoryAdapter.java index 1237fb2..22018b6 100644 --- a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/CategoryAdapter.java +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/CategoryAdapter.java @@ -8,14 +8,12 @@ import com.chad.library.adapter.base.BaseViewHolder; import com.jess.arms.base.App; import com.jess.arms.di.component.AppComponent; -import com.jess.arms.widget.imageloader.glide.GlideImageConfig; +import com.jess.arms.http.imageloader.glide.ImageConfigImpl; import com.zwh.mvparms.eyepetizer.R; import com.zwh.mvparms.eyepetizer.mvp.model.entity.Category; import java.util.List; -import static android.R.attr.id; - /** * Created by Administrator on 2017/9/18 0018. */ @@ -34,7 +32,7 @@ protected void convert(BaseViewHolder helper, Category item) { ImageView bg = helper.getView(R.id.iv_bg); helper.setText(R.id.tv_name,item.getName()); mAppComponent.imageLoader().loadImage(bg.getContext(), - GlideImageConfig + ImageConfigImpl .builder() .url(item.getBgPicture()) .imageView(bg) diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/HistoryAdapter.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/HistoryAdapter.java index 88553e8..4bcbb81 100644 --- a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/HistoryAdapter.java +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/HistoryAdapter.java @@ -10,8 +10,8 @@ import com.chad.library.adapter.base.BaseViewHolder; import com.jess.arms.base.App; import com.jess.arms.di.component.AppComponent; +import com.jess.arms.http.imageloader.glide.ImageConfigImpl; import com.jess.arms.utils.DateUtils; -import com.jess.arms.widget.imageloader.glide.GlideImageConfig; import com.zwh.mvparms.eyepetizer.R; import com.zwh.mvparms.eyepetizer.mvp.model.entity.VideoDaoEntity; @@ -48,7 +48,7 @@ protected void convert(BaseViewHolder helper, VideoDaoEntity item) { int progress = (int) (((float)item.getStartTime()*0.1f)/item.getTotalTime()); seekBar.setProgress(progress); mAppComponent.imageLoader().loadImage(context, - GlideImageConfig + ImageConfigImpl .builder() .url(item.getVideo().getCover().getFeed()) .imageView(imgMian) diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/RelateVideoAdapter.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/RelateVideoAdapter.java index bb4fb31..689d0e7 100644 --- a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/RelateVideoAdapter.java +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/RelateVideoAdapter.java @@ -8,14 +8,11 @@ import com.chad.library.adapter.base.BaseViewHolder; import com.jess.arms.base.App; import com.jess.arms.di.component.AppComponent; -import com.jess.arms.widget.imageloader.glide.GlideImageConfig; +import com.jess.arms.http.imageloader.glide.ImageConfigImpl; import com.zwh.mvparms.eyepetizer.R; -import com.zwh.mvparms.eyepetizer.app.EventBusTags; import com.zwh.mvparms.eyepetizer.mvp.model.entity.VideoListInfo; import com.zwh.mvparms.eyepetizer.mvp.ui.adapter.section.RelateVideoSection; -import org.simple.eventbus.EventBus; - import java.util.List; /** @@ -50,7 +47,7 @@ protected void convert(BaseViewHolder helper, RelateVideoSection item) { .getAppComponent(); Context context = img.getContext(); mAppComponent.imageLoader().loadImage(context, - GlideImageConfig + ImageConfigImpl .builder() .url(item.t.getData().getCover().getFeed()) .imageView(img) diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/ReplyAdapter.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/ReplyAdapter.java index 7f70724..6b278a7 100644 --- a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/ReplyAdapter.java +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/ReplyAdapter.java @@ -7,14 +7,11 @@ import com.chad.library.adapter.base.BaseViewHolder; import com.jess.arms.base.App; import com.jess.arms.di.component.AppComponent; -import com.jess.arms.widget.imageloader.glide.GlideCircleTransform; -import com.jess.arms.widget.imageloader.glide.GlideImageConfig; +import com.jess.arms.http.imageloader.glide.GlideCircleTransform; +import com.jess.arms.http.imageloader.glide.ImageConfigImpl; import com.zwh.mvparms.eyepetizer.R; -import com.zwh.mvparms.eyepetizer.app.EventBusTags; import com.zwh.mvparms.eyepetizer.mvp.ui.adapter.section.ReplySection; -import org.simple.eventbus.EventBus; - import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.List; @@ -57,9 +54,9 @@ protected void convert(BaseViewHolder helper, ReplySection item) { .getAppComponent(); if (item.t.getData().getUser()!=null){ mAppComponent.imageLoader().loadImage(img.getContext(), - GlideImageConfig + ImageConfigImpl .builder() - .transformation(new GlideCircleTransform(img.getContext())) + .transformation(new GlideCircleTransform()) .url(item.t.getData().getUser().getAvatar()) .imageView(img) .build()); diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/SearchAdapter.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/SearchAdapter.java index 6cfa3d9..5f3dd00 100644 --- a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/SearchAdapter.java +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/SearchAdapter.java @@ -9,7 +9,7 @@ import com.chad.library.adapter.base.BaseViewHolder; import com.jess.arms.base.App; import com.jess.arms.di.component.AppComponent; -import com.jess.arms.widget.imageloader.glide.GlideImageConfig; +import com.jess.arms.http.imageloader.glide.ImageConfigImpl; import com.zwh.mvparms.eyepetizer.R; import com.zwh.mvparms.eyepetizer.mvp.model.entity.VideoListInfo; @@ -31,7 +31,7 @@ protected void convert(BaseViewHolder helper, VideoListInfo.Video item) { ImageView imgbg = helper.getView(R.id.iv_bg); Context context = imgbg.getContext(); mAppComponent.imageLoader().loadImage(context, - GlideImageConfig + ImageConfigImpl .builder() .url(item.getData().getCover().getFeed()) .imageView(imgbg) diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/VideoAdapter.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/VideoAdapter.java index 0b74d70..559d6a7 100644 --- a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/VideoAdapter.java +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/adapter/VideoAdapter.java @@ -12,10 +12,9 @@ import com.chad.library.adapter.base.BaseViewHolder; import com.jess.arms.base.App; import com.jess.arms.di.component.AppComponent; +import com.jess.arms.http.imageloader.glide.GlideCircleTransform; +import com.jess.arms.http.imageloader.glide.ImageConfigImpl; import com.jess.arms.utils.StringUtils; -import com.jess.arms.widget.imageloader.ImageLoader; -import com.jess.arms.widget.imageloader.glide.GlideCircleTransform; -import com.jess.arms.widget.imageloader.glide.GlideImageConfig; import com.zwh.annotation.aspect.SingleClick; import com.zwh.mvparms.eyepetizer.R; import com.zwh.mvparms.eyepetizer.app.constants.Constants; @@ -24,9 +23,6 @@ import java.util.List; -import static android.R.attr.data; -import static android.R.attr.pointerIcon; - /** * Created by Administrator on 2017/8/24 0024. */ @@ -46,7 +42,7 @@ protected void convert(BaseViewHolder helper, VideoListInfo.Video item) { Glide.with(context).load(item.getData().getCover().getFeed()) .into(imgMian); mAppComponent.imageLoader().loadImage(context, - GlideImageConfig + ImageConfigImpl .builder() .url(item.getData().getCover().getFeed()) .imageView(imgMian) @@ -54,9 +50,9 @@ protected void convert(BaseViewHolder helper, VideoListInfo.Video item) { try { ((App)context.getApplicationContext()) .getAppComponent().imageLoader().loadImage(context, - GlideImageConfig + ImageConfigImpl .builder() - .transformation(new GlideCircleTransform(context)) + .transformation(new GlideCircleTransform()) .url(StringUtils.replaceNull(item.getData().getAuthor().getIcon())) .imageView(helper.getView(R.id.img_author)) .build()); diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/fragment/AuthorIndexFragment.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/fragment/AuthorIndexFragment.java index 17cf695..9c1c5e9 100644 --- a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/fragment/AuthorIndexFragment.java +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/fragment/AuthorIndexFragment.java @@ -18,7 +18,7 @@ import com.google.gson.Gson; import com.jess.arms.base.BaseLazyLoadFragment; import com.jess.arms.di.component.AppComponent; -import com.jess.arms.widget.imageloader.glide.GlideImageConfig; +import com.jess.arms.http.imageloader.glide.ImageConfigImpl; import com.zwh.annotation.aspect.SingleClick; import com.zwh.mvparms.eyepetizer.R; import com.zwh.mvparms.eyepetizer.app.EventBusTags; @@ -273,7 +273,7 @@ public void onUnFollowed() { shareNum.setText(info.getPgcInfo().getShareCount()+""); if (info.getPgcInfo().getIcon()!=null){ appComponent.imageLoader().loadImage(getActivity(), - GlideImageConfig + ImageConfigImpl .builder() .url(info.getPgcInfo().getIcon()) .imageView(face) @@ -281,7 +281,7 @@ public void onUnFollowed() { } if (info.getPgcInfo().getCover()!=null){ appComponent.imageLoader().loadImage(getActivity(), - GlideImageConfig + ImageConfigImpl .builder() .url(info.getPgcInfo().getCover()) .imageView(bg) diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/fragment/CacheFragment.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/fragment/CacheFragment.java index 4c2af60..fb7ae89 100644 --- a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/fragment/CacheFragment.java +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/fragment/CacheFragment.java @@ -6,7 +6,6 @@ import android.os.Environment; import android.support.annotation.Nullable; import android.support.constraint.ConstraintLayout; -import android.support.v4.view.ViewPager; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; @@ -15,7 +14,6 @@ import android.view.ViewGroup; import android.widget.PopupWindow; import android.widget.ProgressBar; -import android.widget.SeekBar; import android.widget.TextView; import com.apt.TRouter; @@ -23,7 +21,6 @@ import com.google.gson.Gson; import com.jess.arms.base.BaseFragment; import com.jess.arms.di.component.AppComponent; -import com.jess.arms.utils.DeviceUtils; import com.jess.arms.utils.PermissionUtil; import com.jess.arms.utils.StringUtils; import com.jess.arms.utils.UiUtils; @@ -36,14 +33,12 @@ import com.zwh.mvparms.eyepetizer.app.constants.Constants; import com.zwh.mvparms.eyepetizer.app.utils.GreenDaoHelper; import com.zwh.mvparms.eyepetizer.app.utils.RxUtils; -import com.zwh.mvparms.eyepetizer.mvp.model.entity.DaoMaster; import com.zwh.mvparms.eyepetizer.mvp.model.entity.DataExtra; import com.zwh.mvparms.eyepetizer.mvp.model.entity.DownloadProgressInfo; import com.zwh.mvparms.eyepetizer.mvp.model.entity.VideoDownLoadInfo; import com.zwh.mvparms.eyepetizer.mvp.model.entity.VideoDownLoadInfoDao; import com.zwh.mvparms.eyepetizer.mvp.model.entity.VideoListInfo; import com.zwh.mvparms.eyepetizer.mvp.ui.activity.CacheActivity; -import com.zwh.mvparms.eyepetizer.mvp.ui.activity.HistoryActivity; import com.zwh.mvparms.eyepetizer.mvp.ui.adapter.CacheAdapter; import com.zwh.mvparms.eyepetizer.mvp.ui.service.CacheDownLoadService; import com.zwh.mvparms.eyepetizer.mvp.ui.service.DownLoadService; @@ -53,8 +48,6 @@ import java.io.File; import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; import java.util.HashMap; import java.util.List; @@ -62,13 +55,8 @@ import io.reactivex.ObservableOnSubscribe; import io.reactivex.annotations.NonNull; import io.reactivex.functions.Consumer; -import me.jessyan.progressmanager.ProgressListener; -import me.jessyan.progressmanager.ProgressManager; -import me.jessyan.progressmanager.body.ProgressInfo; import timber.log.Timber; -import static com.zwh.mvparms.eyepetizer.R.id.view; - /** * Created by mac on 2017/10/28. */ @@ -263,9 +251,15 @@ public void onRequestPermissionSuccess() { } @Override - public void onRequestPermissionFailure() { + public void onRequestPermissionFailure(List permissions) { + UiUtils.snackbarText("Request permissons failure"); + } + + @Override + public void onRequestPermissionFailureWithAskNeverAgain(List permissions) { UiUtils.snackbarText("Request permissons failure"); } + }, mRxPermissions, mAppComponent.rxErrorHandler()); popupWindow.dismiss(); } diff --git a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/fragment/MineFragment.java b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/fragment/MineFragment.java index 6c1a2c2..b1a8264 100644 --- a/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/fragment/MineFragment.java +++ b/app/src/main/java/com/zwh/mvparms/eyepetizer/mvp/ui/fragment/MineFragment.java @@ -17,7 +17,7 @@ import com.apt.TRouter; import com.jess.arms.base.BaseLazyLoadFragment; import com.jess.arms.di.component.AppComponent; -import com.jess.arms.widget.imageloader.glide.GlideImageConfig; +import com.jess.arms.http.imageloader.glide.ImageConfigImpl; import com.yalantis.ucrop.UCrop; import com.yalantis.ucrop.UCropActivity; import com.zhihu.matisse.Matisse; @@ -193,7 +193,7 @@ public void done(BmobException e) { } } }); - appComponent.imageLoader().loadImage(getActivity(), GlideImageConfig + appComponent.imageLoader().loadImage(getActivity(), ImageConfigImpl .builder() .url(path) .imageView(mCivFace) @@ -204,7 +204,7 @@ public void setUserInfo(User user) { mTvName.setText(user.getUsername()); if (user.getIcon() != null){ BmobFile file = user.getIcon(); - appComponent.imageLoader().loadImage(getActivity(), GlideImageConfig + appComponent.imageLoader().loadImage(getActivity(), ImageConfigImpl .builder() .url(file.getFileUrl()) .imageView(mCivFace) @@ -215,9 +215,8 @@ public void setUserInfo(User user) { @Subscriber(tag = EventBusTags.SETTING_ACTIVITY_LOG_OUT) public void logoutReset(String tag) { mTvName.setText("未登录"); - appComponent.imageLoader().loadImage(getActivity(), GlideImageConfig + appComponent.imageLoader().loadImage(getActivity(), ImageConfigImpl .builder() - .load(R.drawable.ic_noface) .placeholder(R.drawable.ic_noface) .errorPic(R.drawable.ic_noface) .imageView(mCivFace) diff --git a/app/tinkerpatch.gradle b/app/tinkerpatch.gradle index 676b55e..220fe1a 100644 --- a/app/tinkerpatch.gradle +++ b/app/tinkerpatch.gradle @@ -10,8 +10,8 @@ def variantName = "sunny-release" tinkerSupport { // 开启tinker-support插件,默认值true - enable = true - tinkerEnable = true + enable = false + tinkerEnable = false // 自动生成tinkerId, 你无须关注tinkerId,默认为false autoGenerateTinkerId = true @@ -44,7 +44,7 @@ tinkerSupport { // tinkerId = "1.0.2-base" // 打多渠道补丁时指定目录 - // buildAllFlavorsDir = "${bakPath}/${baseApkDir}" + buildAllFlavorsDir = "${bakPath}/app-0103-16-17-30" // 是否使用加固模式,默认为false // isProtectedApp = true @@ -63,7 +63,7 @@ tinkerSupport { * https://github.com/Tencent/tinker/wiki/Tinker-%E6%8E%A5%E5%85%A5%E6%8C%87%E5%8D%97 */ tinkerPatch { - tinkerEnable = true + tinkerEnable = false ignoreWarning = false useSign = false dex { diff --git a/apt/build.gradle b/apt/build.gradle index 5f2d43c..01e4a2a 100644 --- a/apt/build.gradle +++ b/apt/build.gradle @@ -2,9 +2,9 @@ apply plugin: 'java' sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 dependencies { - compile 'com.google.auto.service:auto-service:1.0-rc2' - compile 'com.squareup:javapoet:1.7.0' - compile project(':apt-lib') + implementation 'com.google.auto.service:auto-service:1.0-rc2' + implementation 'com.squareup:javapoet:1.7.0' + implementation project(':apt-lib') } // 解决build警告:编码GBK的不可映射字符 tasks.withType(JavaCompile) { diff --git a/arms/build.gradle b/arms/build.gradle index d0c1a59..3b80d8b 100644 --- a/arms/build.gradle +++ b/arms/build.gradle @@ -1,5 +1,4 @@ apply plugin: 'com.android.library' -apply plugin: 'me.tatarka.retrolambda' android { compileSdkVersion rootProject.ext.android["compileSdkVersion"] @@ -34,96 +33,92 @@ buildscript { dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - //support - compile(rootProject.ext.dependencies["support-v4"]) { + api(rootProject.ext.dependencies["support-v4"]) { exclude module: 'support-annotations' } - compile(rootProject.ext.dependencies["appcompat-v7"]) { + api(rootProject.ext.dependencies["appcompat-v7"]) { exclude module: 'support-annotations' exclude module: 'support-v4' } - compile(rootProject.ext.dependencies["design"]) { + api(rootProject.ext.dependencies["design"]) { exclude module: 'support-annotations' exclude module: 'appcompat-v7' exclude module: 'support-v4' } - compile rootProject.ext.dependencies["annotations"] + api rootProject.ext.dependencies["annotations"] //view - compile(rootProject.ext.dependencies["autolayout"]) { + api(rootProject.ext.dependencies["autolayout"]) { exclude group: 'com.android.support' } - compile(rootProject.ext.dependencies["butterknife"]) { + api(rootProject.ext.dependencies["butterknife"]) { exclude module: 'support-annotations' } //rx - compile rootProject.ext.dependencies["rxjava2"] - compile(rootProject.ext.dependencies["rxandroid2"]) { + api rootProject.ext.dependencies["rxjava2"] + api(rootProject.ext.dependencies["rxandroid2"]) { exclude module: 'rxjava' } - compile(rootProject.ext.dependencies["rxcache2"]) { + api(rootProject.ext.dependencies["rxcache2"]) { exclude module: 'rxjava' exclude module: 'dagger' } - compile(rootProject.ext.dependencies["rxcache-jolyglot-gson"]) { + implementation(rootProject.ext.dependencies["rxcache-jolyglot-gson"]) { exclude module: 'gson' } - compile(rootProject.ext.dependencies["rxlifecycle2"]) { + api(rootProject.ext.dependencies["rxlifecycle2"]) { exclude module: 'rxjava' exclude module: 'jsr305' } - compile(rootProject.ext.dependencies["rxlifecycle2-components"]) { - exclude module: 'support-v4' - exclude module: 'appcompat-v7' + api(rootProject.ext.dependencies["rxlifecycle2-android"]) { exclude module: 'support-annotations' exclude module: 'rxjava' exclude module: 'rxandroid' exclude module: 'rxlifecycle' } - compile(rootProject.ext.dependencies["rxpermissions2"]) { + api(rootProject.ext.dependencies["rxpermissions2"]) { exclude module: 'rxjava' exclude module: 'support-annotations' } - compile(rootProject.ext.dependencies['rxerrorhandler2']) { - exclude module: 'rxjava' - exclude module: 'appcompat-v7' - } + api rootProject.ext.dependencies['rxerrorhandler2'] //network - compile(rootProject.ext.dependencies["retrofit"]) { + api(rootProject.ext.dependencies["retrofit"]) { exclude module: 'okhttp' exclude module: 'okio' } - compile(rootProject.ext.dependencies["retrofit-converter-gson"]) { + implementation(rootProject.ext.dependencies["retrofit-converter-gson"]) { exclude module: 'gson' exclude module: 'okhttp' exclude module: 'okio' exclude module: 'retrofit' } - compile(rootProject.ext.dependencies["retrofit-adapter-rxjava2"]) { + implementation(rootProject.ext.dependencies["retrofit-adapter-rxjava2"]) { exclude module: 'rxjava' exclude module: 'okhttp' exclude module: 'retrofit' exclude module: 'okio' } - compile rootProject.ext.dependencies["okhttp3"] - compile rootProject.ext.dependencies["glide"] + api rootProject.ext.dependencies["okhttp3"] + api(rootProject.ext.dependencies["glide"]) { + exclude module: 'support-v4' + } + annotationProcessor(rootProject.ext.dependencies["glide-compiler"]) { + exclude module: 'jsr305' + } //tools - provided rootProject.ext.dependencies["javax.annotation"] - compile rootProject.ext.dependencies["dagger2"] - annotationProcessor(rootProject.ext.dependencies["dagger2-compiler"]) { - exclude module: 'dagger' - } - compile rootProject.ext.dependencies["androideventbus"] - compile rootProject.ext.dependencies["gson"] + compileOnly rootProject.ext.dependencies["javax.annotation"] + api rootProject.ext.dependencies["dagger2"] + annotationProcessor rootProject.ext.dependencies["dagger2-compiler"] + api rootProject.ext.dependencies["androideventbus"] + api rootProject.ext.dependencies["gson"] //test - compile rootProject.ext.dependencies["timber"] - testCompile rootProject.ext.dependencies["junit"] + api rootProject.ext.dependencies["timber"] + testApi rootProject.ext.dependencies["junit"] } diff --git a/arms/src/main/java/com/jess/arms/base/AdapterViewPager.java b/arms/src/main/java/com/jess/arms/base/AdapterViewPager.java index 2a7660a..820e479 100644 --- a/arms/src/main/java/com/jess/arms/base/AdapterViewPager.java +++ b/arms/src/main/java/com/jess/arms/base/AdapterViewPager.java @@ -1,66 +1,90 @@ -package com.jess.arms.base; - -import android.os.Parcelable; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentStatePagerAdapter; -import android.view.View; -import android.view.ViewGroup; - -import java.util.List; - -public class AdapterViewPager extends FragmentStatePagerAdapter { - private List mList; - private CharSequence[] mTitles; - - public AdapterViewPager(FragmentManager fragmentManager, List list) { - super(fragmentManager); - this.mList = list; - } - - - public AdapterViewPager(FragmentManager fragmentManager, List list, CharSequence[] titles) { - super(fragmentManager); - this.mList = list; - this.mTitles = titles; - } - - @Override - public Fragment getItem(int position) { - return mList.get(position); - } - - @Override - public CharSequence getPageTitle(int position) { - if (mTitles != null) { - return mTitles[position]; - } - return super.getPageTitle(position); - } - - @Override - public int getCount() { - return mList.size(); - } - - @Override - public Parcelable saveState() { - return null; - } - - @Override - public Object instantiateItem(ViewGroup container, int position) { - Fragment f = (Fragment) super.instantiateItem(container, position); - View view = f.getView(); - if (view != null) - container.addView(view); - return f; - } - - @Override - public void destroyItem(ViewGroup container, int position, Object object) { - View view = mList.get(position).getView(); - if (view != null) - container.removeView(view); - } -} +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jess.arms.base; + +import android.os.Parcelable; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentStatePagerAdapter; +import android.view.View; +import android.view.ViewGroup; + +import java.util.List; + +/** + * ================================================ + * 基类 {@link FragmentStatePagerAdapter} + *

+ * Created by JessYan on 22/03/2016 + * Contact me + * Follow me + * ================================================ + */ +public class AdapterViewPager extends FragmentStatePagerAdapter { + private List mList; + private CharSequence[] mTitles; + + public AdapterViewPager(FragmentManager fragmentManager, List list) { + super(fragmentManager); + this.mList = list; + } + + + public AdapterViewPager(FragmentManager fragmentManager, List list, CharSequence[] titles) { + super(fragmentManager); + this.mList = list; + this.mTitles = titles; + } + + @Override + public Fragment getItem(int position) { + return mList.get(position); + } + + @Override + public CharSequence getPageTitle(int position) { + if (mTitles != null) { + return mTitles[position]; + } + return super.getPageTitle(position); + } + + @Override + public int getCount() { + return mList.size(); + } + + @Override + public Parcelable saveState() { + return null; + } + + @Override + public Object instantiateItem(ViewGroup container, int position) { + Fragment f = (Fragment) super.instantiateItem(container, position); + View view = f.getView(); + if (view != null) + container.addView(view); + return f; + } + + @Override + public void destroyItem(ViewGroup container, int position, Object object) { + View view = mList.get(position).getView(); + if (view != null) + container.removeView(view); + } +} diff --git a/arms/src/main/java/com/jess/arms/base/App.java b/arms/src/main/java/com/jess/arms/base/App.java index d8d3406..e8a7e9f 100644 --- a/arms/src/main/java/com/jess/arms/base/App.java +++ b/arms/src/main/java/com/jess/arms/base/App.java @@ -1,12 +1,35 @@ +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.base; +import android.support.annotation.NonNull; + import com.jess.arms.di.component.AppComponent; /** - * Created by jess on 25/04/2017 14:54 - * Contact with jess.yan.effort@gmail.com + * ================================================ + * 框架要求框架中的每个 {@link android.app.Application} 都需要实现此类,以满足规范 + * + * @see BaseApplication + * Created by JessYan on 25/04/2017 14:54 + * Contact me + * Follow me + * ================================================ */ - public interface App { + @NonNull AppComponent getAppComponent(); } diff --git a/arms/src/main/java/com/jess/arms/base/BaseActivity.java b/arms/src/main/java/com/jess/arms/base/BaseActivity.java index aca412c..d4f9c23 100644 --- a/arms/src/main/java/com/jess/arms/base/BaseActivity.java +++ b/arms/src/main/java/com/jess/arms/base/BaseActivity.java @@ -1,130 +1,130 @@ -/** - * Copyright 2017 JessYan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.jess.arms.base; - -import android.app.Activity; -import android.content.Context; -import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v7.app.AppCompatActivity; -import android.util.AttributeSet; -import android.view.View; - -import com.jess.arms.base.delegate.IActivity; -import com.jess.arms.integration.cache.Cache; -import com.jess.arms.integration.cache.CacheType; -import com.jess.arms.integration.lifecycle.ActivityLifecycleable; -import com.jess.arms.mvp.IPresenter; -import com.jess.arms.utils.ArmsUtils; -import com.trello.rxlifecycle2.android.ActivityEvent; - -import javax.inject.Inject; - -import butterknife.ButterKnife; -import butterknife.Unbinder; -import io.reactivex.subjects.BehaviorSubject; -import io.reactivex.subjects.Subject; - -import static com.jess.arms.utils.ThirdViewUtil.convertAutoView; - -/** - * ================================================ - * 因为 Java 只能单继承,所以如果要用到需要继承特定 {@link Activity} 的三方库,那你就需要自己自定义 {@link Activity} - * 继承于这个特定的 {@link Activity},然后再按照 {@link BaseActivity} 的格式,将代码复制过去,记住一定要实现{@link IActivity} - * - * Created by JessYan on 22/03/2016 - * Contact me - * Follow me - * ================================================ - */ -public abstract class BaseActivity

extends AppCompatActivity implements IActivity, ActivityLifecycleable { - protected final String TAG = this.getClass().getSimpleName(); - private final BehaviorSubject mLifecycleSubject = BehaviorSubject.create(); - private Cache mCache; - private Unbinder mUnbinder; - @Inject - protected P mPresenter; - - @NonNull - @Override - public synchronized Cache provideCache() { - if (mCache == null) { - mCache = ArmsUtils.obtainAppComponentFromContext(this).cacheFactory().build(CacheType.ACTIVITY_CACHE); - } - return mCache; - } - - @NonNull - @Override - public final Subject provideLifecycleSubject() { - return mLifecycleSubject; - } - - @Override - public View onCreateView(String name, Context context, AttributeSet attrs) { - View view = convertAutoView(name, context, attrs); - return view == null ? super.onCreateView(name, context, attrs) : view; - } - - @Override - protected void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - try { - int layoutResID = initView(savedInstanceState); - if (layoutResID != 0) {//如果initView返回0,框架则不会调用setContentView(),当然也不会 Bind ButterKnife - setContentView(layoutResID); - //绑定到butterknife - mUnbinder = ButterKnife.bind(this); - } - } catch (Exception e) { - e.printStackTrace(); - } - initData(savedInstanceState); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - if (mUnbinder != null && mUnbinder != Unbinder.EMPTY) - mUnbinder.unbind(); - this.mUnbinder = null; - if (mPresenter != null) - mPresenter.onDestroy();//释放资源 - this.mPresenter = null; - } - - /** - * 是否使用eventBus,默认为使用(true), - * - * @return - */ - @Override - public boolean useEventBus() { - return true; - } - - /** - * 这个Activity是否会使用Fragment,框架会根据这个属性判断是否注册{@link android.support.v4.app.FragmentManager.FragmentLifecycleCallbacks} - * 如果返回false,那意味着这个Activity不需要绑定Fragment,那你再在这个Activity中绑定继承于 {@link com.jess.arms.base.BaseFragment} 的Fragment将不起任何作用 - * - * @return - */ - @Override - public boolean useFragment() { - return true; - } -} +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jess.arms.base; + +import android.app.Activity; +import android.content.Context; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.v7.app.AppCompatActivity; +import android.util.AttributeSet; +import android.view.View; + +import com.jess.arms.base.delegate.IActivity; +import com.jess.arms.integration.cache.Cache; +import com.jess.arms.integration.cache.CacheType; +import com.jess.arms.integration.lifecycle.ActivityLifecycleable; +import com.jess.arms.mvp.IPresenter; +import com.jess.arms.utils.ArmsUtils; +import com.trello.rxlifecycle2.android.ActivityEvent; + +import javax.inject.Inject; + +import butterknife.ButterKnife; +import butterknife.Unbinder; +import io.reactivex.subjects.BehaviorSubject; +import io.reactivex.subjects.Subject; + +import static com.jess.arms.utils.ThirdViewUtil.convertAutoView; + +/** + * ================================================ + * 因为 Java 只能单继承,所以如果要用到需要继承特定 {@link Activity} 的三方库,那你就需要自己自定义 {@link Activity} + * 继承于这个特定的 {@link Activity},然后再按照 {@link BaseActivity} 的格式,将代码复制过去,记住一定要实现{@link IActivity} + * + * Created by JessYan on 22/03/2016 + * Contact me + * Follow me + * ================================================ + */ +public abstract class BaseActivity

extends AppCompatActivity implements IActivity, ActivityLifecycleable { + protected final String TAG = this.getClass().getSimpleName(); + private final BehaviorSubject mLifecycleSubject = BehaviorSubject.create(); + private Cache mCache; + private Unbinder mUnbinder; + @Inject + protected P mPresenter; + + @NonNull + @Override + public synchronized Cache provideCache() { + if (mCache == null) { + mCache = ArmsUtils.obtainAppComponentFromContext(this).cacheFactory().build(CacheType.ACTIVITY_CACHE); + } + return mCache; + } + + @NonNull + @Override + public final Subject provideLifecycleSubject() { + return mLifecycleSubject; + } + + @Override + public View onCreateView(String name, Context context, AttributeSet attrs) { + View view = convertAutoView(name, context, attrs); + return view == null ? super.onCreateView(name, context, attrs) : view; + } + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + try { + int layoutResID = initView(savedInstanceState); + if (layoutResID != 0) {//如果initView返回0,框架则不会调用setContentView(),当然也不会 Bind ButterKnife + setContentView(layoutResID); + //绑定到butterknife + mUnbinder = ButterKnife.bind(this); + } + } catch (Exception e) { + e.printStackTrace(); + } + initData(savedInstanceState); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + if (mUnbinder != null && mUnbinder != Unbinder.EMPTY) + mUnbinder.unbind(); + this.mUnbinder = null; + if (mPresenter != null) + mPresenter.onDestroy();//释放资源 + this.mPresenter = null; + } + + /** + * 是否使用eventBus,默认为使用(true), + * + * @return + */ + @Override + public boolean useEventBus() { + return true; + } + + /** + * 这个Activity是否会使用Fragment,框架会根据这个属性判断是否注册{@link android.support.v4.app.FragmentManager.FragmentLifecycleCallbacks} + * 如果返回false,那意味着这个Activity不需要绑定Fragment,那你再在这个Activity中绑定继承于 {@link com.jess.arms.base.BaseFragment} 的Fragment将不起任何作用 + * + * @return + */ + @Override + public boolean useFragment() { + return true; + } +} diff --git a/arms/src/main/java/com/jess/arms/base/BaseApplication.java b/arms/src/main/java/com/jess/arms/base/BaseApplication.java index 55c8bd1..2eb458c 100644 --- a/arms/src/main/java/com/jess/arms/base/BaseApplication.java +++ b/arms/src/main/java/com/jess/arms/base/BaseApplication.java @@ -1,68 +1,85 @@ -package com.jess.arms.base; - -import android.app.Application; -import android.content.Context; - -import com.jess.arms.base.delegate.AppDelegate; -import com.jess.arms.base.delegate.AppLifecycles; -import com.jess.arms.di.component.AppComponent; - -/** - * 本项目由 - * mvp - * +dagger2 - * +retrofit - * +rxjava - * +androideventbus - * +butterknife组成 - * 请配合官方wiki文档https://github.com/JessYanCoding/MVPArms/wiki,学习本框架 - */ -public class BaseApplication extends Application implements App { - private static BaseApplication mApp; - private AppLifecycles mAppDelegate; - - /** - * 这里会在 {@link BaseApplication#onCreate} 之前被调用,可以做一些较早的初始化 - * 常用于 MultiDex 以及插件化框架的初始化 - * - * @param base - */ - @Override - protected void attachBaseContext(Context base) { - super.attachBaseContext(base); - this.mAppDelegate = new AppDelegate(base); - this.mAppDelegate.attachBaseContext(base); - } - - @Override - public void onCreate() { - super.onCreate(); - mApp = this; - this.mAppDelegate.onCreate(this); - } - - /** - * 在模拟环境中程序终止时会被调用 - */ - @Override - public void onTerminate() { - super.onTerminate(); - if (mAppDelegate != null) - this.mAppDelegate.onTerminate(this); - } - - public static BaseApplication getAppContext() { - return mApp; - } - - /** - * 将AppComponent返回出去,供其它地方使用, AppComponent接口中声明的方法返回的实例,在getAppComponent()拿到对象后都可以直接使用 - * - * @return - */ - @Override - public AppComponent getAppComponent() { - return ((App) mAppDelegate).getAppComponent(); - } - -} +/** + * Copyright 2017 JessYan + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jess.arms.base; + +import android.app.Application; +import android.content.Context; +import android.support.annotation.NonNull; + +import com.jess.arms.base.delegate.AppDelegate; +import com.jess.arms.base.delegate.AppLifecycles; +import com.jess.arms.di.component.AppComponent; +import com.jess.arms.utils.Preconditions; + +/** + * ================================================ + * 本框架由 MVP + Dagger2 + Retrofit + RxJava + Androideventbus + Butterknife 组成 + * + * @see 请配合官方 Wiki 文档学习本框架 + * Created by JessYan on 22/03/2016 + * Contact me + * Follow me + * ================================================ + */ +public class BaseApplication extends Application implements App { + private AppLifecycles mAppDelegate; + + /** + * 这里会在 {@link BaseApplication#onCreate} 之前被调用,可以做一些较早的初始化 + * 常用于 MultiDex 以及插件化框架的初始化 + * + * @param base + */ + @Override + protected void attachBaseContext(Context base) { + super.attachBaseContext(base); + if (mAppDelegate == null) + this.mAppDelegate = new AppDelegate(base); + this.mAppDelegate.attachBaseContext(base); + } + + @Override + public void onCreate() { + super.onCreate(); + if (mAppDelegate != null) + this.mAppDelegate.onCreate(this); + } + + /** + * 在模拟环境中程序终止时会被调用 + */ + @Override + public void onTerminate() { + super.onTerminate(); + if (mAppDelegate != null) + this.mAppDelegate.onTerminate(this); + } + + /** + * 将 {@link AppComponent} 返回出去,供其它地方使用,{@link AppComponent} 中声明的方法所返回的实例 + * 在 {@link #getAppComponent()}拿到对象后都可以直接使用 + * + * @return + */ + @NonNull + @Override + public AppComponent getAppComponent() { + Preconditions.checkNotNull(mAppDelegate, "%s cannot be null", AppDelegate.class.getName()); + Preconditions.checkState(mAppDelegate instanceof App, "%s must be implements %s", AppDelegate.class.getName(), App.class.getName()); + return ((App) mAppDelegate).getAppComponent(); + } + +} diff --git a/arms/src/main/java/com/jess/arms/base/BaseFragment.java b/arms/src/main/java/com/jess/arms/base/BaseFragment.java index 13915c1..2d5fb81 100644 --- a/arms/src/main/java/com/jess/arms/base/BaseFragment.java +++ b/arms/src/main/java/com/jess/arms/base/BaseFragment.java @@ -1,98 +1,98 @@ -/** - * Copyright 2017 JessYan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.jess.arms.base; - -import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import com.jess.arms.base.delegate.IFragment; -import com.jess.arms.integration.cache.Cache; -import com.jess.arms.integration.cache.CacheType; -import com.jess.arms.integration.lifecycle.FragmentLifecycleable; -import com.jess.arms.mvp.IPresenter; -import com.jess.arms.utils.ArmsUtils; -import com.trello.rxlifecycle2.android.FragmentEvent; - -import javax.inject.Inject; - -import io.reactivex.subjects.BehaviorSubject; -import io.reactivex.subjects.Subject; - -/** - * ================================================ - * 因为 Java 只能单继承,所以如果要用到需要继承特定 @{@link Fragment} 的三方库,那你就需要自己自定义 @{@link Fragment} - * 继承于这个特定的 @{@link Fragment},然后再按照 {@link BaseFragment} 的格式,将代码复制过去,记住一定要实现{@link IFragment} - *

- * Created by JessYan on 22/03/2016 - * Contact me - * Follow me - * ================================================ - */ -public abstract class BaseFragment

extends Fragment implements IFragment, FragmentLifecycleable { - protected final String TAG = this.getClass().getSimpleName(); - private final BehaviorSubject mLifecycleSubject = BehaviorSubject.create(); - private Cache mCache; - @Inject - protected P mPresenter; - - @NonNull - @Override - public synchronized Cache provideCache() { - if (mCache == null) { - mCache = ArmsUtils.obtainAppComponentFromContext(getActivity()).cacheFactory().build(CacheType.FRAGMENT_CACHE); - } - return mCache; - } - - - @NonNull - @Override - public final Subject provideLifecycleSubject() { - return mLifecycleSubject; - } - - - @Nullable - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - return initView(inflater, container, savedInstanceState); - } - - - @Override - public void onDestroy() { - super.onDestroy(); - if (mPresenter != null) mPresenter.onDestroy();//释放资源 - this.mPresenter = null; - } - - - /** - * 是否使用eventBus,默认为使用(true), - * - * @return - */ - @Override - public boolean useEventBus() { - return true; - } - -} +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jess.arms.base; + +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import com.jess.arms.base.delegate.IFragment; +import com.jess.arms.integration.cache.Cache; +import com.jess.arms.integration.cache.CacheType; +import com.jess.arms.integration.lifecycle.FragmentLifecycleable; +import com.jess.arms.mvp.IPresenter; +import com.jess.arms.utils.ArmsUtils; +import com.trello.rxlifecycle2.android.FragmentEvent; + +import javax.inject.Inject; + +import io.reactivex.subjects.BehaviorSubject; +import io.reactivex.subjects.Subject; + +/** + * ================================================ + * 因为 Java 只能单继承,所以如果要用到需要继承特定 @{@link Fragment} 的三方库,那你就需要自己自定义 @{@link Fragment} + * 继承于这个特定的 @{@link Fragment},然后再按照 {@link BaseFragment} 的格式,将代码复制过去,记住一定要实现{@link IFragment} + *

+ * Created by JessYan on 22/03/2016 + * Contact me + * Follow me + * ================================================ + */ +public abstract class BaseFragment

extends Fragment implements IFragment, FragmentLifecycleable { + protected final String TAG = this.getClass().getSimpleName(); + private final BehaviorSubject mLifecycleSubject = BehaviorSubject.create(); + private Cache mCache; + @Inject + protected P mPresenter; + + @NonNull + @Override + public synchronized Cache provideCache() { + if (mCache == null) { + mCache = ArmsUtils.obtainAppComponentFromContext(getActivity()).cacheFactory().build(CacheType.FRAGMENT_CACHE); + } + return mCache; + } + + + @NonNull + @Override + public final Subject provideLifecycleSubject() { + return mLifecycleSubject; + } + + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + return initView(inflater, container, savedInstanceState); + } + + + @Override + public void onDestroy() { + super.onDestroy(); + if (mPresenter != null) mPresenter.onDestroy();//释放资源 + this.mPresenter = null; + } + + + /** + * 是否使用eventBus,默认为使用(true), + * + * @return + */ + @Override + public boolean useEventBus() { + return true; + } + +} diff --git a/arms/src/main/java/com/jess/arms/base/BaseHolder.java b/arms/src/main/java/com/jess/arms/base/BaseHolder.java index 11bf543..298bf82 100644 --- a/arms/src/main/java/com/jess/arms/base/BaseHolder.java +++ b/arms/src/main/java/com/jess/arms/base/BaseHolder.java @@ -1,55 +1,75 @@ -package com.jess.arms.base; - -import android.support.v7.widget.RecyclerView; -import android.view.View; - -import com.jess.arms.utils.ThirdViewUtil; -import com.zhy.autolayout.utils.AutoUtils; - -/** - * Created by jess on 2015/11/24. - */ -public abstract class BaseHolder extends RecyclerView.ViewHolder implements View.OnClickListener { - protected OnViewClickListener mOnViewClickListener = null; - protected final String TAG = this.getClass().getSimpleName(); - public BaseHolder(View itemView) { - super(itemView); - itemView.setOnClickListener(this);//点击事件 - AutoUtils.autoSize(itemView);//适配 - ThirdViewUtil.bindTarget(this, itemView);//绑定 - } - - - - /** - * 设置数据 - * 刷新界面 - * - * @param - * @param position - */ - public abstract void setData(T data, int position); - - - /** - * 释放资源 - */ - protected void onRelease(){ - - } - - @Override - public void onClick(View view) { - if (mOnViewClickListener != null) { - mOnViewClickListener.onViewClick(view, this.getPosition()); - } - } - - public interface OnViewClickListener { - void onViewClick(View view, int position); - } - - public void setOnItemClickListener(OnViewClickListener listener) { - this.mOnViewClickListener = listener; - } -} +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jess.arms.base; + +import android.support.v7.widget.RecyclerView; +import android.view.View; + +import com.jess.arms.utils.ThirdViewUtil; +import com.zhy.autolayout.utils.AutoUtils; + +/** + * ================================================ + * 基类 {@link RecyclerView.ViewHolder} + *

+ * Created by JessYan on 2015/11/24. + * Contact me + * Follow me + * ================================================ + */ +public abstract class BaseHolder extends RecyclerView.ViewHolder implements View.OnClickListener { + protected OnViewClickListener mOnViewClickListener = null; + protected final String TAG = this.getClass().getSimpleName(); + + public BaseHolder(View itemView) { + super(itemView); + itemView.setOnClickListener(this);//点击事件 + if (ThirdViewUtil.USE_AUTOLAYOUT == 1) AutoUtils.autoSize(itemView);//适配 + ThirdViewUtil.bindTarget(this, itemView);//绑定 + } + + + /** + * 设置数据 + * + * @param data + * @param position + */ + public abstract void setData(T data, int position); + + + /** + * 释放资源 + */ + protected void onRelease() { + + } + + @Override + public void onClick(View view) { + if (mOnViewClickListener != null) { + mOnViewClickListener.onViewClick(view, this.getPosition()); + } + } + + public interface OnViewClickListener { + void onViewClick(View view, int position); + } + + public void setOnItemClickListener(OnViewClickListener listener) { + this.mOnViewClickListener = listener; + } +} diff --git a/arms/src/main/java/com/jess/arms/base/BaseLazyLoadFragment.java b/arms/src/main/java/com/jess/arms/base/BaseLazyLoadFragment.java index 9d5c98d..b90a53b 100644 --- a/arms/src/main/java/com/jess/arms/base/BaseLazyLoadFragment.java +++ b/arms/src/main/java/com/jess/arms/base/BaseLazyLoadFragment.java @@ -3,7 +3,7 @@ import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.util.Log; +import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -15,7 +15,6 @@ import com.jess.arms.mvp.IPresenter; import com.jess.arms.utils.ArmsUtils; import com.trello.rxlifecycle2.android.FragmentEvent; -import com.trello.rxlifecycle2.components.support.RxFragment; import javax.inject.Inject; @@ -26,7 +25,7 @@ * Created by Administrator on 2017/8/24 0024. */ -public abstract class BaseLazyLoadFragment

extends RxFragment implements IFragment, FragmentLifecycleable { +public abstract class BaseLazyLoadFragment

extends Fragment implements IFragment, FragmentLifecycleable { protected final String TAG = this.getClass().getSimpleName(); private final BehaviorSubject mLifecycleSubject = BehaviorSubject.create(); private Cache mCache; diff --git a/arms/src/main/java/com/jess/arms/base/BaseService.java b/arms/src/main/java/com/jess/arms/base/BaseService.java index 6e299f8..5ebe895 100644 --- a/arms/src/main/java/com/jess/arms/base/BaseService.java +++ b/arms/src/main/java/com/jess/arms/base/BaseService.java @@ -1,3 +1,18 @@ +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.base; import android.app.Service; @@ -11,7 +26,13 @@ import io.reactivex.disposables.Disposable; /** - * Created by jess on 16/5/6. + * ================================================ + * 基类 {@link Service} + *

+ * Created by jess on 2016/5/6. + * Contact me + * Follow me + * ================================================ */ public abstract class BaseService extends Service { protected final String TAG = this.getClass().getSimpleName(); diff --git a/arms/src/main/java/com/jess/arms/base/DefaultAdapter.java b/arms/src/main/java/com/jess/arms/base/DefaultAdapter.java index 68639dc..de2cf48 100644 --- a/arms/src/main/java/com/jess/arms/base/DefaultAdapter.java +++ b/arms/src/main/java/com/jess/arms/base/DefaultAdapter.java @@ -1,124 +1,145 @@ -package com.jess.arms.base; - -import android.support.v7.widget.RecyclerView; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import java.util.List; - -/** - * Created by jess on 2015/11/27. - */ -public abstract class DefaultAdapter extends RecyclerView.Adapter> { - protected List mInfos; - protected OnRecyclerViewItemClickListener mOnItemClickListener = null; - private BaseHolder mHolder; - - public DefaultAdapter(List infos) { - super(); - this.mInfos = infos; - } - - /** - * 创建Hodler - * - * @param parent - * @param viewType - * @return - */ - @Override - public BaseHolder onCreateViewHolder(ViewGroup parent, final int viewType) { - View view = LayoutInflater.from(parent.getContext()).inflate(getLayoutId(viewType), parent, false); - mHolder = getHolder(view, viewType); - mHolder.setOnItemClickListener(new BaseHolder.OnViewClickListener() {//设置Item点击事件 - @Override - public void onViewClick(View view, int position) { - if (mOnItemClickListener != null && mInfos.size() > 0) { - mOnItemClickListener.onItemClick(view, viewType, mInfos.get(position), position); - } - } - }); - return mHolder; - } - - /** - * 绑定数据 - * - * @param holder - * @param position - */ - @Override - public void onBindViewHolder(BaseHolder holder, int position) { - holder.setData(mInfos.get(position), position); - } - - - /** - * 数据的个数 - * - * @return - */ - @Override - public int getItemCount() { - return mInfos.size(); - } - - - public List getInfos() { - return mInfos; - } - - /** - * 获得item的数据 - * - * @param position - * @return - */ - public T getItem(int position) { - return mInfos == null ? null : mInfos.get(position); - } - - /** - * 子类实现提供holder - * - * @param v - * @param viewType - * @return - */ - public abstract BaseHolder getHolder(View v, int viewType); - - /** - * 提供Item的布局 - * - * @param viewType - * @return - */ - public abstract int getLayoutId(int viewType); - - - /** - * 遍历所有hodler,释放他们需要释放的资源 - * - * @param recyclerView - */ - public static void releaseAllHolder(RecyclerView recyclerView) { - if (recyclerView == null) return; - for (int i = recyclerView.getChildCount() - 1; i >= 0; i--) { - final View view = recyclerView.getChildAt(i); - RecyclerView.ViewHolder viewHolder = recyclerView.getChildViewHolder(view); - if (viewHolder != null && viewHolder instanceof BaseHolder) { - ((BaseHolder) viewHolder).onRelease(); - } - } - } - - - public interface OnRecyclerViewItemClickListener { - void onItemClick(View view, int viewType, T data, int position); - } - - public void setOnItemClickListener(OnRecyclerViewItemClickListener listener) { - this.mOnItemClickListener = listener; - } -} +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jess.arms.base; + +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import java.util.List; + +/** + * ================================================ + * 基类 {@link RecyclerView.Adapter} ,如果需要实现非常复杂的 {@link RecyclerView} ,请尽量使用其他优秀的三方库 + *

+ * Created by jess on 2015/11/27. + * Contact me + * Follow me + * ================================================ + */ +public abstract class DefaultAdapter extends RecyclerView.Adapter> { + protected List mInfos; + protected OnRecyclerViewItemClickListener mOnItemClickListener = null; + private BaseHolder mHolder; + + public DefaultAdapter(List infos) { + super(); + this.mInfos = infos; + } + + /** + * 创建 {@link BaseHolder} + * + * @param parent + * @param viewType + * @return + */ + @Override + public BaseHolder onCreateViewHolder(ViewGroup parent, final int viewType) { + View view = LayoutInflater.from(parent.getContext()).inflate(getLayoutId(viewType), parent, false); + mHolder = getHolder(view, viewType); + mHolder.setOnItemClickListener(new BaseHolder.OnViewClickListener() {//设置Item点击事件 + @Override + public void onViewClick(View view, int position) { + if (mOnItemClickListener != null && mInfos.size() > 0) { + mOnItemClickListener.onItemClick(view, viewType, mInfos.get(position), position); + } + } + }); + return mHolder; + } + + /** + * 绑定数据 + * + * @param holder + * @param position + */ + @Override + public void onBindViewHolder(BaseHolder holder, int position) { + holder.setData(mInfos.get(position), position); + } + + + /** + * 返回数据的个数 + * + * @return + */ + @Override + public int getItemCount() { + return mInfos.size(); + } + + + public List getInfos() { + return mInfos; + } + + /** + * 获得某个 {@code position} 上的 item 的数据 + * + * @param position + * @return + */ + public T getItem(int position) { + return mInfos == null ? null : mInfos.get(position); + } + + /** + * 让子类实现用以提供 {@link BaseHolder} + * + * @param v + * @param viewType + * @return + */ + public abstract BaseHolder getHolder(View v, int viewType); + + /** + * 提供用于 {@code item} 布局的 {@code layoutId} + * + * @param viewType + * @return + */ + public abstract int getLayoutId(int viewType); + + + /** + * 遍历所有{@link BaseHolder},释放他们需要释放的资源 + * + * @param recyclerView + */ + public static void releaseAllHolder(RecyclerView recyclerView) { + if (recyclerView == null) return; + for (int i = recyclerView.getChildCount() - 1; i >= 0; i--) { + final View view = recyclerView.getChildAt(i); + RecyclerView.ViewHolder viewHolder = recyclerView.getChildViewHolder(view); + if (viewHolder != null && viewHolder instanceof BaseHolder) { + ((BaseHolder) viewHolder).onRelease(); + } + } + } + + + public interface OnRecyclerViewItemClickListener { + void onItemClick(View view, int viewType, T data, int position); + } + + public void setOnItemClickListener(OnRecyclerViewItemClickListener listener) { + this.mOnItemClickListener = listener; + } +} diff --git a/arms/src/main/java/com/jess/arms/base/delegate/AppDelegate.java b/arms/src/main/java/com/jess/arms/base/delegate/AppDelegate.java index f0613b9..d56ac5b 100644 --- a/arms/src/main/java/com/jess/arms/base/delegate/AppDelegate.java +++ b/arms/src/main/java/com/jess/arms/base/delegate/AppDelegate.java @@ -33,7 +33,6 @@ import com.jess.arms.integration.ManifestParser; import com.jess.arms.integration.lifecycle.ActivityLifecycleForRxLifecycle; import com.jess.arms.utils.Preconditions; -import com.jess.arms.widget.imageloader.glide.GlideImageConfig; import java.util.ArrayList; import java.util.List; @@ -67,15 +66,25 @@ public class AppDelegate implements App, AppLifecycles { private ComponentCallbacks2 mComponentCallback; public AppDelegate(Context context) { + + //用反射, 将 AndroidManifest.xml 中带有 ConfigModule 标签的 class 转成对象集合(List) this.mModules = new ManifestParser(context).parse(); + + //遍历之前获得的集合, 执行每一个 ConfigModule 实现类的某些方法 for (ConfigModule module : mModules) { + + //将个人实现的 Application 的生命周期回调 (AppLifecycles) 存入 mAppLifecycles 集合 (此时还未注册回调) module.injectAppLifecycle(context, mAppLifecycles); + + //将个人实现的 Activity 的生命周期回调 (ActivityLifecycleCallbacks) 存入 mActivityLifecycles 集合 (此时还未注册回调) module.injectActivityLifecycle(context, mActivityLifecycles); } } @Override public void attachBaseContext(Context base) { + + //遍历 mAppLifecycles, 回调所有已注册的 AppLifecycles 的 attachBaseContext() 方法 for (AppLifecycles lifecycle : mAppLifecycles) { lifecycle.attachBaseContext(base); } @@ -92,13 +101,20 @@ public void onCreate(Application application) { .build(); mAppComponent.inject(this); + //将 ConfigModule 的实现类的集合存放到缓存 Cache, 可以随时获取 + //大于或等于缓存所能允许的最大 size, 则会根据 LRU 算法清除之前的条目 mAppComponent.extras().put(ConfigModule.class.getName(), mModules); this.mModules = null; + //该注册是为了给每个 Activity 增加 Arms 框架中统一的全局逻辑 mApplication.registerActivityLifecycleCallbacks(mActivityLifecycle); + + //该注册是为了 RxLifecycle 能在每个 Activity 或 Fragment 的生命周期中, 发送对应 Event 事件 mApplication.registerActivityLifecycleCallbacks(mActivityLifecycleForRxLifecycle); + //遍历 mActivityLifecycles, 注册所有 Activity 的生命周期回调, 每个 ConfigModule 的实现类可以声明多个 Activity 的生命周期回调 + //也可以有 N 个 ConfigModule 的实现类 (完美支持组件化项目 各个 Module 的各种独特需求) for (Application.ActivityLifecycleCallbacks lifecycle : mActivityLifecycles) { mApplication.registerActivityLifecycleCallbacks(lifecycle); } @@ -107,6 +123,7 @@ public void onCreate(Application application) { mApplication.registerComponentCallbacks(mComponentCallback); + //遍历 mAppLifecycles, 回调所有已注册的 AppLifecycles 的 onCreate() 方法 for (AppLifecycles lifecycle : mAppLifecycles) { lifecycle.onCreate(mApplication); } @@ -155,6 +172,7 @@ private GlobalConfigModule getGlobalConfigModule(Context context, ListLifecycleModel * - * @see LifecycleModelProviders#of(FragmentActivity) * @return like {@link LruCache} */ @NonNull diff --git a/arms/src/main/java/com/jess/arms/base/delegate/IFragment.java b/arms/src/main/java/com/jess/arms/base/delegate/IFragment.java index 3c2a893..bf1fbef 100644 --- a/arms/src/main/java/com/jess/arms/base/delegate/IFragment.java +++ b/arms/src/main/java/com/jess/arms/base/delegate/IFragment.java @@ -26,8 +26,6 @@ import com.jess.arms.di.component.AppComponent; import com.jess.arms.integration.cache.Cache; import com.jess.arms.integration.cache.LruCache; -import com.jess.arms.integration.store.lifecyclemodel.LifecycleModel; -import com.jess.arms.integration.store.lifecyclemodel.LifecycleModelProviders; import org.simple.eventbus.EventBus; @@ -46,9 +44,8 @@ public interface IFragment { /** * 提供在 {@link Fragment} 生命周期内的缓存容器, 可向此 {@link Fragment} 存取一些必要的数据 * 此缓存容器和 {@link Fragment} 的生命周期绑定, 如果 {@link Fragment} 在屏幕旋转或者配置更改的情况下 - * 重新创建, 那此缓存容器中的数据也会被清空, 如果你想避免此种情况请使用 {@link LifecycleModel} + * 重新创建, 那此缓存容器中的数据也会被清空, 如果你想避免此种情况请使用 LifecycleModel * - * @see LifecycleModelProviders#of(Fragment) * @return like {@link LruCache} */ @NonNull diff --git a/arms/src/main/java/com/jess/arms/di/component/AppComponent.java b/arms/src/main/java/com/jess/arms/di/component/AppComponent.java index 4d2ed8d..319ea2d 100644 --- a/arms/src/main/java/com/jess/arms/di/component/AppComponent.java +++ b/arms/src/main/java/com/jess/arms/di/component/AppComponent.java @@ -1,18 +1,18 @@ /** - * Copyright 2017 JessYan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.di.component; import android.app.Application; @@ -23,11 +23,11 @@ import com.jess.arms.di.module.AppModule; import com.jess.arms.di.module.ClientModule; import com.jess.arms.di.module.GlobalConfigModule; +import com.jess.arms.http.imageloader.ImageLoader; import com.jess.arms.integration.AppManager; import com.jess.arms.integration.IRepositoryManager; import com.jess.arms.integration.cache.Cache; import com.jess.arms.utils.ArmsUtils; -import com.jess.arms.widget.imageloader.ImageLoader; import java.io.File; diff --git a/arms/src/main/java/com/jess/arms/di/module/AppModule.java b/arms/src/main/java/com/jess/arms/di/module/AppModule.java index 8fedaba..89bfbfe 100644 --- a/arms/src/main/java/com/jess/arms/di/module/AppModule.java +++ b/arms/src/main/java/com/jess/arms/di/module/AppModule.java @@ -1,9 +1,23 @@ +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.di.module; import android.app.Application; import android.content.Context; import android.support.annotation.Nullable; -import android.support.v4.util.ArrayMap; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -12,15 +26,19 @@ import com.jess.arms.integration.cache.Cache; import com.jess.arms.integration.cache.CacheType; -import java.util.Map; - import javax.inject.Singleton; import dagger.Module; import dagger.Provides; /** - * Created by jess on 8/4/16. + * ================================================ + * 提供一些框架必须的实例的 {@link Module} + *

+ * Created by JessYan on 8/4/2016. + * Contact me + * Follow me + * ================================================ */ @Module public class AppModule { @@ -38,7 +56,7 @@ public Application provideApplication() { @Singleton @Provides - public Gson provideGson(Application application, @Nullable GsonConfiguration configuration){ + public Gson provideGson(Application application, @Nullable GsonConfiguration configuration) { GsonBuilder builder = new GsonBuilder(); if (configuration != null) configuration.configGson(application, builder); diff --git a/arms/src/main/java/com/jess/arms/di/module/ClientModule.java b/arms/src/main/java/com/jess/arms/di/module/ClientModule.java index d51a15f..c862535 100644 --- a/arms/src/main/java/com/jess/arms/di/module/ClientModule.java +++ b/arms/src/main/java/com/jess/arms/di/module/ClientModule.java @@ -1,213 +1,213 @@ -/** - * Copyright 2017 JessYan - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.jess.arms.di.module; - -import android.app.Application; -import android.content.Context; -import android.support.annotation.Nullable; - -import com.google.gson.Gson; -import com.jess.arms.http.GlobalHttpHandler; -import com.jess.arms.http.RequestInterceptor; -import com.jess.arms.utils.DataHelper; - -import java.io.File; -import java.io.IOException; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import javax.inject.Named; -import javax.inject.Singleton; - -import dagger.Module; -import dagger.Provides; -import io.rx_cache2.internal.RxCache; -import io.victoralbertos.jolyglot.GsonSpeaker; -import me.jessyan.rxerrorhandler.core.RxErrorHandler; -import me.jessyan.rxerrorhandler.handler.listener.ResponseErrorListener; -import okhttp3.HttpUrl; -import okhttp3.Interceptor; -import okhttp3.OkHttpClient; -import okhttp3.Response; -import retrofit2.Retrofit; -import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; -import retrofit2.converter.gson.GsonConverterFactory; - -/** - * ================================================ - * 提供一些三方库客户端实例的 {@link Module} - *

- * Created by JessYan on 2016/3/14. - * Contact me - * Follow me - * ================================================ - */ -@Module -public class ClientModule { - private static final int TIME_OUT = 10; - - - /** - * 提供 {@link Retrofit} - * - * @param builder - * @param client - * @param httpUrl - * @return - * @author: jess - * @date 8/30/16 1:15 PM - */ - @Singleton - @Provides - Retrofit provideRetrofit(Application application, @Nullable RetrofitConfiguration configuration, Retrofit.Builder builder, OkHttpClient client - , HttpUrl httpUrl, Gson gson) { - builder - .baseUrl(httpUrl)//域名 - .client(client);//设置okhttp - - if (configuration != null) - configuration.configRetrofit(application, builder); - - builder - .addCallAdapterFactory(RxJava2CallAdapterFactory.create())//使用 Rxjava - .addConverterFactory(GsonConverterFactory.create(gson));//使用 Gson - return builder.build(); - } - - /** - * 提供 {@link OkHttpClient} - * - * @param builder - * @return - */ - @Singleton - @Provides - OkHttpClient provideClient(Application application, @Nullable OkhttpConfiguration configuration, OkHttpClient.Builder builder, Interceptor intercept - , @Nullable List interceptors, @Nullable GlobalHttpHandler handler) { - builder - .connectTimeout(TIME_OUT, TimeUnit.SECONDS) - .readTimeout(TIME_OUT, TimeUnit.SECONDS) - .addNetworkInterceptor(intercept); - - if (handler != null) - builder.addInterceptor(new Interceptor() { - @Override - public Response intercept(Chain chain) throws IOException { - return chain.proceed(handler.onHttpRequestBefore(chain, chain.request())); - } - }); - - if (interceptors != null) {//如果外部提供了interceptor的集合则遍历添加 - for (Interceptor interceptor : interceptors) { - builder.addInterceptor(interceptor); - } - } - - if (configuration != null) - configuration.configOkhttp(application, builder); - return builder.build(); - } - - - @Singleton - @Provides - Retrofit.Builder provideRetrofitBuilder() { - return new Retrofit.Builder(); - } - - - @Singleton - @Provides - OkHttpClient.Builder provideClientBuilder() { - return new OkHttpClient.Builder(); - } - - - @Singleton - @Provides - Interceptor provideInterceptor(RequestInterceptor intercept) { - return intercept;//打印请求信息的拦截器 - } - - - /** - * 提供 {@link RxCache} - * - * @param cacheDirectory RxCache缓存路径 - * @return - */ - @Singleton - @Provides - RxCache provideRxCache(Application application, @Nullable RxCacheConfiguration configuration, @Named("RxCacheDirectory") File cacheDirectory) { - RxCache.Builder builder = new RxCache.Builder(); - RxCache rxCache = null; - if (configuration != null) { - rxCache = configuration.configRxCache(application, builder); - } - if (rxCache != null) return rxCache; - return builder - .persistence(cacheDirectory, new GsonSpeaker()); - } - - /** - * 需要单独给 {@link RxCache} 提供缓存路径 - * - * @param cacheDir - * @return - */ - @Singleton - @Provides - @Named("RxCacheDirectory") - File provideRxCacheDirectory(File cacheDir) { - File cacheDirectory = new File(cacheDir, "RxCache"); - return DataHelper.makeDirs(cacheDirectory); - } - - /** - * 提供处理 RxJava 错误的管理器 - * - * @return - */ - @Singleton - @Provides - RxErrorHandler proRxErrorHandler(Application application, ResponseErrorListener listener) { - return RxErrorHandler - .builder() - .with(application) - .responseErrorListener(listener) - .build(); - } - - public interface RetrofitConfiguration { - void configRetrofit(Context context, Retrofit.Builder builder); - } - - public interface OkhttpConfiguration { - void configOkhttp(Context context, OkHttpClient.Builder builder); - } - - public interface RxCacheConfiguration { - /** - * 若想自定义 RxCache 的缓存文件夹或者解析方式, 如改成 fastjson - * 请 {@code return rxCacheBuilder.persistence(cacheDirectory, new FastJsonSpeaker());}, 否则请 {@code return null;} - * - * @param context - * @param builder - * @return - */ - RxCache configRxCache(Context context, RxCache.Builder builder); - } -} +/** + * Copyright 2017 JessYan + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jess.arms.di.module; + +import android.app.Application; +import android.content.Context; +import android.support.annotation.Nullable; + +import com.google.gson.Gson; +import com.jess.arms.http.GlobalHttpHandler; +import com.jess.arms.http.RequestInterceptor; +import com.jess.arms.utils.DataHelper; + +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import javax.inject.Named; +import javax.inject.Singleton; + +import dagger.Module; +import dagger.Provides; +import io.rx_cache2.internal.RxCache; +import io.victoralbertos.jolyglot.GsonSpeaker; +import me.jessyan.rxerrorhandler.core.RxErrorHandler; +import me.jessyan.rxerrorhandler.handler.listener.ResponseErrorListener; +import okhttp3.HttpUrl; +import okhttp3.Interceptor; +import okhttp3.OkHttpClient; +import okhttp3.Response; +import retrofit2.Retrofit; +import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; +import retrofit2.converter.gson.GsonConverterFactory; + +/** + * ================================================ + * 提供一些三方库客户端实例的 {@link Module} + *

+ * Created by JessYan on 2016/3/14. + * Contact me + * Follow me + * ================================================ + */ +@Module +public class ClientModule { + private static final int TIME_OUT = 10; + + + /** + * 提供 {@link Retrofit} + * + * @param builder + * @param client + * @param httpUrl + * @return + * @author: jess + * @date 8/30/16 1:15 PM + */ + @Singleton + @Provides + Retrofit provideRetrofit(Application application, @Nullable RetrofitConfiguration configuration, Retrofit.Builder builder, OkHttpClient client + , HttpUrl httpUrl, Gson gson) { + builder + .baseUrl(httpUrl)//域名 + .client(client);//设置okhttp + + if (configuration != null) + configuration.configRetrofit(application, builder); + + builder + .addCallAdapterFactory(RxJava2CallAdapterFactory.create())//使用 Rxjava + .addConverterFactory(GsonConverterFactory.create(gson));//使用 Gson + return builder.build(); + } + + /** + * 提供 {@link OkHttpClient} + * + * @param builder + * @return + */ + @Singleton + @Provides + OkHttpClient provideClient(Application application, @Nullable OkhttpConfiguration configuration, OkHttpClient.Builder builder, Interceptor intercept + , @Nullable List interceptors, @Nullable GlobalHttpHandler handler) { + builder + .connectTimeout(TIME_OUT, TimeUnit.SECONDS) + .readTimeout(TIME_OUT, TimeUnit.SECONDS) + .addNetworkInterceptor(intercept); + + if (handler != null) + builder.addInterceptor(new Interceptor() { + @Override + public Response intercept(Chain chain) throws IOException { + return chain.proceed(handler.onHttpRequestBefore(chain, chain.request())); + } + }); + + if (interceptors != null) {//如果外部提供了interceptor的集合则遍历添加 + for (Interceptor interceptor : interceptors) { + builder.addInterceptor(interceptor); + } + } + + if (configuration != null) + configuration.configOkhttp(application, builder); + return builder.build(); + } + + + @Singleton + @Provides + Retrofit.Builder provideRetrofitBuilder() { + return new Retrofit.Builder(); + } + + + @Singleton + @Provides + OkHttpClient.Builder provideClientBuilder() { + return new OkHttpClient.Builder(); + } + + + @Singleton + @Provides + Interceptor provideInterceptor(RequestInterceptor intercept) { + return intercept;//打印请求信息的拦截器 + } + + + /** + * 提供 {@link RxCache} + * + * @param cacheDirectory RxCache缓存路径 + * @return + */ + @Singleton + @Provides + RxCache provideRxCache(Application application, @Nullable RxCacheConfiguration configuration, @Named("RxCacheDirectory") File cacheDirectory) { + RxCache.Builder builder = new RxCache.Builder(); + RxCache rxCache = null; + if (configuration != null) { + rxCache = configuration.configRxCache(application, builder); + } + if (rxCache != null) return rxCache; + return builder + .persistence(cacheDirectory, new GsonSpeaker()); + } + + /** + * 需要单独给 {@link RxCache} 提供缓存路径 + * + * @param cacheDir + * @return + */ + @Singleton + @Provides + @Named("RxCacheDirectory") + File provideRxCacheDirectory(File cacheDir) { + File cacheDirectory = new File(cacheDir, "RxCache"); + return DataHelper.makeDirs(cacheDirectory); + } + + /** + * 提供处理 RxJava 错误的管理器 + * + * @return + */ + @Singleton + @Provides + RxErrorHandler proRxErrorHandler(Application application, ResponseErrorListener listener) { + return RxErrorHandler + .builder() + .with(application) + .responseErrorListener(listener) + .build(); + } + + public interface RetrofitConfiguration { + void configRetrofit(Context context, Retrofit.Builder builder); + } + + public interface OkhttpConfiguration { + void configOkhttp(Context context, OkHttpClient.Builder builder); + } + + public interface RxCacheConfiguration { + /** + * 若想自定义 RxCache 的缓存文件夹或者解析方式, 如改成 fastjson + * 请 {@code return rxCacheBuilder.persistence(cacheDirectory, new FastJsonSpeaker());}, 否则请 {@code return null;} + * + * @param context + * @param builder + * @return + */ + RxCache configRxCache(Context context, RxCache.Builder builder); + } +} diff --git a/arms/src/main/java/com/jess/arms/di/module/GlobalConfigModule.java b/arms/src/main/java/com/jess/arms/di/module/GlobalConfigModule.java index 8091525..11a1161 100644 --- a/arms/src/main/java/com/jess/arms/di/module/GlobalConfigModule.java +++ b/arms/src/main/java/com/jess/arms/di/module/GlobalConfigModule.java @@ -1,319 +1,319 @@ -/** - * Copyright 2017 JessYan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.jess.arms.di.module; - -import android.app.Application; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.text.TextUtils; - -import com.bumptech.glide.Glide; -import com.jess.arms.http.BaseUrl; -import com.jess.arms.http.GlobalHttpHandler; -import com.jess.arms.http.RequestInterceptor; -import com.jess.arms.integration.cache.Cache; -import com.jess.arms.integration.cache.CacheType; -import com.jess.arms.integration.cache.LruCache; -import com.jess.arms.utils.DataHelper; -import com.jess.arms.widget.imageloader.BaseImageLoaderStrategy; -import com.jess.arms.widget.imageloader.glide.GlideImageLoaderStrategy; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -import javax.inject.Singleton; - -import dagger.Module; -import dagger.Provides; -import me.jessyan.rxerrorhandler.handler.listener.ResponseErrorListener; -import okhttp3.HttpUrl; -import okhttp3.Interceptor; - -/** - * ================================================ - * 框架独创的建造者模式 {@link Module},可向框架中注入外部配置的自定义参数 - * - * @see GlobalConfigModule Wiki 官方文档 - * Created by JessYan on 2016/3/14. - * Contact me - * Follow me - * ================================================ - */ -@Module -public class GlobalConfigModule { - private HttpUrl mApiUrl; - private BaseUrl mBaseUrl; - private BaseImageLoaderStrategy mLoaderStrategy; - private GlobalHttpHandler mHandler; - private List mInterceptors; - private ResponseErrorListener mErrorListener; - private File mCacheFile; - private ClientModule.RetrofitConfiguration mRetrofitConfiguration; - private ClientModule.OkhttpConfiguration mOkhttpConfiguration; - private ClientModule.RxCacheConfiguration mRxCacheConfiguration; - private AppModule.GsonConfiguration mGsonConfiguration; - private RequestInterceptor.Level mPrintHttpLogLevel; - private Cache.Factory mCacheFactory; - - private GlobalConfigModule(Builder builder) { - this.mApiUrl = builder.apiUrl; - this.mBaseUrl = builder.baseUrl; - this.mLoaderStrategy = builder.loaderStrategy; - this.mHandler = builder.handler; - this.mInterceptors = builder.interceptors; - this.mErrorListener = builder.responseErrorListener; - this.mCacheFile = builder.cacheFile; - this.mRetrofitConfiguration = builder.retrofitConfiguration; - this.mOkhttpConfiguration = builder.okhttpConfiguration; - this.mRxCacheConfiguration = builder.rxCacheConfiguration; - this.mGsonConfiguration = builder.gsonConfiguration; - this.mPrintHttpLogLevel = builder.printHttpLogLevel; - this.mCacheFactory = builder.cacheFactory; - } - - public static Builder builder() { - return new Builder(); - } - - - @Singleton - @Provides - @Nullable - List provideInterceptors() { - return mInterceptors; - } - - - /** - * 提供 BaseUrl,默认使用 <"https://api.github.com/"> - * - * @return - */ - @Singleton - @Provides - HttpUrl provideBaseUrl() { - if (mBaseUrl != null) { - HttpUrl httpUrl = mBaseUrl.url(); - if (httpUrl != null) { - return httpUrl; - } - } - return mApiUrl == null ? HttpUrl.parse("https://api.github.com/") : mApiUrl; - } - - - /** - * 提供图片加载框架,默认使用 {@link Glide} - * - * @return - */ - @Singleton - @Provides - BaseImageLoaderStrategy provideImageLoaderStrategy() { - return mLoaderStrategy == null ? new GlideImageLoaderStrategy() : mLoaderStrategy; - } - - - /** - * 提供处理 Http 请求和响应结果的处理类 - * - * @return - */ - @Singleton - @Provides - @Nullable - GlobalHttpHandler provideGlobalHttpHandler() { - return mHandler; - } - - - /** - * 提供缓存文件 - */ - @Singleton - @Provides - File provideCacheFile(Application application) { - return mCacheFile == null ? DataHelper.getCacheFile(application) : mCacheFile; - } - - - /** - * 提供处理 RxJava 错误的管理器的回调 - * - * @return - */ - @Singleton - @Provides - ResponseErrorListener provideResponseErrorListener() { - return mErrorListener == null ? ResponseErrorListener.EMPTY : mErrorListener; - } - - - @Singleton - @Provides - @Nullable - ClientModule.RetrofitConfiguration provideRetrofitConfiguration() { - return mRetrofitConfiguration; - } - - @Singleton - @Provides - @Nullable - ClientModule.OkhttpConfiguration provideOkhttpConfiguration() { - return mOkhttpConfiguration; - } - - @Singleton - @Provides - @Nullable - ClientModule.RxCacheConfiguration provideRxCacheConfiguration() { - return mRxCacheConfiguration; - } - - @Singleton - @Provides - @Nullable - AppModule.GsonConfiguration provideGsonConfiguration() { - return mGsonConfiguration; - } - - @Singleton - @Provides - @Nullable - RequestInterceptor.Level providePrintHttpLogLevel() { - return mPrintHttpLogLevel; - } - - @Singleton - @Provides - Cache.Factory provideCacheFactory(Application application) { - return mCacheFactory == null ? new Cache.Factory() { - @NonNull - @Override - public Cache build(CacheType type) { - //若想自定义 LruCache 的 size, 或者不想使用 LruCache , 想使用自己自定义的策略 - //并使用 GlobalConfigModule.Builder#cacheFactory() 扩展 - return new LruCache(type.calculateCacheSize(application)); - } - } : mCacheFactory; - } - - - public static final class Builder { - private HttpUrl apiUrl; - private BaseUrl baseUrl; - private BaseImageLoaderStrategy loaderStrategy; - private GlobalHttpHandler handler; - private List interceptors; - private ResponseErrorListener responseErrorListener; - private File cacheFile; - private ClientModule.RetrofitConfiguration retrofitConfiguration; - private ClientModule.OkhttpConfiguration okhttpConfiguration; - private ClientModule.RxCacheConfiguration rxCacheConfiguration; - private AppModule.GsonConfiguration gsonConfiguration; - private RequestInterceptor.Level printHttpLogLevel; - private Cache.Factory cacheFactory; - - private Builder() { - } - - public Builder baseurl(String baseUrl) {//基础url - if (TextUtils.isEmpty(baseUrl)) { - throw new NullPointerException("BaseUrl can not be empty"); - } - this.apiUrl = HttpUrl.parse(baseUrl); - return this; - } - - public Builder baseurl(BaseUrl baseUrl) { - if (baseUrl == null) { - throw new NullPointerException("BaseUrl can not be null"); - } - this.baseUrl = baseUrl; - return this; - } - - public Builder imageLoaderStrategy(BaseImageLoaderStrategy loaderStrategy) {//用来请求网络图片 - this.loaderStrategy = loaderStrategy; - return this; - } - - public Builder globalHttpHandler(GlobalHttpHandler handler) {//用来处理http响应结果 - this.handler = handler; - return this; - } - - public Builder addInterceptor(Interceptor interceptor) {//动态添加任意个interceptor - if (interceptors == null) - interceptors = new ArrayList<>(); - this.interceptors.add(interceptor); - return this; - } - - - public Builder responseErrorListener(ResponseErrorListener listener) {//处理所有RxJava的onError逻辑 - this.responseErrorListener = listener; - return this; - } - - - public Builder cacheFile(File cacheFile) { - this.cacheFile = cacheFile; - return this; - } - - public Builder retrofitConfiguration(ClientModule.RetrofitConfiguration retrofitConfiguration) { - this.retrofitConfiguration = retrofitConfiguration; - return this; - } - - public Builder okhttpConfiguration(ClientModule.OkhttpConfiguration okhttpConfiguration) { - this.okhttpConfiguration = okhttpConfiguration; - return this; - } - - public Builder rxCacheConfiguration(ClientModule.RxCacheConfiguration rxCacheConfiguration) { - this.rxCacheConfiguration = rxCacheConfiguration; - return this; - } - - public Builder gsonConfiguration(AppModule.GsonConfiguration gsonConfiguration) { - this.gsonConfiguration = gsonConfiguration; - return this; - } - - public Builder printHttpLogLevel(RequestInterceptor.Level printHttpLogLevel) { //是否让框架打印 Http 的请求和响应信息 - if (printHttpLogLevel == null) - throw new NullPointerException("printHttpLogLevel == null. Use RequestInterceptor.Level.NONE instead."); - this.printHttpLogLevel = printHttpLogLevel; - return this; - } - - public Builder cacheFactory(Cache.Factory cacheFactory) { - this.cacheFactory = cacheFactory; - return this; - } - - public GlobalConfigModule build() { - return new GlobalConfigModule(this); - } - - - } - - -} +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jess.arms.di.module; + +import android.app.Application; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.text.TextUtils; + +import com.bumptech.glide.Glide; +import com.jess.arms.http.BaseUrl; +import com.jess.arms.http.GlobalHttpHandler; +import com.jess.arms.http.RequestInterceptor; +import com.jess.arms.http.imageloader.BaseImageLoaderStrategy; +import com.jess.arms.http.imageloader.glide.GlideImageLoaderStrategy; +import com.jess.arms.integration.cache.Cache; +import com.jess.arms.integration.cache.CacheType; +import com.jess.arms.integration.cache.LruCache; +import com.jess.arms.utils.DataHelper; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import javax.inject.Singleton; + +import dagger.Module; +import dagger.Provides; +import me.jessyan.rxerrorhandler.handler.listener.ResponseErrorListener; +import okhttp3.HttpUrl; +import okhttp3.Interceptor; + +/** + * ================================================ + * 框架独创的建造者模式 {@link Module},可向框架中注入外部配置的自定义参数 + * + * @see GlobalConfigModule Wiki 官方文档 + * Created by JessYan on 2016/3/14. + * Contact me + * Follow me + * ================================================ + */ +@Module +public class GlobalConfigModule { + private HttpUrl mApiUrl; + private BaseUrl mBaseUrl; + private BaseImageLoaderStrategy mLoaderStrategy; + private GlobalHttpHandler mHandler; + private List mInterceptors; + private ResponseErrorListener mErrorListener; + private File mCacheFile; + private ClientModule.RetrofitConfiguration mRetrofitConfiguration; + private ClientModule.OkhttpConfiguration mOkhttpConfiguration; + private ClientModule.RxCacheConfiguration mRxCacheConfiguration; + private AppModule.GsonConfiguration mGsonConfiguration; + private RequestInterceptor.Level mPrintHttpLogLevel; + private Cache.Factory mCacheFactory; + + private GlobalConfigModule(Builder builder) { + this.mApiUrl = builder.apiUrl; + this.mBaseUrl = builder.baseUrl; + this.mLoaderStrategy = builder.loaderStrategy; + this.mHandler = builder.handler; + this.mInterceptors = builder.interceptors; + this.mErrorListener = builder.responseErrorListener; + this.mCacheFile = builder.cacheFile; + this.mRetrofitConfiguration = builder.retrofitConfiguration; + this.mOkhttpConfiguration = builder.okhttpConfiguration; + this.mRxCacheConfiguration = builder.rxCacheConfiguration; + this.mGsonConfiguration = builder.gsonConfiguration; + this.mPrintHttpLogLevel = builder.printHttpLogLevel; + this.mCacheFactory = builder.cacheFactory; + } + + public static Builder builder() { + return new Builder(); + } + + + @Singleton + @Provides + @Nullable + List provideInterceptors() { + return mInterceptors; + } + + + /** + * 提供 BaseUrl,默认使用 <"https://api.github.com/"> + * + * @return + */ + @Singleton + @Provides + HttpUrl provideBaseUrl() { + if (mBaseUrl != null) { + HttpUrl httpUrl = mBaseUrl.url(); + if (httpUrl != null) { + return httpUrl; + } + } + return mApiUrl == null ? HttpUrl.parse("https://api.github.com/") : mApiUrl; + } + + + /** + * 提供图片加载框架,默认使用 {@link Glide} + * + * @return + */ + @Singleton + @Provides + BaseImageLoaderStrategy provideImageLoaderStrategy() { + return mLoaderStrategy == null ? new GlideImageLoaderStrategy() : mLoaderStrategy; + } + + + /** + * 提供处理 Http 请求和响应结果的处理类 + * + * @return + */ + @Singleton + @Provides + @Nullable + GlobalHttpHandler provideGlobalHttpHandler() { + return mHandler; + } + + + /** + * 提供缓存文件 + */ + @Singleton + @Provides + File provideCacheFile(Application application) { + return mCacheFile == null ? DataHelper.getCacheFile(application) : mCacheFile; + } + + + /** + * 提供处理 RxJava 错误的管理器的回调 + * + * @return + */ + @Singleton + @Provides + ResponseErrorListener provideResponseErrorListener() { + return mErrorListener == null ? ResponseErrorListener.EMPTY : mErrorListener; + } + + + @Singleton + @Provides + @Nullable + ClientModule.RetrofitConfiguration provideRetrofitConfiguration() { + return mRetrofitConfiguration; + } + + @Singleton + @Provides + @Nullable + ClientModule.OkhttpConfiguration provideOkhttpConfiguration() { + return mOkhttpConfiguration; + } + + @Singleton + @Provides + @Nullable + ClientModule.RxCacheConfiguration provideRxCacheConfiguration() { + return mRxCacheConfiguration; + } + + @Singleton + @Provides + @Nullable + AppModule.GsonConfiguration provideGsonConfiguration() { + return mGsonConfiguration; + } + + @Singleton + @Provides + @Nullable + RequestInterceptor.Level providePrintHttpLogLevel() { + return mPrintHttpLogLevel; + } + + @Singleton + @Provides + Cache.Factory provideCacheFactory(Application application) { + return mCacheFactory == null ? new Cache.Factory() { + @NonNull + @Override + public Cache build(CacheType type) { + //若想自定义 LruCache 的 size, 或者不想使用 LruCache , 想使用自己自定义的策略 + //并使用 GlobalConfigModule.Builder#cacheFactory() 扩展 + return new LruCache(type.calculateCacheSize(application)); + } + } : mCacheFactory; + } + + + public static final class Builder { + private HttpUrl apiUrl; + private BaseUrl baseUrl; + private BaseImageLoaderStrategy loaderStrategy; + private GlobalHttpHandler handler; + private List interceptors; + private ResponseErrorListener responseErrorListener; + private File cacheFile; + private ClientModule.RetrofitConfiguration retrofitConfiguration; + private ClientModule.OkhttpConfiguration okhttpConfiguration; + private ClientModule.RxCacheConfiguration rxCacheConfiguration; + private AppModule.GsonConfiguration gsonConfiguration; + private RequestInterceptor.Level printHttpLogLevel; + private Cache.Factory cacheFactory; + + private Builder() { + } + + public Builder baseurl(String baseUrl) {//基础url + if (TextUtils.isEmpty(baseUrl)) { + throw new NullPointerException("BaseUrl can not be empty"); + } + this.apiUrl = HttpUrl.parse(baseUrl); + return this; + } + + public Builder baseurl(BaseUrl baseUrl) { + if (baseUrl == null) { + throw new NullPointerException("BaseUrl can not be null"); + } + this.baseUrl = baseUrl; + return this; + } + + public Builder imageLoaderStrategy(BaseImageLoaderStrategy loaderStrategy) {//用来请求网络图片 + this.loaderStrategy = loaderStrategy; + return this; + } + + public Builder globalHttpHandler(GlobalHttpHandler handler) {//用来处理http响应结果 + this.handler = handler; + return this; + } + + public Builder addInterceptor(Interceptor interceptor) {//动态添加任意个interceptor + if (interceptors == null) + interceptors = new ArrayList<>(); + this.interceptors.add(interceptor); + return this; + } + + + public Builder responseErrorListener(ResponseErrorListener listener) {//处理所有RxJava的onError逻辑 + this.responseErrorListener = listener; + return this; + } + + + public Builder cacheFile(File cacheFile) { + this.cacheFile = cacheFile; + return this; + } + + public Builder retrofitConfiguration(ClientModule.RetrofitConfiguration retrofitConfiguration) { + this.retrofitConfiguration = retrofitConfiguration; + return this; + } + + public Builder okhttpConfiguration(ClientModule.OkhttpConfiguration okhttpConfiguration) { + this.okhttpConfiguration = okhttpConfiguration; + return this; + } + + public Builder rxCacheConfiguration(ClientModule.RxCacheConfiguration rxCacheConfiguration) { + this.rxCacheConfiguration = rxCacheConfiguration; + return this; + } + + public Builder gsonConfiguration(AppModule.GsonConfiguration gsonConfiguration) { + this.gsonConfiguration = gsonConfiguration; + return this; + } + + public Builder printHttpLogLevel(RequestInterceptor.Level printHttpLogLevel) { //是否让框架打印 Http 的请求和响应信息 + if (printHttpLogLevel == null) + throw new NullPointerException("printHttpLogLevel == null. Use RequestInterceptor.Level.NONE instead."); + this.printHttpLogLevel = printHttpLogLevel; + return this; + } + + public Builder cacheFactory(Cache.Factory cacheFactory) { + this.cacheFactory = cacheFactory; + return this; + } + + public GlobalConfigModule build() { + return new GlobalConfigModule(this); + } + + + } + + +} diff --git a/arms/src/main/java/com/jess/arms/di/scope/ActivityScope.java b/arms/src/main/java/com/jess/arms/di/scope/ActivityScope.java index dee1f25..bc77729 100644 --- a/arms/src/main/java/com/jess/arms/di/scope/ActivityScope.java +++ b/arms/src/main/java/com/jess/arms/di/scope/ActivityScope.java @@ -13,8 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.di.scope; +import java.lang.annotation.Documented; import java.lang.annotation.Retention; import javax.inject.Scope; @@ -27,5 +43,6 @@ * correct component. */ @Scope +@Documented @Retention(RUNTIME) public @interface ActivityScope {} diff --git a/arms/src/main/java/com/jess/arms/di/scope/FragmentScope.java b/arms/src/main/java/com/jess/arms/di/scope/FragmentScope.java index f91b00d..7d53052 100644 --- a/arms/src/main/java/com/jess/arms/di/scope/FragmentScope.java +++ b/arms/src/main/java/com/jess/arms/di/scope/FragmentScope.java @@ -13,8 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.di.scope; +import java.lang.annotation.Documented; import java.lang.annotation.Retention; import javax.inject.Scope; @@ -23,9 +39,10 @@ /** * A scoping annotation to permit objects whose lifetime should - * conform to the life of the activity to be memorized in the + * conform to the life of the fragment to be memorized in the * correct component. */ @Scope +@Documented @Retention(RUNTIME) public @interface FragmentScope {} diff --git a/arms/src/main/java/com/jess/arms/http/BaseUrl.java b/arms/src/main/java/com/jess/arms/http/BaseUrl.java index d78fea2..7d90642 100644 --- a/arms/src/main/java/com/jess/arms/http/BaseUrl.java +++ b/arms/src/main/java/com/jess/arms/http/BaseUrl.java @@ -1,16 +1,35 @@ +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.http; import okhttp3.HttpUrl; /** - * Created by jess on 11/07/2017 14:58 - * Contact with jess.yan.effort@gmail.com + * ================================================ + * 针对于 BaseUrl 在 App 启动时不能确定,需要请求服务器接口动态获取的应用场景 + *

+ * Created by JessYan on 11/07/2017 14:58 + * Contact me + * Follow me + * ================================================ */ - public interface BaseUrl { /** - * 针对于 BaseUrl 在 App 启动时不能确定,需要请求服务器接口动态获取的应用场景 - * 在调用 Retrofit 接口之前,使用 Okhttp 或其他方式,请求到正确的 BaseUrl 并通过此方法返回 + * 在调用 Retrofit API 接口之前,使用 Okhttp 或其他方式,请求到正确的 BaseUrl 并通过此方法返回 + * * @return */ HttpUrl url(); diff --git a/arms/src/main/java/com/jess/arms/http/GlobalHttpHandler.java b/arms/src/main/java/com/jess/arms/http/GlobalHttpHandler.java index 61b4264..7a71fef 100644 --- a/arms/src/main/java/com/jess/arms/http/GlobalHttpHandler.java +++ b/arms/src/main/java/com/jess/arms/http/GlobalHttpHandler.java @@ -1,18 +1,43 @@ +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.http; +import com.jess.arms.di.module.GlobalConfigModule; + import okhttp3.Interceptor; import okhttp3.Request; import okhttp3.Response; /** - * Created by jess on 8/30/16 17:47 - * Contact with jess.yan.effort@gmail.com + * ================================================ + * 处理 Http 请求和响应结果的处理类 + * 使用 {@link GlobalConfigModule.Builder#globalHttpHandler(GlobalHttpHandler)} 方法配置 + * + * @see GlobalHttpHandler Wiki 官方文档 + * Created by JessYan on 8/30/16 17:47 + * Contact me + * Follow me + * ================================================ */ public interface GlobalHttpHandler { Response onHttpResultResponse(String httpResult, Interceptor.Chain chain, Response response); Request onHttpRequestBefore(Interceptor.Chain chain, Request request); + //空实现 GlobalHttpHandler EMPTY = new GlobalHttpHandler() { @Override public Response onHttpResultResponse(String httpResult, Interceptor.Chain chain, Response response) { diff --git a/arms/src/main/java/com/jess/arms/http/OkHttpStreamFetcher.java b/arms/src/main/java/com/jess/arms/http/OkHttpStreamFetcher.java index 8331281..da89d0e 100644 --- a/arms/src/main/java/com/jess/arms/http/OkHttpStreamFetcher.java +++ b/arms/src/main/java/com/jess/arms/http/OkHttpStreamFetcher.java @@ -1,9 +1,31 @@ +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.http; +import android.os.Build; +import android.support.annotation.NonNull; +import android.util.Log; + import com.bumptech.glide.Priority; +import com.bumptech.glide.load.DataSource; +import com.bumptech.glide.load.HttpException; import com.bumptech.glide.load.data.DataFetcher; import com.bumptech.glide.load.model.GlideUrl; import com.bumptech.glide.util.ContentLengthInputStream; +import com.bumptech.glide.util.Synthetic; import java.io.IOException; import java.io.InputStream; @@ -15,16 +37,17 @@ import okhttp3.ResponseBody; /** - * Created by jess on 10/04/2017 17:38 - * Contact with jess.yan.effort@gmail.com - * Fetches an {@link InputStream} using the okhttp3library. + * Fetches an {@link InputStream} using the okhttp library. */ -public class OkHttpStreamFetcher implements DataFetcher { +public class OkHttpStreamFetcher implements DataFetcher, + okhttp3.Callback { + private static final String TAG = "OkHttpFetcher"; private final Call.Factory client; private final GlideUrl url; - private InputStream stream; - private ResponseBody responseBody; + @Synthetic InputStream stream; + @Synthetic ResponseBody responseBody; private volatile Call call; + private DataCallback callback; public OkHttpStreamFetcher(Call.Factory client, GlideUrl url) { this.client = client; @@ -32,26 +55,52 @@ public OkHttpStreamFetcher(Call.Factory client, GlideUrl url) { } @Override - public InputStream loadData(Priority priority) throws Exception { + public void loadData(Priority priority, final DataCallback callback) { Request.Builder requestBuilder = new Request.Builder().url(url.toStringUrl()); - for (Map.Entry headerEntry : url.getHeaders().entrySet()) { String key = headerEntry.getKey(); requestBuilder.addHeader(key, headerEntry.getValue()); } Request request = requestBuilder.build(); + this.callback = callback; - Response response; call = client.newCall(request); - response = call.execute(); - responseBody = response.body(); - if (!response.isSuccessful()) { - throw new IOException("Request failed with code: " + response.code()); + if (Build.VERSION.SDK_INT != Build.VERSION_CODES.O) { + call.enqueue(this); + } else { + try { + // Calling execute instead of enqueue is a workaround for #2355, where okhttp throws a + // ClassCastException on O. + onResponse(call, call.execute()); + } catch (IOException e) { + onFailure(call, e); + } catch (ClassCastException e) { + // It's not clear that this catch is necessary, the error may only occur even on O if + // enqueue is used. + onFailure(call, new IOException("Workaround for framework bug on O", e)); + } + } + } + + @Override + public void onFailure(Call call, IOException e) { + if (Log.isLoggable(TAG, Log.DEBUG)) { + Log.d(TAG, "OkHttp failed to obtain result", e); } - long contentLength = responseBody.contentLength(); - stream = ContentLengthInputStream.obtain(responseBody.byteStream(), contentLength); - return stream; + callback.onLoadFailed(e); + } + + @Override + public void onResponse(Call call, Response response) throws IOException { + responseBody = response.body(); + if (response.isSuccessful()) { + long contentLength = responseBody.contentLength(); + stream = ContentLengthInputStream.obtain(responseBody.byteStream(), contentLength); + callback.onDataReady(stream); + } else { + callback.onLoadFailed(new HttpException(response.message(), response.code())); + } } @Override @@ -66,11 +115,7 @@ public void cleanup() { if (responseBody != null) { responseBody.close(); } - } - - @Override - public String getId() { - return url.getCacheKey(); + callback = null; } @Override @@ -80,4 +125,17 @@ public void cancel() { local.cancel(); } } + + @NonNull + @Override + public Class getDataClass() { + return InputStream.class; + } + + @NonNull + @Override + public DataSource getDataSource() { + return DataSource.REMOTE; + } } + diff --git a/arms/src/main/java/com/jess/arms/http/OkHttpUrlLoader.java b/arms/src/main/java/com/jess/arms/http/OkHttpUrlLoader.java index 143a8b8..fa717b5 100644 --- a/arms/src/main/java/com/jess/arms/http/OkHttpUrlLoader.java +++ b/arms/src/main/java/com/jess/arms/http/OkHttpUrlLoader.java @@ -1,12 +1,25 @@ +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.http; -import android.content.Context; - -import com.bumptech.glide.load.data.DataFetcher; -import com.bumptech.glide.load.model.GenericLoaderFactory; +import com.bumptech.glide.load.Options; import com.bumptech.glide.load.model.GlideUrl; import com.bumptech.glide.load.model.ModelLoader; import com.bumptech.glide.load.model.ModelLoaderFactory; +import com.bumptech.glide.load.model.MultiModelLoaderFactory; import java.io.InputStream; @@ -14,8 +27,6 @@ import okhttp3.OkHttpClient; /** - * Created by jess on 10/04/2017 17:37 - * Contact with jess.yan.effort@gmail.com * A simple model loader for fetching media over http/https using OkHttp. */ public class OkHttpUrlLoader implements ModelLoader { @@ -27,8 +38,14 @@ public OkHttpUrlLoader(Call.Factory client) { } @Override - public DataFetcher getResourceFetcher(GlideUrl model, int width, int height) { - return new OkHttpStreamFetcher(client, model); + public boolean handles(GlideUrl url) { + return true; + } + + @Override + public LoadData buildLoadData(GlideUrl model, int width, int height, + Options options) { + return new LoadData<>(model, new OkHttpStreamFetcher(client, model)); } /** @@ -38,6 +55,17 @@ public static class Factory implements ModelLoaderFactory private static volatile Call.Factory internalClient; private Call.Factory client; + private static Call.Factory getInternalClient() { + if (internalClient == null) { + synchronized (Factory.class) { + if (internalClient == null) { + internalClient = new OkHttpClient(); + } + } + } + return internalClient; + } + /** * Constructor for a new Factory that runs requests using a static singleton client. */ @@ -54,19 +82,8 @@ public Factory(Call.Factory client) { this.client = client; } - private static Call.Factory getInternalClient() { - if (internalClient == null) { - synchronized (Factory.class) { - if (internalClient == null) { - internalClient = new OkHttpClient(); - } - } - } - return internalClient; - } - @Override - public ModelLoader build(Context context, GenericLoaderFactory factories) { + public ModelLoader build(MultiModelLoaderFactory multiFactory) { return new OkHttpUrlLoader(client); } diff --git a/arms/src/main/java/com/jess/arms/http/RequestInterceptor.java b/arms/src/main/java/com/jess/arms/http/RequestInterceptor.java index f01dcde..eeb5625 100644 --- a/arms/src/main/java/com/jess/arms/http/RequestInterceptor.java +++ b/arms/src/main/java/com/jess/arms/http/RequestInterceptor.java @@ -1,7 +1,23 @@ +/** + * Copyright 2017 JessYan + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.http; import android.support.annotation.Nullable; +import com.jess.arms.di.module.GlobalConfigModule; import com.jess.arms.utils.CharacterHandler; import com.jess.arms.utils.ZipHelper; @@ -26,8 +42,14 @@ /** - * Created by jess on 7/1/16. - * Contact with jess.yan.effort@gmail.com + * ================================================ + * 解析框架中的网络请求和响应结果,并以日志形式输出,调试神器 + * 可使用 {@link GlobalConfigModule.Builder#printHttpLogLevel(Level)} 控制或关闭日志 + *

+ * Created by JessYan on 7/1/2016. + * Contact me + * Follow me + * ================================================ */ @Singleton public class RequestInterceptor implements Interceptor { @@ -169,6 +191,13 @@ private String parseContent(ResponseBody responseBody, String encoding, Buffer c } } + /** + * 解析请求服务器的请求参数 + * + * @param body + * @return + * @throws UnsupportedEncodingException + */ public static String parseParams(RequestBody body) throws UnsupportedEncodingException { if (isParseable(body.contentType())) { try { @@ -188,6 +217,12 @@ public static String parseParams(RequestBody body) throws UnsupportedEncodingExc return "This params isn't parsed"; } + /** + * 是否可以解析 + * + * @param mediaType + * @return + */ public static boolean isParseable(MediaType mediaType) { if (mediaType == null) return false; return mediaType.toString().toLowerCase().contains("text") diff --git a/arms/src/main/java/com/jess/arms/http/imageloader/BaseImageLoaderStrategy.java b/arms/src/main/java/com/jess/arms/http/imageloader/BaseImageLoaderStrategy.java new file mode 100644 index 0000000..2dee53b --- /dev/null +++ b/arms/src/main/java/com/jess/arms/http/imageloader/BaseImageLoaderStrategy.java @@ -0,0 +1,46 @@ +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jess.arms.http.imageloader; + +import android.content.Context; + +/** + * ================================================ + * 图片加载策略,实现 {@link BaseImageLoaderStrategy} + * 并通过 {@link ImageLoader#setLoadImgStrategy(BaseImageLoaderStrategy)} 配置后,才可进行图片请求 + *

+ * Created by JessYan on 8/5/2016 15:50 + * Contact me + * Follow me + * ================================================ + */ +public interface BaseImageLoaderStrategy { + /** + * 加载图片 + * + * @param ctx + * @param config + */ + void loadImage(Context ctx, T config); + + /** + * 停止加载 + * + * @param ctx + * @param config + */ + void clear(Context ctx, T config); +} diff --git a/arms/src/main/java/com/jess/arms/http/imageloader/ImageConfig.java b/arms/src/main/java/com/jess/arms/http/imageloader/ImageConfig.java new file mode 100644 index 0000000..bf6be95 --- /dev/null +++ b/arms/src/main/java/com/jess/arms/http/imageloader/ImageConfig.java @@ -0,0 +1,52 @@ +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jess.arms.http.imageloader; + +import android.widget.ImageView; + +/** + * ================================================ + * 这里是图片加载配置信息的基类,定义一些所有图片加载框架都可以用的通用参数 + * 每个 {@link BaseImageLoaderStrategy} 应该对应一个 {@link ImageConfig} 实现类 + *

+ * Created by JessYan on 8/5/16 15:19 + * Contact me + * Follow me + * ================================================ + */ +public class ImageConfig { + protected String url; + protected ImageView imageView; + protected int placeholder;//占位符 + protected int errorPic;//错误占位符 + + + public String getUrl() { + return url; + } + + public ImageView getImageView() { + return imageView; + } + + public int getPlaceholder() { + return placeholder; + } + + public int getErrorPic() { + return errorPic; + } +} diff --git a/arms/src/main/java/com/jess/arms/http/imageloader/ImageLoader.java b/arms/src/main/java/com/jess/arms/http/imageloader/ImageLoader.java new file mode 100644 index 0000000..f25e301 --- /dev/null +++ b/arms/src/main/java/com/jess/arms/http/imageloader/ImageLoader.java @@ -0,0 +1,79 @@ +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jess.arms.http.imageloader; + +import android.content.Context; + +import javax.inject.Inject; +import javax.inject.Singleton; + +/** + * ================================================ + * {@link ImageLoader} 使用策略模式和建造者模式,可以动态切换图片请求框架(比如说切换成 Picasso ) + * 当需要切换图片请求框架或图片请求框架升级后变更了 Api 时 + * 这里可以将影响范围降到最低,所以封装 {@link ImageLoader} 是为了屏蔽这个风险 + * + * @see ImageLoader wiki 文档 + * Created by JessYan on 8/5/16 15:57 + * Contact me + * Follow me + * ================================================ + */ +@Singleton +public final class ImageLoader { + private BaseImageLoaderStrategy mStrategy; + + @Inject + public ImageLoader(BaseImageLoaderStrategy strategy) { + setLoadImgStrategy(strategy); + } + + + /** + * 加载图片 + * + * @param context + * @param config + * @param + */ + public void loadImage(Context context, T config) { + this.mStrategy.loadImage(context, config); + } + + /** + * 停止加载或清理缓存 + * + * @param context + * @param config + * @param + */ + public void clear(Context context, T config) { + this.mStrategy.clear(context, config); + } + + /** + * 可在运行时随意切换 {@link BaseImageLoaderStrategy} + * + * @param strategy + */ + public void setLoadImgStrategy(BaseImageLoaderStrategy strategy) { + this.mStrategy = strategy; + } + + public BaseImageLoaderStrategy getLoadImgStrategy() { + return mStrategy; + } +} diff --git a/arms/src/main/java/com/jess/arms/http/imageloader/glide/GlideAppliesOptions.java b/arms/src/main/java/com/jess/arms/http/imageloader/glide/GlideAppliesOptions.java new file mode 100644 index 0000000..2705e7c --- /dev/null +++ b/arms/src/main/java/com/jess/arms/http/imageloader/glide/GlideAppliesOptions.java @@ -0,0 +1,44 @@ +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jess.arms.http.imageloader.glide; + +import android.content.Context; + +import com.bumptech.glide.Glide; +import com.bumptech.glide.GlideBuilder; +import com.jess.arms.http.imageloader.BaseImageLoaderStrategy; + +/** + * ================================================ + * 如果你想具有配置 @{@link Glide} 的权利,则需要让 {@link BaseImageLoaderStrategy} + * 的实现类也必须实现 {@link GlideAppliesOptions} + *

+ * Created by JessYan on 13/08/2017 22:02 + * Contact me + * Follow me + * ================================================ + */ + +public interface GlideAppliesOptions { + + /** + * 配置 @{@link Glide} 的自定义参数,此方法在 @{@link Glide} 初始化时执行(@{@link Glide} 在第一次被调用时初始化),只会执行一次 + * + * @param context + * @param builder {@link GlideBuilder} 此类被用来创建 Glide + */ + void applyGlideOptions(Context context, GlideBuilder builder); +} diff --git a/arms/src/main/java/com/jess/arms/widget/imageloader/glide/GlideCircleTransform.java b/arms/src/main/java/com/jess/arms/http/imageloader/glide/GlideCircleTransform.java similarity index 83% rename from arms/src/main/java/com/jess/arms/widget/imageloader/glide/GlideCircleTransform.java rename to arms/src/main/java/com/jess/arms/http/imageloader/glide/GlideCircleTransform.java index 287c7b2..292c2f9 100644 --- a/arms/src/main/java/com/jess/arms/widget/imageloader/glide/GlideCircleTransform.java +++ b/arms/src/main/java/com/jess/arms/http/imageloader/glide/GlideCircleTransform.java @@ -1,6 +1,5 @@ -package com.jess.arms.widget.imageloader.glide; +package com.jess.arms.http.imageloader.glide; -import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapShader; import android.graphics.Canvas; @@ -9,14 +8,13 @@ import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; import com.bumptech.glide.load.resource.bitmap.BitmapTransformation; +import java.security.MessageDigest; + /** - * Created by Administrator on 2017/8/25 0025. + * Created by Administrator on 2018\1\9 0009. */ public class GlideCircleTransform extends BitmapTransformation { - public GlideCircleTransform(Context context) { - super(context); - } @Override protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) { return circleCrop(pool, toTransform); @@ -46,7 +44,8 @@ private static Bitmap circleCrop(BitmapPool pool, Bitmap source) { return result; } - @Override public String getId() { - return getClass().getName(); + @Override + public void updateDiskCacheKey(MessageDigest messageDigest) { + } } diff --git a/arms/src/main/java/com/jess/arms/http/imageloader/glide/GlideConfiguration.java b/arms/src/main/java/com/jess/arms/http/imageloader/glide/GlideConfiguration.java new file mode 100644 index 0000000..819e221 --- /dev/null +++ b/arms/src/main/java/com/jess/arms/http/imageloader/glide/GlideConfiguration.java @@ -0,0 +1,95 @@ +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jess.arms.http.imageloader.glide; + +import android.content.Context; + +import com.bumptech.glide.Glide; +import com.bumptech.glide.GlideBuilder; +import com.bumptech.glide.Registry; +import com.bumptech.glide.annotation.GlideModule; +import com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool; +import com.bumptech.glide.load.engine.cache.DiskCache; +import com.bumptech.glide.load.engine.cache.DiskLruCacheWrapper; +import com.bumptech.glide.load.engine.cache.LruResourceCache; +import com.bumptech.glide.load.engine.cache.MemorySizeCalculator; +import com.bumptech.glide.load.model.GlideUrl; +import com.bumptech.glide.module.AppGlideModule; +import com.jess.arms.di.component.AppComponent; +import com.jess.arms.http.OkHttpUrlLoader; +import com.jess.arms.http.imageloader.BaseImageLoaderStrategy; +import com.jess.arms.utils.ArmsUtils; +import com.jess.arms.utils.DataHelper; + +import java.io.File; +import java.io.InputStream; + +/** + * ================================================ + * {@link AppGlideModule} 的默认实现类 + * 用于配置缓存文件夹,切换图片请求框架等操作 + *

+ * Created by JessYan on 16/4/15. + * Contact me + * Follow me + * ================================================ + */ +@GlideModule(glideName = "GlideArms") +public class GlideConfiguration extends AppGlideModule { + public static final int IMAGE_DISK_CACHE_MAX_SIZE = 100 * 1024 * 1024;//图片缓存文件最大值为100Mb + + @Override + public void applyOptions(Context context, GlideBuilder builder) { + AppComponent appComponent = ArmsUtils.obtainAppComponentFromContext(context); + builder.setDiskCache(new DiskCache.Factory() { + @Override + public DiskCache build() { + // Careful: the external cache directory doesn't enforce permissions + return DiskLruCacheWrapper.get(DataHelper.makeDirs(new File(appComponent.cacheFile(), "Glide")), IMAGE_DISK_CACHE_MAX_SIZE); + } + }); + + MemorySizeCalculator calculator = new MemorySizeCalculator.Builder(context).build(); + int defaultMemoryCacheSize = calculator.getMemoryCacheSize(); + int defaultBitmapPoolSize = calculator.getBitmapPoolSize(); + + int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize); + int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize); + + builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize)); + builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize)); + + //将配置 Glide 的机会转交给 GlideImageLoaderStrategy,如你觉得框架提供的 GlideImageLoaderStrategy + //并不能满足自己的需求,想自定义 BaseImageLoaderStrategy,那请你最好实现 GlideAppliesOptions + //因为只有成为 GlideAppliesOptions 的实现类,这里才能调用 applyGlideOptions(),让你具有配置 Glide 的权利 + BaseImageLoaderStrategy loadImgStrategy = appComponent.imageLoader().getLoadImgStrategy(); + if (loadImgStrategy instanceof GlideAppliesOptions) { + ((GlideAppliesOptions) loadImgStrategy).applyGlideOptions(context, builder); + } + } + + @Override + public void registerComponents(Context context, Glide glide, Registry registry) { + //Glide 默认使用 HttpURLConnection 做网络请求,在这切换成 Okhttp 请求 + AppComponent appComponent = ArmsUtils.obtainAppComponentFromContext(context); + registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(appComponent.okHttpClient())); + } + + @Override + public boolean isManifestParsingEnabled() { + return false; + } +} diff --git a/arms/src/main/java/com/jess/arms/http/imageloader/glide/GlideImageLoaderStrategy.java b/arms/src/main/java/com/jess/arms/http/imageloader/glide/GlideImageLoaderStrategy.java new file mode 100644 index 0000000..e0a0fa2 --- /dev/null +++ b/arms/src/main/java/com/jess/arms/http/imageloader/glide/GlideImageLoaderStrategy.java @@ -0,0 +1,143 @@ +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jess.arms.http.imageloader.glide; + +import android.content.Context; +import android.graphics.drawable.Drawable; +import android.text.TextUtils; +import android.widget.ImageView; + +import com.bumptech.glide.Glide; +import com.bumptech.glide.GlideBuilder; +import com.bumptech.glide.load.engine.DiskCacheStrategy; +import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions; +import com.jess.arms.di.module.GlobalConfigModule; +import com.jess.arms.http.imageloader.BaseImageLoaderStrategy; +import com.jess.arms.http.imageloader.ImageConfig; + +import io.reactivex.Observable; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.annotations.NonNull; +import io.reactivex.functions.Consumer; +import io.reactivex.schedulers.Schedulers; +import timber.log.Timber; + +/** + * ================================================ + * 此类只是简单的实现了 Glide 加载的策略,方便快速使用,但大部分情况会需要应对复杂的场景 + * 这时可自行实现 {@link BaseImageLoaderStrategy} 和 {@link ImageConfig} 替换现有策略 + * + * @see GlobalConfigModule.Builder#imageLoaderStrategy(BaseImageLoaderStrategy) + * Created by JessYan on 8/5/16 16:28 + * Contact me + * Follow me + * ================================================ + */ +public class GlideImageLoaderStrategy implements BaseImageLoaderStrategy, GlideAppliesOptions { + + @Override + public void loadImage(Context ctx, ImageConfigImpl config) { + if (ctx == null) throw new NullPointerException("Context is required"); + if (config == null) throw new NullPointerException("ImageConfigImpl is required"); + if (TextUtils.isEmpty(config.getUrl())) throw new NullPointerException("Url is required"); + if (config.getImageView() == null) throw new NullPointerException("Imageview is required"); + + + GlideRequests requests; + + requests = GlideArms.with(ctx);//如果context是activity则自动使用Activity的生命周期 + + GlideRequest glideRequest = requests.load(config.getUrl()) + .transition(DrawableTransitionOptions.withCrossFade()) + .centerCrop(); + + switch (config.getCacheStrategy()) {//缓存策略 + case 0: + glideRequest.diskCacheStrategy(DiskCacheStrategy.ALL); + break; + case 1: + glideRequest.diskCacheStrategy(DiskCacheStrategy.NONE); + break; + case 2: + glideRequest.diskCacheStrategy(DiskCacheStrategy.RESOURCE); + break; + case 3: + glideRequest.diskCacheStrategy(DiskCacheStrategy.DATA); + break; + case 4: + glideRequest.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC); + break; + } + if (config.getTransformation() != null) {//glide用它来改变图形的形状 + glideRequest.transform(config.getTransformation()); + } + + + if (config.getPlaceholder() != 0)//设置占位符 + glideRequest.placeholder(config.getPlaceholder()); + + if (config.getErrorPic() != 0)//设置错误的图片 + glideRequest.error(config.getErrorPic()); + + if (config.getFallback() != 0)//设置请求 url 为空图片 + glideRequest.fallback(config.getFallback()); + + + glideRequest + .into(config.getImageView()); + } + + @Override + public void clear(final Context ctx, ImageConfigImpl config) { + if (ctx == null) throw new NullPointerException("Context is required"); + if (config == null) throw new NullPointerException("ImageConfigImpl is required"); + + if (config.getImageViews() != null && config.getImageViews().length > 0) {//取消在执行的任务并且释放资源 + for (ImageView imageView : config.getImageViews()) { + GlideArms.get(ctx).getRequestManagerRetriever().get(ctx).clear(imageView); + } + } + + if (config.isClearDiskCache()) {//清除本地缓存 + Observable.just(0) + .observeOn(Schedulers.io()) + .subscribe(new Consumer() { + @Override + public void accept(@NonNull Integer integer) throws Exception { + Glide.get(ctx).clearDiskCache(); + } + }); + } + + if (config.isClearMemory()) {//清除内存缓存 + Observable.just(0) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Consumer() { + @Override + public void accept(@NonNull Integer integer) throws Exception { + Glide.get(ctx).clearMemory(); + } + }); + } + + } + + + @Override + public void applyGlideOptions(Context context, GlideBuilder builder) { + Timber.w("applyGlideOptions"); + } +} diff --git a/arms/src/main/java/com/jess/arms/widget/imageloader/glide/GlideImageConfig.java b/arms/src/main/java/com/jess/arms/http/imageloader/glide/ImageConfigImpl.java similarity index 65% rename from arms/src/main/java/com/jess/arms/widget/imageloader/glide/GlideImageConfig.java rename to arms/src/main/java/com/jess/arms/http/imageloader/glide/ImageConfigImpl.java index 0360dd1..e899e96 100644 --- a/arms/src/main/java/com/jess/arms/widget/imageloader/glide/GlideImageConfig.java +++ b/arms/src/main/java/com/jess/arms/http/imageloader/glide/ImageConfigImpl.java @@ -1,34 +1,52 @@ -package com.jess.arms.widget.imageloader.glide; +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jess.arms.http.imageloader.glide; import android.widget.ImageView; import com.bumptech.glide.load.resource.bitmap.BitmapTransformation; -import com.bumptech.glide.request.target.Target; -import com.jess.arms.widget.imageloader.ImageConfig; +import com.jess.arms.http.imageloader.ImageConfig; /** - * Created by jess on 8/5/16 15:19 - * contact with jess.yan.effort@gmail.com - * 这里放Glide专属的配置信息,可以一直扩展字段,如果外部调用时想让图片加载框架 - * 做一些操作,比如清除或则切换缓存策略,则可以定义一个int类型的变量,内部根据int做不同过的操作 + * ================================================ + * 这里存放图片请求的配置信息,可以一直扩展字段,如果外部调用时想让图片加载框架 + * 做一些操作,比如清除缓存或者切换缓存策略,则可以定义一个 int 类型的变量,内部根据 switch(int) 做不同的操作 * 其他操作同理 + *

+ * Created by JessYan on 8/5/16 15:19 + * Contact me + * Follow me + * ================================================ */ -public class GlideImageConfig extends ImageConfig { +public class ImageConfigImpl extends ImageConfig { private int cacheStrategy;//0对应DiskCacheStrategy.all,1对应DiskCacheStrategy.NONE,2对应DiskCacheStrategy.SOURCE,3对应DiskCacheStrategy.RESULT + private int fallback; //请求 url 为空,则使用此图片作为占位符 private BitmapTransformation transformation;//glide用它来改变图形的形状 - private Target[] targets; private ImageView[] imageViews; private boolean isClearMemory;//清理内存缓存 private boolean isClearDiskCache;//清理本地缓存 - private GlideImageConfig(Builder builder) { + private ImageConfigImpl(Builder builder) { this.url = builder.url; this.imageView = builder.imageView; this.placeholder = builder.placeholder; this.errorPic = builder.errorPic; + this.fallback = builder.fallback; this.cacheStrategy = builder.cacheStrategy; this.transformation = builder.transformation; - this.targets = builder.targets; this.imageViews = builder.imageViews; this.isClearMemory = builder.isClearMemory; this.isClearDiskCache = builder.isClearDiskCache; @@ -42,10 +60,6 @@ public BitmapTransformation getTransformation() { return transformation; } - public Target[] getTargets() { - return targets; - } - public ImageView[] getImageViews() { return imageViews; } @@ -58,6 +72,10 @@ public boolean isClearDiskCache() { return isClearDiskCache; } + public int getFallback() { + return fallback; + } + public static Builder builder() { return new Builder(); } @@ -68,9 +86,9 @@ public static final class Builder { private ImageView imageView; private int placeholder; private int errorPic; + private int fallback; //请求 url 为空,则使用此图片作为占位符 private int cacheStrategy;//0对应DiskCacheStrategy.all,1对应DiskCacheStrategy.NONE,2对应DiskCacheStrategy.SOURCE,3对应DiskCacheStrategy.RESULT private BitmapTransformation transformation;//glide用它来改变图形的形状 - private Target[] targets; private ImageView[] imageViews; private boolean isClearMemory;//清理内存缓存 private boolean isClearDiskCache;//清理本地缓存 @@ -83,10 +101,6 @@ public Builder url(String url) { this.url = url; return this; } - public Builder load(int resID) { - this.resID = resID; - return this; - } public Builder placeholder(int placeholder) { this.placeholder = placeholder; @@ -98,6 +112,11 @@ public Builder errorPic(int errorPic) { return this; } + public Builder fallback(int fallback) { + this.fallback = fallback; + return this; + } + public Builder imageView(ImageView imageView) { this.imageView = imageView; return this; @@ -113,11 +132,6 @@ public Builder transformation(BitmapTransformation transformation) { return this; } - public Builder targets(Target... targets) { - this.targets = targets; - return this; - } - public Builder imageViews(ImageView... imageViews) { this.imageViews = imageViews; return this; @@ -134,8 +148,8 @@ public Builder isClearDiskCache(boolean isClearDiskCache) { } - public GlideImageConfig build() { - return new GlideImageConfig(this); + public ImageConfigImpl build() { + return new ImageConfigImpl(this); } } } diff --git a/arms/src/main/java/com/jess/arms/integration/AppManager.java b/arms/src/main/java/com/jess/arms/integration/AppManager.java index d02166c..074b1e6 100644 --- a/arms/src/main/java/com/jess/arms/integration/AppManager.java +++ b/arms/src/main/java/com/jess/arms/integration/AppManager.java @@ -1,18 +1,18 @@ /** - * Copyright 2017 JessYan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ + * Copyright 2017 JessYan + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.integration; import android.app.Activity; @@ -57,15 +57,16 @@ public final class AppManager { protected final String TAG = this.getClass().getSimpleName(); public static final String APPMANAGER_MESSAGE = "appmanager_message"; - public static final String IS_NOT_ADD_ACTIVITY_LIST = "is_not_add_activity_list";//true 为不需要加入到 Activity 容器进行统一管理,默认为 false + //true 为不需要加入到 Activity 容器进行统一管理,默认为 false + public static final String IS_NOT_ADD_ACTIVITY_LIST = "is_not_add_activity_list"; public static final int START_ACTIVITY = 5000; public static final int SHOW_SNACKBAR = 5001; public static final int KILL_ALL = 5002; public static final int APP_EXIT = 5003; private Application mApplication; - //管理所有activity + //管理所有存活的 Activity, 容器中的顺序仅仅是 Activity 的创建顺序, 并不能保证和 Activity 任务栈顺序一致 public List mActivityList; - //当前在前台的activity + //当前在前台的 Activity private Activity mCurrentActivity; //提供给外部扩展 AppManager 的 onReceive 方法 private HandleListener mHandleListener; @@ -197,7 +198,7 @@ public void release() { /** * 将在前台的 {@link Activity} 赋值给 {@code currentActivity}, 注意此方法是在 {@link Activity#onResume} 方法执行时将栈顶的 {@link Activity} 赋值给 {@code currentActivity} * 所以在栈顶的 {@link Activity} 执行 {@link Activity#onCreate} 方法时使用 {@link #getCurrentActivity()} 获取的就不是当前栈顶的 {@link Activity}, 可能是上一个 {@link Activity} - * 如果在 App 的第一个 {@link Activity} 执行 {@link Activity#onCreate} 方法时使用 {@link #getCurrentActivity()} 则会出现返回为 {@code null} 的情况 + * 如果在 App 启动第一个 {@link Activity} 执行 {@link Activity#onCreate} 方法时使用 {@link #getCurrentActivity()} 则会出现返回为 {@code null} 的情况 * 想避免这种情况请使用 {@link #getTopActivity()} * * @param currentActivity @@ -223,8 +224,12 @@ public Activity getCurrentActivity() { } /** - * 获取位于栈顶的 {@link Activity}, 此方法不保证获取到的 {@link Activity} 正处于可见状态, 即使 App 进入后台也会返回当前栈顶的 {@link Activity} - * 因此基本不会出现 {@code null} 的情况, 比较适合大部分的使用场景, 如 startActivity, Glide 加载图片 + * 获取最近启动的一个 {@link Activity}, 此方法不保证获取到的 {@link Activity} 正处于前台可见状态 + * 即使 App 进入后台或在这个 {@link Activity} 中打开一个之前已经存在的 {@link Activity}, 这时调用此方法 + * 还是会返回这个最近启动的 {@link Activity}, 因此基本不会出现 {@code null} 的情况 + * 比较适合大部分的使用场景, 如 startActivity + *

+ * Tips: mActivityList 容器中的顺序仅仅是 Activity 的创建顺序, 并不能保证和 Activity 任务栈顺序一致 * * @return */ @@ -254,12 +259,10 @@ public List getActivityList() { * 添加 {@link Activity} 到集合 */ public void addActivity(Activity activity) { - if (mActivityList == null) { - mActivityList = new LinkedList<>(); - } synchronized (AppManager.class) { - if (!mActivityList.contains(activity)) { - mActivityList.add(activity); + List activities = getActivityList(); + if (!activities.contains(activity)) { + activities.add(activity); } } } @@ -309,9 +312,15 @@ public void killActivity(Class activityClass) { Timber.tag(TAG).w("mActivityList == null when killActivity(Class)"); return; } - for (Activity activity : mActivityList) { - if (activity.getClass().equals(activityClass)) { - activity.finish(); + synchronized (AppManager.class) { + Iterator iterator = getActivityList().iterator(); + while (iterator.hasNext()) { + Activity next = iterator.next(); + + if (next.getClass().equals(activityClass)) { + iterator.remove(); + next.finish(); + } } } } @@ -353,7 +362,7 @@ public boolean activityClassIsLive(Class activityClass) { /** - * 获取指定 {@link Activity} class 的实例,没有则返回 null(同一个 {@link Activity} class 有多个实例,则返回最早的实例) + * 获取指定 {@link Activity} class 的实例,没有则返回 null(同一个 {@link Activity} class 有多个实例,则返回最早创建的实例) * * @param activityClass * @return @@ -379,12 +388,13 @@ public void killAll() { // while (getActivityList().size() != 0) { //此方法只能兼容LinkedList // getActivityList().remove(0).finish(); // } - - Iterator iterator = getActivityList().iterator(); - while (iterator.hasNext()) { - Activity next = iterator.next(); - iterator.remove(); - next.finish(); + synchronized (AppManager.class) { + Iterator iterator = getActivityList().iterator(); + while (iterator.hasNext()) { + Activity next = iterator.next(); + iterator.remove(); + next.finish(); + } } } @@ -395,15 +405,17 @@ public void killAll() { */ public void killAll(Class... excludeActivityClasses) { List> excludeList = Arrays.asList(excludeActivityClasses); - Iterator iterator = getActivityList().iterator(); - while (iterator.hasNext()) { - Activity next = iterator.next(); + synchronized (AppManager.class) { + Iterator iterator = getActivityList().iterator(); + while (iterator.hasNext()) { + Activity next = iterator.next(); - if (excludeList.contains(next.getClass())) - continue; + if (excludeList.contains(next.getClass())) + continue; - iterator.remove(); - next.finish(); + iterator.remove(); + next.finish(); + } } } @@ -414,15 +426,17 @@ public void killAll(Class... excludeActivityClasses) { */ public void killAll(String... excludeActivityName) { List excludeList = Arrays.asList(excludeActivityName); - Iterator iterator = getActivityList().iterator(); - while (iterator.hasNext()) { - Activity next = iterator.next(); + synchronized (AppManager.class) { + Iterator iterator = getActivityList().iterator(); + while (iterator.hasNext()) { + Activity next = iterator.next(); - if (excludeList.contains(next.getClass().getName())) - continue; + if (excludeList.contains(next.getClass().getName())) + continue; - iterator.remove(); - next.finish(); + iterator.remove(); + next.finish(); + } } } diff --git a/arms/src/main/java/com/jess/arms/integration/ConfigModule.java b/arms/src/main/java/com/jess/arms/integration/ConfigModule.java index ef1fdc1..da5c3e2 100644 --- a/arms/src/main/java/com/jess/arms/integration/ConfigModule.java +++ b/arms/src/main/java/com/jess/arms/integration/ConfigModule.java @@ -1,3 +1,18 @@ +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.integration; import android.app.Application; @@ -10,14 +25,19 @@ import java.util.List; /** - * 此接口可以给框架配置一些参数,需要实现类实现后,并在AndroidManifest中声明该实现类 - * Created by jess on 12/04/2017 11:37 - * Contact with jess.yan.effort@gmail.com + * ================================================ + * {@link ConfigModule} 可以给框架配置一些参数,需要实现 {@link ConfigModule} 后,在 AndroidManifest 中声明该实现类 + * + * @see ConfigModule wiki 官方文档 + * Created by JessYan on 12/04/2017 11:37 + * Contact me + * Follow me + * ================================================ */ - public interface ConfigModule { /** * 使用{@link GlobalConfigModule.Builder}给框架配置一些配置参数 + * * @param context * @param builder */ @@ -25,7 +45,9 @@ public interface ConfigModule { /** * 使用{@link AppLifecycles}在Application的生命周期中注入一些操作 - * @return + * + * @param context + * @param lifecycles */ void injectAppLifecycle(Context context, List lifecycles); diff --git a/arms/src/main/java/com/jess/arms/integration/IRepositoryManager.java b/arms/src/main/java/com/jess/arms/integration/IRepositoryManager.java index 5fc8fdb..d549326 100644 --- a/arms/src/main/java/com/jess/arms/integration/IRepositoryManager.java +++ b/arms/src/main/java/com/jess/arms/integration/IRepositoryManager.java @@ -1,14 +1,39 @@ +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.integration; +import android.content.Context; + +import com.jess.arms.mvp.IModel; + /** - * Created by jess on 17/03/2017 11:15 - * Contact with jess.yan.effort@gmail.com + * ================================================ + * 用来管理网络请求层,以及数据缓存层,以后可能添加数据库请求层 + * 提供给 {@link IModel} 必要的 Api 做数据处理 + * + * @see RepositoryManager wiki 官方文档 + * Created by JessYan on 17/03/2017 11:15 + * Contact me + * Follow me + * ================================================ */ - public interface IRepositoryManager { /** - * 根据传入的Class获取对应的Retrift service + * 根据传入的 Class 获取对应的 Retrofit service * * @param service * @param @@ -17,7 +42,7 @@ public interface IRepositoryManager { T obtainRetrofitService(Class service); /** - * 根据传入的Class获取对应的RxCache service + * 根据传入的 Class 获取对应的 RxCache service * * @param cache * @param @@ -30,4 +55,6 @@ public interface IRepositoryManager { */ void clearAllCache(); + Context getContext(); + } diff --git a/arms/src/main/java/com/jess/arms/integration/ManifestParser.java b/arms/src/main/java/com/jess/arms/integration/ManifestParser.java index 379dc89..b4c915e 100644 --- a/arms/src/main/java/com/jess/arms/integration/ManifestParser.java +++ b/arms/src/main/java/com/jess/arms/integration/ManifestParser.java @@ -1,3 +1,18 @@ +/** + * Copyright 2017 JessYan + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.integration; import android.content.Context; @@ -8,8 +23,14 @@ import java.util.List; /** - * Created by jess on 12/04/2017 14:41 - * Contact with jess.yan.effort@gmail.com + * ================================================ + * 用于解析 AndroidManifest 中的 Meta 属性 + * 配合 {@link ConfigModule} 使用 + *

+ * Created by JessYan on 12/04/2017 14:41 + * Contact me + * Follow me + * ================================================ */ public final class ManifestParser { private static final String MODULE_VALUE = "ConfigModule"; diff --git a/arms/src/main/java/com/jess/arms/integration/RepositoryManager.java b/arms/src/main/java/com/jess/arms/integration/RepositoryManager.java index 918fe7e..791abe9 100644 --- a/arms/src/main/java/com/jess/arms/integration/RepositoryManager.java +++ b/arms/src/main/java/com/jess/arms/integration/RepositoryManager.java @@ -1,7 +1,27 @@ +/** + * Copyright 2017 JessYan + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.integration; -import java.util.HashMap; -import java.util.Map; +import android.app.Application; +import android.content.Context; + +import com.jess.arms.integration.cache.Cache; +import com.jess.arms.integration.cache.CacheType; +import com.jess.arms.mvp.IModel; +import com.jess.arms.utils.Preconditions; import javax.inject.Inject; import javax.inject.Singleton; @@ -11,60 +31,70 @@ import retrofit2.Retrofit; /** + * ================================================ * 用来管理网络请求层,以及数据缓存层,以后可能添加数据库请求层 - *

- * Created by jess on 13/04/2017 09:52 - * Contact with jess.yan.effort@gmail.com + * 提供给 {@link IModel} 层必要的 Api 做数据处理 + * + * @see RepositoryManager wiki 官方文档 + * Created by JessYan on 13/04/2017 09:52 + * Contact me + * Follow me + * ================================================ */ @Singleton public class RepositoryManager implements IRepositoryManager { private Lazy mRetrofit; private Lazy mRxCache; - private final Map mRetrofitServiceCache = new HashMap<>(); - private final Map mCacheServiceCache = new HashMap<>(); + private Application mApplication; + private Cache mRetrofitServiceCache; + private Cache mCacheServiceCache; + private Cache.Factory mCachefactory; @Inject - public RepositoryManager(Lazy retrofit, Lazy rxCache) { + public RepositoryManager(Lazy retrofit, Lazy rxCache, Application application + , Cache.Factory cachefactory) { this.mRetrofit = retrofit; this.mRxCache = rxCache; + this.mApplication = application; + this.mCachefactory = cachefactory; } /** - * 根据传入的Class获取对应的Retrift service + * 根据传入的 Class 获取对应的 Retrofit service * * @param service * @param * @return */ @Override - public T obtainRetrofitService(Class service) { - T retrofitService; - synchronized (mRetrofitServiceCache) { - retrofitService = (T) mRetrofitServiceCache.get(service.getName()); - if (retrofitService == null) { - retrofitService = mRetrofit.get().create(service); - mRetrofitServiceCache.put(service.getName(), retrofitService); - } + public synchronized T obtainRetrofitService(Class service) { + if (mRetrofitServiceCache == null) + mRetrofitServiceCache = mCachefactory.build(CacheType.RETROFIT_SERVICE_CACHE); + Preconditions.checkNotNull(mRetrofitServiceCache, "Cannot return null from a Cache.Factory#build(int) method"); + T retrofitService = (T) mRetrofitServiceCache.get(service.getCanonicalName()); + if (retrofitService == null) { + retrofitService = mRetrofit.get().create(service); + mRetrofitServiceCache.put(service.getCanonicalName(), retrofitService); } return retrofitService; } /** - * 根据传入的Class获取对应的RxCache service + * 根据传入的 Class 获取对应的 RxCache service * * @param cache * @param * @return */ @Override - public T obtainCacheService(Class cache) { - T cacheService; - synchronized (mCacheServiceCache) { - cacheService = (T) mCacheServiceCache.get(cache.getName()); - if (cacheService == null) { - cacheService = mRxCache.get().using(cache); - mCacheServiceCache.put(cache.getName(), cacheService); - } + public synchronized T obtainCacheService(Class cache) { + if (mCacheServiceCache == null) + mCacheServiceCache = mCachefactory.build(CacheType.CACHE_SERVICE_CACHE); + Preconditions.checkNotNull(mCacheServiceCache, "Cannot return null from a Cache.Factory#build(int) method"); + T cacheService = (T) mCacheServiceCache.get(cache.getCanonicalName()); + if (cacheService == null) { + cacheService = mRxCache.get().using(cache); + mCacheServiceCache.put(cache.getCanonicalName(), cacheService); } return cacheService; } @@ -76,4 +106,9 @@ public T obtainCacheService(Class cache) { public void clearAllCache() { mRxCache.get().evictAll(); } + + @Override + public Context getContext() { + return mApplication; + } } diff --git a/arms/src/main/java/com/jess/arms/integration/lifecycle/ActivityLifecycleForRxLifecycle.java b/arms/src/main/java/com/jess/arms/integration/lifecycle/ActivityLifecycleForRxLifecycle.java index 2f7c93c..68d4a2d 100644 --- a/arms/src/main/java/com/jess/arms/integration/lifecycle/ActivityLifecycleForRxLifecycle.java +++ b/arms/src/main/java/com/jess/arms/integration/lifecycle/ActivityLifecycleForRxLifecycle.java @@ -46,6 +46,10 @@ public class ActivityLifecycleForRxLifecycle implements Application.ActivityLife public ActivityLifecycleForRxLifecycle() { } + /** + * 通过桥梁对象 {@code BehaviorSubject mLifecycleSubject} + * 在每个 Activity 的生命周期中发出对应的生命周期事件 + */ @Override public void onActivityCreated(Activity activity, Bundle savedInstanceState) { if (activity instanceof ActivityLifecycleable) { @@ -99,6 +103,10 @@ public void onActivityDestroyed(Activity activity) { } } + /** + * 从 {@link com.jess.arms.base.BaseActivity} 中获得桥梁对象 {@code BehaviorSubject mLifecycleSubject} + * @see BehaviorSubject 官方中文文档 + */ private Subject obtainSubject(Activity activity) { return ((ActivityLifecycleable) activity).provideLifecycleSubject(); } diff --git a/arms/src/main/java/com/jess/arms/integration/store/lifecyclemodel/EmptyActivityLifecycleCallbacks.java b/arms/src/main/java/com/jess/arms/integration/store/lifecyclemodel/EmptyActivityLifecycleCallbacks.java deleted file mode 100644 index 20c6346..0000000 --- a/arms/src/main/java/com/jess/arms/integration/store/lifecyclemodel/EmptyActivityLifecycleCallbacks.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2017 JessYan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.jess.arms.integration.store.lifecyclemodel; - -import android.app.Activity; -import android.app.Application; -import android.os.Bundle; - -/** - * Created by JessYan on 21/11/2017 16:57 - * Contact me - * Follow me - */ -class EmptyActivityLifecycleCallbacks implements Application.ActivityLifecycleCallbacks { - @Override - public void onActivityCreated(Activity activity, Bundle savedInstanceState) { - } - - @Override - public void onActivityStarted(Activity activity) { - } - - @Override - public void onActivityResumed(Activity activity) { - } - - @Override - public void onActivityPaused(Activity activity) { - } - - @Override - public void onActivityStopped(Activity activity) { - } - - @Override - public void onActivitySaveInstanceState(Activity activity, Bundle outState) { - } - - @Override - public void onActivityDestroyed(Activity activity) { - } -} diff --git a/arms/src/main/java/com/jess/arms/integration/store/lifecyclemodel/HolderFragment.java b/arms/src/main/java/com/jess/arms/integration/store/lifecyclemodel/HolderFragment.java deleted file mode 100644 index 051cf44..0000000 --- a/arms/src/main/java/com/jess/arms/integration/store/lifecyclemodel/HolderFragment.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Copyright 2017 JessYan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.jess.arms.integration.store.lifecyclemodel; - -import android.app.Activity; -import android.app.Application.ActivityLifecycleCallbacks; -import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.annotation.RestrictTo; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentActivity; -import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentManager.FragmentLifecycleCallbacks; -import android.util.Log; - -import java.util.HashMap; -import java.util.Map; - -/** - * @hide 此类为实现 {@link LifecycleModel} 的核心类 - *

- * Created by JessYan on 21/11/2017 16:57 - * Contact me - * Follow me - */ -@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) -public class HolderFragment extends Fragment { - private static final String LOG_TAG = "LifecycleModelStores"; - - private static final HolderFragmentManager sHolderFragmentManager = new HolderFragmentManager(); - - /** - * @hide - */ - @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) - public static final String HOLDER_TAG = - "me.jessyan.arms.state.StateProviderHolderFragment"; - - private final LifecycleModelStore mLifecycleModelStore = new LifecycleModelStore(); - - public HolderFragment() { - setRetainInstance(true); - } - - @Override - public void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - sHolderFragmentManager.holderFragmentCreated(this); - } - - @Override - public void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - } - - @Override - public void onDestroy() { - super.onDestroy(); - mLifecycleModelStore.clear(); - } - - public LifecycleModelStore getLifecycleModelStore() { - return mLifecycleModelStore; - } - - /** - * @hide - */ - @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) - public static HolderFragment holderFragmentFor(FragmentActivity activity) { - return sHolderFragmentManager.holderFragmentFor(activity); - } - - /** - * @hide - */ - @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) - public static HolderFragment holderFragmentFor(Fragment fragment) { - return sHolderFragmentManager.holderFragmentFor(fragment); - } - - @SuppressWarnings("WeakerAccess") - static class HolderFragmentManager { - private Map mNotCommittedActivityHolders = new HashMap<>(); - private Map mNotCommittedFragmentHolders = new HashMap<>(); - - private ActivityLifecycleCallbacks mActivityCallbacks = - new EmptyActivityLifecycleCallbacks() { - @Override - public void onActivityDestroyed(Activity activity) { - HolderFragment fragment = mNotCommittedActivityHolders.remove(activity); - if (fragment != null) { - Log.e(LOG_TAG, "Failed to save a LifecycleModel for " + activity); - } - } - }; - - private boolean mActivityCallbacksIsAdded = false; - - private FragmentLifecycleCallbacks mParentDestroyedCallback = - new FragmentLifecycleCallbacks() { - @Override - public void onFragmentDestroyed(FragmentManager fm, Fragment parentFragment) { - super.onFragmentDestroyed(fm, parentFragment); - HolderFragment fragment = mNotCommittedFragmentHolders.remove( - parentFragment); - if (fragment != null) { - Log.e(LOG_TAG, "Failed to save a LifecycleModel for " + parentFragment); - } - } - }; - - void holderFragmentCreated(Fragment holderFragment) { - Fragment parentFragment = holderFragment.getParentFragment(); - if (parentFragment != null) { - mNotCommittedFragmentHolders.remove(parentFragment); - parentFragment.getFragmentManager().unregisterFragmentLifecycleCallbacks( - mParentDestroyedCallback); - } else { - mNotCommittedActivityHolders.remove(holderFragment.getActivity()); - } - } - - private static HolderFragment findHolderFragment(FragmentManager manager) { - if (manager.isDestroyed()) { - throw new IllegalStateException("Can't access LifecycleModels from onDestroy"); - } - - Fragment fragmentByTag = manager.findFragmentByTag(HOLDER_TAG); - if (fragmentByTag != null && !(fragmentByTag instanceof HolderFragment)) { - throw new IllegalStateException("Unexpected " - + "fragment instance was returned by HOLDER_TAG"); - } - return (HolderFragment) fragmentByTag; - } - - private static HolderFragment createHolderFragment(FragmentManager fragmentManager) { - HolderFragment holder = new HolderFragment(); - fragmentManager.beginTransaction().add(holder, HOLDER_TAG).commitAllowingStateLoss(); - return holder; - } - - HolderFragment holderFragmentFor(FragmentActivity activity) { - FragmentManager fm = activity.getSupportFragmentManager(); - HolderFragment holder = findHolderFragment(fm); - if (holder != null) { - return holder; - } - holder = mNotCommittedActivityHolders.get(activity); - if (holder != null) { - return holder; - } - - if (!mActivityCallbacksIsAdded) { - mActivityCallbacksIsAdded = true; - activity.getApplication().registerActivityLifecycleCallbacks(mActivityCallbacks); - } - holder = createHolderFragment(fm); - mNotCommittedActivityHolders.put(activity, holder); - return holder; - } - - HolderFragment holderFragmentFor(Fragment parentFragment) { - FragmentManager fm = parentFragment.getChildFragmentManager(); - HolderFragment holder = findHolderFragment(fm); - if (holder != null) { - return holder; - } - holder = mNotCommittedFragmentHolders.get(parentFragment); - if (holder != null) { - return holder; - } - - parentFragment.getFragmentManager() - .registerFragmentLifecycleCallbacks(mParentDestroyedCallback, false); - holder = createHolderFragment(fm); - mNotCommittedFragmentHolders.put(parentFragment, holder); - return holder; - } - } -} diff --git a/arms/src/main/java/com/jess/arms/integration/store/lifecyclemodel/LifecycleModel.java b/arms/src/main/java/com/jess/arms/integration/store/lifecyclemodel/LifecycleModel.java deleted file mode 100644 index e065fa2..0000000 --- a/arms/src/main/java/com/jess/arms/integration/store/lifecyclemodel/LifecycleModel.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2017 JessYan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.jess.arms.integration.store.lifecyclemodel; - -import android.app.Activity; -import android.support.v4.app.Fragment; - -/** - * {@link LifecycleModelProviders} 配合 {@link LifecycleModel} 的实现类可以帮助 {@link Activity} 和 {@link Fragment} - * 暂存和管理一些与 UI 相关以及他们必需的数据, 并且这些数据在屏幕旋转或配置更改引起的 {@link Activity} 重建的情况下也会被保留, 直到最后被 finish - * 但是 {@link LifecycleModel} 的实现类切勿直接引用 {@link Activity} 和 {@link Fragment} 以及他们里面 UI 元素 - *

- * 他还可以让开发者能够在绑定在同一个 {@link Activity} 之下的多个不同的 {@link Fragment} 之间共享数据以及通讯 - * 使用这种方式进行通讯, {@link Fragment} 之间不存在任何耦合关系 - *

- *

- * public class UserLifecycleModel implements LifecycleModel {
- *     private int id;
- *
- *     public UserLifecycleModel(int id) {
- *          this.id = id;
- *     }
- *
- *     void doAction() {
- *
- *     }
- * }
- *
- *
- * public class MyActivity extends AppCompatActivity {
- *
- *     protected void onCreate(@Nullable Bundle savedInstanceState) {
- *          LifecycleModelProviders.of(this).put(UserLifecycleModel.class.getName(), new UserLifecycleModel(123));
- *          fragmentManager.beginTransaction().add(R.layout.afragment_container_Id, new AFragment).commit();
- *          fragmentManager.beginTransaction().add(R.layout.bfragment_container_Id, new BFragment).commit();
- *     }
- * }
- * 
- *

- * 只要 AFragment 和 BFragment 绑定在同一个 Activity 下, 并使用同一个 key, 那获取到的 UserLifecycleModel 就是同一个对象 - * 这时就可以使用这个 UserLifecycleModel 进行通讯 (Fragment 之间如何通讯? 比如说接口回调? 观察者模式?) 和共享数据 - * 这时 Fragment 之间并不知道彼此, 也不互相持有, 所以也不存在耦合关系 - *

- *

- * public class AFragment extends Fragment {
- *     public void onStart() {
- *         UserLifecycleModel userLifecycleModel = LifecycleModelProviders.of(getActivity()).get(UserLifecycleModel.class.getName());
- *     }
- * }
- *
- * public class BFragment extends Fragment {
- *     public void onStart() {
- *         UserLifecycleModel userLifecycleModel = LifecycleModelProviders.of(getActivity()).get(UserLifecycleModel.class.getName());
- *     }
- * }
- *
- * 
- * - * @see - * 功能和 Android Architecture 中的 ViewModel 一致, 但放开了权限不仅可以存储 ViewModel, 还可以存储任意自定义对象 - *

- * Created by JessYan on 21/11/2017 16:57 - * Contact me - * Follow me - */ -public interface LifecycleModel { - /** - * 这个方法会在宿主 {@link Activity} 或 {@link Fragment} 被彻底销毁时被调用, 在这个方法中释放一些资源可以避免内存泄漏 - */ - @SuppressWarnings("WeakerAccess") - void onCleared(); -} diff --git a/arms/src/main/java/com/jess/arms/integration/store/lifecyclemodel/LifecycleModelProviders.java b/arms/src/main/java/com/jess/arms/integration/store/lifecyclemodel/LifecycleModelProviders.java deleted file mode 100644 index 3883dab..0000000 --- a/arms/src/main/java/com/jess/arms/integration/store/lifecyclemodel/LifecycleModelProviders.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 2017 JessYan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.jess.arms.integration.store.lifecyclemodel; - -import android.app.Activity; -import android.app.Application; -import android.support.annotation.MainThread; -import android.support.annotation.NonNull; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentActivity; - -/** - * {@link LifecycleModelProviders} 配合 {@link LifecycleModel} 的实现类可以帮助 {@link Activity} 和 {@link Fragment} - * 暂存和管理一些与 UI 相关以及他们必需的数据, 并且这些数据在屏幕旋转或配置更改引起的 {@link Activity} 重建的情况下也会被保留, 直到最后被 finish - * 但是 {@link LifecycleModel} 的实现类切勿直接引用 {@link Activity} 和 {@link Fragment} 以及他们里面 UI 元素 - *

- * 他还可以让开发者能够在绑定在同一个 {@link Activity} 之下的多个不同的 {@link Fragment} 之间共享数据以及通讯 - * 使用这种方式进行通讯, {@link Fragment} 之间不存在任何耦合关系 - *

- *

- * public class UserLifecycleModel implements LifecycleModel {
- *     private int id;
- *
- *     public UserLifecycleModel(int id) {
- *          this.id = id;
- *     }
- *
- *     void doAction() {
- *
- *     }
- * }
- *
- *
- * public class MyActivity extends AppCompatActivity {
- *
- *     protected void onCreate(@Nullable Bundle savedInstanceState) {
- *          LifecycleModelProviders.of(this).put(UserLifecycleModel.class.getName(), new UserLifecycleModel(123));
- *          fragmentManager.beginTransaction().add(R.layout.afragment_container_Id, new AFragment).commit();
- *          fragmentManager.beginTransaction().add(R.layout.bfragment_container_Id, new BFragment).commit();
- *     }
- * }
- * 
- *

- * 只要 AFragment 和 BFragment 绑定在同一个 Activity 下, 并使用同一个 key, 那获取到的 UserLifecycleModel 就是同一个对象 - * 这时就可以使用这个 UserLifecycleModel 进行通讯 (Fragment 之间如何通讯? 比如说接口回调? 观察者模式?) 和共享数据 - * 这时 Fragment 之间并不知道彼此, 也不互相持有, 所以也不存在耦合关系 - *

- *

- * public class AFragment extends Fragment {
- *     public void onStart() {
- *         UserLifecycleModel userLifecycleModel = LifecycleModelProviders.of(getActivity()).get(UserLifecycleModel.class.getName());
- *     }
- * }
- *
- * public class BFragment extends Fragment {
- *     public void onStart() {
- *         UserLifecycleModel userLifecycleModel = LifecycleModelProviders.of(getActivity()).get(UserLifecycleModel.class.getName());
- *     }
- * }
- *
- * 
- * - * @see - * 功能和 Android Architecture 中的 ViewModel 一致, 但放开了权限不仅可以存储 ViewModel, 还可以存储任意自定义对象 - *

- * Created by JessYan on 21/11/2017 16:57 - * Contact me - * Follow me - */ -public class LifecycleModelProviders { - - - private static Application checkApplication(Activity activity) { - Application application = activity.getApplication(); - if (application == null) { - throw new IllegalStateException("Your activity/fragment is not yet attached to " - + "Application. You can't request LifecycleModel before onCreate call."); - } - return application; - } - - private static Activity checkActivity(Fragment fragment) { - Activity activity = fragment.getActivity(); - if (activity == null) { - throw new IllegalStateException("Can't create LifecycleModelStore for detached fragment"); - } - return activity; - } - - /** - * 返回的 {@link LifecycleModelStore} 可以在传入的这个 {code fragment} 的生命范围内一直存活者 - * {@link LifecycleModelStore} 可以存储不同的 {@link LifecycleModel} 实现类 - * 更多信息请查看 {@link LifecycleModelProviders} 顶部的注释 - * - * @param fragment {@link LifecycleModel} 在这个 {code fragment} 的生命范围内被保留 - * @return a LifecycleModelStore instance - */ - @MainThread - public static LifecycleModelStore of(@NonNull Fragment fragment) { - checkApplication(checkActivity(fragment)); - return LifecycleModelStores.of(fragment); - } - - /** - * 返回的 {@link LifecycleModelStore} 可以在传入的这个 {code activity} 的生命范围内一直存活着 - * {@link LifecycleModelStore} 可以存储不同的 {@link LifecycleModel} 实现类 - * 更多信息请查看 {@link LifecycleModelProviders} 顶部的注释 - * - * @param activity {@link LifecycleModel} 在这个 {code activity} 的生命范围内被保留 - * @return a LifecycleModelStore instance - */ - @MainThread - public static LifecycleModelStore of(@NonNull FragmentActivity activity) { - checkApplication(activity); - return LifecycleModelStores.of(activity); - } - -} diff --git a/arms/src/main/java/com/jess/arms/integration/store/lifecyclemodel/LifecycleModelStore.java b/arms/src/main/java/com/jess/arms/integration/store/lifecyclemodel/LifecycleModelStore.java deleted file mode 100644 index cf89ec7..0000000 --- a/arms/src/main/java/com/jess/arms/integration/store/lifecyclemodel/LifecycleModelStore.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2017 JessYan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.jess.arms.integration.store.lifecyclemodel; - -import android.app.Activity; -import android.support.v4.app.Fragment; - -import com.jess.arms.integration.cache.Cache; -import com.jess.arms.integration.cache.LruCache; - -/** - * 这个类的作用为存储 {@link LifecycleModel} - *

- * 此类的实例可以在配置更改或者屏幕旋转导致的 {@link Activity} 重建的情况下被完好无损的保留下来, 所以重建后的新 {@link Activity} - * 持有的实例和重建前持有实例为同一对象 - *

- * 如果当 {@link Activity} 被真正的 {@link Activity#finish()} 不再重建, {@link #clear()} 会被调用 - * 并且之前存储的所有 {@link LifecycleModel} 的 {@link LifecycleModel#onCleared()} 方法也会被调用 - *

- * 通过 {@link LifecycleModelStores} 可向 {@link Activity} 和 {@link Fragment} 提供 {@code LifecycleModelStore} - *

- * Created by JessYan on 21/11/2017 16:57 - * Contact me - * Follow me - */ -public class LifecycleModelStore { - - private final Cache mCache = new LruCache<>(80); - - /** - * 将 {@code lifecycleModel} 以 {@code key} 作为键进行存储 - * - * @param key - * @param lifecycleModel 如果这个 {code key} 之前还存储有其他 {@link LifecycleModel} 对象则返回, 否则返回 {@code null} - */ - public final void put(String key, LifecycleModel lifecycleModel) { - LifecycleModel oldLifecycleModel = mCache.get(key); - if (oldLifecycleModel != null) { - oldLifecycleModel.onCleared(); - } - mCache.put(key, lifecycleModel); - } - - /** - * 根据给定的 {@code key} 获取存储的 {@link LifecycleModel} 实现类 - * - * @param key - * @param - * @return - */ - public final T get(String key) { - return (T) mCache.get(key); - } - - /** - * 根据给定的 {@code key} 移除存储的 {@link LifecycleModel} 实现类 - * - * @param key - * @param - * @return - */ - public final T remove(String key) { - return (T) mCache.remove(key); - } - - /** - * 清理存储的 {@link LifecycleModel}, 并且通知 {@link LifecycleModel#onCleared()} - */ - public final void clear() { - for (String key : mCache.keySet()) { - mCache.get(key).onCleared(); - } - mCache.clear(); - } -} diff --git a/arms/src/main/java/com/jess/arms/integration/store/lifecyclemodel/LifecycleModelStores.java b/arms/src/main/java/com/jess/arms/integration/store/lifecyclemodel/LifecycleModelStores.java deleted file mode 100644 index db6de0c..0000000 --- a/arms/src/main/java/com/jess/arms/integration/store/lifecyclemodel/LifecycleModelStores.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2017 JessYan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.jess.arms.integration.store.lifecyclemodel; - -import android.support.annotation.MainThread; -import android.support.annotation.NonNull; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentActivity; - -/** - * Factory methods for {@link LifecycleModelStore} class. - *

- * Created by JessYan on 21/11/2017 16:57 - * Contact me - * Follow me - */ -@SuppressWarnings("WeakerAccess") -public class LifecycleModelStores { - - private LifecycleModelStores() { - } - - /** - * Returns the {@link LifecycleModelStore} of the given activity. - * - * @param activity an activity whose {@code LifecycleModelStore} is requested - * @return a {@code LifecycleModelStore} - */ - @MainThread - public static LifecycleModelStore of(@NonNull FragmentActivity activity) { - return HolderFragment.holderFragmentFor(activity).getLifecycleModelStore(); - } - - /** - * Returns the {@link LifecycleModelStore} of the given fragment. - * - * @param fragment a fragment whose {@code LifecycleModelStore} is requested - * @return a {@code LifecycleModelStore} - */ - @MainThread - public static LifecycleModelStore of(@NonNull Fragment fragment) { - return HolderFragment.holderFragmentFor(fragment).getLifecycleModelStore(); - } -} diff --git a/arms/src/main/java/com/jess/arms/mvp/BaseModel.java b/arms/src/main/java/com/jess/arms/mvp/BaseModel.java index e42ed55..da53f69 100644 --- a/arms/src/main/java/com/jess/arms/mvp/BaseModel.java +++ b/arms/src/main/java/com/jess/arms/mvp/BaseModel.java @@ -1,20 +1,54 @@ +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.mvp; +import android.arch.lifecycle.Lifecycle; +import android.arch.lifecycle.LifecycleObserver; +import android.arch.lifecycle.LifecycleOwner; +import android.arch.lifecycle.OnLifecycleEvent; + import com.jess.arms.integration.IRepositoryManager; /** - * Created by jess on 8/5/16 12:55 - * contact with jess.yan.effort@gmail.com + * ================================================ + * 基类 Model + * + * @see Model wiki 官方文档 + * Created by JessYan on 08/05/2016 12:55 + * Contact me + * Follow me + * ================================================ */ -public class BaseModel implements IModel { +public class BaseModel implements IModel, LifecycleObserver { protected IRepositoryManager mRepositoryManager;//用于管理网络请求层,以及数据缓存层 public BaseModel(IRepositoryManager repositoryManager) { this.mRepositoryManager = repositoryManager; } + /** + * 在框架中 {@link BasePresenter#onDestroy()} 时会默认调用 {@link IModel#onDestroy()} + */ @Override public void onDestroy() { mRepositoryManager = null; } + + @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) + void onDestroy(LifecycleOwner owner) { + owner.getLifecycle().removeObserver(this); + } } diff --git a/arms/src/main/java/com/jess/arms/mvp/BasePresenter.java b/arms/src/main/java/com/jess/arms/mvp/BasePresenter.java index 7e53c6f..38d35f3 100644 --- a/arms/src/main/java/com/jess/arms/mvp/BasePresenter.java +++ b/arms/src/main/java/com/jess/arms/mvp/BasePresenter.java @@ -1,28 +1,77 @@ +/** + * Copyright 2017 JessYan + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.mvp; +import android.app.Activity; +import android.app.Service; +import android.arch.lifecycle.Lifecycle; +import android.arch.lifecycle.LifecycleObserver; +import android.arch.lifecycle.LifecycleOwner; +import android.arch.lifecycle.OnLifecycleEvent; +import android.support.v4.app.Fragment; +import android.support.v4.app.SupportActivity; +import android.view.View; + +import com.jess.arms.utils.Preconditions; +import com.trello.rxlifecycle2.RxLifecycle; + import org.simple.eventbus.EventBus; import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.Disposable; +import io.reactivex.functions.Action; /** - * Created by jess on 16/4/28. + * ================================================ + * 基类 Presenter + * + * @see Presenter wiki 官方文档 + * Created by JessYan on 4/28/2016 + * Contact me + * Follow me + * ================================================ */ -public class BasePresenter implements IPresenter { +public class BasePresenter implements IPresenter, LifecycleObserver { protected final String TAG = this.getClass().getSimpleName(); protected CompositeDisposable mCompositeDisposable; protected M mModel; protected V mRootView; - + /** + * 如果当前页面同时需要 Model 层和 View 层,则使用此构造函数(默认) + * + * @param model + * @param rootView + */ public BasePresenter(M model, V rootView) { + Preconditions.checkNotNull(model, "%s cannot be null", IModel.class.getName()); + Preconditions.checkNotNull(rootView, "%s cannot be null", IView.class.getName()); this.mModel = model; this.mRootView = rootView; onStart(); } + /** + * 如果当前页面不需要操作数据,只需要 View 层,则使用此构造函数 + * + * @param rootView + */ public BasePresenter(V rootView) { + Preconditions.checkNotNull(rootView, "%s cannot be null", IView.class.getName()); this.mRootView = rootView; onStart(); } @@ -34,14 +83,24 @@ public BasePresenter() { @Override public void onStart() { - if (useEventBus())//如果要使用eventbus请将此方法返回true - EventBus.getDefault().register(this);//注册eventbus + //将 LifecycleObserver 注册给 LifecycleOwner 后 @OnLifecycleEvent 才可以正常使用 + if (mRootView != null && mRootView instanceof LifecycleOwner) { + ((LifecycleOwner) mRootView).getLifecycle().addObserver(this); + if (mModel!= null && mModel instanceof LifecycleObserver){ + ((LifecycleOwner) mRootView).getLifecycle().addObserver((LifecycleObserver) mModel); + } + } + if (useEventBus())//如果要使用 Eventbus 请将此方法返回 true + EventBus.getDefault().register(this);//注册 Eventbus } + /** + * 在框架中 {@link Activity#onDestroy()} 时会默认调用 {@link IPresenter#onDestroy()} + */ @Override public void onDestroy() { - if (useEventBus())//如果要使用eventbus请将此方法返回true - EventBus.getDefault().unregister(this);//解除注册eventbus + if (useEventBus())//如果要使用 Eventbus 请将此方法返回 true + EventBus.getDefault().unregister(this);//解除注册 Eventbus unDispose();//解除订阅 if (mModel != null) mModel.onDestroy(); @@ -51,7 +110,25 @@ public void onDestroy() { } /** - * 是否使用eventBus,默认为使用(true), + * 只有当 {@code mRootView} 不为 null, 并且 {@code mRootView} 实现了 {@link LifecycleOwner} 时, 此方法才会被调用 + * 所以当您想在 {@link Service} 以及一些自定义 {@link View} 或自定义类中使用 {@code Presenter} 时 + * 您也将不能继续使用 {@link OnLifecycleEvent} 绑定生命周期 + * + * @param owner link {@link SupportActivity} and {@link Fragment} + */ + @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) + void onDestroy(LifecycleOwner owner) { + /** + * 注意, 如果在这里调用了 {@link #onDestroy()} 方法, 会出现某些地方引用 {@code mModel} 或 {@code mRootView} 为 null 的情况 + * 比如在 {@link RxLifecycle} 终止 {@link Observable} 时, 在 {@link io.reactivex.Observable#doFinally(Action)} 中却引用了 {@code mRootView} 做一些释放资源的操作, 此时会空指针 + * 或者如果你声明了多个 @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) 时在其他 @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) + * 中引用了 {@code mModel} 或 {@code mRootView} 也可能会出现此情况 + */ + owner.getLifecycle().removeObserver(this); + } + + /** + * 是否使用 {@link EventBus},默认为使用(true), * * @return */ @@ -60,16 +137,26 @@ public boolean useEventBus() { } + /** + * 将 {@link Disposable} 添加到 {@link CompositeDisposable} 中统一管理 + * 可在 {@link Activity#onDestroy()} 中使用 {@link #unDispose()} 停止正在执行的 RxJava 任务,避免内存泄漏 + * 目前框架已使用 {@link RxLifecycle} 避免内存泄漏,此方法作为备用方案 + * + * @param disposable + */ public void addDispose(Disposable disposable) { if (mCompositeDisposable == null) { mCompositeDisposable = new CompositeDisposable(); } - mCompositeDisposable.add(disposable);//将所有disposable放入,集中处理 + mCompositeDisposable.add(disposable);//将所有 Disposable 放入集中处理 } + /** + * 停止集合中正在执行的 RxJava 任务 + */ public void unDispose() { if (mCompositeDisposable != null) { - mCompositeDisposable.clear();//保证activity结束时取消所有正在执行的订阅 + mCompositeDisposable.clear();//保证 Activity 结束时取消所有正在执行的订阅 } } diff --git a/arms/src/main/java/com/jess/arms/mvp/IModel.java b/arms/src/main/java/com/jess/arms/mvp/IModel.java index 6982241..544be84 100644 --- a/arms/src/main/java/com/jess/arms/mvp/IModel.java +++ b/arms/src/main/java/com/jess/arms/mvp/IModel.java @@ -1,10 +1,35 @@ +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.mvp; /** - * Created by jess on 15/12/2016 10:45 - * Contact with jess.yan.effort@gmail.com + * ================================================ + * 框架要求框架中的每个 Model 都需要实现此类,以满足规范 + * + * @see BaseModel + * @see Model wiki 官方文档 + * Created by JessYan on 15/12/2016 10:45 + * Contact me + * Follow me + * ================================================ */ - public interface IModel { + + /** + * 在框架中 {@link BasePresenter#onDestroy()} 时会默认调用 {@link IModel#onDestroy()} + */ void onDestroy(); } diff --git a/arms/src/main/java/com/jess/arms/mvp/IPresenter.java b/arms/src/main/java/com/jess/arms/mvp/IPresenter.java index fe15e59..ea9ea2c 100644 --- a/arms/src/main/java/com/jess/arms/mvp/IPresenter.java +++ b/arms/src/main/java/com/jess/arms/mvp/IPresenter.java @@ -1,9 +1,42 @@ +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.mvp; +import android.app.Activity; + /** - * Created by jess on 16/4/28. + * ================================================ + * 框架要求框架中的每个 Presenter 都需要实现此类,以满足规范 + * + * @see BasePresenter + * @see Presenter wiki 官方文档 + * Created by JessYan on 4/28/2016 + * Contact me + * Follow me + * ================================================ */ public interface IPresenter { + + /** + * 做一些初始化操作 + */ void onStart(); + + /** + * 在框架中 {@link Activity#onDestroy()} 时会默认调用 {@link IPresenter#onDestroy()} + */ void onDestroy(); } diff --git a/arms/src/main/java/com/jess/arms/mvp/IView.java b/arms/src/main/java/com/jess/arms/mvp/IView.java index 8e89c30..92cb149 100644 --- a/arms/src/main/java/com/jess/arms/mvp/IView.java +++ b/arms/src/main/java/com/jess/arms/mvp/IView.java @@ -1,9 +1,32 @@ +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.mvp; +import android.app.Activity; import android.content.Intent; /** - * Created by jess on 16/4/22. + * ================================================ + * 框架要求框架中的每个 View 都需要实现此类,以满足规范 + * + * @see View wiki 官方文档 + * Created by JessYan on 4/22/2016 + * Contact me + * Follow me + * ================================================ */ public interface IView { @@ -23,7 +46,7 @@ public interface IView { void showMessage(String message); /** - * 跳转activity + * 跳转 {@link Activity} */ void launchActivity(Intent intent); /** diff --git a/arms/src/main/java/com/jess/arms/utils/CharacterHandler.java b/arms/src/main/java/com/jess/arms/utils/CharacterHandler.java index 0b850b2..07d4e2e 100644 --- a/arms/src/main/java/com/jess/arms/utils/CharacterHandler.java +++ b/arms/src/main/java/com/jess/arms/utils/CharacterHandler.java @@ -1,3 +1,18 @@ +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.utils; import android.text.InputFilter; @@ -22,11 +37,18 @@ import javax.xml.transform.stream.StreamSource; /** - * Created by zhiyicx on 2016/3/16. + * ================================================ + * 处理字符串的工具类 + *

+ * Created by JessYan on 2016/3/16 + * Contact me + * Follow me + * ================================================ */ public class CharacterHandler { private CharacterHandler() { + throw new IllegalStateException("you can't instantiate me!"); } public static final InputFilter emojiFilter = new InputFilter() {//emoji过滤器 diff --git a/arms/src/main/java/com/jess/arms/utils/DataHelper.java b/arms/src/main/java/com/jess/arms/utils/DataHelper.java index 2e4cf96..8cf66f0 100644 --- a/arms/src/main/java/com/jess/arms/utils/DataHelper.java +++ b/arms/src/main/java/com/jess/arms/utils/DataHelper.java @@ -1,3 +1,18 @@ +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.utils; import android.content.Context; @@ -14,7 +29,13 @@ import java.io.ObjectOutputStream; /** - * Created by zhiyicx on 2016/3/15. + * ================================================ + * 处理数据或本地文件的工具类 + *

+ * Created by JessYan on 2016/3/15 + * Contact me + * Follow me + * ================================================ */ public class DataHelper { private static SharedPreferences mSharedPreferences; @@ -22,6 +43,7 @@ public class DataHelper { private DataHelper() { + throw new IllegalStateException("you can't instantiate me!"); } /** @@ -86,6 +108,30 @@ public static void removeSF(Context context, String key) { mSharedPreferences.edit().remove(key).apply(); } + /** + * 使用递归查找是否存在文件 + * + * @param dir + * @return + */ + public static boolean findFile(File dir) { + if (dir == null) { + return false; + } + if (!dir.isDirectory()) { + return true; + } + File[] files = dir.listFiles(); + for (File file : files) { + if (file.isFile()) { + return true; + } else if (file.isDirectory()) { + findFile(file); // 递归调用继续删除 + } + } + return false; + } + /** * 清除Shareprefrence */ @@ -179,6 +225,7 @@ public static File getCacheFile(Context context) { /** * 获取自定义缓存文件地址 + * * @param context * @return */ @@ -190,10 +237,11 @@ public static String getCacheFilePath(Context context) { /** * 创建未存在的文件夹 + * * @param file * @return */ - public static File makeDirs(File file){ + public static File makeDirs(File file) { if (!file.exists()) { file.mkdirs(); } @@ -249,29 +297,6 @@ public static boolean deleteDir(File dir) { } return true; } - /** - * 使用递归查找是否存在文件 - * - * @param dir - * @return - */ - public static boolean findFile(File dir) { - if (dir == null) { - return false; - } - if (!dir.isDirectory()) { - return true; - } - File[] files = dir.listFiles(); - for (File file : files) { - if (file.isFile()) { - return true; - } else if (file.isDirectory()) { - findFile(file); // 递归调用继续删除 - } - } - return false; - } public static String bytyToString(InputStream in) throws IOException { diff --git a/arms/src/main/java/com/jess/arms/utils/DeviceUtils.java b/arms/src/main/java/com/jess/arms/utils/DeviceUtils.java index 7f4eca9..3a0a80e 100644 --- a/arms/src/main/java/com/jess/arms/utils/DeviceUtils.java +++ b/arms/src/main/java/com/jess/arms/utils/DeviceUtils.java @@ -1,8 +1,22 @@ +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.utils; import android.annotation.TargetApi; import android.app.Activity; -import android.app.ActivityManager; import android.app.Dialog; import android.content.ActivityNotFoundException; import android.content.ClipboardManager; @@ -32,9 +46,17 @@ import java.io.File; import java.lang.reflect.Field; import java.text.NumberFormat; -import java.util.ArrayList; import java.util.List; +/** + * ================================================ + * 获取设备常用信息和处理设备常用操作的工具类 + *

+ * Created by JessYan on 2016/3/15 + * Contact me + * Follow me + * ================================================ + */ @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public class DeviceUtils { // 手机网络类型 @@ -58,6 +80,7 @@ public class DeviceUtils { } private DeviceUtils() { + throw new IllegalStateException("you can't instantiate me!"); } /** @@ -775,21 +798,7 @@ public static boolean isExitsSdcard() { else return false; } - public static boolean isServiceRunning(Context context, String ServiceName) { - if (("").equals(ServiceName) || ServiceName == null) - return false; - ActivityManager myManager = (ActivityManager) context - .getSystemService(Context.ACTIVITY_SERVICE); - ArrayList runningService = (ArrayList) myManager - .getRunningServices(200); - for (int i = 0; i < runningService.size(); i++) { - if (runningService.get(i).service.getClassName().toString() - .equals(ServiceName)) { - return true; - } - } - return false; - } + } diff --git a/arms/src/main/java/com/jess/arms/utils/DrawableProvider.java b/arms/src/main/java/com/jess/arms/utils/DrawableProvider.java index e6ceff8..fb5e570 100644 --- a/arms/src/main/java/com/jess/arms/utils/DrawableProvider.java +++ b/arms/src/main/java/com/jess/arms/utils/DrawableProvider.java @@ -1,3 +1,18 @@ +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.utils; import android.graphics.Bitmap; @@ -10,11 +25,18 @@ import java.io.IOException; /** - * Created by jess on 2015/11/24. + * ================================================ + * 处理 {@link Drawable} 和 {@link Bitmap} 的工具类 + *

+ * Created by JessYan on 2015/11/24 + * Contact me + * Follow me + * ================================================ */ public class DrawableProvider { private DrawableProvider() { + throw new IllegalStateException("you can't instantiate me!"); } /** @@ -32,45 +54,42 @@ public static Drawable getStateListDrawable(Drawable normalDrawable, Drawable pr } /** - * 将radiobutton的drawable动态的缩放 + * 将 TextView/RadioButton 中设置的 drawable 动态的缩放 * * @param percent - * @param rb + * @param tv * @return */ - public static Drawable getScaleDrawableForRadioButton(float percent, TextView rb) { - Drawable[] compoundDrawables = rb.getCompoundDrawables(); + public static Drawable getScaleDrawableForRadioButton(float percent, TextView tv) { + Drawable[] compoundDrawables = tv.getCompoundDrawables(); Drawable drawable = null; for (Drawable d : compoundDrawables) { if (d != null) { drawable = d; } } - drawable.setBounds(0, 0, (int) (drawable.getIntrinsicWidth() * percent + 0.5f), (int) (drawable.getIntrinsicHeight() * percent + 0.5f)); - return drawable; + return getScaleDrawable(percent, drawable); } /** - * 将radiobutton的drawable动态的缩放 + * 将 TextView/RadioButton 中设置的 drawable 动态的缩放 * - * @param rb + * @param tv * @return */ - public static Drawable getScaleDrawableForRadioButton2(float width, TextView rb) { - Drawable[] compoundDrawables = rb.getCompoundDrawables(); + public static Drawable getScaleDrawableForRadioButton2(float width, TextView tv) { + Drawable[] compoundDrawables = tv.getCompoundDrawables(); Drawable drawable = null; for (Drawable d : compoundDrawables) { if (d != null) { drawable = d; } } - float percent = width * 1.0f / drawable.getIntrinsicWidth(); - drawable.setBounds(0, 0, (int) (drawable.getIntrinsicWidth() * percent + 0.5f), (int) (drawable.getIntrinsicHeight() * percent + 0.5f)); - return drawable; + return getScaleDrawable2(width, drawable); } /** - * 传入图片,将图片按传入比例缩小 + * 传入图片,将图片按传入比例缩放 * * @param percent * @return @@ -81,15 +100,14 @@ public static Drawable getScaleDrawable(float percent, Drawable drawable) { } /** - * 传入图片,将图片按传入比例缩小 + * 传入图片,将图片按传入宽度和原始宽度的比例缩放 * * @param width * @return */ public static Drawable getScaleDrawable2(float width, Drawable drawable) { float percent = width * 1.0f / drawable.getIntrinsicWidth(); - drawable.setBounds(0, 0, (int) (drawable.getIntrinsicWidth() * percent + 0.5f), (int) (drawable.getIntrinsicHeight() * percent + 0.5f)); - return drawable; + return getScaleDrawable(percent, drawable); } /** @@ -189,5 +207,4 @@ public static int getBitmapDegree(String path) { return degree; } - -} +} \ No newline at end of file diff --git a/arms/src/main/java/com/jess/arms/utils/FastBlur.java b/arms/src/main/java/com/jess/arms/utils/FastBlur.java index dfce625..ccb26f6 100644 --- a/arms/src/main/java/com/jess/arms/utils/FastBlur.java +++ b/arms/src/main/java/com/jess/arms/utils/FastBlur.java @@ -1,3 +1,18 @@ +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.utils; import android.content.Context; @@ -9,11 +24,18 @@ import android.view.View; /** - * Created by paveld on 3/6/14. + * ================================================ + * 处理高斯模糊的工具类 + *

+ * Created by JessYan on 03/06/2014. + * Contact me + * Follow me + * ================================================ */ public class FastBlur { private FastBlur() { + throw new IllegalStateException("you can't instantiate me!"); } public static Bitmap doBlur(Bitmap sentBitmap, int radius, boolean canReuseInBitmap) { @@ -251,6 +273,13 @@ public static Bitmap doBlur(Bitmap sentBitmap, int radius, boolean canReuseInBit return (bitmap); } + /** + * 给 {@link View} 设置高斯模糊背景图片 + * + * @param context + * @param bkg + * @param view + */ public static void blur(Context context, Bitmap bkg, View view) { long startMs = System.currentTimeMillis(); float radius = 15; @@ -271,6 +300,14 @@ public static void blur(Context context, Bitmap bkg, View view) { Log.w("test", "cost " + (System.currentTimeMillis() - startMs) + "ms"); } + /** + * 将 {@link Bitmap} 高斯模糊并返回 + * + * @param bkg + * @param width + * @param height + * @return + */ public static Bitmap blurBitmap(Bitmap bkg, int width, int height) { long startMs = System.currentTimeMillis(); float radius = 15;//越大模糊效果越大 diff --git a/arms/src/main/java/com/jess/arms/utils/LogUtils.java b/arms/src/main/java/com/jess/arms/utils/LogUtils.java index 75f146a..e3ee6e3 100644 --- a/arms/src/main/java/com/jess/arms/utils/LogUtils.java +++ b/arms/src/main/java/com/jess/arms/utils/LogUtils.java @@ -1,16 +1,40 @@ +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.utils; import android.text.TextUtils; import android.util.Log; - +/** + * ================================================ + * 日志工具类 + *

+ * Created by JessYan on 2015/11/23. + * Contact me + * Follow me + * ================================================ + */ public class LogUtils { private LogUtils() { + throw new IllegalStateException("you can't instantiate me!"); } private final static boolean isLog = true; - public static final String DEFAULT_TAG = "Mvparms"; + public static final String DEFAULT_TAG = "MVPArms"; public static void debugInfo(String tag, String msg) { if (!isLog || TextUtils.isEmpty(msg)) return; @@ -18,12 +42,6 @@ public static void debugInfo(String tag, String msg) { } - /** - * author hhj - * TODO - * - * @param msg void - */ public static void debugInfo(String msg) { debugInfo(DEFAULT_TAG, msg); } @@ -34,25 +52,16 @@ public static void warnInfo(String tag, String msg) { } - /** - * author hhj - * TODO - * - * @param msg void - */ public static void warnInfo(String msg) { warnInfo(DEFAULT_TAG, msg); } /** - * author hhj - * TODO 使用Log来显示调试信息,因为log在实现上每个message有4k字符长度限制 * 所以这里使用自己分节的方式来输出足够长度的message * * @param tag * @param str void */ - public static void debugLongInfo(String tag, String str) { if (!isLog) return; str = str.trim(); @@ -72,12 +81,6 @@ public static void debugLongInfo(String tag, String str) { } } - /** - * author hhj - * TODO - * - * @param str void - */ public static void debugLongInfo(String str) { debugLongInfo(DEFAULT_TAG, str); } diff --git a/arms/src/main/java/com/jess/arms/utils/PermissionUtil.java b/arms/src/main/java/com/jess/arms/utils/PermissionUtil.java index fddfc85..6e5dd24 100644 --- a/arms/src/main/java/com/jess/arms/utils/PermissionUtil.java +++ b/arms/src/main/java/com/jess/arms/utils/PermissionUtil.java @@ -1,32 +1,71 @@ +/** + * Copyright 2017 JessYan + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.utils; import android.Manifest; +import com.tbruyelle.rxpermissions2.Permission; import com.tbruyelle.rxpermissions2.RxPermissions; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import io.reactivex.annotations.NonNull; import me.jessyan.rxerrorhandler.core.RxErrorHandler; import me.jessyan.rxerrorhandler.handler.ErrorHandleSubscriber; import timber.log.Timber; /** - * Created by jess on 17/10/2016 10:09 - * Contact with jess.yan.effort@gmail.com + * ================================================ + * 权限请求工具类 + * + * @see PermissionUtil wiki 官方文档 + * Created by JessYan on 17/10/2016 10:09 + * Contact me + * Follow me + * ================================================ */ - public class PermissionUtil { public static final String TAG = "Permission"; private PermissionUtil() { + throw new IllegalStateException("you can't instantiate me!"); } public interface RequestPermission { + /** + * 权限请求成功 + */ void onRequestPermissionSuccess(); - void onRequestPermissionFailure(); + /** + * 用户拒绝了权限请求, 权限请求失败, 但还可以继续请求该权限 + * + * @param permissions 请求失败的权限名 + */ + void onRequestPermissionFailure(List permissions); + + /** + * 用户拒绝了权限请求并且用户选择了以后不再询问, 权限请求失败, 这时将不能继续请求该权限, 需要提示用户进入设置页面打开该权限 + * + * @param permissions 请求失败的权限名 + */ + void onRequestPermissionFailureWithAskNeverAgain(List permissions); } @@ -40,21 +79,30 @@ public static void requestPermission(final RequestPermission requestPermission, } } - if (needRequest.size() == 0) {//全部权限都已经申请过,直接执行操作 + if (needRequest.isEmpty()) {//全部权限都已经申请过,直接执行操作 requestPermission.onRequestPermissionSuccess(); } else {//没有申请过,则开始申请 rxPermissions - .request(needRequest.toArray(new String[needRequest.size()])) - .subscribe(new ErrorHandleSubscriber(errorHandler) { + .requestEach(needRequest.toArray(new String[needRequest.size()])) + .buffer(permissions.length) + .subscribe(new ErrorHandleSubscriber>(errorHandler) { @Override - public void onNext(Boolean granted) { - if (granted) { - Timber.tag(TAG).d("Request permissons success"); - requestPermission.onRequestPermissionSuccess(); - } else { - Timber.tag(TAG).d("Request permissons failure"); - requestPermission.onRequestPermissionFailure(); + public void onNext(@NonNull List permissions) { + for (Permission p : permissions) { + if (!p.granted) { + if (p.shouldShowRequestPermissionRationale) { + Timber.tag(TAG).d("Request permissions failure"); + requestPermission.onRequestPermissionFailure(Arrays.asList(p.name)); + return; + } else { + Timber.tag(TAG).d("Request permissions failure with ask never again"); + requestPermission.onRequestPermissionFailureWithAskNeverAgain(Arrays.asList(p.name)); + return; + } + } } + Timber.tag(TAG).d("Request permissions success"); + requestPermission.onRequestPermissionSuccess(); } }); } diff --git a/arms/src/main/java/com/jess/arms/utils/Preconditions.java b/arms/src/main/java/com/jess/arms/utils/Preconditions.java index 7e98506..6f7a232 100644 --- a/arms/src/main/java/com/jess/arms/utils/Preconditions.java +++ b/arms/src/main/java/com/jess/arms/utils/Preconditions.java @@ -1,14 +1,33 @@ +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.utils; import android.support.annotation.Nullable; /** - * Created by jess on 26/09/2016 13:59 - * Contact with jess.yan.effort@gmail.com + * ================================================ + * Created by JessYan on 26/09/2016 13:59 + * Contact me + * Follow me + * ================================================ */ - public final class Preconditions { + private Preconditions() { + throw new IllegalStateException("you can't instantiate me!"); } public static void checkArgument(boolean expression) { diff --git a/arms/src/main/java/com/jess/arms/utils/ThirdViewUtil.java b/arms/src/main/java/com/jess/arms/utils/ThirdViewUtil.java index a65c036..c7765b3 100644 --- a/arms/src/main/java/com/jess/arms/utils/ThirdViewUtil.java +++ b/arms/src/main/java/com/jess/arms/utils/ThirdViewUtil.java @@ -1,79 +1,99 @@ -package com.jess.arms.utils; - -import android.app.Activity; -import android.app.Dialog; -import android.content.Context; -import android.content.pm.ApplicationInfo; -import android.content.pm.PackageManager; -import android.support.annotation.Nullable; -import android.util.AttributeSet; -import android.view.View; - -import com.zhy.autolayout.AutoFrameLayout; -import com.zhy.autolayout.AutoLinearLayout; -import com.zhy.autolayout.AutoRelativeLayout; - -import butterknife.ButterKnife; -import butterknife.Unbinder; - -import static com.jess.arms.base.delegate.ActivityDelegate.LAYOUT_FRAMELAYOUT; -import static com.jess.arms.base.delegate.ActivityDelegate.LAYOUT_LINEARLAYOUT; -import static com.jess.arms.base.delegate.ActivityDelegate.LAYOUT_RELATIVELAYOUT; - -/** - * Created by zhiyicx on 2016/3/17. - */ -public class ThirdViewUtil { - public static int USE_AUTOLAYOUT = -1;//0 说明 AndroidManifest 里面没有使用 AutoLauout 的Meta,即不使用 AutoLayout,1 为有 Meta ,即需要使用 - - private ThirdViewUtil() { - } - - public static Unbinder bindTarget(Object target, Object source) { - if (source instanceof Activity) { - return ButterKnife.bind(target, (Activity) source); - } else if (source instanceof View) { - return ButterKnife.bind(target, (View) source); - } else if (source instanceof Dialog) { - return ButterKnife.bind(target, (Dialog) source); - } else { - return Unbinder.EMPTY; - } - } - - @Nullable - public static View convertAutoView(String name, Context context, AttributeSet attrs) { - //本框架并不强制你使用 AutoLayout - //如果你不想使用 AutoLayout ,就不要在 AndroidManifest 中声明, AutoLayout 的 Meta属性(design_width,design_height) - if (USE_AUTOLAYOUT == -1) { - USE_AUTOLAYOUT = 1; - PackageManager packageManager = context.getPackageManager(); - ApplicationInfo applicationInfo; - try { - applicationInfo = packageManager.getApplicationInfo(context - .getPackageName(), PackageManager.GET_META_DATA); - if (applicationInfo == null || applicationInfo.metaData == null - || !applicationInfo.metaData.containsKey("design_width") - || !applicationInfo.metaData.containsKey("design_height")) { - USE_AUTOLAYOUT = 0; - } - } catch (PackageManager.NameNotFoundException e) { - USE_AUTOLAYOUT = 0; - } - } - - if (USE_AUTOLAYOUT == 0) { - return null; - } - - View view = null; - if (name.equals(LAYOUT_FRAMELAYOUT)) { - view = new AutoFrameLayout(context, attrs); - } else if (name.equals(LAYOUT_LINEARLAYOUT)) { - view = new AutoLinearLayout(context, attrs); - } else if (name.equals(LAYOUT_RELATIVELAYOUT)) { - view = new AutoRelativeLayout(context, attrs); - } - return view; - } -} +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jess.arms.utils; + +import android.app.Activity; +import android.app.Dialog; +import android.content.Context; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; +import android.support.annotation.Nullable; +import android.util.AttributeSet; +import android.view.View; + +import com.zhy.autolayout.AutoFrameLayout; +import com.zhy.autolayout.AutoLinearLayout; +import com.zhy.autolayout.AutoRelativeLayout; + +import butterknife.ButterKnife; +import butterknife.Unbinder; + +import static com.jess.arms.base.delegate.ActivityDelegate.LAYOUT_FRAMELAYOUT; +import static com.jess.arms.base.delegate.ActivityDelegate.LAYOUT_LINEARLAYOUT; +import static com.jess.arms.base.delegate.ActivityDelegate.LAYOUT_RELATIVELAYOUT; + +/** + * ================================================ + * Created by JessYan on 17/03/2016 13:59 + * Contact me + * Follow me + * ================================================ + */ +public class ThirdViewUtil { + public static int USE_AUTOLAYOUT = -1;//0 说明 AndroidManifest 里面没有使用 AutoLauout 的Meta,即不使用 AutoLayout,1 为有 Meta ,即需要使用 + + private ThirdViewUtil() { + throw new IllegalStateException("you can't instantiate me!"); + } + + public static Unbinder bindTarget(Object target, Object source) { + if (source instanceof Activity) { + return ButterKnife.bind(target, (Activity) source); + } else if (source instanceof View) { + return ButterKnife.bind(target, (View) source); + } else if (source instanceof Dialog) { + return ButterKnife.bind(target, (Dialog) source); + } else { + return Unbinder.EMPTY; + } + } + + @Nullable + public static View convertAutoView(String name, Context context, AttributeSet attrs) { + //本框架并不强制你使用 AutoLayout + //如果你不想使用 AutoLayout ,就不要在 AndroidManifest 中声明, AutoLayout 的 Meta属性(design_width,design_height) + if (USE_AUTOLAYOUT == -1) { + USE_AUTOLAYOUT = 1; + PackageManager packageManager = context.getPackageManager(); + ApplicationInfo applicationInfo; + try { + applicationInfo = packageManager.getApplicationInfo(context + .getPackageName(), PackageManager.GET_META_DATA); + if (applicationInfo == null || applicationInfo.metaData == null + || !applicationInfo.metaData.containsKey("design_width") + || !applicationInfo.metaData.containsKey("design_height")) { + USE_AUTOLAYOUT = 0; + } + } catch (PackageManager.NameNotFoundException e) { + USE_AUTOLAYOUT = 0; + } + } + + if (USE_AUTOLAYOUT == 0) { + return null; + } + + View view = null; + if (name.equals(LAYOUT_FRAMELAYOUT)) { + view = new AutoFrameLayout(context, attrs); + } else if (name.equals(LAYOUT_LINEARLAYOUT)) { + view = new AutoLinearLayout(context, attrs); + } else if (name.equals(LAYOUT_RELATIVELAYOUT)) { + view = new AutoRelativeLayout(context, attrs); + } + return view; + } +} diff --git a/arms/src/main/java/com/jess/arms/utils/ZipHelper.java b/arms/src/main/java/com/jess/arms/utils/ZipHelper.java index 04cecf5..3840398 100644 --- a/arms/src/main/java/com/jess/arms/utils/ZipHelper.java +++ b/arms/src/main/java/com/jess/arms/utils/ZipHelper.java @@ -1,3 +1,18 @@ +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.utils; import java.io.ByteArrayInputStream; @@ -14,12 +29,19 @@ import java.util.zip.Inflater; /** - * Created by jess on 16/5/10. + * ================================================ + * 处理压缩和解压的工具类 + *

+ * Created by JessYan on 10/05/2016 + * Contact me + * Follow me + * ================================================ */ public class ZipHelper { private ZipHelper() { + throw new IllegalStateException("you can't instantiate me!"); } /** @@ -29,7 +51,7 @@ private ZipHelper() { * @return */ public static String decompressToStringForZlib(byte[] bytesToDecompress) { - return decompressToStringForZlib(bytesToDecompress,"UTF-8"); + return decompressToStringForZlib(bytesToDecompress, "UTF-8"); } diff --git a/arms/src/main/java/com/jess/arms/widget/CustomPopupWindow.java b/arms/src/main/java/com/jess/arms/widget/CustomPopupWindow.java index 3b71b12..9e69edf 100644 --- a/arms/src/main/java/com/jess/arms/widget/CustomPopupWindow.java +++ b/arms/src/main/java/com/jess/arms/widget/CustomPopupWindow.java @@ -1,3 +1,18 @@ +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.widget; import android.graphics.drawable.ColorDrawable; @@ -9,7 +24,18 @@ import android.widget.LinearLayout.LayoutParams; import android.widget.PopupWindow; - +/** + * ================================================ + * 因为继承于 {@link PopupWindow} ,所以它本身就是一个 {@link PopupWindow} + * 因此如果此类里封装的功能并不能满足您的需求(不想过多封装 UI 的东西,这里只提供思想,觉得不满足需求可以自己仿照着封装) + * 您可以直接调用 {@link PopupWindow} 的 Api 满足需求 + * + * @see CustomPopupWindow wiki 官方文档 + * Created by JessYan on 4/22/2016 + * Contact me + * Follow me + * ================================================ + */ public class CustomPopupWindow extends PopupWindow { private View mContentView; private View mParentView; @@ -134,7 +160,7 @@ public Builder animationStyle(int animationStyle) { public CustomPopupWindow build() { if (contentView == null) - throw new IllegalStateException("contentView is required"); + throw new IllegalStateException("ContentView is required"); if (listener == null) throw new IllegalStateException("CustomPopupWindowListener is required"); diff --git a/arms/src/main/java/com/jess/arms/widget/autolayout/AutoAppBarLayout.java b/arms/src/main/java/com/jess/arms/widget/autolayout/AutoAppBarLayout.java index 739ed8a..b31f551 100644 --- a/arms/src/main/java/com/jess/arms/widget/autolayout/AutoAppBarLayout.java +++ b/arms/src/main/java/com/jess/arms/widget/autolayout/AutoAppBarLayout.java @@ -1,15 +1,39 @@ +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.widget.autolayout; import android.content.Context; import android.support.design.widget.AppBarLayout; import android.util.AttributeSet; +import android.view.View; import android.view.ViewGroup; import com.zhy.autolayout.AutoLayoutInfo; import com.zhy.autolayout.utils.AutoLayoutHelper; /** - * Created by jess on 16/4/14. + * ================================================ + * 实现 AndroidAutoLayout 规范的 {@link AppBarLayout} + * 可使用 MVP_generator_solution 中的 AutoView 模版生成各种符合 AndroidAutoLayout 规范的 {@link View} + * + * @see AutoLayout wiki 官方文档 + * Created by JessYan on 4/14/2016 + * Contact me + * Follow me + * ================================================ */ public class AutoAppBarLayout extends AppBarLayout { @@ -24,8 +48,7 @@ public AutoAppBarLayout(Context context, AttributeSet attrs) { } @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) - { + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (!isInEditMode()) mHelper.adjustChildren(); super.onMeasure(widthMeasureSpec, heightMeasureSpec); @@ -33,8 +56,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) @Override - protected void onLayout(boolean changed, int l, int t, int r, int b) - { + protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); } @@ -45,36 +67,30 @@ public LayoutParams generateLayoutParams(AttributeSet attrs) { public static class LayoutParams extends AppBarLayout.LayoutParams - implements AutoLayoutHelper.AutoLayoutParams - { + implements AutoLayoutHelper.AutoLayoutParams { private AutoLayoutInfo mAutoLayoutInfo; - public LayoutParams(Context c, AttributeSet attrs) - { + public LayoutParams(Context c, AttributeSet attrs) { super(c, attrs); mAutoLayoutInfo = AutoLayoutHelper.getAutoLayoutInfo(c, attrs); } @Override - public AutoLayoutInfo getAutoLayoutInfo() - { + public AutoLayoutInfo getAutoLayoutInfo() { return mAutoLayoutInfo; } - public LayoutParams(int width, int height) - { + public LayoutParams(int width, int height) { super(width, height); } - public LayoutParams(ViewGroup.LayoutParams source) - { + public LayoutParams(ViewGroup.LayoutParams source) { super(source); } - public LayoutParams(MarginLayoutParams source) - { + public LayoutParams(MarginLayoutParams source) { super(source); } diff --git a/arms/src/main/java/com/jess/arms/widget/autolayout/AutoCollapsingToolbarLayout.java b/arms/src/main/java/com/jess/arms/widget/autolayout/AutoCollapsingToolbarLayout.java index 80dbc5e..638eae4 100644 --- a/arms/src/main/java/com/jess/arms/widget/autolayout/AutoCollapsingToolbarLayout.java +++ b/arms/src/main/java/com/jess/arms/widget/autolayout/AutoCollapsingToolbarLayout.java @@ -1,15 +1,39 @@ +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.widget.autolayout; import android.content.Context; import android.support.design.widget.CollapsingToolbarLayout; import android.util.AttributeSet; +import android.view.View; import android.view.ViewGroup; import com.zhy.autolayout.AutoLayoutInfo; import com.zhy.autolayout.utils.AutoLayoutHelper; /** - * Created by jess on 16/4/14. + * ================================================ + * 实现 AndroidAutoLayout 规范的 {@link CollapsingToolbarLayout} + * 可使用 MVP_generator_solution 中的 AutoView 模版生成各种符合 AndroidAutoLayout 规范的 {@link View} + * + * @see AutoLayout wiki 官方文档 + * Created by JessYan on 4/14/2016 + * Contact me + * Follow me + * ================================================ */ public class AutoCollapsingToolbarLayout extends CollapsingToolbarLayout { private AutoLayoutHelper mHelper = new AutoLayoutHelper(this); @@ -27,8 +51,7 @@ public AutoCollapsingToolbarLayout(Context context, AttributeSet attrs, int defS } @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) - { + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (!isInEditMode()) mHelper.adjustChildren(); super.onMeasure(widthMeasureSpec, heightMeasureSpec); @@ -36,8 +59,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) @Override - protected void onLayout(boolean changed, int l, int t, int r, int b) - { + protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); } @@ -47,38 +69,31 @@ public LayoutParams generateLayoutParams(AttributeSet attrs) { } - public static class LayoutParams extends CollapsingToolbarLayout.LayoutParams - implements AutoLayoutHelper.AutoLayoutParams - { + implements AutoLayoutHelper.AutoLayoutParams { private AutoLayoutInfo mAutoLayoutInfo; - public LayoutParams(Context c, AttributeSet attrs) - { + public LayoutParams(Context c, AttributeSet attrs) { super(c, attrs); mAutoLayoutInfo = AutoLayoutHelper.getAutoLayoutInfo(c, attrs); } @Override - public AutoLayoutInfo getAutoLayoutInfo() - { + public AutoLayoutInfo getAutoLayoutInfo() { return mAutoLayoutInfo; } - public LayoutParams(int width, int height) - { + public LayoutParams(int width, int height) { super(width, height); } - public LayoutParams(ViewGroup.LayoutParams source) - { + public LayoutParams(ViewGroup.LayoutParams source) { super(source); } - public LayoutParams(MarginLayoutParams source) - { + public LayoutParams(MarginLayoutParams source) { super(source); } diff --git a/arms/src/main/java/com/jess/arms/widget/autolayout/AutoScrollView.java b/arms/src/main/java/com/jess/arms/widget/autolayout/AutoScrollView.java index 5357719..ec923c4 100644 --- a/arms/src/main/java/com/jess/arms/widget/autolayout/AutoScrollView.java +++ b/arms/src/main/java/com/jess/arms/widget/autolayout/AutoScrollView.java @@ -1,8 +1,24 @@ +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.widget.autolayout; import android.content.Context; import android.support.annotation.Nullable; import android.util.AttributeSet; +import android.view.View; import android.view.ViewGroup; import android.widget.ScrollView; @@ -10,7 +26,15 @@ import com.zhy.autolayout.utils.AutoLayoutHelper; /** - * Created by jess on 16/4/14. + * ================================================ + * 实现 AndroidAutoLayout 规范的 {@link ScrollView} + * 可使用 MVP_generator_solution 中的 AutoView 模版生成各种符合 AndroidAutoLayout 规范的 {@link View} + * + * @see AutoLayout wiki 官方文档 + * Created by JessYan on 4/14/2016 + * Contact me + * Follow me + * ================================================ */ public class AutoScrollView extends ScrollView { private AutoLayoutHelper mHelper = new AutoLayoutHelper(this); @@ -28,8 +52,7 @@ public AutoScrollView(Context context, @Nullable AttributeSet attrs, int defStyl } @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) - { + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (!isInEditMode()) mHelper.adjustChildren(); super.onMeasure(widthMeasureSpec, heightMeasureSpec); @@ -37,8 +60,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) @Override - protected void onLayout(boolean changed, int l, int t, int r, int b) - { + protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); } @@ -50,36 +72,30 @@ public LayoutParams generateLayoutParams(AttributeSet attrs) { public static class LayoutParams extends ScrollView.LayoutParams - implements AutoLayoutHelper.AutoLayoutParams - { + implements AutoLayoutHelper.AutoLayoutParams { private AutoLayoutInfo mAutoLayoutInfo; - public LayoutParams(Context c, AttributeSet attrs) - { + public LayoutParams(Context c, AttributeSet attrs) { super(c, attrs); mAutoLayoutInfo = AutoLayoutHelper.getAutoLayoutInfo(c, attrs); } @Override - public AutoLayoutInfo getAutoLayoutInfo() - { + public AutoLayoutInfo getAutoLayoutInfo() { return mAutoLayoutInfo; } - public LayoutParams(int width, int height) - { + public LayoutParams(int width, int height) { super(width, height); } - public LayoutParams(ViewGroup.LayoutParams source) - { + public LayoutParams(ViewGroup.LayoutParams source) { super(source); } - public LayoutParams(MarginLayoutParams source) - { + public LayoutParams(MarginLayoutParams source) { super(source); } diff --git a/arms/src/main/java/com/jess/arms/widget/autolayout/AutoTabLayout.java b/arms/src/main/java/com/jess/arms/widget/autolayout/AutoTabLayout.java index 7caf44c..9114adf 100644 --- a/arms/src/main/java/com/jess/arms/widget/autolayout/AutoTabLayout.java +++ b/arms/src/main/java/com/jess/arms/widget/autolayout/AutoTabLayout.java @@ -1,3 +1,18 @@ +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.widget.autolayout; import android.content.Context; @@ -5,6 +20,7 @@ import android.support.design.widget.TabLayout; import android.util.AttributeSet; import android.util.TypedValue; +import android.view.View; import android.view.ViewGroup; import android.widget.TextView; @@ -13,26 +29,30 @@ import com.zhy.autolayout.utils.DimenUtils; /** - * Created by jess on 16/4/14. + * ================================================ + * 实现 AndroidAutoLayout 规范的 {@link TabLayout} + * 可使用 MVP_generator_solution 中的 AutoView 模版生成各种符合 AndroidAutoLayout 规范的 {@link View} + * + * @see AutoLayout wiki 官方文档 + * Created by JessYan on 4/14/2016 + * Contact me + * Follow me + * ================================================ */ -public class AutoTabLayout extends TabLayout -{ +public class AutoTabLayout extends TabLayout { private static final int NO_VALID = -1; private int mTextSize; private boolean mTextSizeBaseWidth = false; - public AutoTabLayout(Context context) - { + public AutoTabLayout(Context context) { this(context, null); } - public AutoTabLayout(Context context, AttributeSet attrs) - { + public AutoTabLayout(Context context, AttributeSet attrs) { this(context, attrs, 0); } - public AutoTabLayout(Context context, AttributeSet attrs, int defStyleAttr) - { + public AutoTabLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); initTextSizeBaseWidth(context, attrs); @@ -46,45 +66,38 @@ public AutoTabLayout(Context context, AttributeSet attrs, int defStyleAttr) a.recycle(); } - private void initTextSizeBaseWidth(Context context, AttributeSet attrs) - { + private void initTextSizeBaseWidth(Context context, AttributeSet attrs) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AutoTabLayout); mTextSizeBaseWidth = a.getBoolean(R.styleable.AutoTabLayout_auto_textSize_base_width, false); a.recycle(); } - private int loadTextSizeFromTextAppearance(int textAppearanceResId) - { + private int loadTextSizeFromTextAppearance(int textAppearanceResId) { TypedArray a = getContext().obtainStyledAttributes(textAppearanceResId, R.styleable.TextAppearance); - try - { + try { if (!DimenUtils.isPxVal(a.peekValue(R.styleable.TextAppearance_android_textSize))) return NO_VALID; return a.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize, NO_VALID); - } finally - { + } finally { a.recycle(); } } @Override - public void addTab(Tab tab, int position, boolean setSelected) - { + public void addTab(Tab tab, int position, boolean setSelected) { super.addTab(tab, position, setSelected); setUpTabTextSize(tab); } @Override - public void addTab(Tab tab, boolean setSelected) - { + public void addTab(Tab tab, boolean setSelected) { super.addTab(tab, setSelected); setUpTabTextSize(tab); } - private void setUpTabTextSize(Tab tab) - { + private void setUpTabTextSize(Tab tab) { if (mTextSize == NO_VALID || tab.getCustomView() != null) return; ViewGroup tabGroup = (ViewGroup) getChildAt(0); @@ -92,16 +105,13 @@ private void setUpTabTextSize(Tab tab) TextView textView = (TextView) tabContainer.getChildAt(1); - if (AutoUtils.autoed(textView)) - { + if (AutoUtils.autoed(textView)) { return; } - int autoTextSize = 0 ; - if (mTextSizeBaseWidth) - { + int autoTextSize = 0; + if (mTextSizeBaseWidth) { autoTextSize = AutoUtils.getPercentWidthSize(mTextSize); - } else - { + } else { autoTextSize = AutoUtils.getPercentHeightSize(mTextSize); } diff --git a/arms/src/main/java/com/jess/arms/widget/autolayout/AutoToolbar.java b/arms/src/main/java/com/jess/arms/widget/autolayout/AutoToolbar.java index 83da5a6..87f8f1a 100644 --- a/arms/src/main/java/com/jess/arms/widget/autolayout/AutoToolbar.java +++ b/arms/src/main/java/com/jess/arms/widget/autolayout/AutoToolbar.java @@ -1,16 +1,40 @@ +/** + * Copyright 2017 JessYan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jess.arms.widget.autolayout; import android.content.Context; import android.support.annotation.Nullable; import android.support.v7.widget.Toolbar; import android.util.AttributeSet; +import android.view.View; import android.view.ViewGroup; import com.zhy.autolayout.AutoLayoutInfo; import com.zhy.autolayout.utils.AutoLayoutHelper; /** - * Created by jess on 16/4/14. + * ================================================ + * 实现 AndroidAutoLayout 规范的 {@link Toolbar} + * 可使用 MVP_generator_solution 中的 AutoView 模版生成各种符合 AndroidAutoLayout 规范的 {@link View} + * + * @see AutoLayout wiki 官方文档 + * Created by JessYan on 4/14/2016 + * Contact me + * Follow me + * ================================================ */ public class AutoToolbar extends Toolbar { private AutoLayoutHelper mHelper = new AutoLayoutHelper(this); @@ -28,8 +52,7 @@ public AutoToolbar(Context context, @Nullable AttributeSet attrs, int defStyleAt } @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) - { + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (!isInEditMode()) mHelper.adjustChildren(); super.onMeasure(widthMeasureSpec, heightMeasureSpec); @@ -37,8 +60,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) @Override - protected void onLayout(boolean changed, int l, int t, int r, int b) - { + protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); } @@ -50,36 +72,30 @@ public LayoutParams generateLayoutParams(AttributeSet attrs) { public static class LayoutParams extends Toolbar.LayoutParams - implements AutoLayoutHelper.AutoLayoutParams - { + implements AutoLayoutHelper.AutoLayoutParams { private AutoLayoutInfo mAutoLayoutInfo; - public LayoutParams(Context c, AttributeSet attrs) - { + public LayoutParams(Context c, AttributeSet attrs) { super(c, attrs); mAutoLayoutInfo = AutoLayoutHelper.getAutoLayoutInfo(c, attrs); } @Override - public AutoLayoutInfo getAutoLayoutInfo() - { + public AutoLayoutInfo getAutoLayoutInfo() { return mAutoLayoutInfo; } - public LayoutParams(int width, int height) - { + public LayoutParams(int width, int height) { super(width, height); } - public LayoutParams(ViewGroup.LayoutParams source) - { + public LayoutParams(ViewGroup.LayoutParams source) { super(source); } - public LayoutParams(MarginLayoutParams source) - { + public LayoutParams(MarginLayoutParams source) { super(source); } diff --git a/arms/src/main/java/com/jess/arms/widget/imageloader/BaseImageLoaderStrategy.java b/arms/src/main/java/com/jess/arms/widget/imageloader/BaseImageLoaderStrategy.java deleted file mode 100644 index 605e054..0000000 --- a/arms/src/main/java/com/jess/arms/widget/imageloader/BaseImageLoaderStrategy.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.jess.arms.widget.imageloader; - -import android.content.Context; - -/** - * Created by jess on 8/5/16 15:50 - * contact with jess.yan.effort@gmail.com - */ -public interface BaseImageLoaderStrategy { - void loadImage(Context ctx, T config); - void clear(Context ctx, T config); -} diff --git a/arms/src/main/java/com/jess/arms/widget/imageloader/ImageConfig.java b/arms/src/main/java/com/jess/arms/widget/imageloader/ImageConfig.java deleted file mode 100644 index 5b5c102..0000000 --- a/arms/src/main/java/com/jess/arms/widget/imageloader/ImageConfig.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.jess.arms.widget.imageloader; - -import android.widget.ImageView; - -/** - * Created by jess on 8/5/16 15:19 - * contact with jess.yan.effort@gmail.com - * 这里是图片加载配置信息的基类,可以定义一些所有图片加载框架都可以用的通用参数 - */ -public class ImageConfig { - protected String url; - protected ImageView imageView; - protected int placeholder; - protected int errorPic; - - - public String getUrl() { - return url; - } - - public ImageView getImageView() { - return imageView; - } - - public int getPlaceholder() { - return placeholder; - } - - public int getErrorPic() { - return errorPic; - } -} diff --git a/arms/src/main/java/com/jess/arms/widget/imageloader/ImageLoader.java b/arms/src/main/java/com/jess/arms/widget/imageloader/ImageLoader.java deleted file mode 100644 index d366273..0000000 --- a/arms/src/main/java/com/jess/arms/widget/imageloader/ImageLoader.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.jess.arms.widget.imageloader; - -import android.content.Context; - -import javax.inject.Inject; -import javax.inject.Singleton; - -/** - * Created by jess on 8/5/16 15:57 - * contact with jess.yan.effort@gmail.com - */ -@Singleton -public final class ImageLoader { - private BaseImageLoaderStrategy mStrategy; - - @Inject - public ImageLoader(BaseImageLoaderStrategy strategy) { - setLoadImgStrategy(strategy); - } - - - public void loadImage(Context context, T config) { - this.mStrategy.loadImage(context, config); - } - - public void clear(Context context, T config) { - this.mStrategy.clear(context, config); - } - - - public void setLoadImgStrategy(BaseImageLoaderStrategy strategy) { - this.mStrategy = strategy; - } - -} diff --git a/arms/src/main/java/com/jess/arms/widget/imageloader/glide/GlideConfiguration.java b/arms/src/main/java/com/jess/arms/widget/imageloader/glide/GlideConfiguration.java deleted file mode 100644 index 4a2a234..0000000 --- a/arms/src/main/java/com/jess/arms/widget/imageloader/glide/GlideConfiguration.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.jess.arms.widget.imageloader.glide; - -import android.content.Context; - -import com.bumptech.glide.Glide; -import com.bumptech.glide.GlideBuilder; -import com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool; -import com.bumptech.glide.load.engine.cache.DiskCache; -import com.bumptech.glide.load.engine.cache.DiskLruCacheWrapper; -import com.bumptech.glide.load.engine.cache.LruResourceCache; -import com.bumptech.glide.load.engine.cache.MemorySizeCalculator; -import com.bumptech.glide.load.model.GlideUrl; -import com.bumptech.glide.module.GlideModule; -import com.jess.arms.base.App; -import com.jess.arms.di.component.AppComponent; -import com.jess.arms.http.OkHttpUrlLoader; -import com.jess.arms.utils.DataHelper; - -import java.io.File; -import java.io.InputStream; - -/** - * Created by jess on 16/4/15. - */ -public class GlideConfiguration implements GlideModule { - public static final int IMAGE_DISK_CACHE_MAX_SIZE = 100 * 1024 * 1024;//图片缓存文件最大值为100Mb - - @Override - public void applyOptions(Context context, GlideBuilder builder) { - builder.setDiskCache(new DiskCache.Factory() { - @Override - public DiskCache build() { - // Careful: the external cache directory doesn't enforce permissions - AppComponent appComponent = ((App) context.getApplicationContext()).getAppComponent(); - return DiskLruCacheWrapper.get(DataHelper.makeDirs(new File(appComponent.cacheFile(), "Glide")), IMAGE_DISK_CACHE_MAX_SIZE); - } - }); - - MemorySizeCalculator calculator = new MemorySizeCalculator(context); - int defaultMemoryCacheSize = calculator.getMemoryCacheSize(); - int defaultBitmapPoolSize = calculator.getBitmapPoolSize(); - - int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize); - int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize); - - builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize)); - builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize)); - - } - - @Override - public void registerComponents(Context context, Glide glide) { - //Glide默认使用HttpURLConnection做网络请求,在这切换成okhttp请求 - AppComponent appComponent = ((App) context.getApplicationContext()).getAppComponent(); - glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(appComponent.okHttpClient())); - } -} diff --git a/arms/src/main/java/com/jess/arms/widget/imageloader/glide/GlideImageLoaderStrategy.java b/arms/src/main/java/com/jess/arms/widget/imageloader/glide/GlideImageLoaderStrategy.java deleted file mode 100644 index baaed27..0000000 --- a/arms/src/main/java/com/jess/arms/widget/imageloader/glide/GlideImageLoaderStrategy.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.jess.arms.widget.imageloader.glide; - -import android.content.Context; -import android.text.TextUtils; -import android.widget.ImageView; - -import com.bumptech.glide.DrawableRequestBuilder; -import com.bumptech.glide.Glide; -import com.bumptech.glide.RequestManager; -import com.bumptech.glide.load.engine.DiskCacheStrategy; -import com.bumptech.glide.request.target.Target; -import com.jess.arms.widget.imageloader.BaseImageLoaderStrategy; - -import io.reactivex.Observable; -import io.reactivex.annotations.NonNull; -import io.reactivex.functions.Consumer; -import io.reactivex.schedulers.Schedulers; - -/** - * Created by jess on 8/5/16 16:28 - * contact with jess.yan.effort@gmail.com - */ -public class GlideImageLoaderStrategy implements BaseImageLoaderStrategy { - - @Override - public void loadImage(Context ctx, GlideImageConfig config) { - if (ctx == null) throw new NullPointerException("Context is required"); - if (config == null) throw new NullPointerException("GlideImageConfig is required"); - if (TextUtils.isEmpty(config.getUrl())&&config.getPlaceholder()==0) throw new NullPointerException("Url is required"); - if (config.getImageView() == null) throw new NullPointerException("Imageview is required"); - - - RequestManager manager; - - manager = Glide.with(ctx);//如果context是activity则自动使用Activity的生命周期 - - DrawableRequestBuilder requestBuilder = manager.load(config.getUrl()) - .crossFade() - .centerCrop(); - - switch (config.getCacheStrategy()) {//缓存策略 - case 0: - requestBuilder.diskCacheStrategy(DiskCacheStrategy.ALL); - break; - case 1: - requestBuilder.diskCacheStrategy(DiskCacheStrategy.NONE); - break; - case 2: - requestBuilder.diskCacheStrategy(DiskCacheStrategy.SOURCE); - break; - case 3: - requestBuilder.diskCacheStrategy(DiskCacheStrategy.RESULT); - break; - } - - if (config.getTransformation() != null) {//glide用它来改变图形的形状 - requestBuilder.transform(config.getTransformation()); - } - - - if (config.getPlaceholder() != 0)//设置占位符 - requestBuilder.placeholder(config.getPlaceholder()); - - if (config.getErrorPic() != 0)//设置错误的图片 - requestBuilder.error(config.getErrorPic()); - - requestBuilder - .into(config.getImageView()); - } - - @Override - public void clear(final Context ctx, GlideImageConfig config) { - if (ctx == null) throw new NullPointerException("Context is required"); - if (config == null) throw new NullPointerException("GlideImageConfig is required"); - - if (config.getImageViews() != null && config.getImageViews().length > 0) {//取消在执行的任务并且释放资源 - for (ImageView imageView : config.getImageViews()) { - Glide.clear(imageView); - } - } - - if (config.getTargets() != null && config.getTargets().length > 0) {//取消在执行的任务并且释放资源 - for (Target target : config.getTargets()) - Glide.clear(target); - } - - - if (config.isClearDiskCache()) {//清除本地缓存 - Observable.just(0) - .observeOn(Schedulers.io()) - .subscribe(new Consumer() { - @Override - public void accept(@NonNull Integer integer) throws Exception { - Glide.get(ctx).clearDiskCache(); - } - }); - } - - if (config.isClearMemory()) {//清除内存缓存 - Glide.get(ctx).clearMemory(); - } - - - } -} diff --git a/build.gradle b/build.gradle index 712dbbc..b412c33 100644 --- a/build.gradle +++ b/build.gradle @@ -7,15 +7,14 @@ buildscript { maven{ url uri('repo') } + google() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.1' + classpath 'com.android.tools.build:gradle:3.0.1' //Gradle Android Maven plugin classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' //Gradle Bintray Plugin classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3' - //lambda - classpath 'me.tatarka:gradle-retrolambda:3.6.0' //aspectj classpath 'org.aspectj:aspectjtools:1.8.9' classpath 'com.zwh.plugin:gradleplugin:1.0.0' @@ -32,6 +31,7 @@ allprojects { maven { url "https://jitpack.io" } maven { url "https://maven.google.com" } maven { url "https://raw.github.com/bmob/bmob-android-sdk/master" } + google() } } diff --git a/config.gradle b/config.gradle index b878847..8e333b6 100644 --- a/config.gradle +++ b/config.gradle @@ -1,23 +1,24 @@ ext { android = [ - compileSdkVersion : 26, - buildToolsVersion : "26.0.2", + compileSdkVersion : 27, + buildToolsVersion : "27.0.2", minSdkVersion : 17, - targetSdkVersion : 26, - versionCode : 133, - versionName : "1.0.4" + targetSdkVersion : 27, + versionCode : 134, + versionName : "1.0.5" ] version = [ - androidSupportSdkVersion: "26.0.2", + androidSupportSdkVersion: "27.0.2", retrofitSdkVersion : "2.3.0", - dagger2SdkVersion : "2.11", - butterknifeSdkVersion : "8.7.0", + dagger2SdkVersion : "2.13", + glideSdkVersion : "4.4.0", + butterknifeSdkVersion : "8.8.1", rxlifecycleSdkVersion : "1.0", - rxlifecycle2SdkVersion : "2.1.0", - espressoSdkVersion : "2.2.2", - canarySdkVersion : "1.5.1" + rxlifecycle2SdkVersion : "2.2.1", + espressoSdkVersion : "3.0.1", + canarySdkVersion : "1.5.4" ] dependencies = [ @@ -36,7 +37,9 @@ ext { "retrofit-adapter-rxjava2" : "com.squareup.retrofit2:adapter-rxjava2:${version["retrofitSdkVersion"]}", "okhttp3" : "com.squareup.okhttp3:okhttp:3.9.1", "okhttp-urlconnection" : "com.squareup.okhttp:okhttp-urlconnection:2.0.0", - "glide" : "com.github.bumptech.glide:glide:3.8.0", + "glide" : "com.github.bumptech.glide:glide:${version["glideSdkVersion"]}", + "glide-compiler" : "com.github.bumptech.glide:compiler:${version["glideSdkVersion"]}", + "glide-loader-okhttp3" : "com.github.bumptech.glide:okhttp3-integration:${version["glideSdkVersion"]}", "picasso" : "com.squareup.picasso:picasso:2.5.2", "filedownloader" : "com.liulishuo.filedownloader:library:1.6.8", @@ -72,6 +75,7 @@ ext { "rxandroid2" : "io.reactivex.rxjava2:rxandroid:2.0.1", "rxjava2" : "io.reactivex.rxjava2:rxjava:2.1.1", "rxlifecycle2" : "com.trello.rxlifecycle2:rxlifecycle:${version["rxlifecycle2SdkVersion"]}", + "rxlifecycle2-android" : "com.trello.rxlifecycle2:rxlifecycle-android:${version["rxlifecycle2SdkVersion"]}", "rxlifecycle2-components" : "com.trello.rxlifecycle2:rxlifecycle-components:${version["rxlifecycle2SdkVersion"]}", "rxcache2" : "com.github.VictorAlbertos.RxCache:runtime:1.8.1-2.x", "rxpermissions2" : "com.tbruyelle.rxpermissions2:rxpermissions:0.9.4@aar", diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e64b3d8..ab01cce 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip diff --git a/plugin/build.gradle b/plugin/build.gradle index 637db90..46e4c1e 100644 --- a/plugin/build.gradle +++ b/plugin/build.gradle @@ -2,11 +2,11 @@ apply plugin: 'groovy' apply plugin: 'maven' dependencies { - compile gradleApi()//gradle sdk - compile localGroovy()//groovy sdk - compile 'com.android.tools.build:gradle:2.2.2' - compile 'org.javassist:javassist:3.20.0-GA' - compile 'org.aspectj:aspectjtools:1.8.1' + implementation gradleApi()//gradle sdk + implementation localGroovy()//groovy sdk + implementation 'com.android.tools.build:gradle:2.2.2' + implementation 'org.javassist:javassist:3.20.0-GA' + implementation 'org.aspectj:aspectjtools:1.8.1' } uploadArchives { repositories.mavenDeployer {