remove possibly fragile task counter dependent output

This commit is contained in:
akaessens 2020-09-27 13:18:14 +02:00
parent a8baabdb5f
commit 8335ffeada
3 changed files with 9 additions and 24 deletions

View File

@ -20,7 +20,6 @@ public class FbScraper {
protected List<FbEvent> events;
protected List<AsyncTask> tasks;
int remaining_events = 0;
url_type_enum url_type = url_type_enum.EVENT;
private String input_url;
private WeakReference<MainActivity> main; // no context leak with WeakReference
@ -107,23 +106,11 @@ public class FbScraper {
void scrapeEventResultCallback(FbEvent event, int error) {
if (url_type == url_type_enum.EVENT) {
if (event != null) {
main.get().addEvent(event);
main.get().input_helper(main.get().getString(R.string.done), false);
} else {
main.get().input_helper(main.get().getString(error), true);
}
killAllTasks();
} else {
if (event != null) {
main.get().addEvent(event);
remaining_events--;
if (remaining_events <= 0) {
main.get().input_helper(main.get().getString(R.string.done), false);
killAllTasks();
}
main.get().input_helper(main.get().getString(R.string.done), false);
} else if (url_type == url_type_enum.EVENT) {
main.get().input_helper(main.get().getString(error), true);
}
}
@ -152,8 +139,7 @@ public class FbScraper {
protected void scrapePageResultCallback(List<String> event_urls, int error) {
if (event_urls.size() > 0) {
remaining_events = event_urls.size();
main.get().input_helper(main.get().getString(R.string.found_events, event_urls.size()), false);
for (String event_url : event_urls) {
try {
String url = getEventUrl(event_url);
@ -162,7 +148,7 @@ public class FbScraper {
// ignore this event
}
}
} else if (url_type == url_type_enum.PAGE) {
} else {
main.get().input_helper(main.get().getString(error), true);
}
}

View File

@ -19,5 +19,4 @@
<string name="preferences_event_setting">Veranstaltungsliste löschen</string>
<string name="preferences_event_snackbar">"Veranstaltungen gelöscht "</string>
<string name="done">Fertig</string>
<string name="found_events">%1$d Veranstaltungen gefunden</string>
</resources>

View File

@ -8,6 +8,7 @@
<!-- Input hints -->
<string name="hint_add_link">Event link</string>
<string name="done">Done</string>
<string name="helper_add_link">Paste Facebook link to the event</string>
@ -21,6 +22,8 @@
<string name="error_connection">Error: Unable to connect</string>
<string name="error_unknown">Error: Unknown Error</string>
<string name="event_placeholder" translatable="false">Placeholder</string>
<!-- Preferences -->
<string name="preferences_scraper_header" translatable="false">Scraper</string>
<string name="preferences_url_setting">Which URL prefix to use</string>
@ -29,8 +32,5 @@
<string name="preferences_events_header">Events</string>
<string name="preferences_event_setting">Clear event list</string>
<string name="preferences_event_snackbar">Events list cleared</string>
<string name="event_placeholder" translatable="false">Placeholder</string>
<string name="done">Done</string>
<string name="found_events">Found %1$d events</string>
</resources>