Skip to content

Commit

Permalink
Merge pull request #300 from pennlabs/menu-info
Browse files Browse the repository at this point in the history
Menu info
  • Loading branch information
adelq committed Dec 5, 2015
2 parents 7bdc9d8 + 2ac3076 commit 55863f4
Show file tree
Hide file tree
Showing 11 changed files with 312 additions and 5 deletions.
2 changes: 2 additions & 0 deletions PennMobile/PennMobile.iml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/intermediates/fabric/res/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
Expand Down Expand Up @@ -84,6 +85,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-location/8.3.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-maps/8.3.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/io.fabric.sdk.android/fabric/1.3.4/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/fabric" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-runtime-classes" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public Observable<Venue> call(List<Venue> venues) {
.flatMap(new Func1<Venue, Observable<DiningHall>>() {
@Override
public Observable<DiningHall> call(Venue venue) {
DiningHall hall = new DiningHall(venue.id, venue.name, venue.isResidential(), venue.getHours());
DiningHall hall = new DiningHall(venue.id, venue.name, venue.isResidential(), venue.getHours(), venue);
return Observable.just(hall);
}
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
package com.pennapps.labs.pennmobile;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.pennapps.labs.pennmobile.api.Labs;
import com.pennapps.labs.pennmobile.classes.Building;
import com.pennapps.labs.pennmobile.classes.DiningHall;
import com.pennapps.labs.pennmobile.classes.VenueInterval;

import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import java.util.LinkedList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;

/**
* Created by Lily on 11/13/2015.
* Fragment for Dining information (hours, map)
*/
public class DiningInfoFragment extends Fragment {

private DiningHall mDiningHall;
private MainActivity mActivity;
private Labs mLabs;

private GoogleMap map;
private SupportMapFragment mapFragment;

@Bind(R.id.dining_hours) RelativeLayout menuParent;
@Bind(R.id.dining_map_frame) View mapFrame;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mDiningHall = getArguments().getParcelable("DiningHall");
mActivity = (MainActivity) getActivity();
mLabs = MainActivity.getLabsInstance();
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_dining_info, container, false);
v.setBackgroundColor(Color.WHITE);
ButterKnife.bind(this, v);
fillInfo();

return v;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setHasOptionsMenu(true);
FragmentManager fm = getChildFragmentManager();
if (mapFragment == null) {
mapFragment = SupportMapFragment.newInstance();
fm.beginTransaction().add(R.id.dining_map_container, mapFragment).commit();
fm.executePendingTransactions();
}
}

@Override
public void onResume() {
super.onResume();
mActivity.getActionBarToggle().setDrawerIndicatorEnabled(false);
mActivity.getActionBarToggle().syncState();
getActivity().setTitle(mDiningHall.getName());
if (map == null) {
map = mapFragment.getMap();
if (map != null) {
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(39.95198, -75.19368), 17));
map.getUiSettings().setZoomControlsEnabled(false);
}
}
drawMap();
}
private void drawMap() {
String buildingCode = mDiningHall.getName();
if (!buildingCode.equals("")) {
mLabs.buildings(buildingCode)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<List<Building>>() {
@Override
public void call(List<Building> buildings) {
if (!buildings.isEmpty()) {
drawMarker(buildings.get(0).getLatLng());
}
}
});
}
}

private void drawMarker(LatLng diningHallLatLng) {
if (map != null && diningHallLatLng != null && mapFrame != null) {
mapFrame.setVisibility(View.VISIBLE);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(diningHallLatLng, 17));
Marker marker = map.addMarker(new MarkerOptions()
.position(diningHallLatLng)
.title(mDiningHall.getName()));
marker.showInfoWindow();
}
}
public void fillInfo(){
List<VenueInterval> days = mDiningHall.getVenue().allHours();
LinkedList<TextView> vertical = new LinkedList<>();
for (VenueInterval day: days){
vertical = addDiningHour(day, vertical);
}
}

public LinkedList<TextView> addDiningHour(VenueInterval day, LinkedList<TextView> vertical){
TextView textView = new TextView(mActivity);
DateTimeFormatter intervalFormatter = DateTimeFormat.forPattern("yyyy-MM-dd");
DateTime dateTime = intervalFormatter.parseDateTime(day.date);
String dateString = dateTime.dayOfWeek().getAsText() + ", " + dateTime.monthOfYear().getAsString() + "/" + dateTime.dayOfMonth().getAsShortText();
textView.setText(dateString);
textView.setTextAppearance(mActivity, R.style.DiningInfoDate);
textView.setPadding(0, 10, 0, 10);
if (vertical.isEmpty()){
textView.setId(0);
textView.setId(textView.getId()+10);
menuParent.addView(textView);
} else {
textView.setId(vertical.getLast().getId()+1);
RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
param.addRule(RelativeLayout.BELOW, vertical.getLast().getId());
param.setMargins(0, 10, 10, 0);
menuParent.addView(textView, param);
}
vertical.add(textView);
for (VenueInterval.MealInterval meal: day.meals){
TextView mealType = new TextView(mActivity);
mealType.setText(meal.type);
mealType.setId(vertical.getLast().getId() + 1);
RelativeLayout.LayoutParams layparammeal = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
layparammeal.addRule(RelativeLayout.BELOW, vertical.getLast().getId());
layparammeal.setMargins(0, 10, 10, 0);
menuParent.addView(mealType, layparammeal);
vertical.add(mealType);

RelativeLayout.LayoutParams layparamtimes = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
layparamtimes.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, vertical.getLast().getId());
layparamtimes.addRule(RelativeLayout.ALIGN_BOTTOM, vertical.getLast().getId());
layparamtimes.setMargins(0, 10, 0, 0);
TextView mealInt = new TextView(mActivity);
String hoursString = meal.getFormattedHour(meal.open) + " - " + meal.getFormattedHour(meal.close);
mealInt.setText(hoursString);
mealInt.setId(vertical.getLast().getId() + 1);
menuParent.addView(mealInt, layparamtimes);
vertical.add(mealInt);
}
return vertical;
}
@Override
public void onDestroyView() {
super.onDestroyView();
getActivity().setTitle(R.string.dining);
ButterKnife.unbind(this);
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
import android.os.Bundle;
import android.support.annotation.StyleRes;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
Expand All @@ -22,14 +26,41 @@ public class MenuFragment extends Fragment {

private DiningHall mDiningHall;
private MainActivity mActivity;

@Bind(R.id.menu_parent) LinearLayout menuParent;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mDiningHall = getArguments().getParcelable("DiningHall");
mActivity = (MainActivity) getActivity();
setHasOptionsMenu(true);
}


@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.dining, menu);
super.onCreateOptionsMenu(menu, inflater);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.dining_info_button:
Fragment fragment = new DiningInfoFragment();
Bundle args = new Bundle();
args.putParcelable("DiningHall", getArguments().getParcelable("DiningHall"));
fragment.setArguments(args);
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.dining_fragment, fragment)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.addToBackStack(null)
.commit();
return true;
default:
return super.onOptionsItemSelected(item);
}
}

@Override
Expand Down Expand Up @@ -68,6 +99,8 @@ private void addDiningTextView(@StyleRes int style, String text) {
@Override
public void onResume() {
super.onResume();
mActivity.getActionBarToggle().setDrawerIndicatorEnabled(false);
mActivity.getActionBarToggle().syncState();
getActivity().setTitle(mDiningHall.getName() + " Menu");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ public class DiningHall implements Parcelable {
// Refers to whether the dining hall is residential or retail
private boolean residential;
private HashMap<String, Interval> openHours;
private Venue venue;
@SerializedName("tblDayPart") public List<Menu> menus = new ArrayList<>();

public DiningHall(int id, String name, boolean residential, HashMap<String, Interval> hours) {
public DiningHall(int id, String name, boolean residential, HashMap<String, Interval> hours, Venue venue) {
this.id = id;
this.name = name;
this.residential = residential;
this.openHours = hours;
this.venue = venue;
}

protected DiningHall(Parcel in) {
Expand Down Expand Up @@ -96,6 +98,11 @@ public boolean hasMenu() {
return menus.size() > 0;
}


public Venue getVenue(){
return venue;
}

public String closingTime() {
for (Interval openInterval : openHours.values()) {
if (openInterval.containsNow()) {
Expand All @@ -105,7 +112,7 @@ public String closingTime() {
return "";
}

private List<Map.Entry<String, Interval>> orderedHours() {
public List<Map.Entry<String, Interval>> orderedHours() {
List<Map.Entry<String, Interval>> list = new ArrayList<>(openHours.entrySet());
Collections.sort( list, new Comparator<Map.Entry<String, Interval>>() {
public int compare( Map.Entry<String, Interval> x, Map.Entry<String, Interval> y )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,8 @@ public HashMap<String, Interval> getHours() {

return intervals;
}

public List<VenueInterval> allHours(){
return hours;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public Interval getInterval(String date) {
}
DateTime openInstant = DateTime.parse(openTime, DATEFORMAT);
DateTime closeInstant = DateTime.parse(closeTime, DATEFORMAT);

// Close hours sometimes given in AM hours of next day
// Cutoff for "early morning" hours was decided to be 6AM
if (closeInstant.getHourOfDay() < 6) {
Expand All @@ -68,5 +67,20 @@ public Interval getInterval(String date) {

return new Interval(openInstant, closeInstant);
}

public String getFormattedHour(String hours) {
String newHours = hours.substring(0, 5);
int hour = Integer.parseInt(hours.substring(0, 2));
if (hour > 12) {
newHours = "" + (hour - 12) + hours.substring(2, 5);
}
if (hour >= 12) {
newHours += "pm";
}
else {
newHours += "am";
}
return newHours;
}
}
}
47 changes: 47 additions & 0 deletions PennMobile/src/main/res/layout/fragment_dining_info.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/dining_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<FrameLayout
android:id="@+id/dining_map_frame"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="180dp">
<FrameLayout
android:id="@+id/dining_map_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/gradient" />
</FrameLayout>

<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hours"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="10dp"
android:textSize="12pt"
android:id="@+id/info_hours" />

<RelativeLayout
android:id="@+id/dining_hours"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:paddingLeft="16dip"
android:paddingRight="16dip"
android:paddingBottom="20dip"
android:layout_weight="1">

</RelativeLayout>
</LinearLayout>

</ScrollView>
Loading

0 comments on commit 55863f4

Please sign in to comment.