@Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Bundle args = getArguments();
    repositoryId =
        RepositoryId.create(
            args.getString(EXTRA_REPOSITORY_OWNER), args.getString(EXTRA_REPOSITORY_NAME));
    issueNumber = args.getInt(EXTRA_ISSUE_NUMBER);
    user = (User) args.getSerializable(EXTRA_USER);
    isCollaborator = args.getBoolean(EXTRA_IS_COLLABORATOR, false);

    DialogFragmentActivity dialogActivity = (DialogFragmentActivity) getActivity();

    milestoneTask =
        new EditMilestoneTask(dialogActivity, repositoryId, issueNumber) {

          @Override
          protected void onSuccess(Issue editedIssue) throws Exception {
            super.onSuccess(editedIssue);

            updateHeader(editedIssue);
          }
        };

    assigneeTask =
        new EditAssigneeTask(dialogActivity, repositoryId, issueNumber) {

          @Override
          protected void onSuccess(Issue editedIssue) throws Exception {
            super.onSuccess(editedIssue);

            updateHeader(editedIssue);
          }
        };

    labelsTask =
        new EditLabelsTask(dialogActivity, repositoryId, issueNumber) {

          @Override
          protected void onSuccess(Issue editedIssue) throws Exception {
            super.onSuccess(editedIssue);

            updateHeader(editedIssue);
          }
        };

    stateTask =
        new EditStateTask(dialogActivity, repositoryId, issueNumber) {

          @Override
          protected void onSuccess(Issue editedIssue) throws Exception {
            super.onSuccess(editedIssue);

            updateHeader(editedIssue);
          }
        };
  }
Esempio n. 2
0
  public static RepositoryId parseRepositoryFromUrl(String repositoryUrl) {
    String prefix = "*****@*****.**";

    if (repositoryUrl.startsWith(prefix)) {
      String[] parts = repositoryUrl.split(":");

      parts = parts[1].split("/");

      String owner = parts[0];
      String name = parts[1];
      if (name.endsWith(".git")) {
        name = name.replace(".git", "");
      }
      return RepositoryId.create(owner, name);
    }

    return RepositoryId.createFromUrl(repositoryUrl);
  }
  /**
   * Request an image using the contents API if the source URI is a path to a file already in the
   * repository
   *
   * @param source
   * @return
   * @throws IOException
   */
  private Drawable requestRepositoryImage(final String source) throws IOException {
    if (TextUtils.isEmpty(source)) return null;

    Uri uri = Uri.parse(source);
    if (!HOST_DEFAULT.equals(uri.getHost())) return null;

    List<String> segments = uri.getPathSegments();
    if (segments.size() < 5) return null;

    String prefix = segments.get(2);
    // Two types of urls supported:
    // github.com/github/android/raw/master/app/res/drawable-xhdpi/app_icon.png
    // github.com/github/android/blob/master/app/res/drawable-xhdpi/app_icon.png?raw=true
    if (!("raw".equals(prefix)
        || ("blob".equals(prefix) && !TextUtils.isEmpty(uri.getQueryParameter("raw")))))
      return null;

    String owner = segments.get(0);
    if (TextUtils.isEmpty(owner)) return null;
    String name = segments.get(1);
    if (TextUtils.isEmpty(name)) return null;
    String branch = segments.get(3);
    if (TextUtils.isEmpty(branch)) return null;

    StringBuilder path = new StringBuilder(segments.get(4));
    for (int i = 5; i < segments.size(); i++) {
      String segment = segments.get(i);
      if (!TextUtils.isEmpty(segment)) path.append('/').append(segment);
    }

    if (TextUtils.isEmpty(path)) return null;

    List<RepositoryContents> contents =
        service.getContents(RepositoryId.create(owner, name), path.toString(), branch);
    if (contents != null && contents.size() == 1) {
      byte[] content = Base64.decode(contents.get(0).getContent(), DEFAULT);
      Bitmap bitmap = ImageUtils.getBitmap(content, width, MAX_VALUE);
      if (bitmap == null) return loading.getDrawable(source);
      BitmapDrawable drawable = new BitmapDrawable(context.getResources(), bitmap);
      drawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
      return drawable;
    } else return null;
  }
Esempio n. 4
0
 /**
  * Resolve the {@link RepositoryId} referenced by the given intent
  *
  * @param intent
  * @return repository id
  */
 public static RepositoryId repoFrom(Intent intent) {
   String repoName = intent.getStringExtra(EXTRA_REPOSITORY_NAME);
   String repoOwner = intent.getStringExtra(EXTRA_REPOSITORY_OWNER);
   return RepositoryId.create(repoOwner, repoName);
 }
Esempio n. 5
0
  public static boolean repositoryExists(
      RepositoryService repositoryService, String user, String repositoryName) throws IOException {
    RepositoryId repositoryId = RepositoryId.create(user, repositoryName);

    return repositoryExists(repositoryService, repositoryId);
  }