1
0
mirror of https://github.com/akaessens/NoFbEventScraper synced 2025-06-05 23:29:13 +02:00

9 Commits

Author SHA1 Message Date
fc9fb169ef prepare v0.2.1 2020-08-15 19:29:56 +02:00
a1c7720836 links in text color for better visibility 2020-08-15 16:38:12 +02:00
9ab18b496f update jsoup 2020-08-15 15:31:05 +02:00
40a2c7d18f cancel scraping if clear is pressed to prevent inconsitent cleared state
disable add button to prevent creating empty events
2020-08-15 13:51:12 +02:00
fd874d7cb0 fix calendar icon color for dark layout 2020-08-15 13:27:17 +02:00
eafa1bfc1b Merge branch 'master' of github.com:akaessens/NoFbEventScraper 2020-08-15 13:15:50 +02:00
bc9cf04f10 use helper error instead of toast
move clear fuction to text input
more concise add button
remove autocorrect o textfields
closes #10
2020-08-15 13:15:01 +02:00
ac98a4a43c fix tests,
minor design fixes
2020-08-15 11:42:56 +02:00
b9f9038f6e Update README.md 2020-08-15 01:00:03 +02:00
16 changed files with 120 additions and 76 deletions

View File

@ -11,10 +11,8 @@ This source contains the information which is used to create a calendar entry.
# Download # Download
Currently this application is in the submitting process to FDroid. see also [#2](/../../issues/2). Currently this application is in the submitting process to FDroid. see also [#2](/../../issues/2).
Until it is published at FDroid, use [release v0.1.1](https://github.com/akaessens/NoFbEventScraper/releases/download/v0.2.0/app-release.apk). Until it is published at FDroid, use [release v0.2.0](https://github.com/akaessens/NoFbEventScraper/releases/download/v0.2.0/app-release.apk).
# Screenshot # Screenshot
<img src="https://github.com/akaessens/NoFbEventScraper/raw/master/fastlane/metadata/android/en-US/images/phoneScreenshots/1.png" alt="Screenshot 1" width="250"> <img src="https://github.com/akaessens/NoFbEventScraper/raw/master/fastlane/metadata/android/en-US/images/phoneScreenshots/1.png" alt="Screenshot 1" width="250"> <img src="https://github.com/akaessens/NoFbEventScraper/raw/master/fastlane/metadata/android/en-US/images/phoneScreenshots/2.png" alt="Screenshot 2" width="250"> <img src="https://github.com/akaessens/NoFbEventScraper/raw/master/fastlane/metadata/android/en-US/images/phoneScreenshots/3.png" alt="Screenshot 3" width="250">
<img src="https://github.com/akaessens/NoFbEventScraper/raw/master/fastlane/metadata/android/en-US/images/phoneScreenshots/2.png" alt="Screenshot 2" width="250">
<img src="https://github.com/akaessens/NoFbEventScraper/raw/master/fastlane/metadata/android/en-US/images/phoneScreenshots/3.png" alt="Screenshot 3" width="250">

View File

@ -8,8 +8,8 @@ android {
applicationId "com.akdev.nofbeventscraper" applicationId "com.akdev.nofbeventscraper"
minSdkVersion 26 minSdkVersion 26
targetSdkVersion 29 targetSdkVersion 29
versionCode 3 versionCode 4
versionName "0.2.0" versionName "0.2.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }
@ -35,7 +35,7 @@ dependencies {
implementation 'androidx.navigation:navigation-ui:2.3.0' implementation 'androidx.navigation:navigation-ui:2.3.0'
// jsoup HTML parser library @ https://jsoup.org/ // jsoup HTML parser library @ https://jsoup.org/
implementation 'org.jsoup:jsoup:1.11.1' implementation 'org.jsoup:jsoup:1.13.1'
implementation 'com.squareup.picasso:picasso:2.71828' implementation 'com.squareup.picasso:picasso:2.71828'

View File

@ -36,7 +36,7 @@ public class MainActivityUnitTest {
mInstrumentation.removeMonitor(monitor); mInstrumentation.removeMonitor(monitor);
final String exp = "https://m.facebook.com/events/261145401687844"; final String exp = "https://www.facebook.com/events/261145401687844";
String url = "https://www.facebook.com/events/261145401687844"; String url = "https://www.facebook.com/events/261145401687844";
String act = mainActivity.checkURI(url); String act = mainActivity.checkURI(url);

View File

@ -55,12 +55,12 @@ public class ScraperUnitTest {
FbScraper scraper = new FbScraper(null, ""); FbScraper scraper = new FbScraper(null, "");
String in = "foo @[152580919265:274:MagentaMusik 360] bar"; String in = "foo @[152580919265:274:MagentaMusik 360] bar";
String exp = "foo m.facebook.com/152580919265 (MagentaMusik 360) bar"; String exp = "foo MagentaMusik 360 [m.facebook.com/152580919265] bar";
String act = scraper.fixLinks(in); String act = scraper.fixLinks(in);
assertEquals(exp, act); assertEquals(exp, act);
in = "foo @[152580919265:274:MagentaMusik 360] bar @[666666666666:274:NoOfTheBeast]"; in = "foo @[152580919265:274:MagentaMusik 360] bar @[666666666666:274:NoOfTheBeast]";
exp = "foo m.facebook.com/152580919265 (MagentaMusik 360) bar m.facebook.com/666666666666 (NoOfTheBeast)"; exp = "foo MagentaMusik 360 [m.facebook.com/152580919265] bar NoOfTheBeast [m.facebook.com/666666666666]";
act = scraper.fixLinks(in); act = scraper.fixLinks(in);
assertEquals(exp, act); assertEquals(exp, act);

View File

@ -1,15 +1,9 @@
package com.akdev.nofbeventscraper; package com.akdev.nofbeventscraper;
import android.app.Activity;
import android.content.Context;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.text.Editable; import android.text.Editable;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import com.google.android.material.textfield.TextInputEditText;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
@ -80,7 +74,8 @@ public class FbScraper extends AsyncTask<Void, Void, Void> {
protected String fixLinks(String description_in) { protected String fixLinks(String description_in) {
try { try {
// @[152580919265:274:MagentaMusik 360] -> m.facebook.com/152580919265 // @[152580919265:274:MagentaMusik 360] -> m.facebook.com/152580919265
return description_in.replaceAll("@\\[([0-9]{10,}):[0-9]{3}:([^\\]]*)\\]", "m.facebook.com/$1 ($2)"); return description_in.replaceAll("@\\[([0-9]{10,}):[0-9]{3}:([^\\]]*)\\]",
"$2 [m.facebook.com/$1]");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -103,7 +98,7 @@ public class FbScraper extends AsyncTask<Void, Void, Void> {
Document document = null; Document document = null;
try { try {
document = Jsoup.connect(url).get(); document = Jsoup.connect(url).userAgent("Mozilla").get();
try { try {
String json = document.select("script[type = application/ld+json]").first().data(); String json = document.select("script[type = application/ld+json]").first().data();
@ -141,7 +136,7 @@ public class FbScraper extends AsyncTask<Void, Void, Void> {
e.printStackTrace(); e.printStackTrace();
this.error = "Error: Scraping event data failed"; this.error = "Error: Scraping event data failed";
} }
} catch (IOException e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
this.error = "Error: URL not available"; this.error = "Error: URL not available";
} }
@ -160,7 +155,7 @@ public class FbScraper extends AsyncTask<Void, Void, Void> {
this.main.update(event); this.main.update(event);
} }
else { else {
main.toast(error); main.error(error);
this.main.clear(false); this.main.clear(false);
} }
} }

View File

@ -19,15 +19,12 @@ import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.Toast; import android.widget.Toast;
import com.google.android.material.textfield.TextInputLayout;
import com.squareup.picasso.Picasso; import com.squareup.picasso.Picasso;
import java.net.URI;
import java.net.URL; import java.net.URL;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.TimeZone;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
@ -44,6 +41,9 @@ public class MainActivity extends AppCompatActivity {
private TextInputEditText field_event_description; private TextInputEditText field_event_description;
private ImageView toolbar_image_view; private ImageView toolbar_image_view;
private CollapsingToolbarLayout toolbar_layout; private CollapsingToolbarLayout toolbar_layout;
private TextInputLayout input_layout;
private FbScraper scraper;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -52,11 +52,11 @@ public class MainActivity extends AppCompatActivity {
Toolbar toolbar = findViewById(R.id.toolbar); Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
cancel_button = (Button) findViewById(R.id.cancel_button);
ok_button = (Button) findViewById(R.id.ok_button); ok_button = (Button) findViewById(R.id.ok_button);
paste_button = (Button) findViewById(R.id.paste_button); paste_button = (Button) findViewById(R.id.paste_button);
field_uri_input = (TextInputEditText) findViewById(R.id.field_uri_input); field_uri_input = (TextInputEditText) findViewById(R.id.field_uri_input);
input_layout = (TextInputLayout) findViewById(R.id.textInputLayout);
field_event_name = (TextInputEditText) findViewById(R.id.field_event_name); field_event_name = (TextInputEditText) findViewById(R.id.field_event_name);
field_event_start = (TextInputEditText) findViewById(R.id.field_event_start); field_event_start = (TextInputEditText) findViewById(R.id.field_event_start);
field_event_end = (TextInputEditText) findViewById(R.id.field_event_end); field_event_end = (TextInputEditText) findViewById(R.id.field_event_end);
@ -65,6 +65,9 @@ public class MainActivity extends AppCompatActivity {
toolbar_image_view = (ImageView) findViewById(R.id.image_view); toolbar_image_view = (ImageView) findViewById(R.id.image_view);
toolbar_layout = (CollapsingToolbarLayout) findViewById(R.id.toolbar_layout); toolbar_layout = (CollapsingToolbarLayout) findViewById(R.id.toolbar_layout);
ok_button.setEnabled(false);
paste_button.setOnClickListener(new View.OnClickListener() { paste_button.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
@ -78,13 +81,20 @@ public class MainActivity extends AppCompatActivity {
} }
catch (NullPointerException e) { catch (NullPointerException e) {
e.printStackTrace(); e.printStackTrace();
toast("Error: Clipboard empty"); error("Error: Clipboard empty");
} }
startScraping(); startScraping();
} }
}); });
cancel_button.setOnClickListener(new View.OnClickListener() {
input_layout.setEndIconOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
clear(true);
}
});
input_layout.setErrorIconOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
clear(true); clear(true);
@ -110,13 +120,12 @@ public class MainActivity extends AppCompatActivity {
intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, start_epoch); intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, start_epoch);
intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, end_epoch); intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, end_epoch);
intent.putExtra(CalendarContract.Events.EVENT_LOCATION, location); intent.putExtra(CalendarContract.Events.EVENT_LOCATION, location);
intent.putExtra(CalendarContract.Events.DESCRIPTION, uri + "\n" + description); intent.putExtra(CalendarContract.Events.DESCRIPTION, uri + "\n\n" + description);
startActivity(intent); startActivity(intent);
} }
catch (Exception e ) catch (Exception e )
{ {
e.printStackTrace(); e.printStackTrace();
toast("Error: Invalid fields");
} }
} }
@ -217,8 +226,8 @@ public class MainActivity extends AppCompatActivity {
} }
catch (Exception e) { catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
clear(true); clear(false);
toast("Invalid URL"); error("Error: Invalid URL");
str = ""; str = "";
} }
return str; return str;
@ -226,23 +235,31 @@ public class MainActivity extends AppCompatActivity {
public void startScraping() { public void startScraping() {
String str = checkURI(field_uri_input.getText().toString()); error(null);
field_uri_input.setText(str);
try { try {
FbScraper scraper = new FbScraper(this, field_uri_input.getText().toString()); String str = checkURI(field_uri_input.getText().toString());
if (!str.equals(""))
{
field_uri_input.setText(str);
scraper = new FbScraper(this, field_uri_input.getText().toString());
scraper.execute(); scraper.execute();
} }
}
catch (Exception e) { catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
clear(true); clear(false);
toast("Invalid URL"); error("Error: Invalid URL");
} }
} }
public void toast(String str) { public void error(String str) {
Toast.makeText(this, str, Toast.LENGTH_SHORT).show(); //Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
input_layout.setError(str);
} }
public void clear(boolean clearUri) { public void clear(boolean clearUri) {
if (clearUri) { if (clearUri) {
@ -261,10 +278,18 @@ public class MainActivity extends AppCompatActivity {
toolbar_image_view.setImageDrawable(null); toolbar_image_view.setImageDrawable(null);
toolbar_layout.setTitle(getString(R.string.app_name)); toolbar_layout.setTitle(getString(R.string.app_name));
if (scraper!=null)
{
scraper.cancel(true);
scraper = null;
}
ok_button.setEnabled(false);
} }
public void update(FbEvent event) { public void update(FbEvent event) {
field_event_name.setText(event.name); field_event_name.setText(event.name);
input_layout.setError(null);
if (event.name.equals("")) if (event.name.equals(""))
{ {
@ -304,6 +329,8 @@ public class MainActivity extends AppCompatActivity {
{ {
e.printStackTrace(); e.printStackTrace();
} }
ok_button.setEnabled(true);
} }

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M22,3L7,3c-0.69,0 -1.23,0.35 -1.59,0.88L0.37,11.45c-0.22,0.34 -0.22,0.77 0,1.11l5.04,7.56c0.36,0.52 0.9,0.88 1.59,0.88h15c1.1,0 2,-0.9 2,-2L24,5c0,-1.1 -0.9,-2 -2,-2zM18.3,16.3c-0.39,0.39 -1.02,0.39 -1.41,0L14,13.41l-2.89,2.89c-0.39,0.39 -1.02,0.39 -1.41,0 -0.39,-0.39 -0.39,-1.02 0,-1.41L12.59,12 9.7,9.11c-0.39,-0.39 -0.39,-1.02 0,-1.41 0.39,-0.39 1.02,-0.39 1.41,0L14,10.59l2.89,-2.89c0.39,-0.39 1.02,-0.39 1.41,0 0.39,0.39 0.39,1.02 0,1.41L15.41,12l2.89,2.89c0.38,0.38 0.38,1.02 0,1.41z"
android:fillColor="#000000"/>
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M16.53,11.06L15.47,10l-4.88,4.88 -2.12,-2.12 -1.06,1.06L10.59,17l5.94,-5.94zM19,3h-1L18,1h-2v2L8,3L8,1L6,1v2L5,3c-1.11,0 -1.99,0.9 -1.99,2L3,19c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2L21,5c0,-1.1 -0.9,-2 -2,-2zM19,19L5,19L5,8h14v11z"
android:fillColor="#000000"/>
</vector>

View File

@ -70,36 +70,22 @@
android:layout_margin="0dp" android:layout_margin="0dp"
app:contentInsetStart="0dp"> app:contentInsetStart="0dp">
<LinearLayout
android:id="@+id/groupbutton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal"
android:weightSum="2">
<Button
android:id="@+id/cancel_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="8dp"
android:layout_weight="1"
android:padding="12dp"
android:text="@android:string/cancel"
app:cornerRadius="12dp" />
<Button <Button
android:id="@+id/ok_button" android:id="@+id/ok_button"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="8dp" android:layout_marginStart="16dp"
android:layout_marginRight="16dp" android:layout_marginEnd="16dp"
android:layout_weight="1" android:layout_weight="1"
android:padding="12dp" android:padding="12dp"
android:text="@android:string/ok" android:text="@string/add_to_calendar"
app:cornerRadius="12dp" /> android:textColor="#FFFFFF"
</LinearLayout> app:cornerRadius="24dp"
app:icon="@drawable/ic_event_available"
app:iconGravity="textStart"
app:iconPadding="16dp"
app:iconTint="#FFFFFF" />
</com.google.android.material.bottomappbar.BottomAppBar> </com.google.android.material.bottomappbar.BottomAppBar>

View File

@ -31,16 +31,22 @@
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayout" android:id="@+id/textInputLayout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginEnd="16dp"
app:endIconCheckable="false"
app:endIconDrawable="@drawable/ic_backspace_black"
app:endIconMode="custom"
app:errorIconDrawable="@drawable/ic_backspace_black"
app:helperText="@string/add_link_helper"
app:helperTextEnabled="true"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/linearLayout4" app:layout_constraintTop_toBottomOf="@+id/linearLayout4">
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" >
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.TextInputEditText
android:id="@+id/field_uri_input" android:id="@+id/field_uri_input"
@ -50,7 +56,9 @@
android:clickable="true" android:clickable="true"
android:cursorVisible="true" android:cursorVisible="true"
android:hint="@string/add_link_hint" android:hint="@string/add_link_hint"
android:singleLine="true" /> android:inputType="textNoSuggestions"
android:singleLine="true"
android:textColorLink="@color/material_on_background_emphasis_high_type" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<LinearLayout <LinearLayout
@ -85,7 +93,9 @@
android:clickable="true" android:clickable="true"
android:cursorVisible="true" android:cursorVisible="true"
android:hint="Event name" android:hint="Event name"
android:singleLine="true" /> android:inputType="textNoSuggestions"
android:singleLine="true"
android:textColorLink="@color/material_on_background_emphasis_high_type" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
@ -99,6 +109,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:clickable="true" android:clickable="true"
android:cursorVisible="true" android:cursorVisible="true"
android:inputType="textNoSuggestions"
android:hint="Event start" android:hint="Event start"
android:singleLine="true" /> android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
@ -114,6 +125,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:clickable="true" android:clickable="true"
android:cursorVisible="true" android:cursorVisible="true"
android:inputType="textNoSuggestions"
android:hint="Event end" android:hint="Event end"
android:singleLine="true" /> android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
@ -130,6 +142,7 @@
android:autoLink="map" android:autoLink="map"
android:clickable="true" android:clickable="true"
android:cursorVisible="true" android:cursorVisible="true"
android:inputType="textNoSuggestions"
android:hint="Event location" android:hint="Event location"
android:singleLine="true" /> android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
@ -147,7 +160,9 @@
android:clickable="true" android:clickable="true"
android:cursorVisible="true" android:cursorVisible="true"
android:hint="Event description" android:hint="Event description"
android:singleLine="false" /> android:inputType="textNoSuggestions|textMultiLine"
android:singleLine="false"
android:textColorLink="@color/material_on_background_emphasis_high_type" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
</LinearLayout> </LinearLayout>

View File

@ -2,5 +2,5 @@
<resources> <resources>
<color name="colorPrimary">#297DA6</color> <color name="colorPrimary">#297DA6</color>
<color name="colorPrimaryDark">#23607E</color> <color name="colorPrimaryDark">#23607E</color>
<color name="colorAccent">#23607E</color> <color name="colorAccent">#297DA6</color>
</resources> </resources>

View File

@ -2,7 +2,9 @@
<string name="app_name">NoFb Event Scraper</string> <string name="app_name">NoFb Event Scraper</string>
<string name="action_about">About</string> <string name="action_about">About</string>
<string name="action_help">Help</string> <string name="action_help">Help</string>
<string name="add_link_hint">Paste facebook link to the event.</string> <string name="add_link_hint">Event link</string>
<string name="add_link_helper">Paste facebook link to the event.</string>
<string name="add_to_calendar">Add to calendar</string>
<string name="description_heading">Description</string> <string name="description_heading">Description</string>
<string name="description_text">This application was developed to be used without a facebook account. <string name="description_text">This application was developed to be used without a facebook account.

View File

@ -0,0 +1,3 @@
Fixes for new design.
Mew button layout.
Improve input error display.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 91 KiB

After

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 93 KiB

After

Width:  |  Height:  |  Size: 686 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 687 KiB

After

Width:  |  Height:  |  Size: 135 KiB