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);
}
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);
}
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();
}
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;
}
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;
}
}
Aggregations