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-----------------------------------
private class RecentTask extends ParseTask {
private List<TopicSummary> 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);

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;
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());
}
}

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);
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;

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 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.

Loading…
Cancel
Save