From 452f97466f7f9204dc96704cffd9f4208e6f18b7 Mon Sep 17 00:00:00 2001 From: zhaoyubetter Date: Thu, 29 Nov 2018 16:53:56 +0800 Subject: [PATCH] update, use android.app.Loader replace v4 loader --- build.gradle | 2 +- config.gradle | 7 ++-- demo/build.gradle | 41 ++++++++----------- mae-bundles-album/build.gradle | 15 +++---- .../album/image/ImageCursorActivity.java | 7 ++-- .../yu/bundles/album/model/AlbumLoader.java | 2 +- .../bundles/album/model/AlbumMediaLoader.java | 2 +- .../album/model/AlbumMediaModelImpl.java | 4 +- .../bundles/album/model/AlbumModelImpl.java | 4 +- .../album/presenter/AlbumCursorView.java | 18 -------- .../album/presenter/AlbumPresenterImpl.java | 4 +- .../yu/bundles/album/presenter/AlbumView.java | 4 +- 12 files changed, 41 insertions(+), 69 deletions(-) delete mode 100644 mae-bundles-album/src/main/java/com/yu/bundles/album/presenter/AlbumCursorView.java diff --git a/build.gradle b/build.gradle index d76d804..80571b5 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.1' + classpath 'com.android.tools.build:gradle:3.0.0' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/config.gradle b/config.gradle index 72d55c0..9ed4157 100644 --- a/config.gradle +++ b/config.gradle @@ -2,11 +2,10 @@ ext { VERSION_NAME = "3.5.0" VERSION_CODE = 1 - COMPILE_SDK_VERSION = 26 // 25 23 - BUILD_TOOLS_VERSION = "26.0.1" // 25.0.2 23.0.2 + COMPILE_SDK_VERSION = 27 // 25 23 MIN_SDK_VERSION = 14 - TARGET_SDK_VERSION = 23 // 这个千万不能改 - SUPPORT_VERSION = "26.0.2" + TARGET_SDK_VERSION = 23 + SUPPORT_VERSION = "27.1.1" GLIDE_VERSION = '3.7.0' // support依赖支持包 compile_support = [ diff --git a/demo/build.gradle b/demo/build.gradle index a44cc6a..4a3cc13 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -1,13 +1,12 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 26 - buildToolsVersion "26.0.1" + compileSdkVersion COMPILE_SDK_VERSION defaultConfig { applicationId "com.example.demo" minSdkVersion 15 - targetSdkVersion 26 + targetSdkVersion TARGET_SDK_VERSION versionCode 1 versionName VERSION_NAME testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -24,14 +23,14 @@ android { abortOnError false } - android.applicationVariants.all { - variant -> - variant.outputs.each { output -> - if (buildType.name == 'release') { - output.outputFile = new File(output.outputFile.parent, "${getCurrentTime()}_album_${buildType.name}_${defaultConfig.versionName}.apk") - } - } - } +// android.applicationVariants.all { +// variant -> +// variant.outputs.each { output -> +// if (buildType.name == 'release') { +// output.outputFile = new File(output.outputFile.parent, "${getCurrentTime()}_album_${buildType.name}_${defaultConfig.versionName}.apk") +// } +// } +// } } def getCurrentTime() { @@ -40,16 +39,12 @@ def getCurrentTime() { } dependencies { - compile fileTree(include: ['*.jar'], dir: 'libs') - androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { - exclude group: 'com.android.support', module: 'support-annotations' - }) - compile "com.android.support:appcompat-v7:${SUPPORT_VERSION}" - compile 'com.android.support.constraint:constraint-layout:1.0.2' - testCompile 'junit:junit:4.12' - compile project(':mae-bundles-album') // or 使用下面的 - - compile 'com.github.anrwatchdog:anrwatchdog:1.3.0' - - compile "com.github.bumptech.glide:glide:${GLIDE_VERSION}" + implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation "com.android.support:appcompat-v7:${SUPPORT_VERSION}" + implementation 'com.android.support.constraint:constraint-layout:1.0.2' + implementation project(':mae-bundles-album') // or 使用下面的 + + implementation 'com.github.anrwatchdog:anrwatchdog:1.3.0' + + implementation "com.github.bumptech.glide:glide:${GLIDE_VERSION}" } diff --git a/mae-bundles-album/build.gradle b/mae-bundles-album/build.gradle index a6f58f3..b32e498 100644 --- a/mae-bundles-album/build.gradle +++ b/mae-bundles-album/build.gradle @@ -5,7 +5,6 @@ group='com.github.liyuzero' android { compileSdkVersion COMPILE_SDK_VERSION - buildToolsVersion BUILD_TOOLS_VERSION defaultConfig { minSdkVersion MIN_SDK_VERSION @@ -38,15 +37,11 @@ configurations.all { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { - exclude group: 'com.android.support', module: 'support-annotations' - }) - compile "com.android.support:support-annotations:${SUPPORT_VERSION}" - compile "com.android.support:appcompat-v7:${SUPPORT_VERSION}" - compile "com.android.support:design:${SUPPORT_VERSION}" - testCompile 'junit:junit:4.12' - compile 'com.github.liyuzero:MaeMonitorFragment:1.0.1' + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation "com.android.support:support-annotations:${SUPPORT_VERSION}" + implementation "com.android.support:appcompat-v7:${SUPPORT_VERSION}" + implementation "com.android.support:design:${SUPPORT_VERSION}" + api 'com.github.liyuzero:MaeMonitorFragment:1.0.1' } diff --git a/mae-bundles-album/src/main/java/com/yu/bundles/album/image/ImageCursorActivity.java b/mae-bundles-album/src/main/java/com/yu/bundles/album/image/ImageCursorActivity.java index 697c432..3183b97 100644 --- a/mae-bundles-album/src/main/java/com/yu/bundles/album/image/ImageCursorActivity.java +++ b/mae-bundles-album/src/main/java/com/yu/bundles/album/image/ImageCursorActivity.java @@ -1,6 +1,7 @@ package com.yu.bundles.album.image; import android.app.Activity; +import android.app.LoaderManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -12,7 +13,6 @@ import android.support.annotation.StringRes; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; -import android.support.v4.app.LoaderManager; import android.support.v4.content.LocalBroadcastManager; import android.view.MenuItem; import android.view.View; @@ -84,6 +84,7 @@ protected void onCreate(Bundle savedInstanceState) { LocalBroadcastManager.getInstance(getApplicationContext()).registerReceiver(receiver, filter); } + @Override protected void onDestroy() { super.onDestroy(); @@ -256,8 +257,8 @@ public Activity getActivity() { } @Override - public LoaderManager getSupportLoaderManager() { - return super.getSupportLoaderManager(); + public LoaderManager getLoadManager() { + return super.getLoaderManager(); } //--------------------------------- 系统状态处理 ------------------------------------------ diff --git a/mae-bundles-album/src/main/java/com/yu/bundles/album/model/AlbumLoader.java b/mae-bundles-album/src/main/java/com/yu/bundles/album/model/AlbumLoader.java index 438c4fc..0d7c9a9 100644 --- a/mae-bundles-album/src/main/java/com/yu/bundles/album/model/AlbumLoader.java +++ b/mae-bundles-album/src/main/java/com/yu/bundles/album/model/AlbumLoader.java @@ -1,12 +1,12 @@ package com.yu.bundles.album.model; import android.content.Context; +import android.content.CursorLoader; import android.database.Cursor; import android.database.MatrixCursor; import android.database.MergeCursor; import android.net.Uri; import android.provider.MediaStore; -import android.support.v4.content.CursorLoader; import android.text.TextUtils; import com.yu.bundles.album.ConfigBuilder; diff --git a/mae-bundles-album/src/main/java/com/yu/bundles/album/model/AlbumMediaLoader.java b/mae-bundles-album/src/main/java/com/yu/bundles/album/model/AlbumMediaLoader.java index c5149d9..aef649c 100644 --- a/mae-bundles-album/src/main/java/com/yu/bundles/album/model/AlbumMediaLoader.java +++ b/mae-bundles-album/src/main/java/com/yu/bundles/album/model/AlbumMediaLoader.java @@ -1,13 +1,13 @@ package com.yu.bundles.album.model; import android.content.Context; +import android.content.CursorLoader; import android.content.pm.PackageManager; import android.database.Cursor; import android.database.MatrixCursor; import android.database.MergeCursor; import android.net.Uri; import android.provider.MediaStore; -import android.support.v4.content.CursorLoader; import com.yu.bundles.album.ConfigBuilder; import com.yu.bundles.album.entity.Album; diff --git a/mae-bundles-album/src/main/java/com/yu/bundles/album/model/AlbumMediaModelImpl.java b/mae-bundles-album/src/main/java/com/yu/bundles/album/model/AlbumMediaModelImpl.java index 82a8a81..2a96ece 100644 --- a/mae-bundles-album/src/main/java/com/yu/bundles/album/model/AlbumMediaModelImpl.java +++ b/mae-bundles-album/src/main/java/com/yu/bundles/album/model/AlbumMediaModelImpl.java @@ -1,10 +1,10 @@ package com.yu.bundles.album.model; +import android.app.LoaderManager; import android.content.Context; +import android.content.Loader; import android.database.Cursor; import android.os.Bundle; -import android.support.v4.app.LoaderManager; -import android.support.v4.content.Loader; import com.yu.bundles.album.entity.Album; import com.yu.bundles.album.entity.ImageInfo; diff --git a/mae-bundles-album/src/main/java/com/yu/bundles/album/model/AlbumModelImpl.java b/mae-bundles-album/src/main/java/com/yu/bundles/album/model/AlbumModelImpl.java index 4ef2f85..c4348bf 100644 --- a/mae-bundles-album/src/main/java/com/yu/bundles/album/model/AlbumModelImpl.java +++ b/mae-bundles-album/src/main/java/com/yu/bundles/album/model/AlbumModelImpl.java @@ -1,11 +1,11 @@ package com.yu.bundles.album.model; import android.content.Context; +import android.content.Loader; import android.database.Cursor; import android.os.Bundle; import android.support.annotation.NonNull; -import android.support.v4.app.LoaderManager; -import android.support.v4.content.Loader; +import android.app.LoaderManager; /** * Created by liyu on 2017/9/28. diff --git a/mae-bundles-album/src/main/java/com/yu/bundles/album/presenter/AlbumCursorView.java b/mae-bundles-album/src/main/java/com/yu/bundles/album/presenter/AlbumCursorView.java deleted file mode 100644 index 040a63a..0000000 --- a/mae-bundles-album/src/main/java/com/yu/bundles/album/presenter/AlbumCursorView.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.yu.bundles.album.presenter; - -import android.app.Activity; -import android.database.Cursor; -import android.support.annotation.StringRes; -import android.support.v4.app.LoaderManager; - -/** - * Created by liyu on 2017/9/29. - */ - -public interface AlbumCursorView { - Activity getActivity(); - LoaderManager getSupportLoaderManager(); - void showMessage(@StringRes int messageId); - void onAlbumLoad(Cursor cursor); - void onAlbumReset(); -} diff --git a/mae-bundles-album/src/main/java/com/yu/bundles/album/presenter/AlbumPresenterImpl.java b/mae-bundles-album/src/main/java/com/yu/bundles/album/presenter/AlbumPresenterImpl.java index 8fce191..f6841c9 100644 --- a/mae-bundles-album/src/main/java/com/yu/bundles/album/presenter/AlbumPresenterImpl.java +++ b/mae-bundles-album/src/main/java/com/yu/bundles/album/presenter/AlbumPresenterImpl.java @@ -27,8 +27,8 @@ public class AlbumPresenterImpl implements AlbumModelImpl.AlbumCallbacks, AlbumM public AlbumPresenterImpl(@NonNull AlbumView mAlbumView) { this.mAlbumView = mAlbumView; - albumModel = new AlbumModelImpl(mAlbumView.getActivity(), mAlbumView.getSupportLoaderManager(), this); - albumMediaModel = new AlbumMediaModelImpl(mAlbumView.getActivity(), mAlbumView.getSupportLoaderManager(), this); + albumModel = new AlbumModelImpl(mAlbumView.getActivity(), mAlbumView.getLoadManager(), this); + albumMediaModel = new AlbumMediaModelImpl(mAlbumView.getActivity(), mAlbumView.getLoadManager(), this); ImageQueue.init(); } diff --git a/mae-bundles-album/src/main/java/com/yu/bundles/album/presenter/AlbumView.java b/mae-bundles-album/src/main/java/com/yu/bundles/album/presenter/AlbumView.java index 4addf9f..9a8c51d 100644 --- a/mae-bundles-album/src/main/java/com/yu/bundles/album/presenter/AlbumView.java +++ b/mae-bundles-album/src/main/java/com/yu/bundles/album/presenter/AlbumView.java @@ -1,9 +1,9 @@ package com.yu.bundles.album.presenter; import android.app.Activity; +import android.app.LoaderManager; import android.database.Cursor; import android.support.annotation.StringRes; -import android.support.v4.app.LoaderManager; import com.yu.bundles.album.entity.AlbumInfo; @@ -22,7 +22,7 @@ public interface AlbumView { Activity getActivity(); - LoaderManager getSupportLoaderManager(); + LoaderManager getLoadManager(); void showMessage(@StringRes int messageId);