From 4634d6e6929334cacc4f2e3c86ee5e6327f7c296 Mon Sep 17 00:00:00 2001 From: limuyang Date: Sun, 26 Apr 2020 01:17:41 +0800 Subject: [PATCH] =?UTF-8?q?-=E6=9B=B4=E6=96=B0AndroidX=E7=9A=84=E5=AE=8C?= =?UTF-8?q?=E6=95=B4=E6=94=AF=E6=8C=81=EF=BC=9B=20-=E5=89=94=E9=99=A4anko?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 16 +++++------ build.gradle | 4 +-- gradle.properties | 4 +-- gradle/wrapper/gradle-wrapper.properties | 2 +- photolibrary/build.gradle | 27 ++++++++++--------- photolibrary/proguard-rules.pro | 24 +++++++++++++++++ .../photolibrary/activity/LBaseActivity.kt | 2 +- .../activity/LPhotoPickerActivity.kt | 17 +++++++----- .../activity/LPhotoPickerPreviewActivity.kt | 8 +++--- .../photolibrary/engine/LGlideEngine.kt | 2 +- .../photolibrary/engine/LImageEngine.kt | 2 +- .../photolibrary/util/LPhotoFileProvider.kt | 3 ++- .../top/limuyang2/photolibrary/util/Tools.kt | 2 +- .../res/layout/l_activity_photo_picker.xml | 8 +++--- .../l_pp_activity_photo_picker_preview.xml | 4 +-- .../res/layout/l_pp_item_photo_picker.xml | 15 ++++------- 16 files changed, 81 insertions(+), 59 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index f259df4..c031493 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -14,7 +14,7 @@ android { versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - renderscriptTargetApi 27 + renderscriptTargetApi 28 renderscriptSupportModeEnabled true ndk { abiFilters "x86", "armeabi-v7a" @@ -35,18 +35,16 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.2.71" - implementation 'androidx.appcompat:appcompat:1.0.0' + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0' - implementation 'androidx.recyclerview:recyclerview:1.0.0' + implementation 'androidx.recyclerview:recyclerview:1.1.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' - testImplementation 'junit:junit:4.12' - androidTestImplementation 'androidx.test:runner:1.1.0-beta02' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-beta02' + testImplementation 'junit:junit:4.13' - implementation 'com.github.bumptech.glide:glide:4.8.0' + implementation 'com.github.bumptech.glide:glide:4.11.0' - implementation "com.github.xinyuez:easypermissions:2.0.1" + implementation 'pub.devrel:easypermissions:3.0.0' // implementation 'com.github.yalantis:ucrop:2.2.2' // implementation project(path:':library') diff --git a/build.gradle b/build.gradle index 27f0caf..c7f65c1 100755 --- a/build.gradle +++ b/build.gradle @@ -1,13 +1,13 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.2.71' + ext.kotlin_version = '1.3.72' repositories { google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.2.1' + classpath 'com.android.tools.build:gradle:3.6.3' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' // NOTE: Do not place your application dependencies here; they belong diff --git a/gradle.properties b/gradle.properties index 7bf7247..d015431 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -#android.useAndroidX=true -#android.enableJetifier=true \ No newline at end of file +android.useAndroidX=true +android.enableJetifier=true \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 8513ef4..6c36964 100755 --- 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-4.6-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip diff --git a/photolibrary/build.gradle b/photolibrary/build.gradle index 6ddc05c..b21d830 100755 --- a/photolibrary/build.gradle +++ b/photolibrary/build.gradle @@ -6,7 +6,6 @@ android { compileSdkVersion 28 - defaultConfig { minSdkVersion 16 targetSdkVersion 28 @@ -15,7 +14,7 @@ android { testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - renderscriptTargetApi 27 + renderscriptTargetApi 28 renderscriptSupportModeEnabled true } @@ -23,7 +22,10 @@ android { buildTypes { release { minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + consumerProguardFiles 'proguard-rules.pro' + } + debug { + consumerProguardFiles 'proguard-rules.pro' } } @@ -32,20 +34,19 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'com.google.android.material:material:1.0.0' - implementation 'androidx.appcompat:appcompat:1.0.0' - implementation 'androidx.legacy:legacy-support-v4:1.0.0' - implementation 'androidx.recyclerview:recyclerview:1.0.0' + implementation 'com.google.android.material:material:1.1.0' + implementation 'androidx.appcompat:appcompat:1.1.0' + + implementation 'androidx.recyclerview:recyclerview:1.1.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' - testImplementation 'junit:junit:4.12' - androidTestImplementation 'androidx.test:runner:1.1.0-beta02' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-beta02' + testImplementation 'junit:junit:4.13' - implementation 'com.github.mmin18:realtimeblurview:1.1.2' - implementation 'com.github.bumptech.glide:glide:4.8.0' - implementation 'org.jetbrains.anko:anko-coroutines:0.10.7' + implementation 'com.github.mmin18:realtimeblurview:1.2.1' + implementation 'com.github.bumptech.glide:glide:4.11.0' + implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0" implementation 'com.github.chrisbanes:PhotoView:2.2.0' + implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.3" } repositories { diff --git a/photolibrary/proguard-rules.pro b/photolibrary/proguard-rules.pro index f1b4245..08fa120 100755 --- a/photolibrary/proguard-rules.pro +++ b/photolibrary/proguard-rules.pro @@ -19,3 +19,27 @@ # If you keep the line number information, uncomment this to # hide the original source file name. #-renamesourcefileattribute SourceFile +-keep class android.support.v8.renderscript.** { *; } +-keep class androidx.renderscript.** { *; } + +# glide 的混淆代码 +-keep public class * implements com.bumptech.glide.module.GlideModule +-keep public class * extends com.bumptech.glide.module.AppGlideModule +-keep public enum com.bumptech.glide.load.ImageHeaderParser$** { + **[] $VALUES; + public *; +} + +# Kotlin协程 +# ServiceLoader support +-keepnames class kotlinx.coroutines.internal.MainDispatcherFactory {} +-keepnames class kotlinx.coroutines.CoroutineExceptionHandler {} +-keepnames class kotlinx.coroutines.android.AndroidExceptionPreHandler {} +-keepnames class kotlinx.coroutines.android.AndroidDispatcherFactory {} + +# Most of volatile fields are updated with AFU and should not be mangled +-keepclassmembernames class kotlinx.** { + volatile ; +} + +-keep class kotlin.reflect.** { *; } \ No newline at end of file diff --git a/photolibrary/src/main/java/top/limuyang2/photolibrary/activity/LBaseActivity.kt b/photolibrary/src/main/java/top/limuyang2/photolibrary/activity/LBaseActivity.kt index 46f41c7..da3f678 100755 --- a/photolibrary/src/main/java/top/limuyang2/photolibrary/activity/LBaseActivity.kt +++ b/photolibrary/src/main/java/top/limuyang2/photolibrary/activity/LBaseActivity.kt @@ -1,7 +1,7 @@ package top.limuyang2.photolibrary.activity import android.os.Bundle -import android.support.annotation.LayoutRes +import androidx.annotation.LayoutRes import androidx.appcompat.app.AppCompatActivity /** diff --git a/photolibrary/src/main/java/top/limuyang2/photolibrary/activity/LPhotoPickerActivity.kt b/photolibrary/src/main/java/top/limuyang2/photolibrary/activity/LPhotoPickerActivity.kt index 9f25588..7580955 100755 --- a/photolibrary/src/main/java/top/limuyang2/photolibrary/activity/LPhotoPickerActivity.kt +++ b/photolibrary/src/main/java/top/limuyang2/photolibrary/activity/LPhotoPickerActivity.kt @@ -8,16 +8,18 @@ import android.content.res.ColorStateList import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.os.Bundle +import android.provider.Contacts import android.util.TypedValue import android.view.View import androidx.annotation.StyleRes import androidx.core.view.ViewCompat +import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.RecyclerView import kotlinx.android.synthetic.main.l_activity_photo_picker.* -import kotlinx.coroutines.experimental.android.UI -import kotlinx.coroutines.experimental.async -import org.jetbrains.anko.coroutines.experimental.bg +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext import top.limuyang2.photolibrary.R import top.limuyang2.photolibrary.adapter.LPPGridDivider import top.limuyang2.photolibrary.adapter.PhotoPickerRecyclerAdapter @@ -315,10 +317,11 @@ class LPhotoPickerActivity : LBaseActivity() { } override fun initData() { - async(UI) { - val photoModelList = bg { findPhoto(this@LPhotoPickerActivity, showTypeArray) }.await() - this@LPhotoPickerActivity.photoModelList.addAll(photoModelList) - + lifecycleScope.launch { + val list = withContext(Dispatchers.IO) { + findPhoto(this@LPhotoPickerActivity, showTypeArray) + } + photoModelList.addAll(list) reloadPhotos(0) } } diff --git a/photolibrary/src/main/java/top/limuyang2/photolibrary/activity/LPhotoPickerPreviewActivity.kt b/photolibrary/src/main/java/top/limuyang2/photolibrary/activity/LPhotoPickerPreviewActivity.kt index 33bcf28..3ca363a 100755 --- a/photolibrary/src/main/java/top/limuyang2/photolibrary/activity/LPhotoPickerPreviewActivity.kt +++ b/photolibrary/src/main/java/top/limuyang2/photolibrary/activity/LPhotoPickerPreviewActivity.kt @@ -9,11 +9,11 @@ import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.os.Build import android.os.Bundle -import android.support.annotation.StyleRes import android.util.TypedValue import android.view.View import android.view.WindowManager import android.view.animation.DecelerateInterpolator +import androidx.annotation.StyleRes import androidx.core.view.ViewCompat import androidx.core.view.ViewPropertyAnimatorListenerAdapter import androidx.viewpager.widget.ViewPager @@ -42,7 +42,7 @@ class LPhotoPickerPreviewActivity : LBaseActivity() { window.setBackgroundDrawable(ColorDrawable(resources.getColor(R.color.l_pp_photo_preview_bg))) initAttr() setStatusBar() - checkBox.setChecked(true, false) + checkBox.setChecked(checked = true, animate = false) previewTitleTv.text = "1/${intentSelectedPhotos.size}" viewPage.adapter = viewPageAdapter } @@ -67,10 +67,10 @@ class LPhotoPickerPreviewActivity : LBaseActivity() { checkBox.setOnClickListener { if (!checkBox.isChecked) { - checkBox.setChecked(true, true) + checkBox.setChecked(checked = true, animate = true) nowSelectedPhotos.add(currentPath) } else { - checkBox.setChecked(false, true) + checkBox.setChecked(checked = false, animate = true) nowSelectedPhotos.remove(currentPath) } applyBtn.isEnabled = nowSelectedPhotos.isNotEmpty() diff --git a/photolibrary/src/main/java/top/limuyang2/photolibrary/engine/LGlideEngine.kt b/photolibrary/src/main/java/top/limuyang2/photolibrary/engine/LGlideEngine.kt index d949166..ddc6deb 100755 --- a/photolibrary/src/main/java/top/limuyang2/photolibrary/engine/LGlideEngine.kt +++ b/photolibrary/src/main/java/top/limuyang2/photolibrary/engine/LGlideEngine.kt @@ -1,8 +1,8 @@ package top.limuyang2.photolibrary.engine import android.content.Context -import android.support.annotation.DrawableRes import android.widget.ImageView +import androidx.annotation.DrawableRes import com.bumptech.glide.Glide import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions import com.bumptech.glide.request.RequestOptions diff --git a/photolibrary/src/main/java/top/limuyang2/photolibrary/engine/LImageEngine.kt b/photolibrary/src/main/java/top/limuyang2/photolibrary/engine/LImageEngine.kt index 832fe99..fddbbbd 100755 --- a/photolibrary/src/main/java/top/limuyang2/photolibrary/engine/LImageEngine.kt +++ b/photolibrary/src/main/java/top/limuyang2/photolibrary/engine/LImageEngine.kt @@ -1,8 +1,8 @@ package top.limuyang2.photolibrary.engine import android.content.Context -import android.support.annotation.DrawableRes import android.widget.ImageView +import androidx.annotation.DrawableRes interface LImageEngine { /** diff --git a/photolibrary/src/main/java/top/limuyang2/photolibrary/util/LPhotoFileProvider.kt b/photolibrary/src/main/java/top/limuyang2/photolibrary/util/LPhotoFileProvider.kt index 36b3342..0ea5226 100755 --- a/photolibrary/src/main/java/top/limuyang2/photolibrary/util/LPhotoFileProvider.kt +++ b/photolibrary/src/main/java/top/limuyang2/photolibrary/util/LPhotoFileProvider.kt @@ -1,6 +1,7 @@ package top.limuyang2.photolibrary.util -import android.support.v4.content.FileProvider +import androidx.core.content.FileProvider + /** * diff --git a/photolibrary/src/main/java/top/limuyang2/photolibrary/util/Tools.kt b/photolibrary/src/main/java/top/limuyang2/photolibrary/util/Tools.kt index 62eed5f..b7b556a 100755 --- a/photolibrary/src/main/java/top/limuyang2/photolibrary/util/Tools.kt +++ b/photolibrary/src/main/java/top/limuyang2/photolibrary/util/Tools.kt @@ -5,9 +5,9 @@ import android.content.Context import android.graphics.Point import android.os.Build import android.provider.MediaStore -import android.support.annotation.ColorInt import android.text.TextUtils import android.view.WindowManager +import androidx.annotation.ColorInt import top.limuyang2.photolibrary.R import top.limuyang2.photolibrary.model.LPhotoModel import java.io.File diff --git a/photolibrary/src/main/res/layout/l_activity_photo_picker.xml b/photolibrary/src/main/res/layout/l_activity_photo_picker.xml index 6c6cdbd..9bbda97 100755 --- a/photolibrary/src/main/res/layout/l_activity_photo_picker.xml +++ b/photolibrary/src/main/res/layout/l_activity_photo_picker.xml @@ -11,12 +11,12 @@ android:orientation="vertical"> - - @@ -46,8 +46,8 @@ - - + + - - + diff --git a/photolibrary/src/main/res/layout/l_pp_item_photo_picker.xml b/photolibrary/src/main/res/layout/l_pp_item_photo_picker.xml index f528ab0..f6b7d06 100755 --- a/photolibrary/src/main/res/layout/l_pp_item_photo_picker.xml +++ b/photolibrary/src/main/res/layout/l_pp_item_photo_picker.xml @@ -1,6 +1,5 @@ - @@ -9,20 +8,16 @@ android:id="@+id/imgView" android:layout_width="50dp" android:layout_height="50dp" - app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="parent" tools:background="#123456" /> + android:layout_marginEnd="8dp" + android:layout_marginRight="5dp" /> - \ No newline at end of file + \ No newline at end of file