Search in sources :

Example 6 with Label

use of com.meisolsson.githubsdk.model.Label in project PocketHub by pockethub.

the class LabelsDialog method show.

/**
     * Show dialog with given labels selected
     *
     * @param selectedLabels
     */
public void show(Collection<Label> selectedLabels) {
    if (labels == null) {
        load(selectedLabels);
        return;
    }
    final ArrayList<Label> names = new ArrayList<>(labels.values());
    final boolean[] checked = new boolean[names.size()];
    if (selectedLabels != null && !selectedLabels.isEmpty()) {
        Set<String> selectedNames = new HashSet<>();
        for (Label label : selectedLabels) {
            selectedNames.add(label.name());
        }
        for (int i = 0; i < checked.length; i++) {
            if (selectedNames.contains(names.get(i).name())) {
                checked[i] = true;
            }
        }
    }
    LabelsDialogFragment.show(activity, requestCode, activity.getString(R.string.select_labels), null, names, checked);
}
Also used : ArrayList(java.util.ArrayList) Label(com.meisolsson.githubsdk.model.Label) HashSet(java.util.HashSet)

Example 7 with Label

use of com.meisolsson.githubsdk.model.Label in project PocketHub by pockethub.

the class LabelsDialogFragment method onResult.

@Override
protected void onResult(int resultCode) {
    Bundle arguments = getArguments();
    ArrayList<Label> selected = new ArrayList<>();
    boolean[] selectedChoices = arguments.getBooleanArray(ARG_SELECTED_CHOICES);
    ArrayList<Label> choices = getChoices();
    if (selectedChoices != null) {
        for (int i = 0; i < selectedChoices.length; i++) {
            if (selectedChoices[i]) {
                selected.add(choices.get(i));
            }
        }
    }
    arguments.putParcelableArrayList(ARG_SELECTED, selected);
    super.onResult(resultCode);
}
Also used : Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) Label(com.meisolsson.githubsdk.model.Label)

Example 8 with Label

use of com.meisolsson.githubsdk.model.Label in project PocketHub by pockethub.

the class LabelsDialogFragment method onCreateDialog.

@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    Bundle arguments = getArguments();
    Activity activity = getActivity();
    ArrayList<Label> choices = getChoices();
    boolean[] selectedChoices = arguments.getBooleanArray(ARG_SELECTED_CHOICES);
    List<String> selected = new ArrayList<>();
    if (selectedChoices != null) {
        for (int i = 0; i < choices.size(); i++) {
            if (selectedChoices[i]) {
                selected.add(choices.get(i).name());
            }
        }
    }
    arguments.putStringArrayList(ARG_SELECTED, (ArrayList<String>) selected);
    LayoutInflater inflater = activity.getLayoutInflater();
    ListView view = (ListView) inflater.inflate(R.layout.dialog_list_view, null);
    LabelListAdapter adapter = new LabelListAdapter(inflater, choices.toArray(new Label[choices.size()]), selectedChoices);
    view.setAdapter(adapter);
    view.setOnItemClickListener(adapter);
    return new MaterialDialog.Builder(activity).cancelable(true).cancelListener(this).negativeText(R.string.cancel).onNegative(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            LabelsDialogFragment.this.onClick(dialog, BUTTON_NEGATIVE);
        }
    }).neutralText(R.string.clear).onNeutral(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            LabelsDialogFragment.this.onClick(dialog, BUTTON_NEUTRAL);
        }
    }).positiveText(R.string.apply).onPositive(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            LabelsDialogFragment.this.onClick(dialog, BUTTON_POSITIVE);
        }
    }).title(getTitle()).content(getMessage()).customView(view, false).build();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Bundle(android.os.Bundle) Label(com.meisolsson.githubsdk.model.Label) ArrayList(java.util.ArrayList) BaseActivity(com.github.pockethub.android.ui.BaseActivity) Activity(android.app.Activity) ListView(android.widget.ListView) DialogAction(com.afollestad.materialdialogs.DialogAction) LayoutInflater(android.view.LayoutInflater)

Example 9 with Label

use of com.meisolsson.githubsdk.model.Label in project PocketHub by pockethub.

the class IssueFilter method toFilterMap.

/**
     * Create a map of all the request parameters represented by this filter
     *
     * @return non-null map of filter request parameters
     */
public Map<String, Object> toFilterMap() {
    final Map<String, Object> filter = new HashMap<>();
    filter.put(FIELD_SORT, SORT_CREATED);
    filter.put(FIELD_DIRECTION, DIRECTION_DESCENDING);
    if (assignee != null) {
        filter.put(FILTER_ASSIGNEE, assignee.login());
    }
    if (milestone != null) {
        filter.put(FILTER_MILESTONE, Integer.toString(milestone.number()));
    }
    if (labels != null && !labels.isEmpty()) {
        StringBuilder labelsQuery = new StringBuilder();
        for (Label label : labels) {
            labelsQuery.append(label.name()).append(',');
        }
        filter.put(FILTER_LABELS, labelsQuery.toString());
    }
    if (open) {
        filter.put(FILTER_STATE, STATE_OPEN);
    } else {
        filter.put(FILTER_STATE, STATE_CLOSED);
    }
    return filter;
}
Also used : HashMap(java.util.HashMap) Label(com.meisolsson.githubsdk.model.Label)

Example 10 with Label

use of com.meisolsson.githubsdk.model.Label in project PocketHub by pockethub.

the class IssueFragment method onDialogResult.

@Override
public void onDialogResult(int requestCode, int resultCode, Bundle arguments) {
    if (RESULT_OK != resultCode) {
        return;
    }
    switch(requestCode) {
        case ISSUE_MILESTONE_UPDATE:
            milestoneTask.edit(MilestoneDialogFragment.getSelected(arguments));
            break;
        case ISSUE_ASSIGNEE_UPDATE:
            assigneeTask.edit(AssigneeDialogFragment.getSelected(arguments));
            break;
        case ISSUE_LABELS_UPDATE:
            ArrayList<Label> labels = LabelsDialogFragment.getSelected(arguments);
            if (labels != null && !labels.isEmpty()) {
                labelsTask.edit(labels.toArray(new Label[labels.size()]));
            } else {
                labelsTask.edit(null);
            }
            break;
        case ISSUE_CLOSE:
            stateTask.edit(true);
            break;
        case ISSUE_REOPEN:
            stateTask.edit(false);
            break;
        case COMMENT_DELETE:
            final GitHubComment comment = arguments.getParcelable(EXTRA_COMMENT);
            ServiceGenerator.createService(getActivity(), IssueCommentService.class).deleteIssueComment(repositoryId.owner().login(), repositoryId.name(), comment.id()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).compose(this.<Response<Boolean>>bindToLifecycle()).subscribe(new ProgressObserverAdapter<Response<Boolean>>(getActivity(), R.string.deleting_comment) {

                @Override
                public void onSuccess(Response<Boolean> response) {
                    if (items != null) {
                        int commentPosition = findCommentPositionInItems(comment);
                        if (commentPosition >= 0) {
                            issue = issue.toBuilder().comments(issue.comments() - 1).build();
                            items.remove(commentPosition);
                            updateList(issue, items);
                        }
                    } else {
                        refreshIssue();
                    }
                    dismissProgress();
                }

                @Override
                public void onError(Throwable e) {
                    Log.d(TAG, "Exception deleting comment on issue", e);
                    ToastUtils.show(getActivity(), e.getMessage());
                    dismissProgress();
                }
            }.start());
            break;
    }
}
Also used : Response(retrofit2.Response) IssueCommentService(com.meisolsson.githubsdk.service.issues.IssueCommentService) ProgressObserverAdapter(com.github.pockethub.android.rx.ProgressObserverAdapter) Label(com.meisolsson.githubsdk.model.Label) GitHubComment(com.meisolsson.githubsdk.model.GitHubComment)

Aggregations

Label (com.meisolsson.githubsdk.model.Label)12 ArrayList (java.util.ArrayList)7 ProgressObserverAdapter (com.github.pockethub.android.rx.ProgressObserverAdapter)3 Milestone (com.meisolsson.githubsdk.model.Milestone)3 User (com.meisolsson.githubsdk.model.User)3 Bundle (android.os.Bundle)2 TextView (android.widget.TextView)2 IssueRequest (com.meisolsson.githubsdk.model.request.issue.IssueRequest)2 Activity (android.app.Activity)1 Intent (android.content.Intent)1 LayoutInflater (android.view.LayoutInflater)1 ListView (android.widget.ListView)1 DialogAction (com.afollestad.materialdialogs.DialogAction)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 BaseActivity (com.github.pockethub.android.ui.BaseActivity)1 StyledText (com.github.pockethub.android.ui.StyledText)1 GitHubComment (com.meisolsson.githubsdk.model.GitHubComment)1 Issue (com.meisolsson.githubsdk.model.Issue)1 Page (com.meisolsson.githubsdk.model.Page)1 IssueCommentService (com.meisolsson.githubsdk.service.issues.IssueCommentService)1