diff --git a/app/src/main/java/com/akdev/nofbeventscraper/FbScraper.java b/app/src/main/java/com/akdev/nofbeventscraper/FbScraper.java index dc2187c..3daae67 100644 --- a/app/src/main/java/com/akdev/nofbeventscraper/FbScraper.java +++ b/app/src/main/java/com/akdev/nofbeventscraper/FbScraper.java @@ -27,7 +27,7 @@ import java.util.regex.Pattern; */ public class FbScraper extends AsyncTask { - private String error; + private int error; private String input_url; private WeakReference main; // no context leak with WeakReference private FbEvent event; @@ -224,16 +224,16 @@ public class FbScraper extends AsyncTask { } catch (URISyntaxException | MalformedURLException e) { e.printStackTrace(); - this.error = "Error: URL invalid."; + this.error = R.string.error_url; } catch (JSONException e) { e.printStackTrace(); - this.error = "Error: Scraping event data failed"; + this.error = R.string.error_scraping; } catch (IOException e) { e.printStackTrace(); - this.error = "Error: Unable to connect."; + this.error = R.string.error_connection; } catch (Exception e) { e.printStackTrace(); - this.error = "Error: Unknown Error."; + this.error = R.string.error_unknown; } return null; diff --git a/app/src/main/java/com/akdev/nofbeventscraper/MainActivity.java b/app/src/main/java/com/akdev/nofbeventscraper/MainActivity.java index c776a9e..d3237fb 100644 --- a/app/src/main/java/com/akdev/nofbeventscraper/MainActivity.java +++ b/app/src/main/java/com/akdev/nofbeventscraper/MainActivity.java @@ -1,5 +1,6 @@ package com.akdev.nofbeventscraper; +import android.annotation.SuppressLint; import android.content.ClipboardManager; import android.content.Context; import android.content.Intent; @@ -109,16 +110,12 @@ public class MainActivity extends AppCompatActivity { @Override public void onClick(View view) { - try { - ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); - String str = clipboard.getPrimaryClip().getItemAt(0).getText().toString(); + ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); + String str = Objects.requireNonNull(clipboard.getPrimaryClip()).getItemAt(0).getText().toString(); + + clear(true); + edit_text_uri_input.setText(str); - clear(true); - edit_text_uri_input.setText(str); - } catch (NullPointerException e) { - e.printStackTrace(); - error("Error: Clipboard empty"); - } startScraping(); } }); @@ -222,8 +219,13 @@ public class MainActivity extends AppCompatActivity { scraper.execute(); } - public void error(String str) { - layout_uri_input.setError(str); + public void error(Integer resId) { + if (resId != null) { + layout_uri_input.setError(getString(resId)); + } else { + layout_uri_input.setError(null); + } + } /** @@ -276,34 +278,34 @@ public class MainActivity extends AppCompatActivity { edit_text_uri_input.setText(event.url); if (event.name.equals("")) { - edit_text_event_name.setError("no event name detected"); + edit_text_event_name.setError(getString(R.string.error_no_name)); } else { edit_text_event_name.setText(event.name); } if (event.start_date == null) { - edit_text_event_start.setError("no event start date detected"); + edit_text_event_start.setError(getString(R.string.error_no_start_date)); } else { String str = FbEvent.dateTimeToString(event.start_date); edit_text_event_start.setText(str); } if (event.end_date == null) { - edit_text_event_end.setError("no event end date detected"); + edit_text_event_end.setError(getString(R.string.error_no_end_date)); } else { String str = FbEvent.dateTimeToString(event.end_date); edit_text_event_end.setText(str); } if (event.location.equals("")) { - edit_text_event_location.setError("no event location detected"); + edit_text_event_location.setError(getString(R.string.error_no_location)); } else { edit_text_event_location.setText(event.location); layout_event_location.setEndIconVisible(true); } if (event.description.equals("")) { - edit_text_event_description.setError("no event description detected"); + edit_text_event_description.setError(getString(R.string.error_no_description)); } else { edit_text_event_description.setText(event.description); } @@ -317,6 +319,7 @@ public class MainActivity extends AppCompatActivity { } + @SuppressLint("RestrictedApi") @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. diff --git a/app/src/main/res/layout/content_main.xml b/app/src/main/res/layout/content_main.xml index 9c32bc0..0422d3f 100644 --- a/app/src/main/res/layout/content_main.xml +++ b/app/src/main/res/layout/content_main.xml @@ -114,7 +114,6 @@ android:id="@+id/edit_text_event_location" android:layout_width="match_parent" android:layout_height="wrap_content" - android:autoLink="map" android:focusable="false" android:cursorVisible="false" android:hint="@string/hint_event_location" diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index e7ad5cb..388a06a 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -15,4 +15,14 @@ Einfügen von Inhalten aus der Zwischenablage in das URL-Eingabefeld Welcher URL-Präfix ist zu verwenden? Die Nutzung von m.facebook.com ist stabiler und schneller. Die Verwendung von www.facebook.com funktioniert besser bei Ereignissen mit mehreren Instanzen und zeigt eine hochauflösende Vorschau an, geht aber irgendwann kaputt, wenn Facebook das klassische Design deaktiviert. + Fehler: Zwischenablage leer + Fehler: Veranstaltungsname nicht verfügbar + Fehler: Veranstaltungsbeginn nicht verfügbar + Fehler: Veranstaltungsende nicht verfügbar + Fehler: Veranstaltungsort nicht verfügbar + Fehler: Veranstaltungsbeschreibung nicht verfügbar + Fehler: Veranstaltungsdaten nicht gefunden + Fehler: URL ungültig + Fehler: Keine Verbindung möglich + Fehler: Unbekannter Fehler \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 77c2f4d..f276784 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -19,10 +19,24 @@ Add to calendar Paste content from clipboard into the URL input box + + Error: clipboard empty + Error: Event name unavailable + Error: Event start date unavailable + Error: Event end date unavailable + Error: Event location unavailable + Error: Event description unavailable + Error: Scraping event data failed + Error: URL invalid + Error: Unable to connect + Error: Unknown Error + Scraper Which URL prefix to use "Using m.facebook.com is more stable and faster. Using www.facebook.com works better with multiple instance events and will display a high resolution preview but will eventually break when Facebook disables the classic design. " + +