mirror of
https://github.com/akaessens/NoFbEventScraper
synced 2025-06-05 23:29:13 +02:00
update items, cleanup, add intents
This commit is contained in:
@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
*/
|
||||
|
Reference in New Issue
Block a user