<commit_before>/**
 * Hubroid - A GitHub app for Android
 * 
 * Copyright (c) 2011 Idlesoft LLC.
 * 
 * Licensed under the New BSD License.
 */

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

import com.flurry.android.FlurryAgent;

import net.idlesoft.android.apps.github.R;

import org.idlesoft.libraries.ghapi.GitHubAPI;
import org.idlesoft.libraries.ghapi.APIAbstract.Response;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;

import java.io.File;

public class Repository extends Activity {
    private GitHubAPI mGapi = new GitHubAPI();

    private SharedPreferences.Editor mEditor;

    public Intent mIntent;

    private boolean mIsWatching;

    public JSONObject mJson;

    private String mPassword;

    private SharedPreferences mPrefs;

    public ProgressDialog mProgressDialog;

    private String mRepositoryName;

    private String mRepositoryOwner;

    private String mUsername;

    private LoadRepositoryTask mLoadRepositoryTask;

    private static class LoadRepositoryTask extends AsyncTask<Void, Void, Void> {
        public Repository activity;

        protected void onPreExecute() {
            activity.findViewById(R.id.sv_repository_scrollView).setVisibility(View.GONE);
        }

        protected Void doInBackground(Void... params) {
            try {
                Response resp = activity.mGapi.repo.info(activity.mRepositoryOwner, activity.mRepositoryName);
                if (resp.statusCode == 200) {
                    activity.mJson = new JSONObject(resp.resp).getJSONObject("repository");
    
                    final JSONArray watched_list = new JSONObject(activity.mGapi.user.watching(activity.mUsername).resp)
                            .getJSONArray("repositories");
                    final int length = watched_list.length() - 1;
                    for (int i = 0; i <= length; i++) {
                        if (watched_list.getJSONObject(i).getString("name").equalsIgnoreCase(
                                activity.mRepositoryName)) {
                            activity.mIsWatching = true;
                        }
                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
            return null;
        }

        protected void onPostExecute(Void result) {
            activity.loadRepoInfo();
            activity.findViewById(R.id.sv_repository_scrollView).setVisibility(View.VISIBLE);
        }

    }

    public void loadRepoInfo() {
        try {
            // TextView title =
            // (TextView)findViewById(R.id.tv_top_bar_title);
            // title.setText(m_jsonData.getString("name"));
            final TextView repo_name = (TextView) findViewById(R.id.tv_repository_info_name);
            repo_name.setText(mJson.getString("name"));
            repo_name.requestFocus();
            final TextView repo_desc = (TextView) findViewById(R.id.tv_repository_info_description);
            repo_desc.setText(mJson.getString("description"));
            final TextView repo_owner = (TextView) findViewById(R.id.tv_repository_info_owner);
            repo_owner.setText(mJson.getString("owner"));
            final TextView repo_watcher_count = (TextView) findViewById(R.id.tv_repository_info_watchers);
            if (mJson.getInt("watchers") == 1) {
                repo_watcher_count.setText(mJson.getInt("watchers") + " watcher");
            } else {
                repo_watcher_count.setText(mJson.getInt("watchers") + " watchers");
            }
            final TextView repo_fork_count = (TextView) findViewById(R.id.tv_repository_info_forks);
            if (mJson.getInt("forks") == 1) {
                repo_fork_count.setText(mJson.getInt("forks") + " fork");
            } else {
                repo_fork_count.setText(mJson.getInt("forks") + " forks");
            }
            final TextView repo_website = (TextView) findViewById(R.id.tv_repository_info_website);
            if (mJson.getString("homepage") != "") {
                repo_website.setText(mJson.getString("homepage"));
            } else {
                repo_website.setText("N/A");
            }

            /*
             * Let's hold off on putting this in the new version for now...
             * if (m_jsonData.getBoolean("fork") == true) { // Find out what
             * this is a fork of... String forked_user =
             * m_jsonForkData.getJSONObject(0).getString("owner"); String
             * forked_repo =
             * m_jsonForkData.getJSONObject(0).getString("name"); // Show
             * "Fork of:" label, it's value, and the button TextView
             * repo_fork_of_label =
             * (TextView)findViewById(R.id.repository_fork_of_label);
             * repo_fork_of_label.setVisibility(0); TextView repo_fork_of =
             * (TextView)findViewById(R.id.repository_fork_of);
             * repo_fork_of.setText(forked_user + "/" + forked_repo);
             * repo_fork_of.setVisibility(0); Button
             * goto_forked_repository_btn =
             * (Button)findViewById(R.id.goto_forked_repository_btn);
             * goto_forked_repository_btn.setVisibility(0); // Set the
             * onClick listener for the button
             * goto_forked_repository_btn.setOnClickListener
             * (forkedRepo_onClickListener); }
             */
        } catch (final JSONException e) {
            e.printStackTrace();
        }

        ((Button) findViewById(R.id.btn_repository_info_branches))
                .setOnClickListener(new OnClickListener() {
                    public void onClick(final View v) {
                        final Intent intent = new Intent(Repository.this, BranchesList.class);
                        intent.putExtra("repo_name", mRepositoryName);
                        intent.putExtra("repo_owner", mRepositoryOwner);
                        startActivity(intent);
                    }
                });
        ((Button) findViewById(R.id.btn_repository_info_issues))
                .setOnClickListener(new OnClickListener() {
                    public void onClick(final View v) {
                        final Intent intent = new Intent(Repository.this, Issues.class);
                        intent.putExtra("repo_name", mRepositoryName);
                        intent.putExtra("repo_owner", mRepositoryOwner);
                        startActivity(intent);
                    }
                });
        ((Button) findViewById(R.id.btn_repository_info_network))
                .setOnClickListener(new OnClickListener() {
                    public void onClick(final View v) {
                        final Intent intent = new Intent(Repository.this, NetworkList.class);
                        intent.putExtra("repo_name", mRepositoryName);
                        intent.putExtra("username", mRepositoryOwner);
                        startActivity(intent);
                    }
                });
        /*
         * Hold off on this as well... Button user_info_btn =
         * (Button)findViewById(R.id.goto_repo_owner_info_btn);
         * user_info_btn.setOnClickListener(username_onClickListener);
         */
    }

    @Override
    public void onCreate(final Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.repository);

        mPrefs = getSharedPreferences(Hubroid.PREFS_NAME, 0);<commit_msg>Make the repository owner textview link off to that user's profile<commit_after>/**
 * Hubroid - A GitHub app for Android
 * 
 * Copyright (c) 2011 Idlesoft LLC.
 * 
 * Licensed under the New BSD License.
 */

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

import com.flurry.android.FlurryAgent;

import net.idlesoft.android.apps.github.R;

import org.idlesoft.libraries.ghapi.GitHubAPI;
import org.idlesoft.libraries.ghapi.APIAbstract.Response;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.text.Spannable;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;

import java.io.File;

public class Repository extends Activity {
    private GitHubAPI mGapi = new GitHubAPI();

    private SharedPreferences.Editor mEditor;

    public Intent mIntent;

    private boolean mIsWatching;

    public JSONObject mJson;

    private String mPassword;

    private SharedPreferences mPrefs;

    public ProgressDialog mProgressDialog;

    private String mRepositoryName;

    private String mRepositoryOwner;

    private String mUsername;

    private LoadRepositoryTask mLoadRepositoryTask;

    private static class LoadRepositoryTask extends AsyncTask<Void, Void, Void> {
        public Repository activity;

        protected void onPreExecute() {
            activity.findViewById(R.id.sv_repository_scrollView).setVisibility(View.GONE);
        }

        protected Void doInBackground(Void... params) {
            try {
                Response resp = activity.mGapi.repo.info(activity.mRepositoryOwner, activity.mRepositoryName);
                if (resp.statusCode == 200) {
                    activity.mJson = new JSONObject(resp.resp).getJSONObject("repository");
    
                    final JSONArray watched_list = new JSONObject(activity.mGapi.user.watching(activity.mUsername).resp)
                            .getJSONArray("repositories");
                    final int length = watched_list.length() - 1;
                    for (int i = 0; i <= length; i++) {
                        if (watched_list.getJSONObject(i).getString("name").equalsIgnoreCase(
                                activity.mRepositoryName)) {
                            activity.mIsWatching = true;
                        }
                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
            return null;
        }

        protected void onPostExecute(Void result) {
            activity.loadRepoInfo();
            activity.findViewById(R.id.sv_repository_scrollView).setVisibility(View.VISIBLE);
        }

    }

    public void loadRepoInfo() {
        try {
            // TextView title =
            // (TextView)findViewById(R.id.tv_top_bar_title);
            // title.setText(m_jsonData.getString("name"));
            final TextView repo_name = (TextView) findViewById(R.id.tv_repository_info_name);
            repo_name.setText(mJson.getString("name"));
            repo_name.requestFocus();
            final TextView repo_desc = (TextView) findViewById(R.id.tv_repository_info_description);
            repo_desc.setText(mJson.getString("description"));
            final TextView repo_owner = (TextView) findViewById(R.id.tv_repository_info_owner);
            repo_owner.setText(mJson.getString("owner"));
            final TextView repo_watcher_count = (TextView) findViewById(R.id.tv_repository_info_watchers);
            if (mJson.getInt("watchers") == 1) {
                repo_watcher_count.setText(mJson.getInt("watchers") + " watcher");
            } else {
                repo_watcher_count.setText(mJson.getInt("watchers") + " watchers");
            }
            final TextView repo_fork_count = (TextView) findViewById(R.id.tv_repository_info_forks);
            if (mJson.getInt("forks") == 1) {
                repo_fork_count.setText(mJson.getInt("forks") + " fork");
            } else {
                repo_fork_count.setText(mJson.getInt("forks") + " forks");
            }
            final TextView repo_website = (TextView) findViewById(R.id.tv_repository_info_website);
            if (mJson.getString("homepage") != "") {
                repo_website.setText(mJson.getString("homepage"));
            } else {
                repo_website.setText("N/A");
            }

            /* Make the repository owner text link to his/her profile */
            repo_owner.setMovementMethod(LinkMovementMethod.getInstance());
            Spannable spans = (Spannable) repo_owner.getText();
            ClickableSpan clickSpan = new ClickableSpan() {
                public void onClick(View widget) {
                    Intent i = new Intent(Repository.this, Profile.class);
                    try {
                        i.putExtra("username", mJson.getString("owner"));
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    startActivity(i);
                }
            };
            spans.setSpan(clickSpan, 0, spans.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        } catch (final JSONException e) {
            e.printStackTrace();
        }

        ((Button) findViewById(R.id.btn_repository_info_branches))
                .setOnClickListener(new OnClickListener() {
                    public void onClick(final View v) {
                        final Intent intent = new Intent(Repository.this, BranchesList.class);
                        intent.putExtra("repo_name", mRepositoryName);
                        intent.putExtra("repo_owner", mRepositoryOwner);
                        startActivity(intent);
                    }
                });
        ((Button) findViewById(R.id.btn_repository_info_issues))
                .setOnClickListener(new OnClickListener() {
                    public void onClick(final View v) {
                        final Intent intent = new Intent(Repository.this, Issues.class);
                        intent.putExtra("repo_name", mRepositoryName);
                        intent.putExtra("repo_owner", mRepositoryOwner);
                        startActivity(intent);
                    }
                });
        ((Button) findViewById(R.id.btn_repository_info_network))
                .setOnClickListener(new OnClickListener() {
                    public void onClick(final View v) {
                        final Intent intent = new Intent(Repository.this, NetworkList.class);
                        intent.putExtra("repo_name", mRepositoryName);
                        intent.putExtra("username", mRepositoryOwner);
                        startActivity(intent);
                    }
                });
    }

    @Override
    public void onCreate(final Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.repository);

        mPrefs = getSharedPreferences(Hubroid.PREFS_NAME, 0);
{'fraction_non_alphanumeric': 0.09674467250620997, 'fraction_numerical': 0.0019610406589096615, 'mean_word_length': 2.0832325675130994, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5562805', 'n_tokens_mistral': 4094, 'n_tokens_neox': 3839, 'n_words': 747}