<commit_before>package justaway.signinwithtwitter;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;

import twitter4j.MediaEntity;
import twitter4j.Status;
import twitter4j.User;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.support.v4.util.LruCache;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

public class TwitterAdapter extends ArrayAdapter<Row> {
    private Context context;
    private ArrayList<Row> statuses = new ArrayList<Row>();
    private LayoutInflater inflater;
    private int layout;
    private LruCache<String, Bitmap> mMemoryCache;

    public TwitterAdapter(Context context, int textViewResourceId) {
        super(context, textViewResourceId);
        this.inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.context = context;
        this.layout = textViewResourceId;

        // Get max available VM memory, exceeding this amount will throw an
        // OutOfMemory exception. Stored in kilobytes as LruCache takes an
        // int in its constructor.
        final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);

        // Use 1/8th of the available memory for this memory cache.
        final int cacheSize = maxMemory / 2;

        mMemoryCache = new LruCache<String, Bitmap>(cacheSize) {
            @SuppressLint("NewApi")
            @Override
            protected int sizeOf(String key, Bitmap bitmap) {
                // The cache size will be measured in kilobytes rather than
                // number of items.
                return bitmap.getByteCount() / 1024;
            }
        };
    }

    @Override
    public void add(Row row) {
        super.add(row);
        this.statuses.add(row);
    }

    @Override
    public void insert(Row row, int index) {
        super.insert(row, index);
        this.statuses.add(index, row);
    }

    @Override
    public void clear() {
        super.clear();
        this.statuses.clear();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // ビューを受け取る
        View view = convertView;
        if (view == null) {
            // 受け取ったビューがnullなら新しくビューを生成
            view = inflater.inflate(this.layout, null);
        }

        // 表示すべきデータの取得
        Row row = (Row) statuses.get(position);
        Status status = row.getStatus();
        if (status == null) {
            return view;
        }

        Status retweet = status.getRetweetedStatus();
        if (row.isFavorite()) {
            renderStatus(view, status, null, row.getSource());
        } else if (retweet == null) {
            renderStatus(view, status, null, null);
        } else {
            renderStatus(view, retweet, status, null);
        }

        if (position == 0) {
            ((MainActivity) context).showTopView();
        }

        return view;
    }

    private void renderStatus(View view, Status status, Status retweet,
            User favorite) {
        ((TextView) view.findViewById(R.id.display_name)).setText(status
                .getUser().getName());
        ((TextView) view.findViewById(R.id.screen_name)).setText("@"
                + status.getUser().getScreenName());
        ((TextView) view.findViewById(R.id.status)).setText(status.getText());
        ((TextView) view.findViewById(R.id.datetime)).setText(status
                .getCreatedAt().toString());
        ((TextView) view.findViewById(R.id.via)).setText("via "
                + getClientName(status.getSource()));

        // favの場合
        if (favorite != null) {
            ((TextView) view.findViewById(R.id.retweet_by))
                    .setText("favorited by " + favorite.getScreenName()
                            + "(" + favorite.getName() + ")");
            ImageView icon = (ImageView) view.findViewById(R.id.retweet_icon);
            ProgressBar wait = (ProgressBar) view
                    .findViewById(R.id.retweet_wait);
            renderIcon(wait, icon, favorite.getMiniProfileImageURL());
            view.findViewById(R.id.retweet).setVisibility(View.VISIBLE);
        }
        // RTの場合
        else if (retweet != null) {
            ((TextView) view.findViewById(R.id.retweet_by))
                    .setText("retweeted by " + retweet.getUser().getScreenName()
                            + "(" + retweet.getUser().getName() + ") and "
                            + String.valueOf(status.getRetweetCount())
                            + " others");
            ImageView icon = (ImageView) view.findViewById(R.id.retweet_icon);
            ProgressBar wait = (ProgressBar) view
                    .findViewById(R.id.retweet_wait);
            renderIcon(wait, icon, retweet.getUser().getMiniProfileImageURL());
            view.findViewById(R.id.retweet).setVisibility(View.VISIBLE);
        } else {
            view.findViewById(R.id.retweet).setVisibility(View.GONE);
        }

        ImageView icon = (ImageView) view.findViewById(R.id.icon);
        ProgressBar wait = (ProgressBar) view.findViewById(R.id.WaitBar);
        renderIcon(wait, icon, status.getUser().getBiggerProfileImageURL());
        icon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO: UserProfileActivityへ
                System.out.println("icon touch!");
            }
        });

        MediaEntity[] medias = retweet != null ? retweet.getMediaEntities()
                : status.getMediaEntities();
        LinearLayout images = (LinearLayout) view.findViewById(R.id.images);
        images.removeAllViews();
        if (medias.length > 0) {
            for (MediaEntity url : medias) {<commit_msg>Guy to change the format of the date.<commit_after>package justaway.signinwithtwitter;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Locale;

import twitter4j.MediaEntity;
import twitter4j.Status;
import twitter4j.User;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.support.v4.util.LruCache;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

public class TwitterAdapter extends ArrayAdapter<Row> {
    private Context context;
    private ArrayList<Row> statuses = new ArrayList<Row>();
    private LayoutInflater inflater;
    private int layout;
    private LruCache<String, Bitmap> mMemoryCache;

    public TwitterAdapter(Context context, int textViewResourceId) {
        super(context, textViewResourceId);
        this.inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.context = context;
        this.layout = textViewResourceId;

        // Get max available VM memory, exceeding this amount will throw an
        // OutOfMemory exception. Stored in kilobytes as LruCache takes an
        // int in its constructor.
        final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);

        // Use 1/8th of the available memory for this memory cache.
        final int cacheSize = maxMemory / 2;

        mMemoryCache = new LruCache<String, Bitmap>(cacheSize) {
            @SuppressLint("NewApi")
            @Override
            protected int sizeOf(String key, Bitmap bitmap) {
                // The cache size will be measured in kilobytes rather than
                // number of items.
                return bitmap.getByteCount() / 1024;
            }
        };
    }

    @Override
    public void add(Row row) {
        super.add(row);
        this.statuses.add(row);
    }

    @Override
    public void insert(Row row, int index) {
        super.insert(row, index);
        this.statuses.add(index, row);
    }

    @Override
    public void clear() {
        super.clear();
        this.statuses.clear();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // ビューを受け取る
        View view = convertView;
        if (view == null) {
            // 受け取ったビューがnullなら新しくビューを生成
            view = inflater.inflate(this.layout, null);
        }

        // 表示すべきデータの取得
        Row row = (Row) statuses.get(position);
        Status status = row.getStatus();
        if (status == null) {
            return view;
        }

        Status retweet = status.getRetweetedStatus();
        if (row.isFavorite()) {
            renderStatus(view, status, null, row.getSource());
        } else if (retweet == null) {
            renderStatus(view, status, null, null);
        } else {
            renderStatus(view, retweet, status, null);
        }

        if (position == 0) {
            ((MainActivity) context).showTopView();
        }

        return view;
    }

    private void renderStatus(View view, Status status, Status retweet,
            User favorite) {
        ((TextView) view.findViewById(R.id.display_name)).setText(status
                .getUser().getName());
        ((TextView) view.findViewById(R.id.screen_name)).setText("@"
                + status.getUser().getScreenName());
        ((TextView) view.findViewById(R.id.status)).setText(status.getText());
        SimpleDateFormat date_format = new SimpleDateFormat(
                "MM'/'dd' 'hh':'mm':'ss", Locale.ENGLISH);
        ((TextView) view.findViewById(R.id.datetime)).setText(date_format
                .format(status.getCreatedAt()));
        ((TextView) view.findViewById(R.id.via)).setText("via "
                + getClientName(status.getSource()));

        // favの場合
        if (favorite != null) {
            ((TextView) view.findViewById(R.id.retweet_by))
                    .setText("favorited by " + favorite.getScreenName() + "("
                            + favorite.getName() + ")");
            ImageView icon = (ImageView) view.findViewById(R.id.retweet_icon);
            ProgressBar wait = (ProgressBar) view
                    .findViewById(R.id.retweet_wait);
            renderIcon(wait, icon, favorite.getMiniProfileImageURL());
            view.findViewById(R.id.retweet).setVisibility(View.VISIBLE);
        }
        // RTの場合
        else if (retweet != null) {
            ((TextView) view.findViewById(R.id.retweet_by))
                    .setText("retweeted by "
                            + retweet.getUser().getScreenName() + "("
                            + retweet.getUser().getName() + ") and "
                            + String.valueOf(status.getRetweetCount())
                            + " others");
            ImageView icon = (ImageView) view.findViewById(R.id.retweet_icon);
            ProgressBar wait = (ProgressBar) view
                    .findViewById(R.id.retweet_wait);
            renderIcon(wait, icon, retweet.getUser().getMiniProfileImageURL());
            view.findViewById(R.id.retweet).setVisibility(View.VISIBLE);
        } else {
            view.findViewById(R.id.retweet).setVisibility(View.GONE);
        }

        ImageView icon = (ImageView) view.findViewById(R.id.icon);
        ProgressBar wait = (ProgressBar) view.findViewById(R.id.WaitBar);
        renderIcon(wait, icon, status.getUser().getBiggerProfileImageURL());
        icon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO: UserProfileActivityへ
                System.out.println("icon touch!");
            }
        });

        MediaEntity[] medias = retweet != null ? retweet.getMediaEntities()
                : status.getMediaEntities();
        LinearLayout images = (LinearLayout) view.findViewById(R.id.images);
        images.removeAllViews();
        if (medias.length > 0) {
            for (MediaEntity url : medias) {
{'fraction_non_alphanumeric': 0.11260651429481564, 'fraction_numerical': 0.0027076531018555387, 'mean_word_length': 2.239102398761929, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3220583', 'n_tokens_mistral': 3539, 'n_tokens_neox': 3366, 'n_words': 736}