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. 17
      app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java
  2. 11
      app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java
  3. 18
      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

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

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

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

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

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

@ -157,10 +157,20 @@ public class UnreadFragment extends BaseFragment {
@Override
public void onDestroy() {
super.onDestroy();
if (unreadTask!=null && unreadTask.isRunning())
unreadTask.cancel(true);
if (markReadTask!=null && markReadTask.isRunning())
markReadTask.cancel(true);
if (unreadTask!=null){
try{
if(unreadTask.isRunning())
unreadTask.cancel(true);
} // Yes, it happens even though we checked
catch (NullPointerException ignored){ }
}
if (markReadTask!=null){
try{
if(markReadTask.isRunning())
markReadTask.cancel(true);
} // Yes, it happens even though we checked
catch (NullPointerException ignored){ }
}
if(topicSummaries!=null)
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
private static String removeSeconds(String dateTime){
return dateTime.replaceAll("(.*):\\d+(.*)", "$1$2");
return dateTime.replaceAll("(.*):\\d+($|\\s.*)", "$1$2");
}
@VisibleForTesting

Loading…
Cancel
Save