Skip to content

Commit

Permalink
feat: releasae androidx-7.2.0, add finish listener
Browse files Browse the repository at this point in the history
  • Loading branch information
SherlockGougou committed Mar 14, 2023
1 parent ef9357c commit 5820c22
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
27 changes: 27 additions & 0 deletions library/src/main/java/cc/shinichi/library/ImagePreview.kt
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ class ImagePreview {
private set
var onOriginProgressListener: OnOriginProgressListener? = null
private set
var onPageFinishListener: OnPageFinishListener? = null
private set

// 自定义百分比布局layout id
@LayoutRes
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
/**
* 仅加载原图;会强制隐藏查看原图按钮
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package cc.shinichi.library.view.listener

import android.app.Activity
import android.view.View

/**
* @author 工藤
* @email [email protected]
* cc.shinichi.library.view.listener
* create at 2018/12/19 16:23
* description: 页面关闭回调
*/
abstract class OnPageFinishListener {
abstract fun onFinish(activity: Activity)
}
6 changes: 3 additions & 3 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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')
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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
Expand All @@ -416,7 +417,6 @@ public boolean isInterceptDownload() {
return false;
}
})

// 下载过程回调,可自定义toast,如果不设置此回调会使用默认的toast内容
.setDownloadListener(new OnDownloadListener() {
@Override
Expand All @@ -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,使用如下:
Expand Down

0 comments on commit 5820c22

Please sign in to comment.