package com.strengthcoach.strengthcoach.activities;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.strengthcoach.strengthcoach.R;
import com.strengthcoach.strengthcoach.helpers.GPSTracker;

public class MapActivity extends ActionBarActivity {

    GoogleMap m_map;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map);

        SupportMapFragment mapFragment = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map));
        if (mapFragment != null) {
            mapFragment.getMapAsync(new OnMapReadyCallback() {
                @Override
                public void onMapReady(GoogleMap map) {
                    m_map = map;

                    // Get coordinates
                    GPSTracker gpsTracker = new GPSTracker(getBaseContext());
                    double latitude = gpsTracker.getLatitude();
                    double longitude = gpsTracker.getLongitude();
                    LatLng point = new LatLng(latitude, longitude);
                    m_map.moveCamera(CameraUpdateFactory.newLatLngZoom(point, 15));

                    /*
                    BitmapDescriptor defaultMarker =
                            BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED);
                    // Extract content from alert dialog
                    String title = m_trainer.getGym().getName();
                    String snippet = m_trainer.getGym().getAddress().toString();
                    // Creates and adds marker to the map
                    Marker marker = m_map.addMarker(new MarkerOptions()
                            .position(point)
                            .title(title)
                            .snippet(snippet)
                            .icon(defaultMarker));
                    marker.showInfoWindow();
                    */
                }
            });
        } else {
            Toast.makeText(this, "Error - Map Fragment was null!!", Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_map, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

@@ -460,22 +460,344 @@
 s.model.
-LatLng
+BitmapDescriptor;%0Aimport com.google.android.gms.maps.model.BitmapDescriptorFactory;%0Aimport com.google.android.gms.maps.model.LatLng;%0Aimport com.google.android.gms.maps.model.Marker;%0Aimport com.google.android.gms.maps.model.MarkerOptions;%0Aimport com.parse.FindCallback;%0Aimport com.parse.ParseGeoPoint;%0Aimport com.parse.ParseQuery
 ;%0Aimport
@@ -890,16 +890,91 @@
 Tracker;
+%0Aimport com.strengthcoach.strengthcoach.models.Gym;%0A%0Aimport java.util.List;
 %0A%0Apublic
@@ -1539,16 +1539,417 @@
 = map;%0A%0A
+                    m_map.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() %7B%0A                        @Override%0A                        public void onInfoWindowClick(Marker marker) %7B%0A                            // TODO: pass gym information to main activity to show trainers only from there%0A                            finish();%0A                        %7D%0A                    %7D);%0A%0A
         
@@ -2364,11 +2364,389 @@
     
-/*%0A
+ParseQuery%3CGym%3E query = ParseQuery.getQuery(%22Gym%22);%0A                    query.include(%22address%22);%0A                    query.include(%22trainers%22);%0A                    query.findInBackground(new FindCallback%3CGym%3E() %7B%0A                        public void done(List%3CGym%3E gyms, com.parse.ParseException e) %7B%0A                            for (int i = 0; i %3C gyms.size(); i++) %7B%0A            
     
@@ -2814,32 +2814,44 @@
                 
+      
+      
 BitmapDescriptor
@@ -2926,16 +2926,28 @@
         
+            
 // Extra
@@ -2991,24 +2991,36 @@
             
+  
+          
 String title
@@ -3026,36 +3026,86 @@
 e = 
-m_trainer.getGym().getName()
+gyms.get(i).getName() + %22 (%22 + gyms.get(i).getTrainers().size() + %22 trainers)%22
 ;%0A  
@@ -3118,24 +3118,36 @@
             
+ 
+           
 String snipp
@@ -3155,25 +3155,18 @@
 t = 
-m_trainer.getGym(
+gyms.get(i
 ).ge
@@ -3184,24 +3184,238 @@
 toString();%0A
+                                ParseGeoPoint parseGeoPoint = gyms.get(i).point();%0A                                LatLng point = new LatLng(parseGeoPoint.getLatitude(), parseGeoPoint.getLongitude());%0A%0A            
             
@@ -3460,16 +3460,28 @@
 the map%0A
+            
         
@@ -3572,16 +3572,28 @@
         
+    
+        
 .positio
@@ -3601,16 +3601,28 @@
 (point)%0A
+            
         
@@ -3683,16 +3683,28 @@
         
+            
 .snippet
@@ -3741,16 +3741,28 @@
         
+       
+     
 .icon(de
@@ -3772,24 +3772,36 @@
 ltMarker));%0A
+            
             
@@ -3857,10 +3857,67 @@
     
-*/
+        %7D%0A                        %7D%0A                    %7D);
 %0A   

complete map activity