From 5820c224c86617d69cc88a2a407c1d1de72cd3ce Mon Sep 17 00:00:00 2001 From: sherlock Date: Tue, 14 Mar 2023 10:42:12 +0800 Subject: [PATCH] feat: releasae androidx-7.2.0, add finish listener --- README.md | 2 +- .../java/cc/shinichi/library/ImagePreview.kt | 27 +++++++++++++++++++ .../library/view/ImagePreviewActivity.kt | 1 + .../view/listener/OnPageFinishListener.kt | 15 +++++++++++ sample/build.gradle | 6 ++--- .../bigimageviewpager/MainActivity.java | 12 +++++++-- 6 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 library/src/main/java/cc/shinichi/library/view/listener/OnPageFinishListener.kt diff --git a/README.md b/README.md index 299a3f0..47d8aa3 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ allprojects { ``` dependencies { // 添加本框架 BigImageViewPager https://github.com/SherlockGougou/BigImageViewPager - implementation 'com.github.SherlockGougou:BigImageViewPager:androidx-7.1.6' + implementation 'com.github.SherlockGougou:BigImageViewPager:androidx-7.2.0' // 另外还需要依赖 glide implementation 'com.github.bumptech.glide:glide:4.11.0' diff --git a/library/src/main/java/cc/shinichi/library/ImagePreview.kt b/library/src/main/java/cc/shinichi/library/ImagePreview.kt index 2a05468..f5b7751 100644 --- a/library/src/main/java/cc/shinichi/library/ImagePreview.kt +++ b/library/src/main/java/cc/shinichi/library/ImagePreview.kt @@ -135,6 +135,8 @@ class ImagePreview { private set var onOriginProgressListener: OnOriginProgressListener? = null private set + var onPageFinishListener: OnPageFinishListener? = null + private set // 自定义百分比布局layout id @LayoutRes @@ -368,6 +370,11 @@ class ImagePreview { return this } + fun setOnPageFinishListener(onPageFinishListener: OnPageFinishListener): ImagePreview { + this.onPageFinishListener = onPageFinishListener + return this + } + private fun setOnOriginProgressListener(onOriginProgressListener: OnOriginProgressListener): ImagePreview { this.onOriginProgressListener = onOriginProgressListener return this @@ -441,6 +448,26 @@ class ImagePreview { ImagePreviewActivity.activityStart(context) } + /** + * 主动关闭页面 + */ + fun finish() { + val context = contextWeakReference.get() + if (context !is Activity) { + return + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + if (context.isFinishing || context.isDestroyed) { + return + } + } else { + if (context.isFinishing) { + return + } + } + context.finish() + } + enum class LoadStrategy { /** * 仅加载原图;会强制隐藏查看原图按钮 diff --git a/library/src/main/java/cc/shinichi/library/view/ImagePreviewActivity.kt b/library/src/main/java/cc/shinichi/library/view/ImagePreviewActivity.kt index 5ec9be5..1929a1e 100755 --- a/library/src/main/java/cc/shinichi/library/view/ImagePreviewActivity.kt +++ b/library/src/main/java/cc/shinichi/library/view/ImagePreviewActivity.kt @@ -245,6 +245,7 @@ class ImagePreviewActivity : AppCompatActivity(), Handler.Callback, View.OnClick override fun finish() { super.finish() overridePendingTransition(R.anim.fade_in, R.anim.fade_out) + ImagePreview.instance.onPageFinishListener?.onFinish(this) ImagePreview.instance.reset() imagePreviewAdapter?.closePage() } diff --git a/library/src/main/java/cc/shinichi/library/view/listener/OnPageFinishListener.kt b/library/src/main/java/cc/shinichi/library/view/listener/OnPageFinishListener.kt new file mode 100644 index 0000000..d769984 --- /dev/null +++ b/library/src/main/java/cc/shinichi/library/view/listener/OnPageFinishListener.kt @@ -0,0 +1,15 @@ +package cc.shinichi.library.view.listener + +import android.app.Activity +import android.view.View + +/** + * @author 工藤 + * @email qinglingou@gmail.com + * cc.shinichi.library.view.listener + * create at 2018/12/19 16:23 + * description: 页面关闭回调 + */ +abstract class OnPageFinishListener { + abstract fun onFinish(activity: Activity) +} \ No newline at end of file diff --git a/sample/build.gradle b/sample/build.gradle index 467ebc4..ecee595 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -8,8 +8,8 @@ android { applicationId "cc.shinichi.bigimageviewpager" minSdkVersion 14 targetSdkVersion 32 - versionCode 716 - versionName "androidx-7.1.6" + versionCode 720 + versionName "androidx-7.2.0" } buildTypes { release { @@ -57,6 +57,6 @@ dependencies { annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0' implementation 'com.github.bumptech.glide:okhttp3-integration:4.11.0' // library -// implementation 'com.github.SherlockGougou:BigImageViewPager:androidx-7.1.6' +// implementation 'com.github.SherlockGougou:BigImageViewPager:androidx-7.2.0' implementation project(':library') } \ No newline at end of file diff --git a/sample/src/main/java/cc/shinichi/bigimageviewpager/MainActivity.java b/sample/src/main/java/cc/shinichi/bigimageviewpager/MainActivity.java index 0184ba9..a10e38a 100644 --- a/sample/src/main/java/cc/shinichi/bigimageviewpager/MainActivity.java +++ b/sample/src/main/java/cc/shinichi/bigimageviewpager/MainActivity.java @@ -48,6 +48,7 @@ import cc.shinichi.library.view.listener.OnDownloadClickListener; import cc.shinichi.library.view.listener.OnDownloadListener; import cc.shinichi.library.view.listener.OnOriginProgressListener; +import cc.shinichi.library.view.listener.OnPageFinishListener; public class MainActivity extends AppCompatActivity { @@ -406,7 +407,7 @@ public void onPageScrollStateChanged(int state) { @Override public void onClick(Activity activity, View view, int position) { // 可以在此处执行您自己的下载逻辑、埋点统计等信息 - Log.d(TAG, "onClick: position = " + position); + Log.d(TAG, "onDownloadClick: position = " + position); } @Override @@ -416,7 +417,6 @@ public boolean isInterceptDownload() { return false; } }) - // 下载过程回调,可自定义toast,如果不设置此回调会使用默认的toast内容 .setDownloadListener(new OnDownloadListener() { @Override @@ -434,6 +434,14 @@ public void onDownloadFailed(Activity activity, int position) { Toast.makeText(activity, "下载失败", Toast.LENGTH_SHORT).show(); } }) + // 页面关闭回调 + .setOnPageFinishListener(new OnPageFinishListener() { + @Override + public void onFinish(@NonNull Activity activity) { + // ... + Log.d(TAG, "onFinish: "); + } + }) //================================================================================================= // 设置查看原图时的百分比样式:库中带有一个样式:ImagePreview.PROGRESS_THEME_CIRCLE_TEXT,使用如下: