Skip to content

Commit

Permalink
CreateMilestoneTask
Browse files Browse the repository at this point in the history
  • Loading branch information
tsnik committed Dec 17, 2017
1 parent 1d4b946 commit 97ef560
Show file tree
Hide file tree
Showing 2 changed files with 82 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 CreateMilestoneTask 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 CreateMilestoneTask(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 CreateMilestoneTask create() {
showIndeterminate(R.string.creating_milestone);

execute();
return this;
}

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

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

Log.e(TAG, "Exception creating milestone", e);
ToastUtils.show((Activity) getContext(), e.getMessage());
}
}
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@
<string name="reopening_issue">Reopening Issue…</string>
<string name="avatar">Avatar</string>
<string name="creating_issue">Creating Issue…</string>
<string name="creating_milestone">Creating Milestone…</string>
<string name="prefix_created">created\u0020</string>
<string name="prefix_updated">updated\u0020</string>
<string name="prefix_opened">opened\u0020</string>
Expand Down

0 comments on commit 97ef560

Please sign in to comment.