Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into bug-date-crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Motoaleks committed Jan 26, 2018
2 parents 2bcf70e + 5f549cc commit aaeb72d
Show file tree
Hide file tree
Showing 9 changed files with 444 additions and 6 deletions.
3 changes: 2 additions & 1 deletion app/src/main/java/com/github/mobile/api/model/Issue.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
*/
package com.github.mobile.api.model;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

public class Issue {
public class Issue implements Serializable {
public long id;

public Repository repository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ Call<Issue> getIssue(
@Path("repo") String repo,
@Path("number") long number);

@Headers("Accept: application/vnd.github.squirrel-girl-preview")
@GET("repos/{owner}/{repo}/issues")
Call<List<Issue>> getIssues(
@Path("owner") String owner,
@Path("repo") String repo,
@Query("milestone") String milestone);

@Headers({"Accept: application/vnd.github.v3.full+json",
"Accept: application/vnd.github.mockingbird-preview",
"Accept: application/vnd.github.squirrel-girl-preview"})
Expand Down
112 changes: 112 additions & 0 deletions app/src/main/java/com/github/mobile/core/milestone/AddIssueTask.java
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public void onClick(View v) {
if (milestone.number > 0)
actionBar.setTitle(milestone.title);
else
actionBar.setTitle(R.string.new_milestone);
actionBar.setTitle(R.string.ms_new_milestone);
actionBar.setSubtitle(repositoryId.generateId());

titleText.addTextChangedListener(new TextWatcherAdapter() {
Expand Down
126 changes: 126 additions & 0 deletions app/src/main/java/com/github/mobile/ui/milestone/IssueDialog.java
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);
}
}
Loading

0 comments on commit aaeb72d

Please sign in to comment.