<commit_before>package com.github.mobile.android.issue;

import static com.google.common.collect.Lists.newArrayList;
import static org.eclipse.egit.github.core.service.IssueService.STATE_CLOSED;
import static org.eclipse.egit.github.core.service.IssueService.STATE_OPEN;
import android.app.ProgressDialog;

import com.github.mobile.android.DialogFragmentActivity;
import com.github.mobile.android.R.string;
import com.github.mobile.android.SingleChoiceDialogFragment;
import com.github.mobile.android.async.AuthenticatedUserTask;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import org.eclipse.egit.github.core.IRepositoryIdProvider;
import org.eclipse.egit.github.core.Milestone;
import org.eclipse.egit.github.core.service.MilestoneService;

/**
 * Dialog helper to display a list of milestones to select one from
 */
public class MilestoneDialog {

    private MilestoneService service;

    private List<Milestone> repositoryMilestones;

    private final int requestCode;

    private final DialogFragmentActivity activity;

    private final IRepositoryIdProvider repository;

    /**
     * Create dialog helper to display milestones
     *
     * @param activity
     * @param requestCode
     * @param repository
     * @param service
     */
    public MilestoneDialog(final DialogFragmentActivity activity, final int requestCode,
            final IRepositoryIdProvider repository, final MilestoneService service) {
        this.activity = activity;
        this.requestCode = requestCode;
        this.repository = repository;
        this.service = service;
    }

    /**
     * Get milestones
     *
     * @return list of milestones
     */
    public List<Milestone> getMilestones() {
        return repositoryMilestones;
    }

    private void load(final Milestone selectedMilestone) {
        final ProgressDialog loader = new ProgressDialog(activity);
        loader.setMessage("Loading Milestones...");
        loader.show();
        new AuthenticatedUserTask<List<Milestone>>(activity) {

            public List<Milestone> run() throws Exception {
                List<Milestone> milestones = newArrayList();
                milestones.addAll(service.getMilestones(repository, STATE_OPEN));
                milestones.addAll(service.getMilestones(repository, STATE_CLOSED));
                Collections.sort(repositoryMilestones, new Comparator<Milestone>() {

                    public int compare(Milestone m1, Milestone m2) {
                        return m1.getTitle().compareToIgnoreCase(m2.getTitle());
                    }
                });
                return milestones;
            }

            protected void onSuccess(List<Milestone> all) throws Exception {
                repositoryMilestones = all;
                if (!loader.isShowing())
                    return;

                loader.dismiss();
                show(selectedMilestone);
            }

            protected void onException(Exception e) throws RuntimeException {
                loader.dismiss();
            }
        }.execute();
    }

    /**
     * Show dialog with given milestone selected
     *
     * @param selectedMilestone
     */
    public void show(Milestone selectedMilestone) {
        if (repositoryMilestones == null) {
            load(selectedMilestone);
            return;
        }

        final String[] names = new String[repositoryMilestones.size()];
        int checked = -1;
        if (selectedMilestone == null)
            for (int i = 0; i < names.length; i++)<commit_msg>Log exceptions and dismiss when interrupted<commit_after>package com.github.mobile.android.issue;

import static com.google.common.collect.Lists.newArrayList;
import static org.eclipse.egit.github.core.service.IssueService.STATE_CLOSED;
import static org.eclipse.egit.github.core.service.IssueService.STATE_OPEN;
import android.app.ProgressDialog;
import android.util.Log;

import com.github.mobile.android.DialogFragmentActivity;
import com.github.mobile.android.R.string;
import com.github.mobile.android.SingleChoiceDialogFragment;
import com.github.mobile.android.async.AuthenticatedUserTask;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import org.eclipse.egit.github.core.IRepositoryIdProvider;
import org.eclipse.egit.github.core.Milestone;
import org.eclipse.egit.github.core.service.MilestoneService;

/**
 * Dialog helper to display a list of milestones to select one from
 */
public class MilestoneDialog {

    private static final String TAG = "MilestoneDialog";

    private MilestoneService service;

    private List<Milestone> repositoryMilestones;

    private final int requestCode;

    private final DialogFragmentActivity activity;

    private final IRepositoryIdProvider repository;

    /**
     * Create dialog helper to display milestones
     *
     * @param activity
     * @param requestCode
     * @param repository
     * @param service
     */
    public MilestoneDialog(final DialogFragmentActivity activity, final int requestCode,
            final IRepositoryIdProvider repository, final MilestoneService service) {
        this.activity = activity;
        this.requestCode = requestCode;
        this.repository = repository;
        this.service = service;
    }

    /**
     * Get milestones
     *
     * @return list of milestones
     */
    public List<Milestone> getMilestones() {
        return repositoryMilestones;
    }

    private void load(final Milestone selectedMilestone) {
        final ProgressDialog loader = new ProgressDialog(activity);
        loader.setMessage("Loading Milestones...");
        loader.show();
        new AuthenticatedUserTask<List<Milestone>>(activity) {

            public List<Milestone> run() throws Exception {
                List<Milestone> milestones = newArrayList();
                milestones.addAll(service.getMilestones(repository, STATE_OPEN));
                milestones.addAll(service.getMilestones(repository, STATE_CLOSED));
                Collections.sort(milestones, new Comparator<Milestone>() {

                    public int compare(Milestone m1, Milestone m2) {
                        return m1.getTitle().compareToIgnoreCase(m2.getTitle());
                    }
                });
                return milestones;
            }

            protected void onSuccess(List<Milestone> all) throws Exception {
                repositoryMilestones = all;
                if (!loader.isShowing())
                    return;

                loader.dismiss();
                show(selectedMilestone);
            }

            protected void onException(Exception e) throws RuntimeException {
                Log.d(TAG, "Exception loading milestones", e);
                loader.dismiss();
            }

            protected void onInterrupted(Exception e) {
                loader.dismiss();
            }
        }.execute();
    }

    /**
     * Show dialog with given milestone selected
     *
     * @param selectedMilestone
     */
    public void show(Milestone selectedMilestone) {
        if (repositoryMilestones == null) {
            load(selectedMilestone);
            return;
        }

        final String[] names = new String[repositoryMilestones.size()];
        int checked = -1;
        if (selectedMilestone == null)
            for (int i = 0; i < names.length; i++)
{'fraction_non_alphanumeric': 0.08734980423923316, 'fraction_numerical': 0.0016200891049007696, 'mean_word_length': 2.4861176470588235, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5013313', 'n_tokens_mistral': 1934, 'n_tokens_neox': 1817, 'n_words': 438}