diff --git a/Kuroba/app/src/main/java/com/github/adamantcheese/chan/core/presenter/ImageReencodingPresenter.java b/Kuroba/app/src/main/java/com/github/adamantcheese/chan/core/presenter/ImageReencodingPresenter.java index 527c062543..f97d0c9dba 100644 --- a/Kuroba/app/src/main/java/com/github/adamantcheese/chan/core/presenter/ImageReencodingPresenter.java +++ b/Kuroba/app/src/main/java/com/github/adamantcheese/chan/core/presenter/ImageReencodingPresenter.java @@ -88,6 +88,11 @@ public void onDestroy() { public void loadImagePreview() { Reply reply = replyManager.getReply(loadable); + if (reply.file == null) { + showToast(context, R.string.no_file_is_selected); + return; + } + Point displaySize = getDisplaySize(); ImageDecoder.decodeFileOnBackgroundThread(reply.file, //decode to the device width/height, whatever is smaller @@ -110,6 +115,10 @@ public boolean hasAttachedFile() { public Bitmap.CompressFormat getImageFormat() { try { Reply reply = replyManager.getReply(loadable); + if (reply.file == null) { + return null; + } + return BitmapUtils.getImageFormat(reply.file); } catch (Exception e) { Logger.e(TAG, "Error while trying to get image format", e); @@ -121,6 +130,10 @@ public Bitmap.CompressFormat getImageFormat() { public Pair getImageDims() { try { Reply reply = replyManager.getReply(loadable); + if (reply.file == null) { + return null; + } + return BitmapUtils.getImageDims(reply.file); } catch (Exception e) { Logger.e(TAG, "Error while trying to get image dimensions", e); @@ -152,12 +165,12 @@ public void changeImageChecksum(boolean isChecked) { imageOptions.setChangeImageChecksum(isChecked); } - public void applyImageOptions() { + public boolean applyImageOptions() { Reply reply; synchronized (this) { if (cancelable != null) { - return; + return true; } reply = replyManager.getReply(loadable); @@ -170,7 +183,7 @@ public void applyImageOptions() { if (!imageOptions.getRemoveFilename() && !imageOptions.getFixExif() && !imageOptions.getRemoveMetadata() && !imageOptions.getChangeImageChecksum() && imageOptions.getReencodeSettings() == null) { callback.onImageOptionsApplied(reply, false); - return; + return true; } //only the "remove filename" option is selected @@ -178,7 +191,12 @@ public void applyImageOptions() { && !imageOptions.getChangeImageChecksum() && imageOptions.getReencodeSettings() == null) { reply.fileName = getNewImageName(reply.fileName, AS_IS); callback.onImageOptionsApplied(reply, true); - return; + return true; + } + + if (reply.file == null) { + // File is not valid + return false; } //one of the options that affects the image is selected (reencode/remove metadata/change checksum) @@ -218,6 +236,8 @@ public void applyImageOptions() { synchronized (this) { cancelable = localCancelable; } + + return true; } private String getNewImageName(String currentFileName, ReencodeType newType) { diff --git a/Kuroba/app/src/main/java/com/github/adamantcheese/chan/core/site/http/Reply.java b/Kuroba/app/src/main/java/com/github/adamantcheese/chan/core/site/http/Reply.java index e487efce29..ebc108d9f1 100644 --- a/Kuroba/app/src/main/java/com/github/adamantcheese/chan/core/site/http/Reply.java +++ b/Kuroba/app/src/main/java/com/github/adamantcheese/chan/core/site/http/Reply.java @@ -16,6 +16,8 @@ */ package com.github.adamantcheese.chan.core.site.http; +import androidx.annotation.Nullable; + import com.github.adamantcheese.chan.core.model.orm.Loadable; import java.io.File; @@ -36,6 +38,7 @@ public class Reply { public Loadable loadable; + @Nullable public File file; public String fileName = ""; public String name = ""; diff --git a/Kuroba/app/src/main/java/com/github/adamantcheese/chan/core/site/sites/chan4/Chan4ReplyCall.java b/Kuroba/app/src/main/java/com/github/adamantcheese/chan/core/site/sites/chan4/Chan4ReplyCall.java index 2259162507..26101a5ebb 100644 --- a/Kuroba/app/src/main/java/com/github/adamantcheese/chan/core/site/sites/chan4/Chan4ReplyCall.java +++ b/Kuroba/app/src/main/java/com/github/adamantcheese/chan/core/site/sites/chan4/Chan4ReplyCall.java @@ -82,6 +82,10 @@ private void attachFile( ) { RequestBody requestBody; + if (reply.file == null) { + throw new NullPointerException("reply.file is null!"); + } + if (progressListener == null) { requestBody = RequestBody.create(MediaType.parse("application/octet-stream"), reply.file); } else { diff --git a/Kuroba/app/src/main/java/com/github/adamantcheese/chan/core/site/sites/dvach/DvachReplyCall.java b/Kuroba/app/src/main/java/com/github/adamantcheese/chan/core/site/sites/dvach/DvachReplyCall.java index 7def8c3f23..3c2159d0df 100644 --- a/Kuroba/app/src/main/java/com/github/adamantcheese/chan/core/site/sites/dvach/DvachReplyCall.java +++ b/Kuroba/app/src/main/java/com/github/adamantcheese/chan/core/site/sites/dvach/DvachReplyCall.java @@ -85,6 +85,10 @@ private void attachFile( ) { RequestBody requestBody; + if (reply.file == null) { + throw new NullPointerException("reply.file is null!"); + } + if (progressListener == null) { requestBody = RequestBody.create(MediaType.parse("application/octet-stream"), reply.file); } else { diff --git a/Kuroba/app/src/main/java/com/github/adamantcheese/chan/ui/controller/ImageOptionsController.java b/Kuroba/app/src/main/java/com/github/adamantcheese/chan/ui/controller/ImageOptionsController.java index 48d10248d1..a5c4cc5747 100644 --- a/Kuroba/app/src/main/java/com/github/adamantcheese/chan/ui/controller/ImageOptionsController.java +++ b/Kuroba/app/src/main/java/com/github/adamantcheese/chan/ui/controller/ImageOptionsController.java @@ -16,14 +16,12 @@ */ package com.github.adamantcheese.chan.ui.controller; -import android.app.Activity; import android.content.Context; import android.content.res.ColorStateList; import android.graphics.Bitmap; import android.graphics.Point; import android.util.Pair; import android.view.View; -import android.view.Window; import android.widget.CompoundButton; import android.widget.ImageView; import android.widget.LinearLayout; @@ -52,6 +50,7 @@ import static com.github.adamantcheese.chan.utils.AndroidUtils.getString; import static com.github.adamantcheese.chan.utils.AndroidUtils.getWindow; import static com.github.adamantcheese.chan.utils.AndroidUtils.inflate; +import static com.github.adamantcheese.chan.utils.AndroidUtils.showToast; import static com.github.adamantcheese.chan.utils.AnimationUtils.animateStatusBar; public class ImageOptionsController @@ -211,7 +210,14 @@ public void onClick(View v) { if (v == cancel) { imageReencodingHelper.pop(); } else if (v == ok) { - presenter.applyImageOptions(); + if (!presenter.applyImageOptions()) { + // For now we only return false when reply.file == null + showToast( + context, + getString(R.string.could_not_apply_image_options, + context.getString(R.string.reply_file_is_null)) + ); + } } else if (v == viewHolder) { imageReencodingHelper.pop(); } diff --git a/Kuroba/app/src/main/res/values/strings.xml b/Kuroba/app/src/main/res/values/strings.xml index 3cafc0b069..96554b2901 100644 --- a/Kuroba/app/src/main/res/values/strings.xml +++ b/Kuroba/app/src/main/res/values/strings.xml @@ -794,4 +794,6 @@ Don't have a 4chan Pass?
Report a problem/crash Automatic crash reporting By enabling this setting, all collected crash logs will be uploaded automatically on every app restart. Crash reports only collect the crash log itself, app version and basic OS information. + No file is selected + reply.file is null