diff --git a/.circleci/config.yml b/.circleci/config.yml index e4e7e19..6304f0b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,9 +5,10 @@ orbs: jobs: build: - executor: android/android - + docker: + - image: cimg/android:2023.02 steps: - checkout - run: - command: ./gradlew build \ No newline at end of file + command: ./gradlew build + diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index f1b41af..b48f6b0 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -12,9 +12,9 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Set up JDK 1.8 + - name: Set up JDK 11 uses: actions/setup-java@v1 with: - java-version: 1.8 + java-version: 11 - name: Build with Gradle run: ./gradlew build \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index bbcee36..f571dd4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,12 @@ language: android dist: trusty -jdk: oraclejdk8 +jdk: oraclejdk11 sudo: false env: global: - - ANDROID_API_LEVEL=29 - - ANDROID_BUILD_TOOLS_VERSION=29.0.2 + - ANDROID_API_LEVEL=30 + - ANDROID_BUILD_TOOLS_VERSION=30.0.3 - TRAVIS_SECURE_ENV_VARS=true before_install: diff --git a/README.md b/README.md index 86bb8d2..83c3bc1 100644 --- a/README.md +++ b/README.md @@ -16,37 +16,28 @@ ImageViewer for Android 是一个图片查看器,一般用来查看图片详情或查看大图时使用。 ## Gif 展示 -![Image](GIF.gif) +![Image](GIF.gif) ## 引入 ### Gradle: -1. 在Project的 **build.gradle** 里面添加远程仓库 +1. 在Project的 **build.gradle** 或 **setting.gradle** 中添加远程仓库 -```gradle -allprojects { + ```gradle repositories { //... mavenCentral() + maven { url 'https://jitpack.io' } } -} -``` + ``` 2. 在Module的 **build.gradle** 里面添加引入依赖项 -```gradle -implementation 'com.github.jenly1314:imageviewer:1.0.4' -``` - - -以前发布至JCenter的版本 - -```gradle -implementation 'com.king.image:imageviewer:1.0.2' -``` - + ```gradle + implementation 'com.github.jenly1314:imageviewer:1.1.0' + ``` ## 示例 @@ -55,7 +46,7 @@ implementation 'com.king.image:imageviewer:1.0.2' ```Java //图片查看器 - 简单调用 - // data 可以多张图片List或单张图片,支持的类型可以是{@link Uri}, {@code url}, {@code path},{@link File}, {@link DrawableRes resId}…等 +// data 可以多张图片List或单张图片,支持的类型可以是{@link Uri}, {@code url}, {@code path},{@link File}, {@link DrawableRes resId}…等 ImageViewer.load(data)//要加载的图片数据,单张或多张 .imageLoader(new GlideImageLoader())//加载器,imageLoader必须配置,目前内置的有GlideImageLoader或PicassoImageLoader,也可以自己实现 .start(activity,sharedElement);//activity or fragment, 跳转时的共享元素视图 @@ -65,7 +56,7 @@ implementation 'com.king.image:imageviewer:1.0.2' ```Java //图片查看器 - // data 可以多张图片List或单张图片,支持的类型可以是{@link Uri}, {@code url}, {@code path},{@link File}, {@link DrawableRes resId}…等 +// data 可以多张图片List或单张图片,支持的类型可以是{@link Uri}, {@code url}, {@code path},{@link File}, {@link DrawableRes resId}…等 ImageViewer.load(data)//要加载的图片数据,单张或多张 .selection(position)//当前选中位置,默认:0 .indicator(true)//是否显示指示器,默认不显示 @@ -77,49 +68,54 @@ implementation 'com.king.image:imageviewer:1.0.2' ``` ### 相关说明 -> * 使用 **ImageViewer** 时,必须配置一个实现的 **ImageLoader**。 -> * **ImageViewer** 一次可以查看多张图片或单张图片,支持的类型可以是 **Uri**、 **url** 、 **path** 、 **File**、 **Drawable**、 **ImageDataSource** 等 +* 使用 **ImageViewer** 时,必须配置一个实现的 **ImageLoader**。 -> * 目前内置默认实现的 **ImageLoader** 有和 **PicassoImageLoader** ,二者选其一即可,如果二者不满足您的需求,您也可以自己实现一个 **ImageLoader**。 +* **ImageViewer** 一次可以查看多张图片或单张图片,支持的类型可以是 **Uri**、 **url** 、 **path** 、 **File**、 **DrawableRes**、 **ImageDataSource** 等。 -> * 为了保证 **ImageViewer** 体积最小化,和用户更多可能的选择性,并未将 **Glide** 和 **Picasso** 打包进 **aar**。 ->> 当您使用了 **GlideImageLoader** 时,必须依赖[ **Glide** ](https://github.com/bumptech/glide)库。 +* 目前内置默认实现 **ImageLoader** 的有 **GlideImageLoader** 和 **PicassoImageLoader** ,二者选其一即可,如果二者不满足您的需求,您也可以自己实现一个 **ImageLoader**。 ->> 当您使用了 **PicassoImageLoader** 时,必须依赖[ **Picasso** ](https://github.com/square/picasso)库。 +* 为了保证 **ImageViewer** 体积最小化,让用户有更多选择的可能性, **ImageViewer** 仅编译时用到了 **Glide** 和 **Picasso** 。 +> 当你使用了 **GlideImageLoader** 时,则需依赖[ **Glide** ](https://github.com/bumptech/glide)库。 + +> 当你使用了 **PicassoImageLoader** 时,则需依赖[ **Picasso** ](https://github.com/square/picasso)库。 更多使用详情,请查看[app](app)中的源码使用示例 ## 版本记录 +#### v1.1.0:2023-9-16 +* 更新Gradle至v7.3.3 +* 更新compileSdk至30 +* 优化细节 + #### v1.0.4:2022-9-11 -* 优化细节 +* 优化细节 #### v1.0.3:2022-9-10 (从v1.0.3开始发布至 MavenCentral) -* 看大图界面支持自定义扩展 +* 看大图界面支持自定义扩展 #### v1.0.2:2020-12-3 -* 加载的图片数据新增支持ImageDataSource类型,便于扩展 +* 加载的图片数据新增支持ImageDataSource类型,便于扩展 #### v1.0.1:2019-11-15 -* 简化集成步骤 +* 简化集成步骤 #### v1.0.0:2019-11-7 -* ImageViewer初始版本 +* ImageViewer初始版本 ## 赞赏 -如果您喜欢ImageViewer,或感觉ImageViewer帮助到了您,可以点右上角“Star”支持一下,您的支持就是我的动力,谢谢 :smiley:

+ +如果您喜欢ImageViewer,或感觉ImageViewer帮助到了您,可以点右上角“Star”支持一下,您的支持就是我的动力,谢谢 : +smiley:

您也可以扫描下面的二维码,请作者喝杯咖啡 :coffee:

- - - - +
## 关于我 -Name: Jenly +Name: Jenly Email: jenly1314#gmail.com / jenly1314#vip.qq.com diff --git a/app/build.gradle b/app/build.gradle index 059d6cd..551e685 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,17 +1,17 @@ apply plugin: 'com.android.application' android { - compileSdkVersion build_versions.compileSdk - buildToolsVersion build_versions.buildTools + namespace 'com.king.imageviewer.app' + compileSdk build_versions.compileSdk + defaultConfig { applicationId "com.king.imageviewer.app" - minSdkVersion build_versions.minSdk - targetSdkVersion build_versions.targetSdk + minSdk build_versions.minSdk + targetSdk build_versions.targetSdk versionCode app_version.versionCode versionName app_version.versionName - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - multiDexEnabled true + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { @@ -19,10 +19,19 @@ android { proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + lintOptions { + abortOnError false + } + } dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) implementation "androidx.appcompat:appcompat:$versions.appcompat" implementation "androidx.constraintlayout:constraintlayout:$versions.constraintlayout" testImplementation "junit:junit:$versions.junit" @@ -32,8 +41,6 @@ dependencies { implementation "com.github.bumptech.glide:glide:$versions.glide" annotationProcessor "com.github.bumptech.glide:compiler:$versions.glide" - implementation "com.facebook.fresco:fresco:$versions.fresco" - implementation "com.squareup.picasso:picasso:$versions.picasso" implementation project(path: ':imageviewer') diff --git a/app/release/app-release.apk b/app/release/app-release.apk index e0c0690..2df564c 100644 Binary files a/app/release/app-release.apk and b/app/release/app-release.apk differ diff --git a/app/release/output-metadata.json b/app/release/output-metadata.json index 33cd4cd..5de0572 100644 --- a/app/release/output-metadata.json +++ b/app/release/output-metadata.json @@ -1,5 +1,5 @@ { - "version": 2, + "version": 3, "artifactType": { "type": "APK", "kind": "Directory" @@ -10,9 +10,11 @@ { "type": "SINGLE", "filters": [], - "versionCode": 5, - "versionName": "1.0.4", + "attributes": [], + "versionCode": 6, + "versionName": "1.1.0", "outputFile": "app-release.apk" } - ] + ], + "elementType": "File" } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 4914702..3ca9e4d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,13 +1,8 @@ - + - - - - { + if(mOnItemClickListener!=null){ + mOnItemClickListener.onClick(v, holder.getAdapterPosition()); } }); } diff --git a/build.gradle b/build.gradle index e833dea..683b200 100644 --- a/build.gradle +++ b/build.gradle @@ -1,47 +1,9 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. - buildscript { apply from: 'versions.gradle' - repositories { - google() - mavenCentral() - - } - dependencies { - classpath "com.android.tools.build:gradle:$versions.gradle" - classpath "com.vanniktech:gradle-maven-publish-plugin:$versions.mavenPublish" - } -} - -allprojects { - repositories { - google() - mavenCentral() - maven { url 'https://jitpack.io' } - - } -} - -allprojects { - plugins.withId("com.vanniktech.maven.publish") { - mavenPublish { - sonatypeHost = "S01" - } - } -} - -task clean(type: Delete) { - delete rootProject.buildDir -} - -allprojects { - tasks.withType(Javadoc) { - options{ - encoding "UTF-8" - charSet 'UTF-8' - links "http://docs.oracle.com/javase/8/docs/api" - } - options.addStringOption('Xdoclint:none', '-quiet') - failOnError false - } -} +}// Top-level build file where you can add configuration options common to all sub-projects/modules. +plugins { + id 'com.android.application' version '7.2.1' apply false + id 'com.android.library' version '7.2.1' apply false + id 'org.jetbrains.kotlin.android' version '1.7.0' apply false + id 'com.vanniktech.maven.publish' version '0.22.0' apply false +} \ No newline at end of file diff --git a/gitpack.yml b/gitpack.yml new file mode 100644 index 0000000..adb3fe1 --- /dev/null +++ b/gitpack.yml @@ -0,0 +1,2 @@ +jdk: + - openjdk11 diff --git a/gradle.properties b/gradle.properties index 628961a..79ff53a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,12 +19,11 @@ android.useAndroidX = true android.enableJetifier = true android.debug.obsoleteApi=true +VERSION_NAME=1.1.0 +VERSION_CODE=6 GROUP=com.github.jenly1314 -VERSION_NAME=1.0.4 -VERSION_CODE=5 POM_DESCRIPTION=ImageViewer for Android -POM_INCEPTION_YEAR=2020 POM_URL=https://github.com/jenly1314/ImageViewer POM_SCM_URL=https://github.com/jenly1314/ImageViewer @@ -41,7 +40,10 @@ POM_DEVELOPER_ID=jenly POM_DEVELOPER_NAME=Jenly Yu POM_DEVELOPER_URL=https://github.com/jenly1314/ -#RELEASE_REPOSITORY_URL=https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ -#SNAPSHOT_REPOSITORY_URL=https://s01.oss.sonatype.org/content/repositories/snapshots/ +SONATYPE_HOST=S01 + +RELEASE_REPOSITORY_URL=https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ +SNAPSHOT_REPOSITORY_URL=https://s01.oss.sonatype.org/content/repositories/snapshots/ + RELEASE_SIGNING_ENABLED=false diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2a4f51b..28e4042 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Nov 06 11:18:11 CST 2019 -distributionBase = GRADLE_USER_HOME -distributionPath = wrapper/dists -zipStoreBase = GRADLE_USER_HOME -zipStorePath = wrapper/dists -distributionUrl = https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip +#Thu Jan 10 09:17:54 CST 2019 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip \ No newline at end of file diff --git a/imageviewer/build.gradle b/imageviewer/build.gradle index 53c0dec..671dd26 100644 --- a/imageviewer/build.gradle +++ b/imageviewer/build.gradle @@ -3,36 +3,33 @@ apply plugin: 'com.vanniktech.maven.publish' //apply from: 'bintray.gradle' android { - compileSdkVersion build_versions.compileSdk - buildToolsVersion build_versions.buildTools + namespace 'com.king.image.imageviewer' + compileSdk build_versions.compileSdk defaultConfig { - minSdkVersion build_versions.minSdk - targetSdkVersion build_versions.targetSdk - versionCode app_version.versionCode - versionName app_version.versionName + minSdk build_versions.minSdk + targetSdk build_versions.targetSdk testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - consumerProguardFiles 'consumer-rules.pro' + consumerProguardFiles "consumer-rules.pro" } - buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } - + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } lintOptions { abortOnError false warning 'InvalidPackage' } - } dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) - api "androidx.appcompat:appcompat:$versions.appcompat" testImplementation "junit:junit:$versions.junit" androidTestImplementation "androidx.test:runner:$versions.runner" diff --git a/imageviewer/src/main/AndroidManifest.xml b/imageviewer/src/main/AndroidManifest.xml index ac43401..e648513 100644 --- a/imageviewer/src/main/AndroidManifest.xml +++ b/imageviewer/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - + diff --git a/imageviewer/src/main/java/com/king/image/imageviewer/ImageDataSource.java b/imageviewer/src/main/java/com/king/image/imageviewer/ImageDataSource.java index 0b01fb3..0f63e0c 100644 --- a/imageviewer/src/main/java/com/king/image/imageviewer/ImageDataSource.java +++ b/imageviewer/src/main/java/com/king/image/imageviewer/ImageDataSource.java @@ -7,12 +7,15 @@ import androidx.annotation.DrawableRes; /** + * 图片数据源;当数据集合为对象时,可通过实现此接口来将图片数据源直接返回; + * * @author Jenly */ public interface ImageDataSource { /** * 返回图片数据源 + * * @return {@link Uri}, {@code url}, {@code path},{@link File}, {@link DrawableRes resId} */ Object getDataSource(); diff --git a/imageviewer/src/main/java/com/king/image/imageviewer/ImageViewer.java b/imageviewer/src/main/java/com/king/image/imageviewer/ImageViewer.java index be361fd..35a3c89 100644 --- a/imageviewer/src/main/java/com/king/image/imageviewer/ImageViewer.java +++ b/imageviewer/src/main/java/com/king/image/imageviewer/ImageViewer.java @@ -9,12 +9,6 @@ import android.os.Bundle; import android.view.View; -import com.king.image.imageviewer.loader.ImageLoader; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -23,6 +17,12 @@ import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; +import com.king.image.imageviewer.loader.ImageLoader; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + /** * ImageViewer 是一个图片查看器。一般用来查看图片详情或查看大图时使用。 *

@@ -34,9 +34,11 @@ * * @author Jenly */ +@SuppressWarnings("unused") public final class ImageViewer { + public static final String SHARED_ELEMENT = "shared_element"; - private ViewerSpec mViewerSpec; + private final ViewerSpec mViewerSpec; private ActivityOptionsCompat mOptionsCompat; @@ -250,6 +252,7 @@ public ImageViewer imageViewerClass(Class cls) { /** * 设置扩展数据 相当于 {@code intent.putExtras(extras)} + * * @param extras * @return */ @@ -290,7 +293,7 @@ public void start(@NonNull Activity activity) { public void start(@NonNull Activity activity, @Nullable View sharedElement) { initResource(activity); Intent intent = new Intent(activity, imageViewerClass); - if(extrasBundle != null){ + if (extrasBundle != null) { intent.putExtras(extrasBundle); } activity.startActivity(intent, obtainActivityOptionsCompatBundle(activity, sharedElement)); @@ -314,24 +317,26 @@ public void start(@NonNull Fragment fragment) { public void start(@NonNull Fragment fragment, @Nullable View sharedElement) { initResource(fragment.getContext()); Intent intent = new Intent(fragment.getContext(), imageViewerClass); - if(extrasBundle != null){ + if (extrasBundle != null) { intent.putExtras(extrasBundle); } + fragment.startActivity(intent, obtainActivityOptionsCompatBundle(fragment.getActivity(), sharedElement)); } /** * 获取 ActivityOptionsCompat 转 Bundle - * @param activity - * @param sharedElement + * + * @param activity {@link Activity} + * @param sharedElement 共享元素 * @return */ - private Bundle obtainActivityOptionsCompatBundle(Activity activity, @Nullable View sharedElement){ + private Bundle obtainActivityOptionsCompatBundle(Activity activity, @Nullable View sharedElement) { if (mOptionsCompat == null) { if (sharedElement != null) { - mOptionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, sharedElement, ImageViewerActivity.SHARED_ELEMENT); + mOptionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, sharedElement, SHARED_ELEMENT); } else { - mOptionsCompat = ActivityOptionsCompat.makeCustomAnimation(activity, R.anim.iv_anim_in, R.anim.iv_anim_out); + mOptionsCompat = ActivityOptionsCompat.makeCustomAnimation(activity, R.anim.image_viewer_anim_in, R.anim.image_viewer_anim_out); } } return mOptionsCompat.toBundle(); diff --git a/imageviewer/src/main/java/com/king/image/imageviewer/ImageViewerActivity.java b/imageviewer/src/main/java/com/king/image/imageviewer/ImageViewerActivity.java index 3c05ceb..a1f1fb1 100644 --- a/imageviewer/src/main/java/com/king/image/imageviewer/ImageViewerActivity.java +++ b/imageviewer/src/main/java/com/king/image/imageviewer/ImageViewerActivity.java @@ -1,10 +1,10 @@ package com.king.image.imageviewer; import android.os.Bundle; -import android.os.PersistableBundle; import android.view.View; import android.widget.TextView; +import androidx.annotation.LayoutRes; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.core.view.ViewCompat; @@ -15,96 +15,78 @@ */ public class ImageViewerActivity extends AppCompatActivity { - static final String SHARED_ELEMENT = "shared_element"; - private TextView tvIndicator; ImageViewerAdapter mAdapter; - ViewerSpec mViewerSpec; - private int mSize; private boolean isShowIndicator; - @Override - public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) { - super.onCreate(savedInstanceState, persistentState); - } - @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - mViewerSpec = ViewerSpec.INSTANCE; - setRequestedOrientation(mViewerSpec.orientation); - setTheme(mViewerSpec.theme); + setRequestedOrientation(ViewerSpec.INSTANCE.orientation); + setTheme(ViewerSpec.INSTANCE.theme); setContentView(getLayoutId()); init(); } - protected int getLayoutId(){ + /** + * 获取布局 + * + * @return 返回布局ID + */ + @LayoutRes + protected int getLayoutId() { return R.layout.image_viewer_activity; } - protected void init(){ + /** + * 初始化 + */ + protected void init() { tvIndicator = findViewById(R.id.tvIndicator); ViewPager2 viewPager = findViewById(R.id.viewPager); viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() { - @Override - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - super.onPageScrolled(position, positionOffset, positionOffsetPixels); - } - @Override public void onPageSelected(int position) { super.onPageSelected(position); - if(isShowIndicator){ - updateIndicator(position,mSize); + if (isShowIndicator) { + updateIndicator(position, mSize); } } - - @Override - public void onPageScrollStateChanged(int state) { - super.onPageScrollStateChanged(state); - } }); - ViewCompat.setTransitionName(viewPager,SHARED_ELEMENT); + ViewCompat.setTransitionName(viewPager, ImageViewer.SHARED_ELEMENT); - mAdapter = new ImageViewerAdapter(mViewerSpec.listData); + mAdapter = new ImageViewerAdapter(ViewerSpec.INSTANCE.listData); viewPager.setAdapter(mAdapter); - mAdapter.setOnItemClickListener(new ImageViewerAdapter.OnItemClickListener() { - @Override - public void onClick(View v, int position) { - onBackPressed(); - } - }); + mAdapter.setOnItemClickListener((v, position) -> onBackPressed()); - - int position = mViewerSpec.position; + int position = ViewerSpec.INSTANCE.position; mSize = mAdapter.getItemCount(); - if(position>=0){ - viewPager.setCurrentItem(position,false); - updateIndicator(position,mSize); + if (position >= 0) { + viewPager.setCurrentItem(position, false); + updateIndicator(position, mSize); } - isShowIndicator = mViewerSpec.isShowIndicator && mSize > 0; - if(isShowIndicator){ + isShowIndicator = ViewerSpec.INSTANCE.isShowIndicator && mSize > 0; + if (isShowIndicator) { tvIndicator.setVisibility(View.VISIBLE); } } - private void updateIndicator(int position,int size){ - tvIndicator.setText(String.format("%s/%s",Math.min(position + 1,size),size)); + /** + * 更新指示器 + * + * @param position + * @param size + */ + private void updateIndicator(int position, int size) { + tvIndicator.setText(String.format("%s/%s", Math.min(position + 1, size), size)); } - @Override - protected void onDestroy() { - if(mViewerSpec != null ){ - mViewerSpec.imageLoader = null; - } - super.onDestroy(); - } } diff --git a/imageviewer/src/main/java/com/king/image/imageviewer/ImageViewerAdapter.java b/imageviewer/src/main/java/com/king/image/imageviewer/ImageViewerAdapter.java index a342efa..7ee6107 100644 --- a/imageviewer/src/main/java/com/king/image/imageviewer/ImageViewerAdapter.java +++ b/imageviewer/src/main/java/com/king/image/imageviewer/ImageViewerAdapter.java @@ -5,57 +5,63 @@ import android.view.ViewGroup; import android.widget.ImageView; -import java.util.ArrayList; -import java.util.List; - import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView.Adapter; +import java.util.ArrayList; +import java.util.List; + /** * @author Jenly */ public class ImageViewerAdapter extends Adapter { - private List mDatas; + private final List mListData; private OnItemClickListener mOnItemClickListener; - public ImageViewerAdapter(List list){ - this.mDatas = list !=null ? list : new ArrayList<>(); + public ImageViewerAdapter(List list) { + this.mListData = list != null ? list : new ArrayList<>(); } @NonNull @Override public ImageHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.vp_image_viewer_item,parent,false); + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.image_viewer_list_item, parent, false); return new ImageHolder(view); } @Override - public void onBindViewHolder(@NonNull ImageHolder holder, final int position) { - holder.displayImage(mDatas.get(position)); - holder.photoView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if(mOnItemClickListener!=null){ - mOnItemClickListener.onClick(v,position); - } + public void onBindViewHolder(@NonNull ImageHolder holder, int position) { + holder.displayImage(mListData.get(position)); + holder.photoView.setOnClickListener(v -> { + if (mOnItemClickListener != null) { + mOnItemClickListener.onClick(v, holder.getAdapterPosition()); } }); } @Override public int getItemCount() { - return mDatas != null ? mDatas.size() : 0; + return mListData != null ? mListData.size() : 0; } - void setOnItemClickListener(OnItemClickListener listener){ + void setOnItemClickListener(OnItemClickListener listener) { this.mOnItemClickListener = listener; } - public interface OnItemClickListener{ - void onClick(View v,int position); + /** + * 点击Item监听 + */ + public interface OnItemClickListener { + /** + * 点击Item + * + * @param v + * @param position + */ + void onClick(View v, int position); } static class ImageHolder extends RecyclerView.ViewHolder { @@ -67,12 +73,11 @@ private ImageHolder(@NonNull View itemView) { photoView = itemView.findViewById(R.id.photoView); } - private void displayImage(Object data){ - if(ViewerSpec.INSTANCE.imageLoader != null){ - ViewerSpec.INSTANCE.imageLoader.loadImage(photoView.getContext(),photoView,data,ViewerSpec.INSTANCE.placeholderDrawable,ViewerSpec.INSTANCE.errorDrawable); + private void displayImage(Object data) { + if (ViewerSpec.INSTANCE.imageLoader != null) { + ViewerSpec.INSTANCE.imageLoader.loadImage(photoView.getContext(), photoView, data, ViewerSpec.INSTANCE.placeholderDrawable, ViewerSpec.INSTANCE.errorDrawable); } } - } } diff --git a/imageviewer/src/main/java/com/king/image/imageviewer/ViewerSpec.java b/imageviewer/src/main/java/com/king/image/imageviewer/ViewerSpec.java index 1b0e735..ca0feec 100644 --- a/imageviewer/src/main/java/com/king/image/imageviewer/ViewerSpec.java +++ b/imageviewer/src/main/java/com/king/image/imageviewer/ViewerSpec.java @@ -13,6 +13,7 @@ /** * @author Jenly */ +@SuppressWarnings("unused") enum ViewerSpec { INSTANCE; @@ -36,10 +37,29 @@ enum ViewerSpec { int orientation = ActivityInfo.SCREEN_ORIENTATION_BEHIND; + public int getPosition() { + return position; + } + + public List getListData() { + return listData; + } + + public boolean isShowIndicator() { + return isShowIndicator; + } + + public int getTheme() { + return theme; + } + + public int getOrientation() { + return orientation; + } + void reset(){ position = 0; listData = null; - imageLoader = null; isShowIndicator = false; placeholderDrawable = null; errorDrawable = null; diff --git a/imageviewer/src/main/java/com/king/image/imageviewer/loader/GlideImageLoader.java b/imageviewer/src/main/java/com/king/image/imageviewer/loader/GlideImageLoader.java index 04c7dad..f425fef 100644 --- a/imageviewer/src/main/java/com/king/image/imageviewer/loader/GlideImageLoader.java +++ b/imageviewer/src/main/java/com/king/image/imageviewer/loader/GlideImageLoader.java @@ -18,10 +18,10 @@ */ public class GlideImageLoader implements ImageLoader { @Override - public void loadImage(Context context, ImageView imageView,Object data, @Nullable Drawable placeholderDrawable,@Nullable Drawable errorDrawable) { - if(data instanceof ImageDataSource){ + public void loadImage(Context context, ImageView imageView, Object data, @Nullable Drawable placeholderDrawable, @Nullable Drawable errorDrawable) { + if (data instanceof ImageDataSource) { Glide.with(context).load(((ImageDataSource) data).getDataSource()).placeholder(placeholderDrawable).error(errorDrawable).into(imageView); - }else{ + } else { Glide.with(context).load(data).placeholder(placeholderDrawable).error(errorDrawable).into(imageView); } } diff --git a/imageviewer/src/main/java/com/king/image/imageviewer/loader/ImageLoader.java b/imageviewer/src/main/java/com/king/image/imageviewer/loader/ImageLoader.java index 4aca243..40d9005 100644 --- a/imageviewer/src/main/java/com/king/image/imageviewer/loader/ImageLoader.java +++ b/imageviewer/src/main/java/com/king/image/imageviewer/loader/ImageLoader.java @@ -12,7 +12,6 @@ import androidx.annotation.DrawableRes; import androidx.annotation.Nullable; - /** * 图片加载器,目前内置实现的加载器有{@link GlideImageLoader} 和 {@link PicassoImageLoader}。 * 如果目前已有的加载器不满足您的需求,您也可以自己实现{@link ImageLoader} @@ -23,11 +22,12 @@ public interface ImageLoader { /** * 加载图片 - * @param context - * @param imageView - * @param data 图片数据源 支持 {@link Uri}, {@code url}, {@code path},{@link File}, {@link DrawableRes resId}, {@link ImageDataSource}...等 - * @param placeholderDrawable 占位图 - * @param errorDrawable 加载失败时显示的图片 + * + * @param context {@link Context} + * @param imageView {@link ImageView} + * @param data 图片数据源 支持 {@link Uri}, {@code url}, {@code path},{@link File}, {@link DrawableRes resId}, {@link ImageDataSource}...等 + * @param placeholderDrawable 占位图片 + * @param errorDrawable 加载失败时显示的图片 */ - void loadImage(Context context, ImageView imageView,Object data, @Nullable Drawable placeholderDrawable,@Nullable Drawable errorDrawable); + void loadImage(Context context, ImageView imageView, Object data, @Nullable Drawable placeholderDrawable, @Nullable Drawable errorDrawable); } diff --git a/imageviewer/src/main/java/com/king/image/imageviewer/loader/PicassoImageLoader.java b/imageviewer/src/main/java/com/king/image/imageviewer/loader/PicassoImageLoader.java index a57c740..1611748 100644 --- a/imageviewer/src/main/java/com/king/image/imageviewer/loader/PicassoImageLoader.java +++ b/imageviewer/src/main/java/com/king/image/imageviewer/loader/PicassoImageLoader.java @@ -23,38 +23,35 @@ public class PicassoImageLoader implements ImageLoader { @Override - public void loadImage(Context context, ImageView imageView,Object data, @Nullable Drawable placeholderDrawable,@Nullable Drawable errorDrawable) { + public void loadImage(Context context, ImageView imageView, Object data, @Nullable Drawable placeholderDrawable, @Nullable Drawable errorDrawable) { RequestCreator requestCreator; - if(data instanceof ImageDataSource){ + if (data instanceof ImageDataSource) { requestCreator = getRequestCreate(((ImageDataSource) data).getDataSource()); - }else{ + } else { requestCreator = getRequestCreate(data); } - if(requestCreator != null){ - if(placeholderDrawable != null){ - requestCreator.placeholder(placeholderDrawable); - } - if(errorDrawable != null){ - requestCreator.error(errorDrawable); - } - requestCreator.into(imageView); + if (placeholderDrawable != null) { + requestCreator.placeholder(placeholderDrawable); } - + if (errorDrawable != null) { + requestCreator.error(errorDrawable); + } + requestCreator.into(imageView); } - private RequestCreator getRequestCreate(Object data){ - if(data instanceof Uri){ - return Picasso.get().load((Uri)data); + private RequestCreator getRequestCreate(Object data) { + if (data instanceof Uri) { + return Picasso.get().load((Uri) data); } - if(data instanceof String){ - return Picasso.get().load((String)data); + if (data instanceof String) { + return Picasso.get().load((String) data); } - if(data instanceof Integer){ + if (data instanceof Integer) { return Picasso.get().load((Integer) data); } - if(data instanceof File){ + if (data instanceof File) { return Picasso.get().load((File) data); } - return null; + throw new IllegalArgumentException("Illegal value type " + data.getClass().getCanonicalName()); } } diff --git a/imageviewer/src/main/res/anim/iv_anim_in.xml b/imageviewer/src/main/res/anim/image_viewer_anim_in.xml similarity index 100% rename from imageviewer/src/main/res/anim/iv_anim_in.xml rename to imageviewer/src/main/res/anim/image_viewer_anim_in.xml diff --git a/imageviewer/src/main/res/anim/iv_anim_out.xml b/imageviewer/src/main/res/anim/image_viewer_anim_out.xml similarity index 100% rename from imageviewer/src/main/res/anim/iv_anim_out.xml rename to imageviewer/src/main/res/anim/image_viewer_anim_out.xml diff --git a/imageviewer/src/main/res/layout/image_viewer_activity.xml b/imageviewer/src/main/res/layout/image_viewer_activity.xml index f30ef65..d45dba7 100644 --- a/imageviewer/src/main/res/layout/image_viewer_activity.xml +++ b/imageviewer/src/main/res/layout/image_viewer_activity.xml @@ -12,6 +12,6 @@ android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_alignParentBottom="true" - android:layout_marginBottom="@dimen/ivIndicatorMarginBottom" + android:layout_marginBottom="@dimen/imageViewerIndicatorMarginBottom" android:visibility="gone"/> \ No newline at end of file diff --git a/imageviewer/src/main/res/layout/vp_image_viewer_item.xml b/imageviewer/src/main/res/layout/image_viewer_list_item.xml similarity index 100% rename from imageviewer/src/main/res/layout/vp_image_viewer_item.xml rename to imageviewer/src/main/res/layout/image_viewer_list_item.xml diff --git a/imageviewer/src/main/res/values-v21/styles.xml b/imageviewer/src/main/res/values-v21/styles.xml index cfae6cc..ca5dbd8 100644 --- a/imageviewer/src/main/res/values-v21/styles.xml +++ b/imageviewer/src/main/res/values-v21/styles.xml @@ -2,12 +2,12 @@ diff --git a/imageviewer/src/main/res/values/colors.xml b/imageviewer/src/main/res/values/colors.xml index 674181d..6bc1d22 100644 --- a/imageviewer/src/main/res/values/colors.xml +++ b/imageviewer/src/main/res/values/colors.xml @@ -1,7 +1,8 @@ - #FF000000 - #FF000000 - #FFFFFFFF + #FF000000 + #FF000000 + #FFFFFFFF + \ No newline at end of file diff --git a/imageviewer/src/main/res/values/dimens.xml b/imageviewer/src/main/res/values/dimens.xml index c0e14eb..e091615 100644 --- a/imageviewer/src/main/res/values/dimens.xml +++ b/imageviewer/src/main/res/values/dimens.xml @@ -1,7 +1,7 @@ - 16sp - 20dp + 16sp + 20dp \ No newline at end of file diff --git a/imageviewer/src/main/res/values/styles.xml b/imageviewer/src/main/res/values/styles.xml index c603626..79e8b41 100644 --- a/imageviewer/src/main/res/values/styles.xml +++ b/imageviewer/src/main/res/values/styles.xml @@ -2,13 +2,12 @@ \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 7ffb519..e86ca43 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,26 @@ -include ':app', ':imageviewer' +pluginManagement { + repositories { + gradlePluginPortal() + maven { + url "https://maven.aliyun.com/repository/public" + } + google() + mavenCentral() + } +} +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + maven { + url "https://maven.aliyun.com/repository/public" + } + google() + mavenCentral() + maven { url 'https://jitpack.io' } + } +} + rootProject.name='ImageViewer' +include ':app' +include':imageviewer' + diff --git a/versions.gradle b/versions.gradle index 7eeaa92..a902954 100644 --- a/versions.gradle +++ b/versions.gradle @@ -1,34 +1,32 @@ //App def app_version = [:] -app_version.versionCode = 5 -app_version.versionName = "1.0.4" +app_version.versionCode = 6 +app_version.versionName = "1.1.0" ext.app_version = app_version //build version def build_versions = [:] build_versions.minSdk = 16 -build_versions.targetSdk = 29 -build_versions.compileSdk = 29 -build_versions.buildTools = "29.0.3" +build_versions.targetSdk = 30 +build_versions.compileSdk = 30 +build_versions.buildTools = "30.0.3" ext.build_versions = build_versions // App dependencies def versions = [:] -versions.mavenPublish = '0.18.0' -versions.gradle = "4.2.2" +versions.mavenPublish = '0.22.0' versions.appcompat = "1.1.0" versions.constraintlayout = "1.1.3" versions.junit = "4.12" versions.runner = "1.1.1" versions.espressoCore = "3.1.1" -versions.recyclerview = "1.2.0" +versions.recyclerview = "1.2.1" versions.viewpager2 = "1.0.0" versions.PhotoView = "2.3.0" -versions.glide = "4.10.0" -versions.fresco = "2.6.0" -versions.picasso = "2.71828" +versions.glide = "4.16.0" +versions.picasso = "2.8" ext.versions = versions \ No newline at end of file