From 5952bf4b60247353aa5e9fbbd92e217288e83b5c Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Mon, 6 Jul 2020 14:23:31 -0400 Subject: [PATCH] why does java mandates catching exception bruh --- app/build.gradle | 2 +- .../instagrabber/adapters/PostsAdapter.java | 22 ++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index a7b20ccb..e60dbbfb 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,7 +10,7 @@ android { targetSdkVersion 29 versionCode 27 - versionName '16.6-a5' + versionName '16.6-a6' multiDexEnabled true diff --git a/app/src/main/java/awais/instagrabber/adapters/PostsAdapter.java b/app/src/main/java/awais/instagrabber/adapters/PostsAdapter.java index 0098d86e..888e3cdc 100755 --- a/app/src/main/java/awais/instagrabber/adapters/PostsAdapter.java +++ b/app/src/main/java/awais/instagrabber/adapters/PostsAdapter.java @@ -1,6 +1,7 @@ package awais.instagrabber.adapters; import android.graphics.drawable.Drawable; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -20,10 +21,14 @@ import java.net.HttpURLConnection; import java.net.URL; import java.util.ArrayList; +import awais.instagrabber.BuildConfig; import awais.instagrabber.R; import awais.instagrabber.adapters.viewholder.PostViewHolder; import awais.instagrabber.models.PostModel; import awais.instagrabber.models.enums.MediaItemType; +import awaisomereport.LogCollector; + +import static awais.instagrabber.utils.Utils.logCollector; public final class PostsAdapter extends RecyclerView.Adapter { private final ArrayList postModels; @@ -80,11 +85,18 @@ public final class PostsAdapter extends RecyclerView.Adapter { @Override public boolean onLoadFailed(@Nullable final GlideException e, final Object model, final Target target, final boolean isFirstResource) { holder.progressView.setVisibility(View.GONE); - final HttpURLConnection conn = (HttpURLConnection) new URL(postModel.getDisplayUrl()).openConnection(); - conn.setUseCaches(false); - conn.connect(); - if (conn.getResponseCode() != HttpURLConnection.HTTP_GONE) - glideRequestManager.load(postModel.getDisplayUrl()).into(holder.postImage); + try { + final HttpURLConnection conn = (HttpURLConnection) new URL(postModel.getDisplayUrl()).openConnection(); + conn.setUseCaches(false); + conn.connect(); + if (conn.getResponseCode() != HttpURLConnection.HTTP_GONE) + glideRequestManager.load(postModel.getDisplayUrl()).into(holder.postImage); + } + catch (Exception urle) { + if (logCollector != null) + logCollector.appendException(urle, LogCollector.LogFile.ASYNC_POST_FETCHER, "doInBackground"); + if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", urle); + } return false; } }).into(holder.postImage);