<commit_before>/*
   Copyright 2010 <NAME>

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */

package it.agileday.ui.twitter;

import it.agileday.R;
import it.aglieday.data.Tweet;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

class TweetsAdapter extends BaseAdapter {
	private final List<Tweet> tweets;
	private final Context context;

	public TweetsAdapter(Context context) {
		this.context = context;
		this.tweets = new ArrayList<Tweet>();
		this.tweets.add(null);
	}

	public void addTweets(Collection<Tweet> tweets) {
		this.tweets.addAll(this.tweets.size() - 1, tweets);
		// this.tweets.addAll(tweets);
	}

	public void addLoading() {
		this.tweets.add(null);
	}

	private LayoutInflater getLayoutInflater() {
		return (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return tweets.size();
	}

	@Override
	public Tweet getItem(int position) {
		return tweets.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Tweet tweet = getItem(position);
		return tweet != null ? getTweetView(tweet, convertView, parent) : getLoadingView(convertView, parent);
	}

	private View getLoadingView(View convertView, ViewGroup parent) {
		View ret = convertView;
		if (ret == null || ret.getId() != R.id.items_loading_twitter) {
			ret = getLayoutInflater().inflate(R.layout.items_loading_twitter, parent, false);
		}
		return ret;
	}

	private View getTweetView(Tweet tweet, View convertView, ViewGroup parent) {
		View ret = convertView;
		if (ret == null || ret.getId() != R.id.item_twitter) {
			ret = getLayoutInflater().inflate(R.layout.item_twitter, parent, false);
		}
		TextView text = (TextView) ret.findViewById(R.id.text);
		text.setText(tweet.text);
		ImageView image = (ImageView) ret.findViewById(R.id.image);
		image.setImageBitmap(tweet.profileImage);
		return ret;
	}
}<commit_msg>Added TODOs<commit_after>/*
   Copyright 2010 <NAME>

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */

package it.agileday.ui.twitter;

import it.agileday.R;
import it.aglieday.data.Tweet;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

class TweetsAdapter extends BaseAdapter {
	private final List<Tweet> tweets;
	private final Context context;

	public TweetsAdapter(Context context) {
		this.context = context;
		this.tweets = new ArrayList<Tweet>();
		this.tweets.add(null);
	}

	public void addTweets(Collection<Tweet> tweets) {
		this.tweets.addAll(this.tweets.size() - 1, tweets);
		// this.tweets.addAll(tweets);
	}

	public void addLoading() {
		this.tweets.add(null);
	}

	private LayoutInflater getLayoutInflater() {
		return (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return tweets.size();
	}

	@Override
	public Tweet getItem(int position) {
		return tweets.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Tweet tweet = getItem(position);
		return tweet != null ? getTweetView(tweet, convertView, parent) : getLoadingView(convertView, parent);
	}

	private View getLoadingView(View convertView, ViewGroup parent) {
		View ret = convertView;
		if (ret == null || ret.getId() != R.id.items_loading_twitter) {
			ret = getLayoutInflater().inflate(R.layout.items_loading_twitter, parent, false);
		}
		return ret;
	}

	private View getTweetView(Tweet tweet, View convertView, ViewGroup parent) {
		View ret = convertView;
		if (ret == null || ret.getId() != R.id.item_twitter) {
			ret = getLayoutInflater().inflate(R.layout.item_twitter, parent, false);
		}
		TextView text = (TextView) ret.findViewById(R.id.text);
		text.setText(tweet.text);
		// TODO use Html.fromHtml()
		// TODO use http://developer.android.com/reference/android/text/util/Linkify.html
		ImageView image = (ImageView) ret.findViewById(R.id.image);
		image.setImageBitmap(tweet.profileImage);
		return ret;
	}
}
{'fraction_non_alphanumeric': 0.10189328743545611, 'fraction_numerical': 0.003098106712564544, 'mean_word_length': 3.743673469387755, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4740672', 'n_tokens_mistral': 1921, 'n_tokens_neox': 1743, 'n_words': 485}