Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@

# Keep data models used for JSON parsing (Gson/Fruit)
-keep class me.ghui.v2er.network.bean.** { *; }
# Keep ImagesInfo and related classes for Fruit HTML parsing
-keep class me.ghui.v2er.module.imgviewer.ImagesInfo { *; }
-keep class me.ghui.v2er.module.imgviewer.ImagesInfo$* { *; }
-keep class me.ghui.v2er.module.imgviewer.ImagesInfo$*$* { *; }

# Keep classes with native methods
-keepclasseswithmembernames class * {
Expand Down
46 changes: 41 additions & 5 deletions app/src/main/java/me/ghui/v2er/module/gallery/GalleryActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@ public class GalleryActivity extends BaseActivity implements SwipeToDismissTouch
private ImagesInfo mData;

public static void open(ImagesInfo imgsData, Context context) {
// Validate images data before opening gallery
if (imgsData == null || imgsData.getImages() == null || imgsData.getImages().isEmpty()) {
Voast.show("图片不存在");
return;
}

// Check if at least one valid image exists
boolean hasValidImage = false;
for (ImagesInfo.Images.Image img : imgsData.getImages()) {
if (img != null && img.getUrl() != null) {
hasValidImage = true;
break;
}
}

if (!hasValidImage) {
Voast.show("图片不存在");
return;
}

Navigator.from(context)
.putExtra(EXTRA_IMG_DATA, imgsData)
.to(GalleryActivity.class)
Expand Down Expand Up @@ -134,12 +154,22 @@ public void onPageScrollStateChanged(int state) {

private String getCurrentImage() {
int index = mViewPager.getCurrentItem();
if (mData == null || mData.getImages() == null ||
index < 0 || index >= mData.getImages().size() ||
mData.getImages().get(index) == null) {
return null;
}
return mData.getImages().get(index).getUrl();
}

private void saveImage() {
String currentImage = getCurrentImage();
if (currentImage == null) {
Voast.show("图片不存在");
return;
}
// Already have permission, do the thing
glideRequest(getCurrentImage()).into(new SimpleTarget<File>() {
glideRequest(currentImage).into(new SimpleTarget<File>() {
@Override
public void onResourceReady(File file, Transition<? super File> transition) {
if (!FileUtils.isExternalStorageWritable()) {
Expand All @@ -148,7 +178,7 @@ public void onResourceReady(File file, Transition<? super File> transition) {
}
Observable.just(file)
.compose(RxUtils.io_main())
.map(f -> FileUtils.saveImg(f, Utils.getTypeFromImgUrl(getCurrentImage())))
.map(f -> FileUtils.saveImg(f, Utils.getTypeFromImgUrl(currentImage)))
.subscribe(new BaseConsumer<String>() {
@Override
public void onConsume(String path) {
Expand All @@ -166,19 +196,25 @@ public void onConsume(String path) {

@Override
public boolean onMenuItemClick(MenuItem item) {
String currentImage = getCurrentImage();
if (currentImage == null) {
Voast.show("图片不存在");
return false;
}

switch (item.getItemId()) {
case R.id.action_open_in_browser:
Utils.openInBrowser(getCurrentImage(), this);
Utils.openInBrowser(currentImage, this);
break;
case R.id.action_save:
//check write external permission then do save stuff
saveImage();
break;
case R.id.action_share:
glideRequest(getCurrentImage()).into(new SimpleTarget<File>() {
glideRequest(currentImage).into(new SimpleTarget<File>() {
@Override
public void onResourceReady(File file, Transition<? super File> transition) {
Utils.shareImg(file, Utils.getTypeFromImgUrl(getCurrentImage()), GalleryActivity.this);
Utils.shareImg(file, Utils.getTypeFromImgUrl(currentImage), GalleryActivity.this);
}
});
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public void destroyItem(ViewGroup container, int position, Object object) {
}

private ImagesInfo.Images.Image getItem(int postion) {
if (mImagesInfo == null || mImagesInfo.getImages() == null ||
postion < 0 || postion >= mImagesInfo.getImages().size()) {
return null;
}
return mImagesInfo.getImages().get(postion);
Comment on lines 51 to 56
Copy link

Copilot AI Sep 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parameter name has a typo: 'postion' should be 'position'.

Suggested change
private ImagesInfo.Images.Image getItem(int postion) {
if (mImagesInfo == null || mImagesInfo.getImages() == null ||
postion < 0 || postion >= mImagesInfo.getImages().size()) {
return null;
}
return mImagesInfo.getImages().get(postion);
private ImagesInfo.Images.Image getItem(int position) {
if (mImagesInfo == null || mImagesInfo.getImages() == null ||
position < 0 || position >= mImagesInfo.getImages().size()) {
return null;
}
return mImagesInfo.getImages().get(position);

Copilot uses AI. Check for mistakes.
Comment on lines 51 to 56
Copy link

Copilot AI Sep 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable name has a typo: 'postion' should be 'position' (appears twice in this condition).

Suggested change
private ImagesInfo.Images.Image getItem(int postion) {
if (mImagesInfo == null || mImagesInfo.getImages() == null ||
postion < 0 || postion >= mImagesInfo.getImages().size()) {
return null;
}
return mImagesInfo.getImages().get(postion);
private ImagesInfo.Images.Image getItem(int position) {
if (mImagesInfo == null || mImagesInfo.getImages() == null ||
position < 0 || position >= mImagesInfo.getImages().size()) {
return null;
}
return mImagesInfo.getImages().get(position);

Copilot uses AI. Check for mistakes.
}

Expand All @@ -59,7 +63,13 @@ public Object instantiateItem(ViewGroup container, int position) {
root.setOnImageClicked(mOnImageClickedListener);
container.addView(root);
// TODO: 2019/1/4 support svg
String url = getItem(position).getUrl();
ImagesInfo.Images.Image image = getItem(position);
if (image == null || image.getUrl() == null) {
// This shouldn't happen now that we validate before opening gallery
// But keep it as a safety net
return root;
}
String url = image.getUrl();
if (!Utils.isSVG(url)) {
GlideApp.with(mContext)
.load(url)
Expand Down
Loading