Skip to content

Commit

Permalink
remove temporary ft references
Browse files Browse the repository at this point in the history
  • Loading branch information
lilyidi authored and adelq committed Dec 4, 2015
1 parent c4e0b96 commit a847c1b
Show file tree
Hide file tree
Showing 4 changed files with 244 additions and 4 deletions.
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.
*/
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<List<Building>>() {
@Override
public void call(List<Building> 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<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);
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);
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
48 changes: 48 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,48 @@
<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"
android:layout_weight="1">
<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"
></TextView>
<RelativeLayout
android:id="@+id/dining_hours"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="16dip"
android:paddingRight="16dip"
android:paddingBottom="20dip"
android:layout_weight="1">

</RelativeLayout>
</LinearLayout>

</ScrollView>
8 changes: 8 additions & 0 deletions PennMobile/src/main/res/menu/dining.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item android:id="@+id/dining_info_button"
android:icon="@drawable/ic_info"
app:showAsAction="ifRoom"
android:title="@string/dining_info"/>
</menu>

0 comments on commit a847c1b

Please sign in to comment.