diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java index f366f295..86860ec1 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java +++ b/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 fetchedCategories) { + private void onForumTaskFinished(int resultCode, ArrayList fetchedCategories) { if (resultCode == NetworkResultCodes.SUCCESSFUL) { categories.clear(); categories.addAll(fetchedCategories); @@ -191,8 +196,8 @@ public class ForumFragment extends BaseFragment { private class ForumTask extends NewParseTask> { private HttpUrl forumUrl = SessionManager.forumUrl; //may change upon collapse/expand - public ForumTask(OnTaskStartedListener onTaskStartedListener, - OnNetworkTaskFinishedListener> onParseTaskFinishedListener) { + ForumTask(OnTaskStartedListener onTaskStartedListener, + OnNetworkTaskFinishedListener> onParseTaskFinishedListener) { super(onTaskStartedListener, onParseTaskFinishedListener); } diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java index c266660a..673dc32a 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java +++ b/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; } diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java index ffb0ede4..8bac71ba 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java +++ b/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(); } diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ThmmyDateTimeParser.java b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ThmmyDateTimeParser.java index e9813de2..3c398bd1 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ThmmyDateTimeParser.java +++ b/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