<commit_before>
package com.nasageek.utexasutilities.fragments;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.CalendarContract;
import android.provider.CalendarContract.Calendars;
import android.support.design.widget.TabLayout;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.FrameLayout;
import android.widget.Toast;

import com.commonsware.cwac.security.RuntimePermissionUtils;
import com.nasageek.utexasutilities.R;
import com.nasageek.utexasutilities.WrappedViewPager;
import com.nasageek.utexasutilities.activities.ScheduleActivity;
import com.nasageek.utexasutilities.model.Classtime;
import com.nasageek.utexasutilities.model.UTClass;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
import java.util.Vector;

public class DoubleDatePickerDialogFragment extends ExportScheduleDialogFragment {

    private List<View> datePickers;
    private DatePicker startDatePicker, endDatePicker;

    public static final String[] EVENT_PROJECTION = new String[] {
            Calendars._ID, // 0
            Calendars.ACCOUNT_NAME, // 1
            Calendars.CALENDAR_DISPLAY_NAME, // 2
            Calendars.OWNER_ACCOUNT, // 3
            Calendars.VISIBLE, // 4
            Calendars.CALENDAR_ACCESS_LEVEL
    // 5
    };

    // The indices for the projection array above.
    private static final int PROJECTION_ID_INDEX = 0;
    private static final int PROJECTION_ACCOUNT_NAME_INDEX = 1;
    private static final int PROJECTION_DISPLAY_NAME_INDEX = 2;
    private static final int PROJECTION_OWNER_ACCOUNT_INDEX = 3;
    private static final int PROJECTION_DISPLAY_INDEX = 4;
    private static final int PROJECTION_ACCESS_LEVEL_INDEX = 5;

    public DoubleDatePickerDialogFragment() {
    }

    public static DoubleDatePickerDialogFragment newInstance(ArrayList<UTClass> classList) {
        DoubleDatePickerDialogFragment ddpdf = new DoubleDatePickerDialogFragment();
        Bundle args = new Bundle();
        args.putParcelableArrayList("classList", classList);
        ddpdf.setArguments(args);
        return ddpdf;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(DialogFragment.STYLE_NO_TITLE, 0);
    }

    /*
     * @Override public Dialog onCreateDialog(Bundle savedInstanceState) { View
     * view = getActivity().getLayoutInflater().inflate(R.layout.
     * double_date_picker_dialog_fragment_layout, null); AlertDialog.Builder
     * build = new AlertDialog.Builder(getActivity());
     * build.setView(view). setPositiveButton("Okay", null).
     * setNegativeButton("Cancel", null).
     * setTitle("Choose start and end dates"); initialisePaging(view); return
     * build.create(); }
     */

    public void setupScheduleData() {
        Calendar startDate = new GregorianCalendar(startDatePicker.getYear(),
                startDatePicker.getMonth(), startDatePicker.getDayOfMonth());
        Calendar endDate = new GregorianCalendar(endDatePicker.getYear(),
                endDatePicker.getMonth(), endDatePicker.getDayOfMonth());
        if (startDate.after(endDate)) {
            Toast.makeText(getActivity(),
                    "Start date must be before end date.", Toast.LENGTH_SHORT)
                    .show();
            return;
        }
        ContentResolver cr = getActivity().getContentResolver();

        SimpleDateFormat formatter = new SimpleDateFormat("hh:mmaa", Locale.US);
        ArrayList<UTClass> classList = getArguments().getParcelableArrayList(
                "classList");
        SimpleDateFormat endDateFormatter = new SimpleDateFormat(
                "yyyyMMdd'T000000Z'", Locale.US);
        // roll forward one because RRULE will not place events
        // on the specified end date
        endDate.roll(Calendar.DATE, true);

        String endDateString = endDateFormatter.format(endDate.getTime());
        ArrayList<ContentValues> valuesList = new ArrayList<>();

        // copying our original selected start date for
        // comparison to each class
        // start date later
        Calendar selectedStartDate = (Calendar) startDate.clone();
        for (UTClass clz : classList) {
            for (Classtime clt : clz.getClassTimes()) {
                Date classStartTime = null, classEndTime = null;

                try {
                    classStartTime = formatter.parse(clt.getStartTime());
                    classEndTime = formatter.parse(clt.getEndTime());
                } catch (ParseException e1) {
                    Toast.makeText(getActivity(),
                            "Error parsing " + clt.getCourseId()
                                    + " start/end time. Export canceled.",
                            Toast.LENGTH_LONG);
                    e1.printStackTrace();
                    DoubleDatePickerDialogFragment.this.dismiss();<commit_msg>Schedule export: Actually show toast on date parse failure<commit_after>
package com.nasageek.utexasutilities.fragments;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.CalendarContract;
import android.provider.CalendarContract.Calendars;
import android.support.design.widget.TabLayout;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.FrameLayout;
import android.widget.Toast;

import com.commonsware.cwac.security.RuntimePermissionUtils;
import com.nasageek.utexasutilities.R;
import com.nasageek.utexasutilities.WrappedViewPager;
import com.nasageek.utexasutilities.activities.ScheduleActivity;
import com.nasageek.utexasutilities.model.Classtime;
import com.nasageek.utexasutilities.model.UTClass;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
import java.util.Vector;

public class DoubleDatePickerDialogFragment extends ExportScheduleDialogFragment {

    private List<View> datePickers;
    private DatePicker startDatePicker, endDatePicker;

    public static final String[] EVENT_PROJECTION = new String[] {
            Calendars._ID, // 0
            Calendars.ACCOUNT_NAME, // 1
            Calendars.CALENDAR_DISPLAY_NAME, // 2
            Calendars.OWNER_ACCOUNT, // 3
            Calendars.VISIBLE, // 4
            Calendars.CALENDAR_ACCESS_LEVEL
    // 5
    };

    // The indices for the projection array above.
    private static final int PROJECTION_ID_INDEX = 0;
    private static final int PROJECTION_ACCOUNT_NAME_INDEX = 1;
    private static final int PROJECTION_DISPLAY_NAME_INDEX = 2;
    private static final int PROJECTION_OWNER_ACCOUNT_INDEX = 3;
    private static final int PROJECTION_DISPLAY_INDEX = 4;
    private static final int PROJECTION_ACCESS_LEVEL_INDEX = 5;

    public DoubleDatePickerDialogFragment() {
    }

    public static DoubleDatePickerDialogFragment newInstance(ArrayList<UTClass> classList) {
        DoubleDatePickerDialogFragment ddpdf = new DoubleDatePickerDialogFragment();
        Bundle args = new Bundle();
        args.putParcelableArrayList("classList", classList);
        ddpdf.setArguments(args);
        return ddpdf;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(DialogFragment.STYLE_NO_TITLE, 0);
    }

    /*
     * @Override public Dialog onCreateDialog(Bundle savedInstanceState) { View
     * view = getActivity().getLayoutInflater().inflate(R.layout.
     * double_date_picker_dialog_fragment_layout, null); AlertDialog.Builder
     * build = new AlertDialog.Builder(getActivity());
     * build.setView(view). setPositiveButton("Okay", null).
     * setNegativeButton("Cancel", null).
     * setTitle("Choose start and end dates"); initialisePaging(view); return
     * build.create(); }
     */

    public void setupScheduleData() {
        Calendar startDate = new GregorianCalendar(startDatePicker.getYear(),
                startDatePicker.getMonth(), startDatePicker.getDayOfMonth());
        Calendar endDate = new GregorianCalendar(endDatePicker.getYear(),
                endDatePicker.getMonth(), endDatePicker.getDayOfMonth());
        if (startDate.after(endDate)) {
            Toast.makeText(getActivity(),
                    "Start date must be before end date.", Toast.LENGTH_SHORT)
                    .show();
            return;
        }
        ContentResolver cr = getActivity().getContentResolver();

        SimpleDateFormat formatter = new SimpleDateFormat("hh:mmaa", Locale.US);
        ArrayList<UTClass> classList = getArguments().getParcelableArrayList(
                "classList");
        SimpleDateFormat endDateFormatter = new SimpleDateFormat(
                "yyyyMMdd'T000000Z'", Locale.US);
        // roll forward one because RRULE will not place events
        // on the specified end date
        endDate.roll(Calendar.DATE, true);

        String endDateString = endDateFormatter.format(endDate.getTime());
        ArrayList<ContentValues> valuesList = new ArrayList<>();

        // copying our original selected start date for
        // comparison to each class
        // start date later
        Calendar selectedStartDate = (Calendar) startDate.clone();
        for (UTClass clz : classList) {
            for (Classtime clt : clz.getClassTimes()) {
                Date classStartTime = null, classEndTime = null;

                try {
                    classStartTime = formatter.parse(clt.getStartTime());
                    classEndTime = formatter.parse(clt.getEndTime());
                } catch (ParseException e1) {
                    Toast.makeText(getActivity(),
                            "Error parsing " + clt.getCourseId()
                                    + " start/end time. Export canceled.",
                            Toast.LENGTH_LONG).show();
                    e1.printStackTrace();
                    DoubleDatePickerDialogFragment.this.dismiss();
{'fraction_non_alphanumeric': 0.08925679323375922, 'fraction_numerical': 0.004138923879791255, 'mean_word_length': 3.053610503282276, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '381295', 'n_tokens_mistral': 3102, 'n_tokens_neox': 2921, 'n_words': 653}