mirror of
https://github.com/akaessens/NoFbEventScraper
synced 2025-06-05 23:29:13 +02:00
use helper error instead of toast
move clear fuction to text input more concise add button remove autocorrect o textfields closes #10
This commit is contained in:
@ -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;
|
||||||
@ -142,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";
|
||||||
}
|
}
|
||||||
@ -161,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ 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.URL;
|
import java.net.URL;
|
||||||
@ -40,6 +41,7 @@ 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;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -48,11 +50,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);
|
||||||
@ -61,6 +63,7 @@ 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);
|
||||||
|
|
||||||
|
|
||||||
paste_button.setOnClickListener(new View.OnClickListener() {
|
paste_button.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
@ -74,13 +77,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);
|
||||||
@ -106,13 +116,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");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -213,8 +222,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;
|
||||||
@ -222,23 +231,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());
|
||||||
scraper.execute();
|
|
||||||
|
|
||||||
|
if (!str.equals(""))
|
||||||
|
{
|
||||||
|
field_uri_input.setText(str);
|
||||||
|
FbScraper scraper = new FbScraper(this, field_uri_input.getText().toString());
|
||||||
|
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,6 +278,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
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(""))
|
||||||
{
|
{
|
||||||
|
9
app/src/main/res/drawable/ic_backspace_black.xml
Normal file
9
app/src/main/res/drawable/ic_backspace_black.xml
Normal 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>
|
9
app/src/main/res/drawable/ic_event_available.xml
Normal file
9
app/src/main/res/drawable/ic_event_available.xml
Normal 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>
|
@ -70,38 +70,21 @@
|
|||||||
android:layout_margin="0dp"
|
android:layout_margin="0dp"
|
||||||
app:contentInsetStart="0dp">
|
app:contentInsetStart="0dp">
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/groupbutton"
|
<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_gravity="bottom"
|
android:layout_marginStart="16dp"
|
||||||
android:orientation="horizontal"
|
android:layout_marginEnd="16dp"
|
||||||
android:weightSum="2">
|
android:layout_weight="1"
|
||||||
|
android:padding="12dp"
|
||||||
<Button
|
android:text="@string/add_to_calendar"
|
||||||
android:id="@+id/cancel_button"
|
android:textColor="#FFFFFF"
|
||||||
android:layout_width="match_parent"
|
app:cornerRadius="24dp"
|
||||||
android:layout_height="wrap_content"
|
app:icon="@drawable/ic_event_available"
|
||||||
android:layout_marginStart="16dp"
|
app:iconGravity="textStart"
|
||||||
android:layout_marginEnd="8dp"
|
app:iconPadding="16dp" />
|
||||||
android:textColor="#FFFFFF"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:padding="12dp"
|
|
||||||
android:text="@android:string/cancel"
|
|
||||||
app:cornerRadius="12dp" />
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/ok_button"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="8dp"
|
|
||||||
android:layout_marginEnd="16dp"
|
|
||||||
android:textColor="#FFFFFF"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:padding="12dp"
|
|
||||||
android:text="@android:string/ok"
|
|
||||||
app:cornerRadius="12dp" />
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</com.google.android.material.bottomappbar.BottomAppBar>
|
</com.google.android.material.bottomappbar.BottomAppBar>
|
||||||
|
|
||||||
|
@ -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,6 +56,7 @@
|
|||||||
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:inputType="textNoSuggestions"
|
||||||
android:singleLine="true" />
|
android:singleLine="true" />
|
||||||
</com.google.android.material.textfield.TextInputLayout>
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
@ -84,6 +91,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 name"
|
android:hint="Event name"
|
||||||
android:singleLine="true" />
|
android:singleLine="true" />
|
||||||
</com.google.android.material.textfield.TextInputLayout>
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
@ -99,6 +107,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 +123,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 +140,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>
|
||||||
@ -145,6 +156,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:autoLink="web"
|
android:autoLink="web"
|
||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
|
android:inputType="textNoSuggestions|textMultiLine"
|
||||||
android:cursorVisible="true"
|
android:cursorVisible="true"
|
||||||
android:hint="Event description"
|
android:hint="Event description"
|
||||||
android:singleLine="false" />
|
android:singleLine="false" />
|
||||||
|
@ -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.
|
||||||
|
Reference in New Issue
Block a user