Browse Source

Fixed a RecentFragment bug (hopefully)

pull/24/head
Ezerous 7 years ago
parent
commit
d0e19100b6
No known key found for this signature in database GPG Key ID: 262B2954BBA319E3
  1. 10
      app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java
  2. 3
      app/src/main/java/gr/thmmy/mthmmy/receiver/Receiver.java
  3. 6
      app/src/main/java/gr/thmmy/mthmmy/services/DownloadService.java
  4. 4
      app/src/main/java/gr/thmmy/mthmmy/services/NotificationService.java

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

@ -140,16 +140,18 @@ public class RecentFragment extends BaseFragment {
//---------------------------------------ASYNC TASK----------------------------------- //---------------------------------------ASYNC TASK-----------------------------------
private class RecentTask extends ParseTask { private class RecentTask extends ParseTask {
private List<TopicSummary> fetchedRecent;
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
progressBar.setVisibility(ProgressBar.VISIBLE); progressBar.setVisibility(ProgressBar.VISIBLE);
fetchedRecent = new ArrayList<>();
} }
@Override @Override
public void parse(Document document) throws ParseException { public void parse(Document document) throws ParseException {
Elements recent = document.select("#block8 :first-child div"); Elements recent = document.select("#block8 :first-child div");
if (!recent.isEmpty()) { if (!recent.isEmpty()) {
topicSummaries.clear();
for (int i = 0; i < recent.size(); i += 3) { for (int i = 0; i < recent.size(); i += 3) {
String link = recent.get(i).child(0).attr("href"); String link = recent.get(i).child(0).attr("href");
String title = recent.get(i).child(0).attr("title"); String title = recent.get(i).child(0).attr("title");
@ -180,7 +182,7 @@ public class RecentFragment extends BaseFragment {
} else } else
throw new ParseException("Parsing failed (dateTime)"); throw new ParseException("Parsing failed (dateTime)");
topicSummaries.add(new TopicSummary(link, title, lastUser, dateTime)); fetchedRecent.add(new TopicSummary(link, title, lastUser, dateTime));
} }
return; return;
} }
@ -190,7 +192,11 @@ public class RecentFragment extends BaseFragment {
@Override @Override
protected void postParsing(ParseTask.ResultCode result) { protected void postParsing(ParseTask.ResultCode result) {
if (result == ResultCode.SUCCESS) if (result == ResultCode.SUCCESS)
{
topicSummaries.clear();
topicSummaries.addAll(fetchedRecent);
recentAdapter.notifyDataSetChanged(); recentAdapter.notifyDataSetChanged();
}
progressBar.setVisibility(ProgressBar.INVISIBLE); progressBar.setVisibility(ProgressBar.INVISIBLE);
swipeRefreshLayout.setRefreshing(false); swipeRefreshLayout.setRefreshing(false);

3
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; import static gr.thmmy.mthmmy.services.DownloadService.STARTED;
public class Receiver extends BroadcastReceiver { 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_ID = "Downloads";
private static final String DOWNLOADS_CHANNEL_NAME = "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) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
notificationManager.createNotificationChannel(new NotificationChannel(DOWNLOADS_CHANNEL_ID, DOWNLOADS_CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH)); 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());
} }
} }

6
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); Intent intent = new Intent(ACTION_DOWNLOAD);
switch (type) { switch (type) {
case STARTED: { 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_TEXT, "Download Started");
intent.putExtra(EXTRA_NOTIFICATION_TICKER, "Downloading..."); intent.putExtra(EXTRA_NOTIFICATION_TICKER, "Downloading...");
break; break;
} }
case COMPLETED: { 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_TEXT, "Download Completed");
intent.putExtra(EXTRA_NOTIFICATION_TICKER, "Download Completed"); intent.putExtra(EXTRA_NOTIFICATION_TICKER, "Download Completed");
break; break;
} }
case FAILED: { 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_TEXT, "Download Failed");
intent.putExtra(EXTRA_NOTIFICATION_TICKER, "Download Failed"); intent.putExtra(EXTRA_NOTIFICATION_TICKER, "Download Failed");
break; break;

4
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 int requestCode = 0;
private static final String NEW_POSTS_COUNT = "newPostsCount"; 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 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. * Create and show a new post notification.

Loading…
Cancel
Save