mirror of
https://github.com/akaessens/NoFbEventScraper
synced 2025-06-05 23:29:13 +02:00
rewrite layout and catch url errors
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
package com.akdev.nofbeventscraper;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
@ -10,20 +12,18 @@ import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class FbScraper extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
private String url;
|
||||
private View popupView;
|
||||
private MainActivity main;
|
||||
public FbEvent event;
|
||||
|
||||
public FbScraper(View popupView, String url) {
|
||||
public FbScraper(MainActivity main, String url) {
|
||||
this.url = url;
|
||||
this.popupView = popupView;
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -34,10 +34,6 @@ public class FbScraper extends AsyncTask<Void, Void, Void> {
|
||||
try {
|
||||
document = Jsoup.connect(url).get();
|
||||
|
||||
Log.d("url", url);
|
||||
|
||||
//String event_name = document.title();
|
||||
|
||||
String json = document.select("#u_0_j").first().data();
|
||||
|
||||
try {
|
||||
@ -49,11 +45,12 @@ public class FbScraper extends AsyncTask<Void, Void, Void> {
|
||||
String event_description = reader.getString("description");
|
||||
String location = reader.getJSONObject("location").getString("name");
|
||||
|
||||
|
||||
String image_url = reader.getString("image");
|
||||
|
||||
this.event = new FbEvent(event_name, event_start, event_end, event_description, location, image_url);
|
||||
|
||||
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -77,16 +74,7 @@ public class FbScraper extends AsyncTask<Void, Void, Void> {
|
||||
protected void onPostExecute(Void aVoid) {
|
||||
super.onPostExecute(aVoid);
|
||||
|
||||
TextInputEditText field_name = (TextInputEditText) this.popupView.findViewById(R.id.field_event_name);
|
||||
TextInputEditText field_start = (TextInputEditText) this.popupView.findViewById(R.id.field_event_start);
|
||||
TextInputEditText field_end = (TextInputEditText) this.popupView.findViewById(R.id.field_event_end);
|
||||
TextInputEditText field_location = (TextInputEditText) this.popupView.findViewById(R.id.field_event_location);
|
||||
|
||||
field_name.setText(event.name);
|
||||
field_start.setText(event.start_date);
|
||||
field_end.setText(event.end_date);
|
||||
field_location.setText(event.location);
|
||||
|
||||
main.update(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user