<commit_before>package com.veyndan.redditclient;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.design.widget.Snackbar;
import android.support.v7.widget.RecyclerView;
import android.text.format.DateUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupMenu;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.ToggleButton;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import butterknife.ButterKnife;
import rawjava.Reddit;
import rawjava.model.Link;
import rawjava.model.Source;
import rawjava.model.Thing;
import rawjava.network.VoteDirection;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class PostAdapter extends RecyclerView.Adapter<PostAdapter.PostViewHolder> {

    private static final String TAG = "veyndan_PostAdapter";

    private final List<Thing<Link>> posts;
    private final Reddit reddit;
    private final int width;

    public PostAdapter(List<Thing<Link>> posts, Reddit reddit, int width) {
        this.posts = posts;
        this.reddit = reddit;
        this.width = width;
    }

    @Override
    public PostAdapter.PostViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post, parent, false);
        return new PostViewHolder(v);
    }

    @Override
    public void onBindViewHolder(final PostAdapter.PostViewHolder holder, int position) {
        Thing<Link> post = posts.get(position);
        final Context context = holder.itemView.getContext();

        holder.title.setText(post.data.title);

        CharSequence age = DateUtils.getRelativeTimeSpanString(
                TimeUnit.SECONDS.toMillis(post.data.createdUtc), System.currentTimeMillis(),
                DateUtils.SECOND_IN_MILLIS,
                DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_NO_NOON | DateUtils.FORMAT_NO_MIDNIGHT | DateUtils.FORMAT_NO_MONTH_DAY);

        holder.subtitle.setText(context.getString(R.string.subtitle, post.data.author, age, post.data.subreddit));

        holder.image.setImageDrawable(null);
        if (!post.data.isSelf) {
            holder.urlContainer.setVisibility(View.VISIBLE);

            holder.urlContainer.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Thing<Link> post = posts.get(holder.getAdapterPosition());
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(post.data.url));
                    context.startActivity(intent);
                }
            });

            String urlHost;
            try {
                urlHost = new URL(post.data.url).getHost();
            } catch (MalformedURLException e) {
                Log.e(TAG, e.getMessage(), e);
                urlHost = post.data.url;
            }

            holder.url.setText(urlHost);

            if (post.data.preview != null && !post.data.preview.images.isEmpty()) {
                holder.image.setVisibility(View.VISIBLE);
                holder.imageProgress.setVisibility(View.VISIBLE);
                Source source = post.data.preview.images.get(0).source;
                Glide.with(context)
                        .load(source.url)
                        .listener(new RequestListener<String, GlideDrawable>() {
                            @Override
                            public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
                                holder.imageProgress.setVisibility(View.GONE);
                                return false;
                            }

                            @Override
                            public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                                holder.imageProgress.setVisibility(View.GONE);
                                return false;
                            }
                        })
                        .into(holder.image);
                holder.image.getLayoutParams().height = (int) ((float) width / source.width * source.height);
            } else {
                holder.image.setVisibility(View.GONE);
                holder.imageProgress.setVisibility(View.GONE);
            }
        } else {
            holder.urlContainer.setVisibility(View.GONE);
            holder.image.setVisibility(View.GONE);
        }

        final String points = context.getResources().getQuantityString(R.plurals.points, post.data.score, post.data.score);
        final String comments = context.getResources().getQuantityString(R.plurals.comments, post.data.numComments, post.data.numComments);
        holder.score.setText(context.getString(R.string.score, points, comments));
<commit_msg>If picture is a direct link to Imgur, display it without the url<commit_after>package com.veyndan.redditclient;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.design.widget.Snackbar;
import android.support.v7.widget.RecyclerView;
import android.text.format.DateUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupMenu;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.ToggleButton;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import butterknife.ButterKnife;
import rawjava.Reddit;
import rawjava.model.Link;
import rawjava.model.Source;
import rawjava.model.Thing;
import rawjava.network.VoteDirection;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class PostAdapter extends RecyclerView.Adapter<PostAdapter.PostViewHolder> {

    private static final String TAG = "veyndan_PostAdapter";

    private final List<Thing<Link>> posts;
    private final Reddit reddit;
    private final int width;

    public PostAdapter(List<Thing<Link>> posts, Reddit reddit, int width) {
        this.posts = posts;
        this.reddit = reddit;
        this.width = width;
    }

    @Override
    public PostAdapter.PostViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post, parent, false);
        return new PostViewHolder(v);
    }

    @Override
    public void onBindViewHolder(final PostAdapter.PostViewHolder holder, int position) {
        Thing<Link> post = posts.get(position);
        final Context context = holder.itemView.getContext();

        holder.title.setText(post.data.title);

        CharSequence age = DateUtils.getRelativeTimeSpanString(
                TimeUnit.SECONDS.toMillis(post.data.createdUtc), System.currentTimeMillis(),
                DateUtils.SECOND_IN_MILLIS,
                DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_NO_NOON | DateUtils.FORMAT_NO_MIDNIGHT | DateUtils.FORMAT_NO_MONTH_DAY);

        holder.subtitle.setText(context.getString(R.string.subtitle, post.data.author, age, post.data.subreddit));

        holder.image.setImageDrawable(null);
        if (!post.data.isSelf && post.data.preview != null && !post.data.preview.images.isEmpty() && post.data.url.contains("i.imgur.com/")) {
            holder.urlContainer.setVisibility(View.VISIBLE);
            holder.url.setVisibility(View.GONE);

            holder.urlContainer.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Thing<Link> post = posts.get(holder.getAdapterPosition());
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(post.data.url));
                    context.startActivity(intent);
                }
            });

            holder.image.setVisibility(View.VISIBLE);
            holder.imageProgress.setVisibility(View.VISIBLE);
            Glide.with(context)
                    .load(post.data.url)
                    .listener(new RequestListener<String, GlideDrawable>() {
                        @Override
                        public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
                            holder.imageProgress.setVisibility(View.GONE);
                            return false;
                        }

                        @Override
                        public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                            holder.imageProgress.setVisibility(View.GONE);
                            return false;
                        }
                    })
                    .into(holder.image);
            Source source = post.data.preview.images.get(0).source;
            holder.image.getLayoutParams().height = (int) ((float) width / source.width * source.height);
        } else if (!post.data.isSelf) {
            holder.urlContainer.setVisibility(View.VISIBLE);
            holder.url.setVisibility(View.VISIBLE);

            holder.urlContainer.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Thing<Link> post = posts.get(holder.getAdapterPosition());
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(post.data.url));
                    context.startActivity(intent);
                }
            });

            String urlHost;
            try {
                urlHost = new URL(post.data.url).getHost();
            } catch (MalformedURLException e) {
                Log.e(TAG, e.getMessage(), e);
                urlHost = post.data.url;
            }

            holder.url.setText(urlHost);

            if (post.data.preview != null && !post.data.preview.images.isEmpty()) {
                holder.image.setVisibility(View.VISIBLE);
                holder.imageProgress.setVisibility(View.VISIBLE);
                Source source = post.data.preview.images.get(0).source;
                Glide.with(context)
                        .load(source.url)
                        .listener(new RequestListener<String, GlideDrawable>() {
                            @Override
                            public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
                                holder.imageProgress.setVisibility(View.GONE);
                                return false;
                            }

                            @Override
                            public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                                holder.imageProgress.setVisibility(View.GONE);
                                return false;
                            }
                        })
                        .into(holder.image);
                holder.image.getLayoutParams().height = (int) ((float) width / source.width * source.height);
            } else {
                holder.image.setVisibility(View.GONE);
                holder.imageProgress.setVisibility(View.GONE);
            }
        } else {
            holder.urlContainer.setVisibility(View.GONE);
        }

        final String points = context.getResources().getQuantityString(R.plurals.points, post.data.score, post.data.score);
        final String comments = context.getResources().getQuantityString(R.plurals.comments, post.data.numComments, post.data.numComments);
        holder.score.setText(context.getString(R.string.score, points, comments));

{'fraction_non_alphanumeric': 0.09630831016373186, 'fraction_numerical': 0.0003861600247142416, 'mean_word_length': 2.2982679572083544, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '978582', 'n_tokens_mistral': 3445, 'n_tokens_neox': 3330, 'n_words': 608}