Skip to content

Commit

Permalink
EditMilestone Task
Browse files Browse the repository at this point in the history
  • Loading branch information
tsnik committed Dec 17, 2017
1 parent 97ef560 commit f789379
Showing 1 changed file with 81 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright 2012 GitHub Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.mobile.core.milestone;

import android.accounts.Account;
import android.app.Activity;
import android.util.Log;

import com.github.mobile.R;
import com.github.mobile.api.model.Milestone;
import com.github.mobile.api.service.MilestoneService;
import com.github.mobile.ui.ProgressDialogTask;
import com.github.mobile.util.ToastUtils;
import com.google.inject.Inject;

public class EditMilestoneTask extends ProgressDialogTask<Milestone> {
private static final String TAG = "CreateMilestoneTask";

@Inject
private MilestoneService service;

private final String owner;
private final String repo;
private final Milestone milestone;

/**
* Create task to create an {@link Milestone}
*
* @param activity
* @param owner
* @param repo
* @param milestone
*/
public EditMilestoneTask(final Activity activity,
final String owner,
final String repo,
final Milestone milestone) {
super(activity);
this.owner = owner;
this.repo = repo;
this.milestone = milestone;
}

/**
* Create milestone
*
* @return this task
*/
public EditMilestoneTask create() {
showIndeterminate(R.string.updating_milestone);

execute();
return this;
}

@Override
public Milestone run(Account account) throws Exception {
return service.editMilestone(owner, repo, milestone.number, milestone).execute().body();
}

@Override
protected void onException(Exception e) throws RuntimeException {
super.onException(e);

Log.e(TAG, "Exception editing milestone", e);
ToastUtils.show((Activity) getContext(), e.getMessage());
}
}

0 comments on commit f789379

Please sign in to comment.