Browse Source

Crash fix (MainActivity fragments)

pull/68/head
Ezerous 5 years ago
parent
commit
80cbba140b
No known key found for this signature in database GPG Key ID: 262B2954BBA319E3
  1. 13
      app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java
  2. 9
      app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java
  3. 14
      app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java
  4. 2
      app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ThmmyDateTimeParser.java

13
app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java

@ -158,19 +158,24 @@ public class ForumFragment extends BaseFragment {
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
if (forumTask != null && forumTask.getStatus() != AsyncTask.Status.RUNNING) if (forumTask!=null){
try{
if(forumTask.isRunning())
forumTask.cancel(true); forumTask.cancel(true);
} // Yes, it happens even though we checked
catch (NullPointerException ignored){ }
}
} }
public interface ForumFragmentInteractionListener extends FragmentInteractionListener { public interface ForumFragmentInteractionListener extends FragmentInteractionListener {
void onForumFragmentInteraction(Board board); void onForumFragmentInteraction(Board board);
} }
public void onForumTaskStarted() { private void onForumTaskStarted() {
progressBar.setVisibility(ProgressBar.VISIBLE); progressBar.setVisibility(ProgressBar.VISIBLE);
} }
public void onForumTaskFinished(int resultCode, ArrayList<Category> fetchedCategories) { private void onForumTaskFinished(int resultCode, ArrayList<Category> fetchedCategories) {
if (resultCode == NetworkResultCodes.SUCCESSFUL) { if (resultCode == NetworkResultCodes.SUCCESSFUL) {
categories.clear(); categories.clear();
categories.addAll(fetchedCategories); categories.addAll(fetchedCategories);
@ -191,7 +196,7 @@ public class ForumFragment extends BaseFragment {
private class ForumTask extends NewParseTask<ArrayList<Category>> { private class ForumTask extends NewParseTask<ArrayList<Category>> {
private HttpUrl forumUrl = SessionManager.forumUrl; //may change upon collapse/expand private HttpUrl forumUrl = SessionManager.forumUrl; //may change upon collapse/expand
public ForumTask(OnTaskStartedListener onTaskStartedListener, ForumTask(OnTaskStartedListener onTaskStartedListener,
OnNetworkTaskFinishedListener<ArrayList<Category>> onParseTaskFinishedListener) { OnNetworkTaskFinishedListener<ArrayList<Category>> onParseTaskFinishedListener) {
super(onTaskStartedListener, onParseTaskFinishedListener); super(onTaskStartedListener, onParseTaskFinishedListener);
} }

9
app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java

@ -85,7 +85,6 @@ public class RecentFragment extends BaseFragment {
if (topicSummaries.isEmpty()) { if (topicSummaries.isEmpty()) {
recentTask = new RecentTask(this::onRecentTaskStarted, this::onRecentTaskFinished); recentTask = new RecentTask(this::onRecentTaskStarted, this::onRecentTaskFinished);
recentTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, SessionManager.indexUrl.toString()); recentTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, SessionManager.indexUrl.toString());
} }
Timber.d("onActivityCreated"); Timber.d("onActivityCreated");
} }
@ -128,8 +127,13 @@ public class RecentFragment extends BaseFragment {
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
if (recentTask!=null && recentTask.isRunning()) if (recentTask!=null){
try{
if(recentTask.isRunning())
recentTask.cancel(true); recentTask.cancel(true);
} // Yes, it happens even though we checked
catch (NullPointerException ignored){ }
}
} }
@ -191,7 +195,6 @@ public class RecentFragment extends BaseFragment {
else else
throw new ParseException("Parsing failed (dateTime)"); throw new ParseException("Parsing failed (dateTime)");
} }
return fetchedRecent; return fetchedRecent;
} }

14
app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java

@ -157,10 +157,20 @@ public class UnreadFragment extends BaseFragment {
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
if (unreadTask!=null && unreadTask.isRunning()) if (unreadTask!=null){
try{
if(unreadTask.isRunning())
unreadTask.cancel(true); unreadTask.cancel(true);
if (markReadTask!=null && markReadTask.isRunning()) } // Yes, it happens even though we checked
catch (NullPointerException ignored){ }
}
if (markReadTask!=null){
try{
if(markReadTask.isRunning())
markReadTask.cancel(true); markReadTask.cancel(true);
} // Yes, it happens even though we checked
catch (NullPointerException ignored){ }
}
if(topicSummaries!=null) if(topicSummaries!=null)
topicSummaries.clear(); topicSummaries.clear();
} }

2
app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ThmmyDateTimeParser.java

@ -99,7 +99,7 @@ public class ThmmyDateTimeParser {
// Converts e.g. 12:16:48 -> 12:16, October 03, 2019, 16:40:18 -> 12:16 October 03, 2019, 16:40 // Converts e.g. 12:16:48 -> 12:16, October 03, 2019, 16:40:18 -> 12:16 October 03, 2019, 16:40
private static String removeSeconds(String dateTime){ private static String removeSeconds(String dateTime){
return dateTime.replaceAll("(.*):\\d+(.*)", "$1$2"); return dateTime.replaceAll("(.*):\\d+($|\\s.*)", "$1$2");
} }
@VisibleForTesting @VisibleForTesting

Loading…
Cancel
Save