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

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

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

import org.eclipse.egit.github.core.Gist;
import org.eclipse.egit.github.core.client.GitHubClient;
import org.eclipse.egit.github.core.service.GistService;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import java.io.IOException;

public class SingleGist extends BaseActivity {
    private String mGistId;

    private String mGistOwner;

    private String mGistDescription;

    private String mGistUpdatedDate;

    private String mGistCreatedDate;

    private String mGistURL;

    private int mGistFileCount;

    private LoadGistTask mTask;

    protected JSONObject buildListItem(final String title, final String content)
            throws JSONException {
        return new JSONObject().put("title", title).put("content", content);
    }

    protected void buildUI()
    {
        final JSONArray listItems = new JSONArray();
        try {
            if (!mGistOwner.equals(""))
                listItems.put(buildListItem("Owner", mGistOwner));
            if (!mGistDescription.equals(""))
                listItems.put(buildListItem("Description", mGistDescription));
            if (!mGistURL.equals(""))
                listItems.put(buildListItem("Gist URL", mGistURL));
            if (!mGistUpdatedDate.equals(""))
                listItems.put(buildListItem("Last Updated", mGistUpdatedDate));
            if (!mGistCreatedDate.equals(""))
                listItems.put(buildListItem("Created On", mGistCreatedDate));
            listItems.put(buildListItem("Files", String.valueOf(mGistFileCount)));
        } catch (JSONException e) {
            e.printStackTrace();
        }

        final ListView infoList = (ListView) findViewById(R.id.lv_gist_info);
        final SingleGistInfoListAdapter adapter = new SingleGistInfoListAdapter(this, infoList);
        adapter.loadData(listItems);
        adapter.pushData();
        infoList.setAdapter(adapter);

        infoList.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(final AdapterView<?> parent, final View v,
                    final int position, final long id) {
                try {
                    final String title = ((JSONObject) listItems.get(position))
                            .getString("title");
                    final String content = ((JSONObject) listItems.get(position))
                            .getString("content");
                    final Intent intent;

                    if (title.equals("Owner")) {
                        intent = new Intent(SingleGist.this, Profile.class);
                        intent.putExtra("username", content);
                    } else if (title.equals("Gist URL")) {
                        intent = new Intent("android.intent.action.VIEW", Uri.parse(mGistURL));
                    } else if (title.equals("Files")) {
                        intent = new Intent(SingleGist.this, GistFilesList.class);
                        intent.putExtra("gistId", mGistId);
                    } else {
                        intent = null;
                    }
                    if (intent != null) {
                        startActivity(intent);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    private static class LoadGistTask extends AsyncTask<Void, Void, Boolean>
    {
        public SingleGist activity;

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            activity.getActionBar().setProgressBarVisibility(View.VISIBLE);
        }

        protected Boolean doInBackground(Void... params) {
            GitHubClient client = new GitHubClient();
            GistService gs = new GistService(client);

            try {
                Gist g = gs.getGist(activity.mGistId); 
                activity.mGistOwner = g.getUser().getLogin();
                activity.mGistDescription = g.getDescription();
                activity.mGistUpdatedDate = g.getUpdatedAt().toString();
                activity.mGistCreatedDate = g.getCreatedAt().toString();
                activity.mGistURL = g.getHtmlUrl();
                activity.mGistFileCount = g.getFiles().size();
            } catch (IOException e) {
                e.printStackTrace();
                return false;
            }

            return true;
        }

        @Override
        protected void onPostExecute(Boolean result) {
            if (result) {<commit_msg>Use GitHubClient instance managed by the activity<commit_after>/**
 * Hubroid - A GitHub app for Android
 *
 * Copyright (c) 2011 <NAME>.
 *
 * Licensed under the New BSD License.
 */

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

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

import org.eclipse.egit.github.core.Gist;
import org.eclipse.egit.github.core.client.GitHubClient;
import org.eclipse.egit.github.core.service.GistService;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import java.io.IOException;

public class SingleGist extends BaseActivity {
    private String mGistId;

    private String mGistOwner;

    private String mGistDescription;

    private String mGistUpdatedDate;

    private String mGistCreatedDate;

    private String mGistURL;

    private int mGistFileCount;

    private LoadGistTask mTask;

    protected JSONObject buildListItem(final String title, final String content)
            throws JSONException {
        return new JSONObject().put("title", title).put("content", content);
    }

    protected void buildUI()
    {
        final JSONArray listItems = new JSONArray();
        try {
            if (!mGistOwner.equals(""))
                listItems.put(buildListItem("Owner", mGistOwner));
            if (!mGistDescription.equals(""))
                listItems.put(buildListItem("Description", mGistDescription));
            if (!mGistURL.equals(""))
                listItems.put(buildListItem("Gist URL", mGistURL));
            if (!mGistUpdatedDate.equals(""))
                listItems.put(buildListItem("Last Updated", mGistUpdatedDate));
            if (!mGistCreatedDate.equals(""))
                listItems.put(buildListItem("Created On", mGistCreatedDate));
            listItems.put(buildListItem("Files", String.valueOf(mGistFileCount)));
        } catch (JSONException e) {
            e.printStackTrace();
        }

        final ListView infoList = (ListView) findViewById(R.id.lv_gist_info);
        final SingleGistInfoListAdapter adapter = new SingleGistInfoListAdapter(this, infoList);
        adapter.loadData(listItems);
        adapter.pushData();
        infoList.setAdapter(adapter);

        infoList.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(final AdapterView<?> parent, final View v,
                    final int position, final long id) {
                try {
                    final String title = ((JSONObject) listItems.get(position))
                            .getString("title");
                    final String content = ((JSONObject) listItems.get(position))
                            .getString("content");
                    final Intent intent;

                    if (title.equals("Owner")) {
                        intent = new Intent(SingleGist.this, Profile.class);
                        intent.putExtra("username", content);
                    } else if (title.equals("Gist URL")) {
                        intent = new Intent("android.intent.action.VIEW", Uri.parse(mGistURL));
                    } else if (title.equals("Files")) {
                        intent = new Intent(SingleGist.this, GistFilesList.class);
                        intent.putExtra("gistId", mGistId);
                    } else {
                        intent = null;
                    }
                    if (intent != null) {
                        startActivity(intent);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    private static class LoadGistTask extends AsyncTask<Void, Void, Boolean>
    {
        public SingleGist activity;

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            activity.getActionBar().setProgressBarVisibility(View.VISIBLE);
        }

        protected Boolean doInBackground(Void... params) {
            GistService gs = new GistService(activity.getGitHubClient());

            try {
                Gist g = gs.getGist(activity.mGistId); 
                activity.mGistOwner = g.getUser().getLogin();
                activity.mGistDescription = g.getDescription();
                activity.mGistUpdatedDate = g.getUpdatedAt().toString();
                activity.mGistCreatedDate = g.getCreatedAt().toString();
                activity.mGistURL = g.getHtmlUrl();
                activity.mGistFileCount = g.getFiles().size();
            } catch (IOException e) {
                e.printStackTrace();
                return false;
            }

            return true;
        }

        @Override
        protected void onPostExecute(Boolean result) {
            if (result) {
{'fraction_non_alphanumeric': 0.10073686251696723, 'fraction_numerical': 0.0007756447547023463, 'mean_word_length': 2.0581085087459234, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '137627', 'n_tokens_mistral': 2737, 'n_tokens_neox': 2603, 'n_words': 564}