-
Notifications
You must be signed in to change notification settings - Fork 434
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from AndreySBer/feature-addIssueToMilestone
Add issue to milestone #10
- Loading branch information
Showing
9 changed files
with
444 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
app/src/main/java/com/github/mobile/core/milestone/AddIssueTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* 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 com.github.mobile.R; | ||
import com.github.mobile.api.model.Issue; | ||
import com.github.mobile.api.service.IssueService; | ||
import com.github.mobile.api.service.MilestoneService; | ||
import com.github.mobile.core.issue.IssueStore; | ||
import com.github.mobile.ui.DialogFragmentActivity; | ||
import com.github.mobile.ui.ProgressDialogTask; | ||
import com.github.mobile.ui.milestone.IssueDialog; | ||
import com.google.inject.Inject; | ||
|
||
import org.eclipse.egit.github.core.IRepositoryIdProvider; | ||
import org.eclipse.egit.github.core.Milestone; | ||
|
||
import static com.github.mobile.RequestCodes.ISSUE_MILESTONE_UPDATE; | ||
|
||
/** | ||
* Task to add an issue to a milestone | ||
*/ | ||
public class AddIssueTask extends ProgressDialogTask<com.github.mobile.api.model.Milestone> { | ||
|
||
@Inject | ||
private IssueService service; | ||
|
||
@Inject | ||
private MilestoneService milestoneService; | ||
|
||
@Inject | ||
private IssueStore store; | ||
|
||
private final IssueDialog issueDialog; | ||
|
||
private final IRepositoryIdProvider repositoryId; | ||
|
||
private int issueNumber; | ||
|
||
private final int milestoneNumber; | ||
|
||
/** | ||
* Create task to add an issue to a milestone | ||
* | ||
* @param activity | ||
* @param repositoryId | ||
* @param milestoneNumber | ||
*/ | ||
public AddIssueTask(final DialogFragmentActivity activity, | ||
final IRepositoryIdProvider repositoryId, final int milestoneNumber) { | ||
super(activity); | ||
|
||
this.repositoryId = repositoryId; | ||
this.milestoneNumber = milestoneNumber; | ||
issueDialog = new IssueDialog(activity, ISSUE_MILESTONE_UPDATE, | ||
repositoryId, service); | ||
} | ||
|
||
@Override | ||
protected com.github.mobile.api.model.Milestone run(Account account) throws Exception { | ||
org.eclipse.egit.github.core.Issue editedIssue = new org.eclipse.egit.github.core.Issue(); | ||
editedIssue.setNumber(issueNumber); | ||
editedIssue.setMilestone(new Milestone().setNumber(milestoneNumber)); | ||
store.editIssue(repositoryId, editedIssue); | ||
String[] rep = repositoryId.generateId().split("/"); | ||
return milestoneService.getMilestone(rep[0], rep[1], milestoneNumber).execute().body(); | ||
} | ||
|
||
/** | ||
* Prompt for issue selection | ||
* | ||
* @return this task | ||
*/ | ||
public AddIssueTask prompt() { | ||
issueDialog.show(); | ||
return this; | ||
} | ||
|
||
/** | ||
* Add issue to the milestone | ||
* | ||
* @param issue | ||
* @return this task | ||
*/ | ||
public AddIssueTask edit(Issue issue) { | ||
if (issue != null) | ||
issueNumber = issue.number; | ||
else | ||
issueNumber = -1; | ||
|
||
showIndeterminate(R.string.updating_milestone); | ||
|
||
super.execute(); | ||
|
||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
app/src/main/java/com/github/mobile/ui/milestone/IssueDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* 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.ui.milestone; | ||
|
||
import android.accounts.Account; | ||
import android.util.Log; | ||
|
||
import com.github.mobile.R; | ||
import com.github.mobile.api.model.Issue; | ||
import com.github.mobile.api.service.IssueService; | ||
import com.github.mobile.ui.DialogFragmentActivity; | ||
import com.github.mobile.ui.ProgressDialogTask; | ||
import com.github.mobile.util.ToastUtils; | ||
|
||
import org.eclipse.egit.github.core.IRepositoryIdProvider; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Dialog helper to display a list of issues to select one from | ||
*/ | ||
public class IssueDialog { | ||
|
||
private static final String TAG = "IssueDialog"; | ||
|
||
private IssueService service; | ||
|
||
private ArrayList<Issue> repositoryIssues; | ||
|
||
private final int requestCode; | ||
|
||
private final DialogFragmentActivity activity; | ||
|
||
private final IRepositoryIdProvider repository; | ||
|
||
/** | ||
* Create dialog helper to display issue | ||
* | ||
* @param activity | ||
* @param requestCode | ||
* @param repository | ||
* @param service | ||
*/ | ||
public IssueDialog(final DialogFragmentActivity activity, | ||
final int requestCode, final IRepositoryIdProvider repository, | ||
final IssueService service) { | ||
this.activity = activity; | ||
this.requestCode = requestCode; | ||
this.repository = repository; | ||
this.service = service; | ||
} | ||
|
||
/** | ||
* Get issues | ||
* | ||
* @return list of issues | ||
*/ | ||
public List<Issue> getIssues() { | ||
return repositoryIssues; | ||
} | ||
|
||
private void load() { | ||
new ProgressDialogTask<ArrayList<Issue>>(activity) { | ||
|
||
@Override | ||
public ArrayList<Issue> run(Account account) throws Exception { | ||
ArrayList<Issue> issues = new ArrayList<Issue>(); | ||
String[] repid = repository.generateId().split("/"); | ||
issues.addAll(service.getIssues(repid[0],repid[1], "none").execute().body()); | ||
return issues; | ||
} | ||
|
||
@Override | ||
protected void onSuccess(ArrayList<Issue> all) throws Exception { | ||
super.onSuccess(all); | ||
|
||
repositoryIssues = all; | ||
show(); | ||
} | ||
|
||
@Override | ||
protected void onException(Exception e) throws RuntimeException { | ||
super.onException(e); | ||
|
||
Log.d(TAG, "Exception loading issues", e); | ||
ToastUtils.show(activity, e, R.string.error_issues_load); | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
showIndeterminate(R.string.loading_issues); | ||
|
||
super.execute(); | ||
} | ||
}.execute(); | ||
} | ||
|
||
/** | ||
* Show dialog | ||
* | ||
*/ | ||
public void show() { | ||
if (repositoryIssues == null) { | ||
load(); | ||
return; | ||
} | ||
|
||
IssueDialogFragment.show(activity, requestCode, | ||
activity.getString(R.string.ms_select_issue), null, | ||
repositoryIssues); | ||
} | ||
} |
Oops, something went wrong.