
package net.idlesoft.android.apps.github.activities;

import android.content.Intent;
import android.os.Bundle;

public class GitHubIntentFilter extends BaseActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        final String uri = getIntent().getDataString();
        final String[] parts = uri.split("/");
        final Intent intent = new Intent();

        if (parts[2].equalsIgnoreCase("github.com")) {
            if (parts.length <= 3) {
                /* User only meant to go to github.com */
            } else {
                if (parts[3].equalsIgnoreCase("blog") || parts[3].equalsIgnoreCase("explore")
                        || parts[3].equalsIgnoreCase("languages")
                        || parts[3].equalsIgnoreCase("timeline")
                        || parts[3].equalsIgnoreCase("login") || parts[3].equalsIgnoreCase("inbox")
                        || parts[3].equalsIgnoreCase("repositories")) {
                    /* do nothing */
                } else if (parts[3].equalsIgnoreCase("search")) {
                    intent.setClass(getApplicationContext(), Search.class);
                    startActivity(intent);
                } else if (parts.length == 4) {
                    intent.setClass(getApplicationContext(), Profile.class);
                    intent.putExtra("username", parts[3]);
                    startActivity(intent);
                } else if (parts.length == 5) {
                    intent.setClass(getApplicationContext(), SingleRepository.class);
                    intent.putExtra("repo_owner", parts[3]);
                    intent.putExtra("repo_name", parts[4]);
                    startActivity(intent);
                } else if (parts.length >= 6) {
                    if (parts[5].equalsIgnoreCase("issues")) {
                        intent.setClass(getApplicationContext(), Issues.class);
                        intent.putExtra("repo_owner", parts[3]);
                        intent.putExtra("repo_name", parts[4]);
                        if (parts.length > 6 && parts[6] != null) {
                            intent.setClass(getApplicationContext(), SingleIssue.class);
                            intent.putExtra("number", Integer.parseInt(parts[6]));
                        }
                        startActivity(intent);
                    } else if (parts[5].equalsIgnoreCase("network")) {
                        intent.setClass(getApplicationContext(), NetworkList.class);
                        intent.putExtra("repo_owner", parts[3]);
                        intent.putExtra("repo_name", parts[4]);
                        startActivity(intent);
                    } else if (parts[5].equalsIgnoreCase("commits")) {
                        if (parts.length > 6 && parts[6] != null) {
                            intent.setClass(getApplicationContext(), CommitsList.class);
                            intent.putExtra("repo_owner", parts[3]);
                            intent.putExtra("repo_name", parts[4]);
                            intent.putExtra("branch_name", parts[6]);
                            startActivity(intent);
                        }
                    } else if (parts[5].equalsIgnoreCase("commit")) {
                        if (parts.length > 6 && parts[6] != null) {
                            intent.setClass(getApplicationContext(), SingleCommit.class);
                            intent.putExtra("repo_owner", parts[3]);
                            intent.putExtra("repo_name", parts[4]);
                            intent.putExtra("commit_sha", parts[6]);
                            startActivity(intent);
                        }
                    } else if (parts[5].equalsIgnoreCase("branches")) {
                        intent.setClass(getApplicationContext(), BranchesList.class);
                        intent.putExtra("repo_owner", parts[3]);
                        intent.putExtra("repo_name", parts[4]);
                        startActivity(intent);
                    }
                }
            }
        } else if (parts[2].equalsIgnoreCase("gist.github.com")) {
            if (parts.length == 4) {
                intent.setClass(getApplicationContext(), SingleGist.class);
                intent.putExtra("gistId", parts[3]);
                startActivity(intent);
            }
        }
        finish();
    }
}

@@ -2249,33 +2249,259 @@
     
-intent.putExtra(%22n
+final int issueNumber;%0A                            if (parts%5B6%5D.contains(%22#%22)) %7B%0A                                issueNumber = Integer.parseInt(parts%5B6%5D.split(%22#%22)%5B0%5D);%0A                            %7D else %7B%0A                                issueN
 umber
-%22,
+ =
  Int
@@ -2523,16 +2523,113 @@
 arts%5B6%5D)
+;%0A                            %7D%0A                            intent.putExtra(%22number%22, issueNumber
 );%0A     

Fix crash when trying to process certain GitHub issue URLs