Commit 718ee0d9 authored by Robert Hitt's avatar Robert Hitt

Status duration display can now be configured

parent 1953fa47
......@@ -3,8 +3,10 @@ package srct.whatsopen.views.adapters;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.preference.PreferenceManager;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
......@@ -57,22 +59,16 @@ public class FacilityListAdapter extends
public void onBindViewHolder(ViewHolder holder, int position) {
Facility facility = getData().get(position);
displayStatusDurationText(facility, holder);
// highlight the open facilities
if(facility.isOpen()) {
// 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()) {
......@@ -87,6 +83,42 @@ public class FacilityListAdapter extends
textView.setText(facility.getName());
}
// Sets the duration text according to the user's settings
private void displayStatusDurationText(Facility facility, ViewHolder holder) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
String setting = preferences.getString("list_view_information_preference",
"display_duration_both");
switch(setting) {
case "display_duration_open":
setStatusDurationText(holder, facility.isOpen());
break;
case "display_duration_closed":
setStatusDurationText(holder, !facility.isOpen());
break;
case "display_duration_none":
setStatusDurationText(holder, false);
break;
case "display_duration_both":default:
setStatusDurationText(holder, true);
break;
}
}
private void setStatusDurationText(ViewHolder holder, boolean showDuration) {
if(showDuration) {
// display the duration text
setItemPaddingInDp(holder.textLayout, 8);
holder.durationTextView.setVisibility(View.VISIBLE);
holder.nameTextView.setTypeface(null, Typeface.BOLD);
} else {
setItemPaddingInDp(holder.textLayout, 15);
holder.durationTextView.setVisibility(View.GONE);
holder.nameTextView.setTypeface(null, Typeface.NORMAL);
}
}
// Helper method to set the facility item layout's padding
// Have to convert from pixels to dp
private void setItemPaddingInDp(LinearLayout layout, int paddingPx) {
......
......@@ -11,14 +11,16 @@
<string name="title_notification">Notification Preferences</string>
<string name="title_turn_off_vibrations">Turn off vibrations</string>
<string-array name="entries_list_view_information_preference">
<item>Both</item>
<item>Only for open Facilities</item>
<item>Only for closed Facilities</item>
<item>Both</item>
<item>None</item>
</string-array>
<string-array name="entryvalues_list_view_information_preference">
<item>display_duration_both</item>
<item>display_duration_open</item>
<item>display_duration_closed</item>
<item>display_duration_both</item>
<item>display_duration_none</item>
</string-array>
</resources>
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