<commit_before>package org.lagonette.app.app.widget.maps;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.BitmapDescriptor;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.maps.android.clustering.Cluster;
import com.google.maps.android.clustering.ClusterManager;
import com.google.maps.android.clustering.view.DefaultClusterRenderer;
import com.google.maps.android.ui.IconGenerator;

import org.lagonette.app.R;
import org.lagonette.app.app.widget.glide.PartnerMarkerTarget;
import org.lagonette.app.room.entity.statement.LocationItem;
import org.lagonette.app.tools.functions.main.Provider;
import org.lagonette.app.tools.functions.main.TriConsumer;

public class PartnerRenderer
		extends DefaultClusterRenderer<LocationItem> {

	public static final float Z_INDEX_ITEM = 0f;

	public static final float Z_INDEX_SELECTED_ITEM = 1f;

	public static final int MIN_CLUSTER_SIZE = 7;

	private static final String TAG = "PartnerRenderer";

	private final IconGenerator mClusterIconGenerator;

	private final BitmapDescriptor mPartnerPlaceholderBitmapDescriptor;

	private final BitmapDescriptor mExchangeOfficePlaceholderBitmapDescriptor;

	private final BitmapDescriptor mSelectedPartnerPlaceholderBitmapDescriptor;

	private final BitmapDescriptor mSelectedExchangeOfficePlaceholderBitmapDescriptor;

	@NonNull
	private final Context mContext;

	private final int mItemSize;

	@NonNull
	private final IconGenerator mIconGenerator;

	@NonNull
	private final View mPartnerView;

	@NonNull
	private final View mSelectedPartnerView;

	@NonNull
	private final ImageView mPartnerIconView;

	@NonNull
	private final ImageView mSelectedPartnerIconView;

	@NonNull
	private final Drawable mPartnerBackgroundDrawable;

	@NonNull
	private final Drawable mExchangeOfficeBackgroundDrawable;

	@NonNull
	private final Drawable mSelectedPartnerBackgroundDrawable;

	@NonNull
	private final Drawable mSelectedExchangeOfficeBackgroundDrawable;

	@NonNull
	private final Provider<Marker> mGetSelectedItem;

	@NonNull
	private SparseArray<BitmapDescriptor> mPartnerBitmapDescriptors;

	@NonNull
	private SparseArray<BitmapDescriptor> mExchangeOfficeBitmapDescriptors;

	@NonNull
	private SparseArray<BitmapDescriptor> mSelectedPartnerBitmapDescriptors;

	@NonNull
	private SparseArray<BitmapDescriptor> mSelectedExchangeOfficeBitmapDescriptors;

	public PartnerRenderer(
			@NonNull Context context,
			@NonNull LayoutInflater layoutInflater,
			@NonNull GoogleMap map,
			@NonNull ClusterManager<LocationItem> clusterManager,
			@NonNull Provider<Marker> getSelectedItem) {
		super(context, map, clusterManager);
		mContext = context;

		mGetSelectedItem = getSelectedItem;

		mPartnerBitmapDescriptors = new SparseArray<>();
		mExchangeOfficeBitmapDescriptors = new SparseArray<>();
		mSelectedPartnerBitmapDescriptors = new SparseArray<>();
		mSelectedExchangeOfficeBitmapDescriptors = new SparseArray<>();

		Resources resources = context.getResources();
		mItemSize = resources.getDimensionPixelSize(R.dimen.map_item_size);

		Context appContext = context.getApplicationContext();

		mIconGenerator = new IconGenerator(appContext);
		mClusterIconGenerator = new IconGenerator(appContext);

		View clusterView = layoutInflater.inflate(R.layout.item_cluster, null);
		mClusterIconGenerator.setContentView(clusterView);
		mClusterIconGenerator.setBackground(null);


		mPartnerView = layoutInflater.inflate(R.layout.item_partner, null);
		mPartnerIconView = mPartnerView.findViewById(R.id.item_partner_icon);

		mPartnerBackgroundDrawable = ContextCompat.getDrawable(context, R.drawable.bg_item_partner);
		mPartnerView.setBackground(mPartnerBackgroundDrawable);
		mPartnerPlaceholderBitmapDescriptor = createBitmapDescriptor(mPartnerView);

		mExchangeOfficeBackgroundDrawable = ContextCompat.getDrawable(context, R.drawable.bg_item_exchange_office);
		mPartnerView.setBackground(mExchangeOfficeBackgroundDrawable);
		mExchangeOfficePlaceholderBitmapDescriptor = createBitmapDescriptor(mPartnerView);


		mSelectedPartnerView = layoutInflater.inflate(R.layout.item_partner_selected, null);
		mSelectedPartnerIconView = mSelectedPartnerView.findViewById(R.id.item_partner_icon);

		mSelectedPartnerBackgroundDrawable = ContextCompat.getDrawable(context, R.drawable.bg_item_partner);
		mSelectedPartnerView.setBackground(mSelectedPartnerBackgroundDrawable);
		mSelectedPartnerPlaceholderBitmapDescriptor = createBitmapDescriptor(mSelectedPartnerView);

		mSelectedExchangeOfficeBackgroundDrawable = ContextCompat.getDrawable(context, R.drawable.bg_item_exchange_office);
		mSelectedPartnerView.setBackground(mSelectedExchangeOfficeBackgroundDrawable);
		mSelectedExchangeOfficePlaceholderBitmapDescriptor = createBitmapDescriptor(mSelectedPartnerView);


		setMinClusterSize(MIN_CLUSTER_SIZE);
	}

	private BitmapDescriptor createBitmapDescriptor(@NonNull View contentView) {
		mIconGenerator.setContentView(contentView);
		mIconGenerator.setBackground(null);
		return BitmapDescriptorFactory.fromBitmap(mIconGenerator.makeIcon());
	}

	//TODO Display just a point instead of logo when zoom is huge

	@Override
	protected void onBeforeClusterItemRendered(
			final LocationItem locationItem,
			final MarkerOptions markerOptions) {
		render(locationItem, markerOptions, this::onItemBitmapReady, false);
	}
<commit_msg>Update TODO<commit_after>package org.lagonette.app.app.widget.maps;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.BitmapDescriptor;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.maps.android.clustering.Cluster;
import com.google.maps.android.clustering.ClusterManager;
import com.google.maps.android.clustering.view.DefaultClusterRenderer;
import com.google.maps.android.ui.IconGenerator;

import org.lagonette.app.R;
import org.lagonette.app.app.widget.glide.PartnerMarkerTarget;
import org.lagonette.app.room.entity.statement.LocationItem;
import org.lagonette.app.tools.functions.main.Provider;
import org.lagonette.app.tools.functions.main.TriConsumer;

public class PartnerRenderer
		extends DefaultClusterRenderer<LocationItem> {

	public static final float Z_INDEX_ITEM = 0f;

	public static final float Z_INDEX_SELECTED_ITEM = 1f;

	public static final int MIN_CLUSTER_SIZE = 7;

	private static final String TAG = "PartnerRenderer";

	private final IconGenerator mClusterIconGenerator;

	private final BitmapDescriptor mPartnerPlaceholderBitmapDescriptor;

	private final BitmapDescriptor mExchangeOfficePlaceholderBitmapDescriptor;

	private final BitmapDescriptor mSelectedPartnerPlaceholderBitmapDescriptor;

	private final BitmapDescriptor mSelectedExchangeOfficePlaceholderBitmapDescriptor;

	@NonNull
	private final Context mContext;

	private final int mItemSize;

	@NonNull
	private final IconGenerator mIconGenerator;

	@NonNull
	private final View mPartnerView;

	@NonNull
	private final View mSelectedPartnerView;

	@NonNull
	private final ImageView mPartnerIconView;

	@NonNull
	private final ImageView mSelectedPartnerIconView;

	@NonNull
	private final Drawable mPartnerBackgroundDrawable;

	@NonNull
	private final Drawable mExchangeOfficeBackgroundDrawable;

	@NonNull
	private final Drawable mSelectedPartnerBackgroundDrawable;

	@NonNull
	private final Drawable mSelectedExchangeOfficeBackgroundDrawable;

	@NonNull
	private final Provider<Marker> mGetSelectedItem;

	@NonNull
	private SparseArray<BitmapDescriptor> mPartnerBitmapDescriptors;

	@NonNull
	private SparseArray<BitmapDescriptor> mExchangeOfficeBitmapDescriptors;

	@NonNull
	private SparseArray<BitmapDescriptor> mSelectedPartnerBitmapDescriptors;

	@NonNull
	private SparseArray<BitmapDescriptor> mSelectedExchangeOfficeBitmapDescriptors;

	public PartnerRenderer(
			@NonNull Context context,
			@NonNull LayoutInflater layoutInflater,
			@NonNull GoogleMap map,
			@NonNull ClusterManager<LocationItem> clusterManager,
			@NonNull Provider<Marker> getSelectedItem) {
		super(context, map, clusterManager);
		mContext = context;

		mGetSelectedItem = getSelectedItem;

		mPartnerBitmapDescriptors = new SparseArray<>();
		mExchangeOfficeBitmapDescriptors = new SparseArray<>();
		mSelectedPartnerBitmapDescriptors = new SparseArray<>();
		mSelectedExchangeOfficeBitmapDescriptors = new SparseArray<>();

		Resources resources = context.getResources();
		mItemSize = resources.getDimensionPixelSize(R.dimen.map_item_size);

		Context appContext = context.getApplicationContext();

		mIconGenerator = new IconGenerator(appContext);
		mClusterIconGenerator = new IconGenerator(appContext);

		View clusterView = layoutInflater.inflate(R.layout.item_cluster, null);
		mClusterIconGenerator.setContentView(clusterView);
		mClusterIconGenerator.setBackground(null);


		mPartnerView = layoutInflater.inflate(R.layout.item_partner, null);
		mPartnerIconView = mPartnerView.findViewById(R.id.item_partner_icon);

		mPartnerBackgroundDrawable = ContextCompat.getDrawable(context, R.drawable.bg_item_partner);
		mPartnerView.setBackground(mPartnerBackgroundDrawable);
		mPartnerPlaceholderBitmapDescriptor = createBitmapDescriptor(mPartnerView);

		mExchangeOfficeBackgroundDrawable = ContextCompat.getDrawable(context, R.drawable.bg_item_exchange_office);
		mPartnerView.setBackground(mExchangeOfficeBackgroundDrawable);
		mExchangeOfficePlaceholderBitmapDescriptor = createBitmapDescriptor(mPartnerView);


		mSelectedPartnerView = layoutInflater.inflate(R.layout.item_partner_selected, null);
		mSelectedPartnerIconView = mSelectedPartnerView.findViewById(R.id.item_partner_icon);

		mSelectedPartnerBackgroundDrawable = ContextCompat.getDrawable(context, R.drawable.bg_item_partner);
		mSelectedPartnerView.setBackground(mSelectedPartnerBackgroundDrawable);
		mSelectedPartnerPlaceholderBitmapDescriptor = createBitmapDescriptor(mSelectedPartnerView);

		mSelectedExchangeOfficeBackgroundDrawable = ContextCompat.getDrawable(context, R.drawable.bg_item_exchange_office);
		mSelectedPartnerView.setBackground(mSelectedExchangeOfficeBackgroundDrawable);
		mSelectedExchangeOfficePlaceholderBitmapDescriptor = createBitmapDescriptor(mSelectedPartnerView);


		setMinClusterSize(MIN_CLUSTER_SIZE);
	}

	private BitmapDescriptor createBitmapDescriptor(@NonNull View contentView) {
		mIconGenerator.setContentView(contentView);
		mIconGenerator.setBackground(null);
		return BitmapDescriptorFactory.fromBitmap(mIconGenerator.makeIcon());
	}

	@Override
	protected void onBeforeClusterItemRendered(
			final LocationItem locationItem,
			final MarkerOptions markerOptions) {
		render(locationItem, markerOptions, this::onItemBitmapReady, false);
	}

{'fraction_non_alphanumeric': 0.07201505302771126, 'fraction_numerical': 0.0006842285323297981, 'mean_word_length': 7.648668639053255, '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': '6890895', 'n_tokens_mistral': 3455, 'n_tokens_neox': 3227, 'n_words': 593}