// Path: app/src/main/java/com/nasageek/utexasutilities/AnalyticsHandler.java
// public class AnalyticsHandler {
// 
//     private static FirebaseAnalytics analyticsTracker;
// 
//     private AnalyticsHandler() {
//         // do nothing
//     }
// 
//     public static void initTrackerIfNeeded(Context con, boolean enabled) {
//         if (analyticsTracker == null) {
//             analyticsTracker = FirebaseAnalytics.getInstance(con);
//             analyticsTracker.setAnalyticsCollectionEnabled(enabled);
//         }
//     }
// 
//     public static void trackLogoutEvent() {
//         analyticsTracker.logEvent("logout", null);
//     }
// 
//     public static void trackCalendarExportEvent() {
//         analyticsTracker.logEvent("export_calendar", null);
//     }
// 
//     public static void trackMapAllClassesEvent() {
//         analyticsTracker.logEvent("map_all_classes", null);
//     }
// 
//     public static void trackGetDirectionsEvent() {
//         analyticsTracker.logEvent("get_directions", null);
//     }
// 
//     public static void trackBusRouteEvent() {
//         analyticsTracker.logEvent("view_bus_route", null);
//     }
// }


import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.AsyncQueryHandler;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.provider.CalendarContract;
import android.support.annotation.NonNull;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.widget.Toast;
import com.nasageek.utexasutilities.AnalyticsHandler;
import com.nasageek.utexasutilities.R;
import java.util.ArrayList;
                    ArrayList<ContentValues> cvList = getArguments().getParcelableArrayList(
                            "valuesList");
                    ArrayList<Integer> indices = getArguments().getIntegerArrayList("indices");
                    int selection = indices.get(which);

                    for (int i = 0; i < cvList.size(); i++) {
                        cvList.get(i).put(CalendarContract.Events.CALENDAR_ID, selection);
                        cih.startInsert(i, null, CalendarContract.Events.CONTENT_URI, cvList.get(i));
                    }
                })
                .setTitle("Select calendar")
                .create();
    }

    // Suppress because handler is very shortlived
    @SuppressLint("HandlerLeak")
    class CalendarInsertHandler extends AsyncQueryHandler {

        public CalendarInsertHandler(ContentResolver cr) {
            super(cr);
        }

        @Override
        public void onInsertComplete(int token, Object cookie, Uri uri) {
            if (token == getArguments().getParcelableArrayList("valuesList").size() - 1) {
                Log.d("CalendarStuff", "insert finished");
                Toast.makeText(
                        parentAct,
                        "This schedule has been exported successfully. It may take a minute or two "
                                + "for it to show up on your calendar.", Toast.LENGTH_LONG).show();
// Path: app/src/main/java/com/nasageek/utexasutilities/AnalyticsHandler.java
// public class AnalyticsHandler {
// 
//     private static FirebaseAnalytics analyticsTracker;
// 
//     private AnalyticsHandler() {
//         // do nothing
//     }
// 
//     public static void initTrackerIfNeeded(Context con, boolean enabled) {
//         if (analyticsTracker == null) {
//             analyticsTracker = FirebaseAnalytics.getInstance(con);
//             analyticsTracker.setAnalyticsCollectionEnabled(enabled);
//         }
//     }
// 
//     public static void trackLogoutEvent() {
//         analyticsTracker.logEvent("logout", null);
//     }
// 
//     public static void trackCalendarExportEvent() {
//         analyticsTracker.logEvent("export_calendar", null);
//     }
// 
//     public static void trackMapAllClassesEvent() {
//         analyticsTracker.logEvent("map_all_classes", null);
//     }
// 
//     public static void trackGetDirectionsEvent() {
//         analyticsTracker.logEvent("get_directions", null);
//     }
// 
//     public static void trackBusRouteEvent() {
//         analyticsTracker.logEvent("view_bus_route", null);
//     }
// }


// Path: app/src/main/java/com/nasageek/utexasutilities/fragments/PickCalendarDialogFragment.java
import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.AsyncQueryHandler;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.provider.CalendarContract;
import android.support.annotation.NonNull;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.widget.Toast;
import com.nasageek.utexasutilities.AnalyticsHandler;
import com.nasageek.utexasutilities.R;
import java.util.ArrayList;

                    ArrayList<ContentValues> cvList = getArguments().getParcelableArrayList(
                            "valuesList");
                    ArrayList<Integer> indices = getArguments().getIntegerArrayList("indices");
                    int selection = indices.get(which);

                    for (int i = 0; i < cvList.size(); i++) {
                        cvList.get(i).put(CalendarContract.Events.CALENDAR_ID, selection);
                        cih.startInsert(i, null, CalendarContract.Events.CONTENT_URI, cvList.get(i));
                    }
                })
                .setTitle("Select calendar")
                .create();
    }

    // Suppress because handler is very shortlived
    @SuppressLint("HandlerLeak")
    class CalendarInsertHandler extends AsyncQueryHandler {

        public CalendarInsertHandler(ContentResolver cr) {
            super(cr);
        }

        @Override
        public void onInsertComplete(int token, Object cookie, Uri uri) {
            if (token == getArguments().getParcelableArrayList("valuesList").size() - 1) {
                Log.d("CalendarStuff", "insert finished");
                Toast.makeText(
                        parentAct,
                        "This schedule has been exported successfully. It may take a minute or two "
                                + "for it to show up on your calendar.", Toast.LENGTH_LONG).show();
                AnalyticsHandler.trackCalendarExportEvent();