Skip to content

Commit a9fcdec

Browse files
committed
优化细节
1 parent 9721523 commit a9fcdec

File tree

6 files changed

+41
-41
lines changed

6 files changed

+41
-41
lines changed

README.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ allprojects {
3737
2. 在Module的 **build.gradle** 里面添加引入依赖项
3838

3939
```gradle
40-
implementation 'com.github.jenly1314:imageviewer:1.0.3'
40+
implementation 'com.github.jenly1314:imageviewer:1.0.4'
4141
```
4242

4343

@@ -48,16 +48,6 @@ implementation 'com.king.image:imageviewer:1.0.2'
4848
```
4949

5050

51-
###### 如果Gradle出现compile失败的情况,可以在Project的build.gradle里面添加如下:(也可以使用上面的GitPack来complie)
52-
```gradle
53-
allprojects {
54-
repositories {
55-
//...
56-
maven { url 'https://dl.bintray.com/jenly/maven' }
57-
}
58-
}
59-
```
60-
6151
## 示例
6252

6353
### 代码示例
@@ -103,6 +93,9 @@ allprojects {
10393

10494
## 版本记录
10595

96+
#### v1.0.4:2022-9-11
97+
* 优化细节
98+
10699
#### v1.0.3:2022-9-10 (从v1.0.3开始发布至 MavenCentral)
107100
* 看大图界面支持自定义扩展
108101

app/release/app-release.apk

-21 Bytes
Binary file not shown.

app/release/output-metadata.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
{
1111
"type": "SINGLE",
1212
"filters": [],
13-
"versionCode": 4,
14-
"versionName": "1.0.3",
13+
"versionCode": 5,
14+
"versionName": "1.0.4",
1515
"outputFile": "app-release.apk"
1616
}
1717
]

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ android.enableJetifier = true
2020
android.debug.obsoleteApi=true
2121

2222
GROUP=com.github.jenly1314
23-
VERSION_NAME=1.0.3
24-
VERSION_CODE=4
23+
VERSION_NAME=1.0.4
24+
VERSION_CODE=5
2525

2626
POM_DESCRIPTION=ImageViewer for Android
2727
POM_INCEPTION_YEAR=2020

imageviewer/src/main/java/com/king/image/imageviewer/ImageViewer.java

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public final class ImageViewer {
4242

4343
private Class<?> imageViewerClass;
4444

45+
private Bundle extrasBundle;
46+
4547
private int placeholderDrawableId;
4648
private int errorDrawableId;
4749

@@ -246,6 +248,16 @@ public ImageViewer imageViewerClass(Class<?> cls) {
246248
return this;
247249
}
248250

251+
/**
252+
* 设置扩展数据 相当于 {@code intent.putExtras(extras)}
253+
* @param extras
254+
* @return
255+
*/
256+
public ImageViewer extras(Bundle extras) {
257+
extrasBundle = extras;
258+
return this;
259+
}
260+
249261
/**
250262
* 初始化资源
251263
*
@@ -277,22 +289,11 @@ public void start(@NonNull Activity activity) {
277289
*/
278290
public void start(@NonNull Activity activity, @Nullable View sharedElement) {
279291
initResource(activity);
280-
Intent intent = new Intent(activity, ImageViewerActivity.class);
281-
282-
if (mOptionsCompat == null) {
283-
if (sharedElement != null) {
284-
mOptionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, sharedElement, ImageViewerActivity.SHARED_ELEMENT);
285-
} else {
286-
mOptionsCompat = ActivityOptionsCompat.makeCustomAnimation(activity, R.anim.iv_anim_in, R.anim.iv_anim_out);
287-
}
292+
Intent intent = new Intent(activity, imageViewerClass);
293+
if(extrasBundle != null){
294+
intent.putExtras(extrasBundle);
288295
}
289-
290-
Bundle bundle = null;
291-
if (mOptionsCompat != null) {
292-
bundle = mOptionsCompat.toBundle();
293-
}
294-
295-
activity.startActivity(intent, bundle);
296+
activity.startActivity(intent, obtainActivityOptionsCompatBundle(activity, sharedElement));
296297
}
297298

298299
/**
@@ -313,21 +314,27 @@ public void start(@NonNull Fragment fragment) {
313314
public void start(@NonNull Fragment fragment, @Nullable View sharedElement) {
314315
initResource(fragment.getContext());
315316
Intent intent = new Intent(fragment.getContext(), imageViewerClass);
317+
if(extrasBundle != null){
318+
intent.putExtras(extrasBundle);
319+
}
320+
fragment.startActivity(intent, obtainActivityOptionsCompatBundle(fragment.getActivity(), sharedElement));
321+
}
316322

323+
/**
324+
* 获取 ActivityOptionsCompat 转 Bundle
325+
* @param activity
326+
* @param sharedElement
327+
* @return
328+
*/
329+
private Bundle obtainActivityOptionsCompatBundle(Activity activity, @Nullable View sharedElement){
317330
if (mOptionsCompat == null) {
318331
if (sharedElement != null) {
319-
mOptionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(fragment.getActivity(), sharedElement, ImageViewerActivity.SHARED_ELEMENT);
332+
mOptionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, sharedElement, ImageViewerActivity.SHARED_ELEMENT);
320333
} else {
321-
mOptionsCompat = ActivityOptionsCompat.makeCustomAnimation(fragment.getContext(), R.anim.iv_anim_in, R.anim.iv_anim_out);
334+
mOptionsCompat = ActivityOptionsCompat.makeCustomAnimation(activity, R.anim.iv_anim_in, R.anim.iv_anim_out);
322335
}
323336
}
324-
325-
Bundle bundle = null;
326-
if (mOptionsCompat != null) {
327-
bundle = mOptionsCompat.toBundle();
328-
}
329-
330-
fragment.startActivity(intent, bundle);
337+
return mOptionsCompat.toBundle();
331338
}
332339

333340
}

versions.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//App
22
def app_version = [:]
3-
app_version.versionCode = 4
4-
app_version.versionName = "1.0.3"
3+
app_version.versionCode = 5
4+
app_version.versionName = "1.0.4"
55
ext.app_version = app_version
66

77
//build version

0 commit comments

Comments
 (0)