1
0
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:
akaessens
2020-08-15 13:11:14 +02:00
parent ac98a4a43c
commit bc9cf04f10
7 changed files with 85 additions and 58 deletions

View File

@ -1,15 +1,9 @@
package com.akdev.nofbeventscraper;
import android.app.Activity;
import android.content.Context;
import android.os.AsyncTask;
import android.text.Editable;
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.JSONObject;
@ -142,7 +136,7 @@ public class FbScraper extends AsyncTask<Void, Void, Void> {
e.printStackTrace();
this.error = "Error: Scraping event data failed";
}
} catch (IOException e) {
} catch (Exception e) {
e.printStackTrace();
this.error = "Error: URL not available";
}
@ -161,7 +155,7 @@ public class FbScraper extends AsyncTask<Void, Void, Void> {
this.main.update(event);
}
else {
main.toast(error);
main.error(error);
this.main.clear(false);
}
}

View File

@ -19,6 +19,7 @@ import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
import com.google.android.material.textfield.TextInputLayout;
import com.squareup.picasso.Picasso;
import java.net.URL;
@ -40,6 +41,7 @@ public class MainActivity extends AppCompatActivity {
private TextInputEditText field_event_description;
private ImageView toolbar_image_view;
private CollapsingToolbarLayout toolbar_layout;
private TextInputLayout input_layout;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -48,11 +50,11 @@ public class MainActivity extends AppCompatActivity {
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
cancel_button = (Button) findViewById(R.id.cancel_button);
ok_button = (Button) findViewById(R.id.ok_button);
paste_button = (Button) findViewById(R.id.paste_button);
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_start = (TextInputEditText) findViewById(R.id.field_event_start);
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_layout = (CollapsingToolbarLayout) findViewById(R.id.toolbar_layout);
paste_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@ -74,13 +77,20 @@ public class MainActivity extends AppCompatActivity {
}
catch (NullPointerException e) {
e.printStackTrace();
toast("Error: Clipboard empty");
error("Error: Clipboard empty");
}
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
public void onClick(View view) {
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_END_TIME, end_epoch);
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);
}
catch (Exception e )
{
e.printStackTrace();
toast("Error: Invalid fields");
}
}
@ -213,8 +222,8 @@ public class MainActivity extends AppCompatActivity {
}
catch (Exception e) {
e.printStackTrace();
clear(true);
toast("Invalid URL");
clear(false);
error("Error: Invalid URL");
str = "";
}
return str;
@ -222,23 +231,31 @@ public class MainActivity extends AppCompatActivity {
public void startScraping() {
String str = checkURI(field_uri_input.getText().toString());
field_uri_input.setText(str);
error(null);
try {
String str = checkURI(field_uri_input.getText().toString());
if (!str.equals(""))
{
field_uri_input.setText(str);
FbScraper scraper = new FbScraper(this, field_uri_input.getText().toString());
scraper.execute();
}
}
catch (Exception e) {
e.printStackTrace();
clear(true);
toast("Invalid URL");
clear(false);
error("Error: Invalid URL");
}
}
public void toast(String str) {
Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
public void error(String str) {
//Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
input_layout.setError(str);
}
public void clear(boolean clearUri) {
if (clearUri) {
@ -261,6 +278,7 @@ public class MainActivity extends AppCompatActivity {
public void update(FbEvent event) {
field_event_name.setText(event.name);
input_layout.setError(null);
if (event.name.equals(""))
{

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,38 +70,21 @@
android:layout_margin="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_marginStart="16dp"
android:layout_marginEnd="8dp"
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_marginStart="16dp"
android:layout_marginEnd="16dp"
android:textColor="#FFFFFF"
android:layout_weight="1"
android:padding="12dp"
android:text="@android:string/ok"
app:cornerRadius="12dp" />
</LinearLayout>
android:text="@string/add_to_calendar"
android:textColor="#FFFFFF"
app:cornerRadius="24dp"
app:icon="@drawable/ic_event_available"
app:iconGravity="textStart"
app:iconPadding="16dp" />
</com.google.android.material.bottomappbar.BottomAppBar>

View File

@ -31,16 +31,22 @@
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="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_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/linearLayout4"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" >
app:layout_constraintTop_toBottomOf="@+id/linearLayout4">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/field_uri_input"
@ -50,6 +56,7 @@
android:clickable="true"
android:cursorVisible="true"
android:hint="@string/add_link_hint"
android:inputType="textNoSuggestions"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
@ -84,6 +91,7 @@
android:layout_height="wrap_content"
android:clickable="true"
android:cursorVisible="true"
android:inputType="textNoSuggestions"
android:hint="Event name"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
@ -99,6 +107,7 @@
android:layout_height="wrap_content"
android:clickable="true"
android:cursorVisible="true"
android:inputType="textNoSuggestions"
android:hint="Event start"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
@ -114,6 +123,7 @@
android:layout_height="wrap_content"
android:clickable="true"
android:cursorVisible="true"
android:inputType="textNoSuggestions"
android:hint="Event end"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
@ -130,6 +140,7 @@
android:autoLink="map"
android:clickable="true"
android:cursorVisible="true"
android:inputType="textNoSuggestions"
android:hint="Event location"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
@ -145,6 +156,7 @@
android:layout_height="wrap_content"
android:autoLink="web"
android:clickable="true"
android:inputType="textNoSuggestions|textMultiLine"
android:cursorVisible="true"
android:hint="Event description"
android:singleLine="false" />

View File

@ -2,7 +2,9 @@
<string name="app_name">NoFb Event Scraper</string>
<string name="action_about">About</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_text">This application was developed to be used without a facebook account.