From 07adaa9e75727c567901816568c0bcdbbf1d94d3 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Tue, 22 Oct 2019 13:07:40 +0300 Subject: [PATCH] Fixed crashes --- app/build.gradle | 4 +-- .../latestPosts/LatestPostsFragment.java | 11 +++---- .../activities/topic/tasks/TopicTask.java | 32 +++++++++++++------ .../gr/thmmy/mthmmy/utils/NetworkTask.java | 2 +- 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 2a0d01e2..60fbf711 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -80,9 +80,9 @@ dependencies { implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.cardview:cardview:1.0.0' implementation 'androidx.recyclerview:recyclerview:1.0.0' - implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0-alpha05' + implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0-beta01' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' - implementation 'androidx.exifinterface:exifinterface:1.1.0-beta01' + implementation 'androidx.exifinterface:exifinterface:1.1.0-rc01' implementation 'com.google.android.material:material:1.0.0' implementation 'com.google.firebase:firebase-core:17.0.0' implementation 'com.google.firebase:firebase-messaging:19.0.1' diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java index 59fa6421..6bb84d82 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java @@ -25,6 +25,7 @@ import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.base.BaseActivity; import gr.thmmy.mthmmy.base.BaseFragment; import gr.thmmy.mthmmy.model.PostSummary; +import gr.thmmy.mthmmy.utils.parsing.ParseException; import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import okhttp3.Request; @@ -176,13 +177,9 @@ public class LatestPostsFragment extends BaseFragment implements LatestPostsAdap } protected void onPostExecute(Boolean result) { - if (!result) { //Parse failed! - Timber.d("Parse failed!"); - Toast.makeText(getContext() - , "Fatal error!\n Aborting...", Toast.LENGTH_LONG).show(); - getActivity().finish(); - } - //Parse was successful + if (Boolean.FALSE.equals(result)) + Timber.e(new ParseException("Parsing failed(latest posts)"),"ParseException"); + progressBar.setVisibility(ProgressBar.INVISIBLE); latestPostsAdapter.notifyDataSetChanged(); isLoadingMore = false; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTask.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTask.java index a4aeef61..23b3e602 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTask.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTask.java @@ -6,6 +6,9 @@ import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import gr.thmmy.mthmmy.activities.topic.TopicParser; @@ -41,18 +44,27 @@ public class TopicTask extends AsyncTask { @Override protected TopicTaskResult doInBackground(String... strings) { Document topic = null; + String newPageUrl = strings[0]; + //TODO: Perhaps decode all URLs app-wide (i.e. in BaseApplication)? + try { + //Decodes e.g. any %3B to ; + newPageUrl = URLDecoder.decode(newPageUrl, StandardCharsets.UTF_8.displayName()); + } catch (UnsupportedEncodingException e) { + Timber.e(e, "Unsupported Encoding"); + } + //Finds the index of message focus if present int postFocus = 0; - { - if (newPageUrl.contains("msg")) { - String tmp = newPageUrl.substring(newPageUrl.indexOf("msg") + 3); - if (tmp.contains(";")) - postFocus = Integer.parseInt(tmp.substring(0, tmp.indexOf(";"))); - else if (tmp.contains("#")) - postFocus = Integer.parseInt(tmp.substring(0, tmp.indexOf("#"))); - } + + //TODO: Better parseInt handling - may rarely fail + if (newPageUrl.contains("msg")) { + String tmp = newPageUrl.substring(newPageUrl.indexOf("msg") + 3); + if (tmp.contains(";")) + postFocus = Integer.parseInt(tmp.substring(0, tmp.indexOf(';'))); + else if (tmp.contains("#")) + postFocus = Integer.parseInt(tmp.substring(0, tmp.indexOf('#'))); } Request request = new Request.Builder() @@ -120,10 +132,10 @@ public class TopicTask extends AsyncTask { } private boolean isUnauthorized(Document document) { - return document != null && document.select("body:contains(The topic or board you" + + return document != null && !document.select("body:contains(The topic or board you" + " are looking for appears to be either missing or off limits to you.)," + "body:contains(Το θέμα ή πίνακας που ψάχνετε ή δεν υπάρχει ή δεν " + - "είναι προσβάσιμο από εσάς.)").size() > 0; + "είναι προσβάσιμο από εσάς.)").isEmpty(); } @Override diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/NetworkTask.java b/app/src/main/java/gr/thmmy/mthmmy/utils/NetworkTask.java index 524a4033..86db3441 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/NetworkTask.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/NetworkTask.java @@ -47,7 +47,7 @@ public abstract class NetworkTask extends ExternalAsyncTask try { responseBodyString = response.body().string(); } catch (NullPointerException npe) { - Timber.wtf(npe, "Invalid response. Detatails: https://square.github.io/okhttp/3.x/okhttp/okhttp3/Response.html#body--"); + Timber.wtf(npe, "Invalid response. Details: https://square.github.io/okhttp/3.x/okhttp/okhttp3/Response.html#body--"); return new Parcel<>(NetworkResultCodes.NETWORK_ERROR, null); } catch (IOException e) { Timber.e(e, "Error getting response body string");