package dev.paytrack.paytrack.activity;

import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;

import java.util.ArrayList;

import dev.paytrack.paytrack.adapter.PaymentAdapter;
import dev.paytrack.paytrack.model.PaymentItem;
import dev.paytrack.paytrack.R;
import dev.paytrack.paytrack.utils.Utils;

public class TripActivity extends AppCompatActivity {

    private GoogleMap mMap;
    private MapView mMapView;

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

        mMapView = (MapView) findViewById(R.id.mapView);

        ArrayList<PaymentItem> paymentItems = new ArrayList<>();
        paymentItems.add(
                new PaymentItem(
                        "Starbucks Pl. Universitat",
                        4.70
                )
        );
        paymentItems.add(
                new PaymentItem(
                        "Restaurante el Puma",
                        12.30
                )
        );
        paymentItems.add(
                new PaymentItem(
                        "Tiger",
                        1.00
                )
        );

        RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        assert recyclerView != null;
        recyclerView.setLayoutManager(linearLayoutManager);
        recyclerView.setAdapter(new PaymentAdapter(paymentItems));

        initialitzeMap();
    }

    private void initialitzeMap() {
        mMapView.getMapAsync(new OnMapReadyCallback() {
            @Override
            public void onMapReady(GoogleMap googleMap) {
                mMap = googleMap;

                //we search for the fib
                LatLng BCN = getLocationFromAddress("Barcelona");
                if (BCN != null) {
                    CameraPosition cameraPosition = new CameraPosition.Builder()
                            .target(BCN)      // Sets the center to BCN
                            .zoom(10)         // we set the zoom
                            .build();
                    mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), 5000, null);
                }
                locateTransactions();
            }
        });
    }

    private void locateTransactions() {

    }

    public LatLng getLocationFromAddress(String strAddress) {
        return Utils.getLocationFromAddress(strAddress, getApplicationContext());
    }
}

@@ -573,96 +573,328 @@
 del.
-CameraPosition;%0Aimport com.google.android.gms.maps.model.LatLng;%0A%0Aimport java.util.Array
+BitmapDescriptorFactory;%0Aimport com.google.android.gms.maps.model.CameraPosition;%0Aimport com.google.android.gms.maps.model.LatLng;%0Aimport com.google.android.gms.maps.model.MarkerOptions;%0A%0Aimport java.text.DateFormat;%0Aimport java.text.SimpleDateFormat;%0Aimport java.util.ArrayList;%0Aimport java.util.Date;%0Aimport java.util.
 List
@@ -945,24 +945,73 @@
 entAdapter;%0A
+import dev.paytrack.paytrack.domain.Transaction;%0A
 import dev.p
@@ -1078,16 +1078,73 @@
 rack.R;%0A
+import dev.paytrack.paytrack.service.TransactionService;%0A
 import d
@@ -1292,16 +1292,68 @@
 pView;%0A%0A
+    private TransactionService transactionService;%0A%0A
     @Ove
@@ -3321,16 +3321,538 @@
 ons() %7B%0A
+        List%3CTransaction%3E transactions = transactionService.getTransactionsByOriginIbanBetweenDates(%22iban%22, new Date(), new Date());%0A        for (Transaction t : transactions) %7B%0A            LatLng position = getLocationFromAddress(t.getCounterPartyName());%0A            if (position != null) %7B%0A                MarkerOptions marker = new MarkerOptions()%0A                        .position(position)%0A                        .title(String.valueOf(t.getAmount()));%0A                mMap.addMarker(marker);%0A            %7D%0A        %7D
 %0A    %7D%0A%0A

add locateTransactions