package org.example.proyecto;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.support.v7.app.NotificationCompat;

import java.util.Calendar;

/**
 * Created by Victor on 18/09/2016.
 */
public class ServicioNotificacion extends Service {

    Calendar c;

    @Override public void onCreate() {

        c = Calendar.getInstance();

    }

    @Override
    public int onStartCommand(Intent intent,int flags,int idArranque){

        if (AdaptadorCiudades.correr){

            NotificationCompat.Builder notific = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
                    .setContentTitle("Condiciones adecuadas")
                    .setSmallIcon(R.drawable.correr)
                    .setContentText("Correr en "+AdaptadorCiudades.ciudad)
                    .setWhen(System.currentTimeMillis())
                    .setDefaults(Notification.DEFAULT_SOUND)
                    .setDefaults(Notification.DEFAULT_VIBRATE);

            PendingIntent intencionPendiente = PendingIntent.getActivity(
                    this,0,new Intent(this,MainActivity.class),0);

            notific.setContentIntent(intencionPendiente);

            NotificationManager notificationManager = (NotificationManager)
                    getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.notify(1, notific.build());

        }

        if (AdaptadorCiudades.tenis){

            NotificationCompat.Builder notific = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
                    .setContentTitle("Condiciones adecuadas")
                    .setSmallIcon(R.drawable.tenis)
                    .setContentText("Tenis/Padel en "+AdaptadorCiudades.ciudad)
                    .setWhen(System.currentTimeMillis())
                    .setDefaults(Notification.DEFAULT_SOUND)
                    .setDefaults(Notification.DEFAULT_VIBRATE);

            PendingIntent intencionPendiente = PendingIntent.getActivity(
                    this,0,new Intent(this,MainActivity.class),0);

            notific.setContentIntent(intencionPendiente);

            NotificationManager notificationManager = (NotificationManager)
                    getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.notify(2, notific.build());
        }

        AdaptadorCiudades.correr = false;
        AdaptadorCiudades.tenis = false;

        return START_STICKY;
    }


    @Override public void onDestroy() {

    }

    @Override public IBinder onBind(Intent intencion) {
        return null;
    }
}
