<commit_before>package com.expidevapps.android.measurements.support.v4.fragment;

import android.annotation.SuppressLint;
import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.expidevapps.android.measurements.R;
import com.expidevapps.android.measurements.db.GmaDao;
import com.expidevapps.android.measurements.model.Ministry;
import com.expidevapps.android.measurements.model.Ministry.Mcc;
import com.expidevapps.android.measurements.model.Training;
import com.expidevapps.android.measurements.service.GoogleAnalyticsManager;
import com.expidevapps.android.measurements.sync.GmaSyncService;
import com.google.android.gms.maps.model.LatLng;

import org.ccci.gto.android.common.util.AsyncTaskCompat;
import org.joda.time.LocalDate;

import java.security.SecureRandom;

import butterknife.InjectView;
import butterknife.OnClick;
import butterknife.Optional;

import static com.expidevapps.android.measurements.Constants.ARG_MCC;
import static com.expidevapps.android.measurements.Constants.ARG_MINISTRY_ID;
import static com.expidevapps.android.measurements.sync.BroadcastUtils.updateTrainingBroadcast;

public class CreateTrainingFragment extends BaseEditTrainingDialogFragment {
    private static String ARG_LOCATION = CreateTrainingFragment.class.getName() + ".ARG_LOCATION";

    @SuppressLint("TrulyRandom")
    private static final SecureRandom RAND = new SecureRandom();

    @NonNull
    private String mMinistryId = Ministry.INVALID_ID;
    @NonNull
    private Mcc mMcc = Mcc.UNKNOWN;
    @Nullable
    private LatLng mLocation;

    @Optional
    @Nullable
    @InjectView(R.id.training_update)
    TextView mSaveView;

    @Optional
    @Nullable
    @InjectView(R.id.training_delete)
    Button mDeleteTraining;

    public static Bundle buildArgs(@NonNull final String guid, @NonNull final String ministryId, @NonNull final Mcc mcc,
                                   @NonNull final LatLng location) {
        final Bundle args = buildArgs(guid);
        args.putString(ARG_MINISTRY_ID, ministryId);
        args.putString(ARG_MCC, mcc.toString());
        args.putParcelable(ARG_LOCATION, location);
        return args;
    }

    public static CreateTrainingFragment newInstance(@NonNull final String guid, @NonNull final String ministryId,
                                                     @NonNull final Mcc mcc, @NonNull final LatLng location) {
        final CreateTrainingFragment fragment = new CreateTrainingFragment();
        fragment.setArguments(buildArgs(guid, ministryId, mcc, location));
        return fragment;
    }

    /* BEGIN lifecycle */

    @Override
    public void onCreate(final Bundle savedState) {
        super.onCreate(savedState);

        final Bundle args = this.getArguments();
        mMinistryId = args != null ? args.getString(ARG_MINISTRY_ID) : Ministry.INVALID_ID;
        mMcc = args != null ? Mcc.fromRaw(args.getString(ARG_MCC)) : Mcc.UNKNOWN;
        mLocation = args != null ? args.<LatLng>getParcelable(ARG_LOCATION) : null;
    }

    @Override
    public void onStart() {
        super.onStart();
        updateTitle(R.string.title_dialog_training_create);
        setTrainingDate(LocalDate.now());
        setupViews();
    }

    @Optional
    @OnClick(R.id.training_update)
    void onSaveTraining() {
        // create new church object
        final Training training = new Training();
        training.setNew(true);
        training.setMinistryId(mMinistryId);
        training.setMcc(mMcc);
        training.setDate(mTrainingDate);
        if (mLocation != null) {
            training.setLatitude(mLocation.latitude);
            training.setLongitude(mLocation.longitude);
        }
        if (mTrainingName != null) {
            training.setName(mTrainingName.getText().toString());
        }
        if (mTrainingTypeSpinner != null) {
            final Object trainingType = mTrainingTypeSpinner.getSelectedItem();
            training.setType(((String) trainingType).equalsIgnoreCase(Training.TRAINING_TYPE_OTHER) ? "" : (String) trainingType);
        }
        if (mTrainingParticipants != null) {
            training.setParticipants(Integer.valueOf(mTrainingParticipants.getText().toString()));
        }

        // save new church
        AsyncTaskCompat.execute(new CreateTrainingRunnable(getActivity().getApplicationContext(), mGuid, training));

        // dismiss the dialog
        this.dismiss();
    }

    /* END lifecycle */

    private void setupViews() {
        if (mTrainingMcc != null) {
            mTrainingMcc.setText(mMcc.toString());
        }<commit_msg>checks for blank training name and participants<commit_after>package com.expidevapps.android.measurements.support.v4.fragment;

import android.annotation.SuppressLint;
import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.expidevapps.android.measurements.R;
import com.expidevapps.android.measurements.db.GmaDao;
import com.expidevapps.android.measurements.model.Ministry;
import com.expidevapps.android.measurements.model.Ministry.Mcc;
import com.expidevapps.android.measurements.model.Training;
import com.expidevapps.android.measurements.service.GoogleAnalyticsManager;
import com.expidevapps.android.measurements.sync.GmaSyncService;
import com.google.android.gms.maps.model.LatLng;

import org.ccci.gto.android.common.util.AsyncTaskCompat;
import org.joda.time.LocalDate;

import java.security.SecureRandom;

import butterknife.InjectView;
import butterknife.OnClick;
import butterknife.Optional;

import static com.expidevapps.android.measurements.Constants.ARG_MCC;
import static com.expidevapps.android.measurements.Constants.ARG_MINISTRY_ID;
import static com.expidevapps.android.measurements.sync.BroadcastUtils.updateTrainingBroadcast;

public class CreateTrainingFragment extends BaseEditTrainingDialogFragment {
    private static String ARG_LOCATION = CreateTrainingFragment.class.getName() + ".ARG_LOCATION";

    @SuppressLint("TrulyRandom")
    private static final SecureRandom RAND = new SecureRandom();

    @NonNull
    private String mMinistryId = Ministry.INVALID_ID;
    @NonNull
    private Mcc mMcc = Mcc.UNKNOWN;
    @Nullable
    private LatLng mLocation;

    @Optional
    @Nullable
    @InjectView(R.id.training_update)
    TextView mSaveView;

    @Optional
    @Nullable
    @InjectView(R.id.training_delete)
    Button mDeleteTraining;

    public static Bundle buildArgs(@NonNull final String guid, @NonNull final String ministryId, @NonNull final Mcc mcc,
                                   @NonNull final LatLng location) {
        final Bundle args = buildArgs(guid);
        args.putString(ARG_MINISTRY_ID, ministryId);
        args.putString(ARG_MCC, mcc.toString());
        args.putParcelable(ARG_LOCATION, location);
        return args;
    }

    public static CreateTrainingFragment newInstance(@NonNull final String guid, @NonNull final String ministryId,
                                                     @NonNull final Mcc mcc, @NonNull final LatLng location) {
        final CreateTrainingFragment fragment = new CreateTrainingFragment();
        fragment.setArguments(buildArgs(guid, ministryId, mcc, location));
        return fragment;
    }

    /* BEGIN lifecycle */

    @Override
    public void onCreate(final Bundle savedState) {
        super.onCreate(savedState);

        final Bundle args = this.getArguments();
        mMinistryId = args != null ? args.getString(ARG_MINISTRY_ID) : Ministry.INVALID_ID;
        mMcc = args != null ? Mcc.fromRaw(args.getString(ARG_MCC)) : Mcc.UNKNOWN;
        mLocation = args != null ? args.<LatLng>getParcelable(ARG_LOCATION) : null;
    }

    @Override
    public void onStart() {
        super.onStart();
        updateTitle(R.string.title_dialog_training_create);
        setTrainingDate(LocalDate.now());
        setupViews();
    }

    @Optional
    @OnClick(R.id.training_update)
    void onSaveTraining() {
        // create new church object
        final Training training = new Training();
        training.setNew(true);
        training.setMinistryId(mMinistryId);
        training.setMcc(mMcc);
        training.setDate(mTrainingDate);
        if (mLocation != null) {
            training.setLatitude(mLocation.latitude);
            training.setLongitude(mLocation.longitude);
        }
        if (mTrainingName != null) {
            if (!mTrainingName.getText().toString().isEmpty()) {
                training.setName(mTrainingName.getText().toString());
            }
            else {
                return;
            }
        }
        if (mTrainingTypeSpinner != null) {
            final Object trainingType = mTrainingTypeSpinner.getSelectedItem();
            training.setType(((String) trainingType).equalsIgnoreCase(Training.TRAINING_TYPE_OTHER) ? "" : (String) trainingType);
        }
        if (mTrainingParticipants != null) {
            training.setParticipants(
                    !mTrainingParticipants.getText().toString().isEmpty() ? Integer.valueOf(mTrainingParticipants.getText().toString()) : 0);
        }

        // save new church
        AsyncTaskCompat.execute(new CreateTrainingRunnable(getActivity().getApplicationContext(), mGuid, training));

        // dismiss the dialog
        this.dismiss();
    }

    /* END lifecycle */

    private void setupViews() {
        if (mTrainingMcc != null) {
            mTrainingMcc.setText(mMcc.toString());
        }
{'fraction_non_alphanumeric': 0.09636525700703179, 'fraction_numerical': 0.0004951965930474399, 'mean_word_length': 3.3043478260869565, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6039326', 'n_tokens_mistral': 2888, 'n_tokens_neox': 2789, 'n_words': 541}