From d0e19100b65cabbd9f6c188e3f833b5adfa134ab Mon Sep 17 00:00:00 2001 From: Ezerous Date: Wed, 13 Jun 2018 16:03:05 +0300 Subject: [PATCH] Fixed a RecentFragment bug (hopefully) --- .../mthmmy/activities/main/recent/RecentFragment.java | 10 ++++++++-- .../main/java/gr/thmmy/mthmmy/receiver/Receiver.java | 3 ++- .../java/gr/thmmy/mthmmy/services/DownloadService.java | 6 +++--- .../gr/thmmy/mthmmy/services/NotificationService.java | 4 ++-- 4 files changed, 15 insertions(+), 8 deletions(-) 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 593b5542..9f9be77e 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 @@ -140,16 +140,18 @@ public class RecentFragment extends BaseFragment { //---------------------------------------ASYNC TASK----------------------------------- private class RecentTask extends ParseTask { + private List fetchedRecent; + @Override protected void onPreExecute() { progressBar.setVisibility(ProgressBar.VISIBLE); + fetchedRecent = new ArrayList<>(); } @Override public void parse(Document document) throws ParseException { Elements recent = document.select("#block8 :first-child div"); if (!recent.isEmpty()) { - topicSummaries.clear(); for (int i = 0; i < recent.size(); i += 3) { String link = recent.get(i).child(0).attr("href"); String title = recent.get(i).child(0).attr("title"); @@ -180,7 +182,7 @@ public class RecentFragment extends BaseFragment { } else throw new ParseException("Parsing failed (dateTime)"); - topicSummaries.add(new TopicSummary(link, title, lastUser, dateTime)); + fetchedRecent.add(new TopicSummary(link, title, lastUser, dateTime)); } return; } @@ -190,7 +192,11 @@ public class RecentFragment extends BaseFragment { @Override protected void postParsing(ParseTask.ResultCode result) { if (result == ResultCode.SUCCESS) + { + topicSummaries.clear(); + topicSummaries.addAll(fetchedRecent); recentAdapter.notifyDataSetChanged(); + } progressBar.setVisibility(ProgressBar.INVISIBLE); swipeRefreshLayout.setRefreshing(false); diff --git a/app/src/main/java/gr/thmmy/mthmmy/receiver/Receiver.java b/app/src/main/java/gr/thmmy/mthmmy/receiver/Receiver.java index 8d805922..f37e5078 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/receiver/Receiver.java +++ b/app/src/main/java/gr/thmmy/mthmmy/receiver/Receiver.java @@ -28,6 +28,7 @@ import static gr.thmmy.mthmmy.services.DownloadService.SAVE_DIR; import static gr.thmmy.mthmmy.services.DownloadService.STARTED; public class Receiver extends BroadcastReceiver { + private static final String NOTIFICATION_TAG = "DOWNLOADS"; private static final String DOWNLOADS_CHANNEL_ID = "Downloads"; private static final String DOWNLOADS_CHANNEL_NAME = "Downloads"; @@ -80,7 +81,7 @@ public class Receiver extends BroadcastReceiver { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) notificationManager.createNotificationChannel(new NotificationChannel(DOWNLOADS_CHANNEL_ID, DOWNLOADS_CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH)); - notificationManager.notify(id, notificationBuilder.build()); + notificationManager.notify(NOTIFICATION_TAG, id, notificationBuilder.build()); } } diff --git a/app/src/main/java/gr/thmmy/mthmmy/services/DownloadService.java b/app/src/main/java/gr/thmmy/mthmmy/services/DownloadService.java index 15aa0d98..be081a25 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/services/DownloadService.java +++ b/app/src/main/java/gr/thmmy/mthmmy/services/DownloadService.java @@ -181,19 +181,19 @@ public class DownloadService extends IntentService { Intent intent = new Intent(ACTION_DOWNLOAD); switch (type) { case STARTED: { - intent.putExtra(EXTRA_NOTIFICATION_TITLE, "\"" + fileName + "\" downloading..."); + intent.putExtra(EXTRA_NOTIFICATION_TITLE, "\"" + fileName + "\""); intent.putExtra(EXTRA_NOTIFICATION_TEXT, "Download Started"); intent.putExtra(EXTRA_NOTIFICATION_TICKER, "Downloading..."); break; } case COMPLETED: { - intent.putExtra(EXTRA_NOTIFICATION_TITLE, "\"" + fileName + "\" finished downloading."); + intent.putExtra(EXTRA_NOTIFICATION_TITLE, "\"" + fileName + "\""); intent.putExtra(EXTRA_NOTIFICATION_TEXT, "Download Completed"); intent.putExtra(EXTRA_NOTIFICATION_TICKER, "Download Completed"); break; } case FAILED: { - intent.putExtra(EXTRA_NOTIFICATION_TITLE, "\"" + fileName + "\" failed."); + intent.putExtra(EXTRA_NOTIFICATION_TITLE, "\"" + fileName + "\""); intent.putExtra(EXTRA_NOTIFICATION_TEXT, "Download Failed"); intent.putExtra(EXTRA_NOTIFICATION_TICKER, "Download Failed"); break; diff --git a/app/src/main/java/gr/thmmy/mthmmy/services/NotificationService.java b/app/src/main/java/gr/thmmy/mthmmy/services/NotificationService.java index 3bf9b658..6e4419c0 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/services/NotificationService.java +++ b/app/src/main/java/gr/thmmy/mthmmy/services/NotificationService.java @@ -61,9 +61,9 @@ public class NotificationService extends FirebaseMessagingService { private static int requestCode = 0; private static final String NEW_POSTS_COUNT = "newPostsCount"; - private static final String NEW_POST_TAG = "NEW_POST"; //notification tag + private static final String NEW_POST_TAG = "NEW_POST"; private static final String SUMMARY_TAG = "SUMMARY"; - private static final String DELETED_MESSAGES_TAG = "DELETED_MESSAGES_TAG"; //notification tag + private static final String DELETED_MESSAGES_TAG = "DELETED_MESSAGES"; /** * Create and show a new post notification.