Commit b7c65322 authored by Robert Hitt's avatar Robert Hitt
Browse files

Open facilities now display open duration

parent d60e67b2
......@@ -3,14 +3,18 @@ package srct.whatsopen.views.adapters;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import java.util.Calendar;
import butterknife.BindView;
import butterknife.ButterKnife;
......@@ -55,9 +59,18 @@ public class FacilityListAdapter extends
// set the RV cell to be highlighted
holder.itemView.setBackgroundColor(ContextCompat
.getColor(context, R.color.facilityOpen));
// show the duration that the facility will be open
setItemPaddingInDp(holder.textLayout, 8);
holder.durationTextView.setVisibility(View.VISIBLE);
holder.nameTextView.setTypeface(null, Typeface.BOLD);
} else {
holder.itemView.setBackgroundColor(ContextCompat
.getColor(context, R.color.facilityClosed));
setItemPaddingInDp(holder.textLayout, 15);
holder.durationTextView.setVisibility(View.GONE);
holder.nameTextView.setTypeface(null, Typeface.NORMAL);
}
if(facility.isFavorited()) {
......@@ -72,16 +85,27 @@ public class FacilityListAdapter extends
textView.setText(facility.getName());
}
// Helper method to set the facility item layout's padding
// Have to convert from pixels to dp
private void setItemPaddingInDp(LinearLayout layout, int paddingPx) {
float scale = context.getResources().getDisplayMetrics().density;
int paddingTop = (int) (paddingPx*scale + 0.5f);
int paddingBottom = (int) (paddingPx*scale + 0.5f);
layout.setPadding(0, paddingTop, 0, paddingBottom);
}
// Set up for the Recycler View cells
public class ViewHolder extends RecyclerView.ViewHolder implements FacilityView {
@BindView(R.id.facility_name)
TextView nameTextView;
@BindView(R.id.favorite_button)
ImageButton favoriteButton;
@BindView(R.id.facility_name) TextView nameTextView;
@BindView(R.id.favorite_button) ImageButton favoriteButton;
@BindView(R.id.facility_duration) TextView durationTextView;
@BindView(R.id.text_layout) LinearLayout textLayout;
FacilityPresenter mPresenter;
Facility data;
private FacilityPresenter mPresenter;
private Facility data;
private String duration;
public ViewHolder(final View itemView) {
super(itemView);
......@@ -94,6 +118,9 @@ public class FacilityListAdapter extends
// Set up presenter
mPresenter = new FacilityPresenter();
mPresenter.attachView(this);
duration = mPresenter.getStatusDuration(data, Calendar.getInstance());
durationTextView.setText(duration);
}
// transitions to the facility's detail view
......
......@@ -5,20 +5,28 @@
android:layout_height="wrap_content"
android:elevation="2dp">
<RelativeLayout android:id="@+id/text_layout"
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="?android:attr/selectableItemBackground"
android:layout_weight="1">
<LinearLayout android:id="@+id/text_layout"
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:layout_width="0dp"
android:orientation="vertical"
android:layout_height="match_parent"
android:background="?android:attr/selectableItemBackground"
android:layout_weight="1">
<TextView android:id="@+id/facility_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/facilityText"
android:paddingLeft="10dp"/>
</RelativeLayout>
<TextView android:id="@+id/facility_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:textColor="@color/facilityText"
android:paddingLeft="16dp"/>
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment