diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningInfoFragment.java b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningInfoFragment.java new file mode 100644 index 000000000..a170d4172 --- /dev/null +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningInfoFragment.java @@ -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. + */ +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(); + final String location = mDiningHall.getName(); + if (!buildingCode.equals("")) { + mLabs.buildings(buildingCode) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Action1>() { + @Override + public void call(List buildings) { + if (!buildings.isEmpty()) { + drawMarker(buildings.get(0).getLatLng(), location); + } + } + }); + } + } + + private void drawMarker(LatLng courseLatLng, String meetingLocation) { + if (map != null && courseLatLng != null && mapFrame != null) { + mapFrame.setVisibility(View.VISIBLE); + map.moveCamera(CameraUpdateFactory.newLatLngZoom(courseLatLng, 17)); + Marker marker = map.addMarker(new MarkerOptions() + .position(courseLatLng) + .title(mDiningHall.getName())); + marker.showInfoWindow(); + } + } + public void fillInfo(){ + List days = mDiningHall.getVenue().allHours(); + LinkedList vertical = new LinkedList<>(); + for (VenueInterval day: days){ + vertical = addDiningHour(day, vertical); + } + } + + public LinkedList addDiningHour(VenueInterval day, LinkedList vertical){ + TextView textView = new TextView(mActivity); + DateTimeFormatter intervalFormatter = DateTimeFormat.forPattern("yyyy-MM-dd"); + DateTime dateTime = intervalFormatter.parseDateTime(day.date); + textView.setText(dateTime.dayOfWeek().getAsText() + ", " + dateTime.monthOfYear().getAsString() + "/" + dateTime.dayOfMonth().getAsShortText()); + 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); + mealType.setTextAppearance(mActivity, R.style.DiningInfoType); + 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); + mealInt.setText(meal.getFormattedHour(meal.open) + " - " + meal.getFormattedHour(meal.close)); + mealInt.setTextAppearance(mActivity, R.style.DiningInfoHours); + 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); + } + +} + diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MenuFragment.java b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MenuFragment.java index 6c5885b98..f93c930b0 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MenuFragment.java +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MenuFragment.java @@ -53,10 +53,10 @@ public boolean onOptionsItemSelected(MenuItem item) { args.putParcelable("DiningHall", getArguments().getParcelable("DiningHall")); fragment.setArguments(args); FragmentTransaction ft = getFragmentManager().beginTransaction(); - ft.replace(R.id.dining_fragment, fragment); - ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); - ft.addToBackStack(null); - ft.commit(); + ft.replace(R.id.dining_fragment, fragment) + .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) + .addToBackStack(null) + .commit(); return true; default: return super.onOptionsItemSelected(item); diff --git a/PennMobile/src/main/res/layout/fragment_dining_info.xml b/PennMobile/src/main/res/layout/fragment_dining_info.xml new file mode 100644 index 000000000..5a9f8cde2 --- /dev/null +++ b/PennMobile/src/main/res/layout/fragment_dining_info.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + diff --git a/PennMobile/src/main/res/menu/dining.xml b/PennMobile/src/main/res/menu/dining.xml new file mode 100644 index 000000000..a2b93c3ed --- /dev/null +++ b/PennMobile/src/main/res/menu/dining.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file