<commit_before>package com.earth.places.adapters;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.support.design.widget.Snackbar;
import android.support.v4.content.ContextCompat;
import android.support.v7.graphics.Palette;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;
import com.earth.places.R;
import com.earth.places.activities.MainActivity;
import com.earth.places.fragment.FragmentBookmarks;
import com.earth.places.models.Place;
import com.earth.places.models.Places;
import com.earth.places.utilities.Bookmarks;
import com.earth.places.utilities.Constants;
import com.earth.places.utilities.Utils;
import com.mikepenz.google_material_typeface_library.GoogleMaterial;
import com.mikepenz.iconics.IconicsDrawable;

import java.util.ArrayList;

public class PlaceAdapter extends RecyclerView.Adapter<PlaceAdapter.PlacesViewHolder> {

    private ClickListener clickListener;
    private ArrayList<Place> placesList;
    private Activity context;
    private IconicsDrawable iconBookmark;
    private IconicsDrawable iconBookmarkBorder;

    private IconicsDrawable city, country, nationalPark, map, misc;

    public PlaceAdapter(Activity context, ClickListener clickListener) {
        this.context = context;
        this.clickListener = clickListener;

        // Create Drawables just one time when the Adapter is initialized, not for each PlacesViewHolder
        iconBookmark = new IconicsDrawable(context).icon(GoogleMaterial.Icon.gmd_bookmark).color(Color.WHITE).sizeDp(24);
        iconBookmarkBorder = new IconicsDrawable(context).icon(GoogleMaterial.Icon.gmd_bookmark_border).color(Color.WHITE).sizeDp(24);

        final int size = 18;
        final int color = ContextCompat.getColor(context, R.color.white);
        city = new IconicsDrawable(context).icon(GoogleMaterial.Icon.gmd_location_city).color(color).sizeDp(size);
        country = new IconicsDrawable(context).icon(GoogleMaterial.Icon.gmd_terrain).color(color).sizeDp(size);
        nationalPark = new IconicsDrawable(context).icon(GoogleMaterial.Icon.gmd_nature).color(color).sizeDp(size);
        map = new IconicsDrawable(context).icon(GoogleMaterial.Icon.gmd_map).color(color).sizeDp(size);
        misc = new IconicsDrawable(context).icon(GoogleMaterial.Icon.gmd_more).color(color).sizeDp(size);

    }

    @Override
    public PlacesViewHolder onCreateViewHolder(ViewGroup parent, int index) {
        return new PlacesViewHolder(LayoutInflater.from(context).inflate(R.layout.fragment_places_item, parent, false));
    }

    public void setData(ArrayList<Place> placesList) {

        this.placesList = placesList;
        notifyDataSetChanged();
    }

    @Override
    public void onBindViewHolder(final PlacesViewHolder holder, final int index) {

        if (MainActivity.tabLayout.getTabAt(0).isSelected()) {
            Bookmarks.init(context);
            boolean state = Bookmarks.isBookmarked(Places.getPlacesList().get(index).getId());
            holder.stateReaction(state, false);
        }

        if (MainActivity.tabLayout.getTabAt(1).isSelected())
            holder.drawableBookmark.setImageDrawable(iconBookmark);


        final Place place = placesList.get(index);
        final String sight = place.getSight();

        final String[] url = place.getUrl().replace(" ", "").split("\\|");


        Glide.with(context.getApplicationContext())
                .load(url[0] != null ? url[0] :  place.getUrl())
                .asBitmap()
                .override(800, 500)
                .fitCenter()
                .priority(Priority.IMMEDIATE)
                .listener(new RequestListener<String, Bitmap>() {
                    @Override
                    public boolean onException(Exception e, String model, Target<Bitmap> target, boolean isFirstResource) {
                        Log.d("PlaceView", "Toolbar Image onException: ");
                        return false;
                    }

                    @Override
                    public boolean onResourceReady(Bitmap resource, String model, Target<Bitmap> target, boolean isFromMemoryCache, boolean isFirstResource) {
                        holder.layout.setVisibility(View.VISIBLE);

                        new Palette.Builder(resource).generate(new Palette.PaletteAsyncListener() {
                            @Override
                            public void onGenerated(Palette palette) {

                                if (palette == null) return;
                                int color = Utils.colorFromPalette(context, palette);
                                Places.getPlacesList().get(index).setColor(color);
                            }
                        });

                        return false;
                    }
                })
                .into(holder.image);


        holder.sight.setText(sight);
        holder.place.setText(place.getPlace());
        holder.continent.setText(place.getContinent());

        holder.place.setTypeface(Utils.customTypeface(context, 1));<commit_msg>I have the feeling, the images are now loading a bit faster.<commit_after>package com.earth.places.adapters;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.support.design.widget.Snackbar;
import android.support.v4.content.ContextCompat;
import android.support.v7.graphics.Palette;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.afollestad.inquiry.Inquiry;
import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;
import com.earth.places.R;
import com.earth.places.activities.MainActivity;
import com.earth.places.fragment.FragmentBookmarks;
import com.earth.places.models.Place;
import com.earth.places.models.Places;
import com.earth.places.utilities.Bookmarks;
import com.earth.places.utilities.Constants;
import com.earth.places.utilities.Utils;
import com.mikepenz.google_material_typeface_library.GoogleMaterial;
import com.mikepenz.iconics.IconicsDrawable;

import java.util.ArrayList;

public class PlaceAdapter extends RecyclerView.Adapter<PlaceAdapter.PlacesViewHolder> {

    private ClickListener clickListener;
    private ArrayList<Place> placesList;
    private Activity context;
    private IconicsDrawable iconBookmark;
    private IconicsDrawable iconBookmarkBorder;

    private IconicsDrawable city, country, nationalPark, map, misc;

    public PlaceAdapter(Activity context, ClickListener clickListener) {
        this.context = context;
        this.clickListener = clickListener;

        // Create Drawables just one time when the Adapter is initialized, not for each PlacesViewHolder
        iconBookmark = new IconicsDrawable(context).icon(GoogleMaterial.Icon.gmd_bookmark).color(Color.WHITE).sizeDp(24);
        iconBookmarkBorder = new IconicsDrawable(context).icon(GoogleMaterial.Icon.gmd_bookmark_border).color(Color.WHITE).sizeDp(24);

        final int size = 18;
        final int color = ContextCompat.getColor(context, R.color.white);
        city = new IconicsDrawable(context).icon(GoogleMaterial.Icon.gmd_location_city).color(color).sizeDp(size);
        country = new IconicsDrawable(context).icon(GoogleMaterial.Icon.gmd_terrain).color(color).sizeDp(size);
        nationalPark = new IconicsDrawable(context).icon(GoogleMaterial.Icon.gmd_nature).color(color).sizeDp(size);
        map = new IconicsDrawable(context).icon(GoogleMaterial.Icon.gmd_map).color(color).sizeDp(size);
        misc = new IconicsDrawable(context).icon(GoogleMaterial.Icon.gmd_more).color(color).sizeDp(size);

    }

    @Override
    public PlacesViewHolder onCreateViewHolder(ViewGroup parent, int index) {
        return new PlacesViewHolder(LayoutInflater.from(context).inflate(R.layout.fragment_places_item, parent, false));
    }

    public void setData(ArrayList<Place> placesList) {

        this.placesList = placesList;
        notifyDataSetChanged();
    }

    @Override
    public void onBindViewHolder(final PlacesViewHolder holder, final int index) {

        final Place place = placesList.get(index);
        final String sight = place.getSight();
        final String[] url = place.getUrl().replace(" ", "").split("\\|");

        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                Glide.with(context.getApplicationContext())
                        .load(url[0])
                        .asBitmap()
                        .override(1200, 900)
                        .centerCrop()
                        .priority(Priority.IMMEDIATE)
                        .listener(new RequestListener<String, Bitmap>() {
                            @Override
                            public boolean onException(Exception e, String model, Target<Bitmap> target, boolean isFirstResource) {
                                Log.d("PlaceView", "Toolbar Image onException: ");
                                return false;
                            }

                            @Override
                            public boolean onResourceReady(Bitmap resource, String model, Target<Bitmap> target, boolean isFromMemoryCache, boolean isFirstResource) {
                                holder.layout.setVisibility(View.VISIBLE);

                                new Palette.Builder(resource).generate(new Palette.PaletteAsyncListener() {
                                    @Override
                                    public void onGenerated(Palette palette) {

                                        if (palette == null) return;
                                        int color = Utils.colorFromPalette(context, palette);
                                        Places.getPlacesList().get(index).setColor(color);
                                    }
                                });

                                return false;
                            }
                        })
                        .into(holder.image);
            }
        });

        thread.setPriority(Thread.MAX_PRIORITY);
        thread.run();



        if (MainActivity.tabLayout.getTabAt(0).isSelected()) {
            Bookmarks.init(context);
            holder.stateReaction(Bookmarks.isBookmarked(Places.getPlacesList().get(index).getId()), false);
            Inquiry.deinit();
        }

        if (MainActivity.tabLayout.getTabAt(1).isSelected())
            holder.drawableBookmark.setImageDrawable(iconBookmark);

        holder.sight.setText(sight);
        holder.place.setText(place.getPlace());
        holder.continent.setText(place.getContinent());

        holder.place.setTypeface(Utils.customTypeface(context, 1));
{'fraction_non_alphanumeric': 0.09801336146272856, 'fraction_numerical': 0.0035161744022503515, 'mean_word_length': 2.6117460317460317, 'pattern_counts': {'":': 0, '<': 15, '<?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': 11, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '676533', 'n_tokens_mistral': 3109, 'n_tokens_neox': 2935, 'n_words': 540}