do not display empty information or placeholders

This commit is contained in:
akaessens 2020-09-26 15:45:49 +02:00
parent 6977fad449
commit 2750ad86e8
4 changed files with 60 additions and 37 deletions

View File

@ -58,26 +58,39 @@ public class EventAdapter extends
// Set item views based on your views and data model // Set item views based on your views and data model
if (!event.name.equals("")) {
holder.text_view_event_name.setText(event.name); holder.text_view_event_name.setText(event.name);
if (!event.location.equals("")) {
holder.text_view_event_location.setText(event.location);
} else {
holder.text_view_event_location.setVisibility(View.GONE);
holder.image_view_event_location.setVisibility(View.GONE);
} }
if (event.start_date != null) { if (event.start_date != null) {
String str = FbEvent.dateTimeToString(event.start_date); String str = FbEvent.dateTimeToString(event.start_date);
holder.text_view_event_start.setText(str); holder.text_view_event_start.setText(str);
} else {
holder.text_view_event_start.setVisibility(View.GONE);
if (event.end_date == null) {
holder.image_view_event_time.setVisibility(View.GONE);
}
} }
if (event.end_date != null) { if (event.end_date != null) {
String str = FbEvent.dateTimeToString(event.end_date); String str = FbEvent.dateTimeToString(event.end_date);
holder.text_view_event_end.setText(str); holder.text_view_event_end.setText(str);
} else {
holder.text_view_event_end.setVisibility(View.GONE);
} }
if (!event.location.equals("")) {
holder.text_view_event_location.setText(event.location);
}
if (!event.description.equals("")) { if (!event.description.equals("")) {
holder.text_view_event_description.setText(event.description); holder.text_view_event_description.setText(event.description);
} else {
holder.text_view_event_description.setVisibility(View.GONE);
} }
try { try {
@ -152,11 +165,11 @@ public class EventAdapter extends
/* /*
* Image dialog * Image dialog
*/ */
holder.image_view_event_image.setOnClickListener(new View.OnClickListener() {
View.OnClickListener listener = new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
final Dialog dialog = new Dialog(view.getContext(), android.R.style.Theme_Translucent_NoTitleBar); final Dialog dialog = new Dialog(view.getContext(), android.R.style.Theme_Translucent_NoTitleBar);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_image); dialog.setContentView(R.layout.dialog_image);
@ -170,20 +183,26 @@ public class EventAdapter extends
} }
}); });
try {
Picasso.get() Picasso.get()
.load(event.image_url) .load(event.image_url)
.into(image); .into(image, new com.squareup.picasso.Callback() {
@Override
public void onSuccess() {
dialog.show(); dialog.show();
} catch (Exception e) {
e.printStackTrace();
}
}
} }
); @Override
public void onError(Exception e) {
dialog.dismiss();
}
});
}
};
holder.image_view_event_image.setOnClickListener(listener);
} }
@ -202,6 +221,7 @@ public class EventAdapter extends
protected TextView text_view_event_description; protected TextView text_view_event_description;
protected ImageView image_view_event_image; protected ImageView image_view_event_image;
protected ImageView image_view_event_location; protected ImageView image_view_event_location;
protected ImageView image_view_event_time;
protected Button button_add_to_calendar; protected Button button_add_to_calendar;
protected boolean description_collapsed = true; protected boolean description_collapsed = true;
@ -216,6 +236,7 @@ public class EventAdapter extends
text_view_event_description = item_view.findViewById(R.id.text_view_event_description); 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_image = item_view.findViewById(R.id.image_view_event_image);
image_view_event_location = item_view.findViewById(R.id.image_view_event_location); image_view_event_location = item_view.findViewById(R.id.image_view_event_location);
image_view_event_time = item_view.findViewById(R.id.image_view_event_time);
button_add_to_calendar = item_view.findViewById(R.id.button_add_to_calendar); button_add_to_calendar = item_view.findViewById(R.id.button_add_to_calendar);
} }

View File

@ -20,12 +20,12 @@ public class FbEvent {
public final String image_url; public final String image_url;
public FbEvent() { public FbEvent() {
url = "url"; url = "";
name= "name"; name= "";
start_date = null; start_date = null;
end_date = null; end_date = null;
description = "description"; description = "";
location = "location"; location = "";
image_url = null; image_url = null;
} }

View File

@ -227,6 +227,7 @@ public class FbScraper extends AsyncTask<Void, Void, Void> {
FbEvent event = new FbEvent(url, name, start_date, end_date, description, location, image_url); FbEvent event = new FbEvent(url, name, start_date, end_date, description, location, image_url);
this.events.add(event); this.events.add(event);
this.events.add(new FbEvent());
} catch (URISyntaxException | MalformedURLException e) { } catch (URISyntaxException | MalformedURLException e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -74,6 +74,7 @@
<ImageView <ImageView
style="?android:attr/borderlessButtonStyle" style="?android:attr/borderlessButtonStyle"
android:id="@+id/image_view_event_time"
android:layout_width="40dp" android:layout_width="40dp"
android:layout_height="40dp" android:layout_height="40dp"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"