update items, cleanup, add intents

This commit is contained in:
akaessens 2020-09-24 22:00:48 +02:00
parent 3c5876f6bc
commit 551a3c21a9
8 changed files with 227 additions and 287 deletions

View File

@ -39,6 +39,8 @@ dependencies {
implementation 'org.jsoup:jsoup:1.13.1'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'jp.wasabeef:picasso-transformations:2.2.1'
implementation 'androidx.preference:preference:1.1.1'
implementation "androidx.webkit:webkit:1.3.0"

View File

@ -4,20 +4,24 @@ package com.akdev.nofbeventscraper;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.provider.CalendarContract;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;
import com.google.android.material.textview.MaterialTextView;
import com.squareup.picasso.Picasso;
import java.util.List;
import jp.wasabeef.picasso.transformations.CropCircleTransformation;
import static com.akdev.nofbeventscraper.FbEvent.dateTimeToEpoch;
public class EventAdapter extends
RecyclerView.Adapter<EventAdapter.ViewHolder> {
@ -35,109 +39,148 @@ public class EventAdapter extends
LayoutInflater inflater = LayoutInflater.from(context);
// Inflate the custom layout
View contact_view = inflater.inflate(R.layout.item_event, parent, false);
View view = inflater.inflate(R.layout.item_event, parent, false);
// Return a new holder instance
final ViewHolder holder = new ViewHolder(contact_view);
final ViewHolder holder = new ViewHolder(view);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(final EventAdapter.ViewHolder holder, int position) {
// Get the data model based on position
final FbEvent event = events.get(position);
// Set item views based on your views and data model
if (!event.name.equals("")) {
holder.text_view_event_name.setText(event.name);
}
if (event.start_date != null) {
String str = FbEvent.dateTimeToString(event.start_date);
holder.text_view_event_start.setText(str);
}
if (event.end_date != null) {
String str = FbEvent.dateTimeToString(event.end_date);
holder.text_view_event_end.setText(str);
}
if (!event.location.equals("")) {
holder.text_view_event_location.setText(event.location);
}
if (!event.description.equals("")) {
holder.text_view_event_description.setText(event.description);
}
try {
Picasso.get()
.load(event.image_url)
.placeholder(R.mipmap.ic_launcher)
.transform(new CropCircleTransformation())
.into(holder.image_view_event_image);
} catch (Exception e) {
e.printStackTrace();
}
/*
* Maps button: launch maps intent
*/
/*holder.layout_event_location.setEndIconOnClickListener(new View.OnClickListener() {
View.OnClickListener location_click_listener = new View.OnClickListener() {
@Override
public void onClick(View view) {
String map_search = "geo:0,0?q=" + holder.edit_text_event_location.getText();
String map_search = "geo:0,0?q=" + event.location;
Uri intent_uri = Uri.parse(map_search);
Intent map_intent = new Intent(Intent.ACTION_VIEW, intent_uri);
if (map_intent.resolveActivity(context.getPackageManager()) != null) {
context.startActivity(map_intent);
if (map_intent.resolveActivity(view.getContext().getPackageManager()) != null) {
view.getContext().startActivity(map_intent);
}
}
});*/
};
holder.image_view_event_location.setOnClickListener(location_click_listener);
holder.text_view_event_location.setOnClickListener(location_click_listener);
/*
* Add to calendar button: launch calendar application with current event
*/
holder.button_add_to_calendar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
return new ViewHolder(contact_view);
}
@Override
public void onBindViewHolder(EventAdapter.ViewHolder holder, int position) {
// Get the data model based on position
FbEvent event = events.get(position);
Long start_epoch = dateTimeToEpoch(event.start_date);
Long end_epoch = dateTimeToEpoch(event.end_date);
// Set item views based on your views and data model
if (event.name.equals("")) {
//holder.edit_text_event_name.setError(R.string.error_no_name);
} else {
holder.edit_text_event_name.setText(event.name);
}
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra(CalendarContract.Events.TITLE, event.name);
intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, start_epoch);
intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, end_epoch);
intent.putExtra(CalendarContract.Events.EVENT_LOCATION, event.location);
if (event.start_date == null) {
//holder.edit_text_event_start.setError(getString(R.string.error_no_start_date));
} else {
String str = FbEvent.dateTimeToString(event.start_date);
holder.edit_text_event_start.setText(str);
}
// prepend url in description
String desc = event.url + "\n\n" + event.description;
intent.putExtra(CalendarContract.Events.DESCRIPTION, desc);
if (event.end_date == null) {
//edit_text_event_end.setError(getString(R.string.error_no_end_date));
} else {
String str = FbEvent.dateTimeToString(event.end_date);
holder.edit_text_event_end.setText(str);
}
if (intent.resolveActivity(view.getContext().getPackageManager()) != null) {
view.getContext().startActivity(intent);
}
}
});
/*
* Expand and collapse description
*/
holder.text_view_event_description.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (holder.description_collapsed) {
holder.description_collapsed = false;
holder.text_view_event_description.setMaxLines(Integer.MAX_VALUE);
} else {
holder.description_collapsed = true;
holder.text_view_event_description.setMaxLines(5);
}
}
});
if (event.location.equals("")) {
//edit_text_event_location.setError(getString(R.string.error_no_location));
} else {
holder.edit_text_event_location.setText(event.location);
//layout_event_location.setEndIconVisible(true);
}
if (event.description.equals("")) {
//holder.edit_text_event_description.setError(getString(R.string.error_no_description));
} else {
holder.edit_text_event_description.setText(event.description);
}
if (event.image_url == null) {
holder.image_view_event_image.setVisibility(View.GONE);
}
else {
Picasso.get()
.load(event.image_url).into(holder.image_view_event_image);
}
//.placeholder(R.drawable.ic_banner_foreground)*/
}
// Returns the total count of items in the list
@Override
public int getItemCount() {
return events.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
public static class ViewHolder extends RecyclerView.ViewHolder {
protected MaterialTextView edit_text_event_name;
protected MaterialTextView edit_text_event_start;
protected MaterialTextView edit_text_event_end;
protected MaterialTextView edit_text_event_location;
protected MaterialTextView edit_text_event_description;
protected TextView text_view_event_name;
protected TextView text_view_event_start;
protected TextView text_view_event_end;
protected TextView text_view_event_location;
protected TextView text_view_event_description;
protected ImageView image_view_event_image;
//protected TextInputLayout layout_event_location;
protected ImageView image_view_event_location;
protected Button button_add_to_calendar;
protected boolean description_collapsed = true;
public ViewHolder(View item_view) {
super(item_view);
edit_text_event_name = (MaterialTextView) item_view.findViewById(R.id.edit_text_event_name);
edit_text_event_start = (MaterialTextView) item_view.findViewById(R.id.edit_text_event_start);
edit_text_event_end = (MaterialTextView) item_view.findViewById(R.id.edit_text_event_end);
edit_text_event_location = (MaterialTextView) item_view.findViewById(R.id.edit_text_event_location);
edit_text_event_description = (MaterialTextView) item_view.findViewById(R.id.edit_text_event_description);
image_view_event_image = (ImageView) item_view.findViewById(R.id.image_view_event_image);
//layout_event_location = (TextInputLayout) item_view.findViewById(R.id.layout_event_location);
text_view_event_name = item_view.findViewById(R.id.text_view_event_name);
text_view_event_start = item_view.findViewById(R.id.text_view_event_start);
text_view_event_end = item_view.findViewById(R.id.text_view_event_end);
text_view_event_location = item_view.findViewById(R.id.text_view_event_location);
text_view_event_description = item_view.findViewById(R.id.text_view_event_description);
image_view_event_image = item_view.findViewById(R.id.image_view_event_image);
image_view_event_location = item_view.findViewById(R.id.image_view_event_location);
button_add_to_calendar = item_view.findViewById(R.id.button_add_to_calendar);
}
}
}

View File

@ -10,7 +10,6 @@ import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.view.menu.MenuBuilder;
@ -46,7 +45,7 @@ public class MainActivity extends AppCompatActivity {
public void onRestoreInstanceState(Bundle state) {
super.onRestoreInstanceState(state);
if (! state.getBoolean("events_empty") ) {
if (!state.getBoolean("events_empty")) {
startScraping();
}
@ -66,28 +65,24 @@ public class MainActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edit_text_uri_input = (TextInputEditText) findViewById(R.id.edit_text_uri_input);
layout_uri_input = (TextInputLayout) findViewById(R.id.layout_uri_input);
edit_text_uri_input = findViewById(R.id.edit_text_uri_input);
layout_uri_input = findViewById(R.id.layout_uri_input);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
//ok_button = (Button) findViewById(R.id.ok_button);
paste_button = (ExtendedFloatingActionButton) findViewById(R.id.paste_button);
//ok_button.setEnabled(false);
paste_button = findViewById(R.id.paste_button);
/*
* initialize recycler view with empty list of events
* scroll horizontal with snapping
*/
RecyclerView recycler_view = (RecyclerView) findViewById(R.id.recycler_view);
RecyclerView recycler_view = findViewById(R.id.recycler_view);
events = createEventList();
adapter = new EventAdapter(events);
recycler_view.setAdapter(adapter);
linear_layout_manager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
recycler_view.setLayoutManager(linear_layout_manager);
//recycler_view.setHasFixedSize(true);
//SnapHelper snap_helper = new LinearSnapHelper();
//snap_helper.attachToRecyclerView(recycler_view);
recycler_view.setHasFixedSize(true);
/*
@ -125,35 +120,6 @@ public class MainActivity extends AppCompatActivity {
layout_uri_input.setErrorIconOnClickListener(listener);
/*
* Add to calendar button: launch calendar application with current event
*/
/*ok_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
FbEvent event = events.get(linear_layout_manager.findFirstCompletelyVisibleItemPosition());
Long start_epoch = dateTimeToEpoch(event.start_date);
Long end_epoch = dateTimeToEpoch(event.end_date);
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra(CalendarContract.Events.TITLE, event.name);
intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, start_epoch);
intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, end_epoch);
intent.putExtra(CalendarContract.Events.EVENT_LOCATION, event.location);
// prepend url in description
String desc = event.url + "\n\n" + event.description;
intent.putExtra(CalendarContract.Events.DESCRIPTION, desc);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
});
/*
* Enter button in uri input: start scraping
*/

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<size
android:height="8dp"
android:width="0dp"/>
</shape>

View File

@ -1,9 +0,0 @@
<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="M12,2C8.14,2 5,5.14 5,9c0,5.25 7,13 7,13s7,-7.75 7,-13c0,-3.86 -3.14,-7 -7,-7zM16,10h-3v3h-2v-3L8,10L8,8h3L11,5h2v3h3v2z"
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="M20.5,3l-0.16,0.03L15,5.1 9,3 3.36,4.9c-0.21,0.07 -0.36,0.25 -0.36,0.48V20.5c0,0.28 0.22,0.5 0.5,0.5l0.16,-0.03L9,18.9l6,2.1 5.64,-1.9c0.21,-0.07 0.36,-0.25 0.36,-0.48V3.5c0,-0.28 -0.22,-0.5 -0.5,-0.5zM15,19l-6,-2.11V5l6,2.11V19z"
android:fillColor="#000000"/>
</vector>

View File

@ -0,0 +1,12 @@
<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="M11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z"
android:fillColor="#000000"/>
<path
android:pathData="M12.5,7H11v6l5.25,3.15 0.75,-1.23 -4.5,-2.67z"
android:fillColor="#000000"/>
</vector>

View File

@ -4,7 +4,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/card"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp">
<LinearLayout
@ -16,6 +16,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:gravity="center_vertical"
android:orientation="horizontal">
@ -23,72 +24,110 @@
android:id="@+id/image_view_event_image"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginRight="8dp"
android:layout_marginEnd="8dp"
android:contentDescription="thumbnail"
android:scaleType="centerCrop" />
<LinearLayout
android:layout_width="match_parent"
<TextView
android:id="@+id/text_view_event_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/error_no_name"
android:textAppearance="?attr/textAppearanceHeadline6" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/image_view_event_location"
style="?android:attr/borderlessButtonStyle"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginEnd="8dp"
android:scaleType="centerCrop"
android:src="@drawable/ic_map"
android:background="?android:attr/selectableItemBackground"
app:tint="@color/material_on_surface_emphasis_high_type" />
<TextView
android:id="@+id/text_view_event_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/error_no_location"
android:textAppearance="?attr/textAppearanceBody1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
style="?android:attr/borderlessButtonStyle"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginEnd="8dp"
android:background="?android:attr/selectableItemBackground"
android:clickable="false"
android:src="@drawable/ic_schedule"
app:tint="@color/material_on_surface_emphasis_high_type" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="vertical">
<TextView
android:id="@+id/edit_text_event_name"
android:id="@+id/text_view_event_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hint_event_name"
android:textAppearance="?attr/textAppearanceHeadline6" />
android:text="@string/error_no_start_date"
android:textAppearance="?attr/textAppearanceBody2" />
<TextView
android:id="@+id/edit_text_event_location"
android:id="@+id/text_view_event_end"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/hint_event_location"
android:textAppearance="?attr/textAppearanceBody2"
android:textColor="?android:attr/textColorSecondary" />
android:text="@string/error_no_end_date"
android:textAppearance="?attr/textAppearanceBody2" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="@+id/text_view_event_description"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dp"
android:ellipsize="end"
android:maxLines="5"
android:text="abc\nabc\nabc\nabc\nabc\nabc\nabc\n"
android:textAppearance="?attr/textAppearanceBody2"
android:textColor="?android:attr/textColorSecondary" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/edit_text_event_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hint_event_start"
android:textAppearance="?attr/textAppearanceBody2" />
<TextView
android:id="@+id/edit_text_event_end"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hint_event_end"
android:textAppearance="?attr/textAppearanceBody2" />
<TextView
android:id="@+id/edit_text_event_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/hint_event_description"
android:textAppearance="?attr/textAppearanceBody2"
android:textColor="?android:attr/textColorSecondary" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:id="@+id/button_add_to_calendar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/button_add"
android:textColor="@android:color/white"
@ -97,123 +136,8 @@
app:iconTint="@android:color/white" />
<ImageButton
style="?android:attr/borderlessButtonStyle"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:gravity="end"
android:maxWidth="10dp"
android:src="@drawable/ic_add_location"
android:tint="@color/material_on_surface_emphasis_high_type" />
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
<!--
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp">
<LinearLayout
android:id="@+id/linear_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@drawable/divider"
android:orientation="vertical"
android:showDividers="middle">
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edit_text_event_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:cursorVisible="false"
android:focusable="false"
android:hint="@string/hint_event_name"
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
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edit_text_event_start"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:cursorVisible="false"
android:focusable="false"
android:hint="@string/hint_event_start"
android:inputType="textNoSuggestions"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edit_text_event_end"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:cursorVisible="false"
android:focusable="false"
android:hint="@string/hint_event_end"
android:inputType="textNoSuggestions"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/layout_event_location"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:endIconDrawable="@drawable/ic_add_location"
app:endIconMode="custom">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edit_text_event_location"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:cursorVisible="false"
android:focusable="false"
android:hint="@string/hint_event_location"
android:inputType="textNoSuggestions"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edit_text_event_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoLink="web"
android:cursorVisible="false"
android:focusable="false"
android:hint="@string/hint_event_description"
android:inputType="textNoSuggestions|textMultiLine"
android:singleLine="false"
android:textColorLink="@color/material_on_background_emphasis_high_type" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>-->