Browse Source

Fixed crashes

pull/67/merge
Ezerous 5 years ago
parent
commit
07adaa9e75
  1. 4
      app/build.gradle
  2. 11
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java
  3. 24
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTask.java
  4. 2
      app/src/main/java/gr/thmmy/mthmmy/utils/NetworkTask.java

4
app/build.gradle

@ -80,9 +80,9 @@ dependencies {
implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0' implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview: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.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.android.material:material:1.0.0'
implementation 'com.google.firebase:firebase-core:17.0.0' implementation 'com.google.firebase:firebase-core:17.0.0'
implementation 'com.google.firebase:firebase-messaging:19.0.1' implementation 'com.google.firebase:firebase-messaging:19.0.1'

11
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.BaseActivity;
import gr.thmmy.mthmmy.base.BaseFragment; import gr.thmmy.mthmmy.base.BaseFragment;
import gr.thmmy.mthmmy.model.PostSummary; import gr.thmmy.mthmmy.model.PostSummary;
import gr.thmmy.mthmmy.utils.parsing.ParseException;
import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; import gr.thmmy.mthmmy.utils.parsing.ParseHelpers;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
import okhttp3.Request; import okhttp3.Request;
@ -176,13 +177,9 @@ public class LatestPostsFragment extends BaseFragment implements LatestPostsAdap
} }
protected void onPostExecute(Boolean result) { protected void onPostExecute(Boolean result) {
if (!result) { //Parse failed! if (Boolean.FALSE.equals(result))
Timber.d("Parse failed!"); Timber.e(new ParseException("Parsing failed(latest posts)"),"ParseException");
Toast.makeText(getContext()
, "Fatal error!\n Aborting...", Toast.LENGTH_LONG).show();
getActivity().finish();
}
//Parse was successful
progressBar.setVisibility(ProgressBar.INVISIBLE); progressBar.setVisibility(ProgressBar.INVISIBLE);
latestPostsAdapter.notifyDataSetChanged(); latestPostsAdapter.notifyDataSetChanged();
isLoadingMore = false; isLoadingMore = false;

24
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 org.jsoup.nodes.Element;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import gr.thmmy.mthmmy.activities.topic.TopicParser; import gr.thmmy.mthmmy.activities.topic.TopicParser;
@ -41,18 +44,27 @@ public class TopicTask extends AsyncTask<String, Void, TopicTaskResult> {
@Override @Override
protected TopicTaskResult doInBackground(String... strings) { protected TopicTaskResult doInBackground(String... strings) {
Document topic = null; Document topic = null;
String newPageUrl = strings[0]; 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 //Finds the index of message focus if present
int postFocus = 0; int postFocus = 0;
{
//TODO: Better parseInt handling - may rarely fail
if (newPageUrl.contains("msg")) { if (newPageUrl.contains("msg")) {
String tmp = newPageUrl.substring(newPageUrl.indexOf("msg") + 3); String tmp = newPageUrl.substring(newPageUrl.indexOf("msg") + 3);
if (tmp.contains(";")) if (tmp.contains(";"))
postFocus = Integer.parseInt(tmp.substring(0, tmp.indexOf(";"))); postFocus = Integer.parseInt(tmp.substring(0, tmp.indexOf(';')));
else if (tmp.contains("#")) else if (tmp.contains("#"))
postFocus = Integer.parseInt(tmp.substring(0, tmp.indexOf("#"))); postFocus = Integer.parseInt(tmp.substring(0, tmp.indexOf('#')));
}
} }
Request request = new Request.Builder() Request request = new Request.Builder()
@ -120,10 +132,10 @@ public class TopicTask extends AsyncTask<String, Void, TopicTaskResult> {
} }
private boolean isUnauthorized(Document document) { 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.)," + " are looking for appears to be either missing or off limits to you.)," +
"body:contains(Το θέμα ή πίνακας που ψάχνετε ή δεν υπάρχει ή δεν " + "body:contains(Το θέμα ή πίνακας που ψάχνετε ή δεν υπάρχει ή δεν " +
"είναι προσβάσιμο από εσάς.)").size() > 0; "είναι προσβάσιμο από εσάς.)").isEmpty();
} }
@Override @Override

2
app/src/main/java/gr/thmmy/mthmmy/utils/NetworkTask.java

@ -47,7 +47,7 @@ public abstract class NetworkTask<T> extends ExternalAsyncTask<String, Parcel<T>
try { try {
responseBodyString = response.body().string(); responseBodyString = response.body().string();
} catch (NullPointerException npe) { } 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); return new Parcel<>(NetworkResultCodes.NETWORK_ERROR, null);
} catch (IOException e) { } catch (IOException e) {
Timber.e(e, "Error getting response body string"); Timber.e(e, "Error getting response body string");

Loading…
Cancel
Save