Skip to content

Commit

Permalink
优化细节
Browse files Browse the repository at this point in the history
  • Loading branch information
jenly1314 committed Sep 11, 2022
1 parent 9721523 commit a9fcdec
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 41 deletions.
15 changes: 4 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ allprojects {
2. 在Module的 **build.gradle** 里面添加引入依赖项

```gradle
implementation 'com.github.jenly1314:imageviewer:1.0.3'
implementation 'com.github.jenly1314:imageviewer:1.0.4'
```


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


###### 如果Gradle出现compile失败的情况,可以在Project的build.gradle里面添加如下:(也可以使用上面的GitPack来complie)
```gradle
allprojects {
repositories {
//...
maven { url 'https://dl.bintray.com/jenly/maven' }
}
}
```

## 示例

### 代码示例
Expand Down Expand Up @@ -103,6 +93,9 @@ allprojects {

## 版本记录

#### v1.0.4:2022-9-11
* 优化细节

#### v1.0.3:2022-9-10 (从v1.0.3开始发布至 MavenCentral)
* 看大图界面支持自定义扩展

Expand Down
Binary file modified app/release/app-release.apk
Binary file not shown.
4 changes: 2 additions & 2 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
{
"type": "SINGLE",
"filters": [],
"versionCode": 4,
"versionName": "1.0.3",
"versionCode": 5,
"versionName": "1.0.4",
"outputFile": "app-release.apk"
}
]
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ android.enableJetifier = true
android.debug.obsoleteApi=true

GROUP=com.github.jenly1314
VERSION_NAME=1.0.3
VERSION_CODE=4
VERSION_NAME=1.0.4
VERSION_CODE=5

POM_DESCRIPTION=ImageViewer for Android
POM_INCEPTION_YEAR=2020
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public final class ImageViewer {

private Class<?> imageViewerClass;

private Bundle extrasBundle;

private int placeholderDrawableId;
private int errorDrawableId;

Expand Down Expand Up @@ -246,6 +248,16 @@ public ImageViewer imageViewerClass(Class<?> cls) {
return this;
}

/**
* 设置扩展数据 相当于 {@code intent.putExtras(extras)}
* @param extras
* @return
*/
public ImageViewer extras(Bundle extras) {
extrasBundle = extras;
return this;
}

/**
* 初始化资源
*
Expand Down Expand Up @@ -277,22 +289,11 @@ public void start(@NonNull Activity activity) {
*/
public void start(@NonNull Activity activity, @Nullable View sharedElement) {
initResource(activity);
Intent intent = new Intent(activity, ImageViewerActivity.class);

if (mOptionsCompat == null) {
if (sharedElement != null) {
mOptionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, sharedElement, ImageViewerActivity.SHARED_ELEMENT);
} else {
mOptionsCompat = ActivityOptionsCompat.makeCustomAnimation(activity, R.anim.iv_anim_in, R.anim.iv_anim_out);
}
Intent intent = new Intent(activity, imageViewerClass);
if(extrasBundle != null){
intent.putExtras(extrasBundle);
}

Bundle bundle = null;
if (mOptionsCompat != null) {
bundle = mOptionsCompat.toBundle();
}

activity.startActivity(intent, bundle);
activity.startActivity(intent, obtainActivityOptionsCompatBundle(activity, sharedElement));
}

/**
Expand All @@ -313,21 +314,27 @@ 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){
intent.putExtras(extrasBundle);
}
fragment.startActivity(intent, obtainActivityOptionsCompatBundle(fragment.getActivity(), sharedElement));
}

/**
* 获取 ActivityOptionsCompat 转 Bundle
* @param activity
* @param sharedElement
* @return
*/
private Bundle obtainActivityOptionsCompatBundle(Activity activity, @Nullable View sharedElement){
if (mOptionsCompat == null) {
if (sharedElement != null) {
mOptionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(fragment.getActivity(), sharedElement, ImageViewerActivity.SHARED_ELEMENT);
mOptionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, sharedElement, ImageViewerActivity.SHARED_ELEMENT);
} else {
mOptionsCompat = ActivityOptionsCompat.makeCustomAnimation(fragment.getContext(), R.anim.iv_anim_in, R.anim.iv_anim_out);
mOptionsCompat = ActivityOptionsCompat.makeCustomAnimation(activity, R.anim.iv_anim_in, R.anim.iv_anim_out);
}
}

Bundle bundle = null;
if (mOptionsCompat != null) {
bundle = mOptionsCompat.toBundle();
}

fragment.startActivity(intent, bundle);
return mOptionsCompat.toBundle();
}

}
4 changes: 2 additions & 2 deletions versions.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//App
def app_version = [:]
app_version.versionCode = 4
app_version.versionName = "1.0.3"
app_version.versionCode = 5
app_version.versionName = "1.0.4"
ext.app_version = app_version

//build version
Expand Down

0 comments on commit a9fcdec

Please sign in to comment.