-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #300 from pennlabs/menu-info
Menu info
- Loading branch information
Showing
11 changed files
with
312 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
184 changes: 184 additions & 0 deletions
184
PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningInfoFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.