<commit_before>package com.carlosefonseca.common.widgets;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import android.widget.ImageView;
import com.carlosefonseca.common.R;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.util.Collection;
import java.util.List;

public class GalleryPlus extends FrameLayout {

    private Gallery galleryView;
    private ImageView arrowLeftView;
    private ImageView arrowRightView;
    private boolean hideIfEmpty;
    @Nullable private Double aspectRatio;

    public GalleryPlus(Context context) {
        super(context);
        init();
    }

    public GalleryPlus(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
        inflate(getContext(), R.layout.cef_gallery_plus, this);
        galleryView = (Gallery) findViewById(R.id.gallery);
        arrowLeftView = (ImageView) findViewById(R.id.arrow_left);
        arrowRightView = (ImageView) findViewById(R.id.arrow_right);
        galleryView.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                setArrowsForPage(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    protected void setArrowsForPage(int position) {
        final int count = galleryView.getAdapter().getCount();
        if (count > 1) {
            if (position == 0 && arrowLeftView.getVisibility() == VISIBLE) {
                arrowLeftView.setVisibility(GONE);
                return;
            } else if (position > 0 && arrowLeftView.getVisibility() == GONE) {
                arrowLeftView.setVisibility(VISIBLE);
                return;
            }
            if (position == count - 1 && arrowRightView.getVisibility() == VISIBLE) {
                arrowRightView.setVisibility(GONE);
            } else if (position < count - 1 && arrowRightView.getVisibility() == GONE) {
                arrowRightView.setVisibility(VISIBLE);
            }
        } else {
            arrowLeftView.setVisibility(GONE);
            arrowRightView.setVisibility(GONE);
        }
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        if (aspectRatio != null) {
            final int h = (int) (getMeasuredWidth() * aspectRatio);
            galleryView.getLayoutParams().height = h;
            setMeasuredDimension(widthMeasureSpec, h);
        }
    }

    public boolean isEmpty() {
        return galleryView.getAdapter().getCount() == 0;
    }<commit_msg>Bug fix on GalleryPlus<commit_after>package com.carlosefonseca.common.widgets;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import android.widget.ImageView;
import com.carlosefonseca.common.R;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.util.Collection;
import java.util.List;

public class GalleryPlus extends FrameLayout {

    private Gallery galleryView;
    private ImageView arrowLeftView;
    private ImageView arrowRightView;
    private boolean hideIfEmpty;
    @Nullable private Double aspectRatio;

    public GalleryPlus(Context context) {
        super(context);
        init();
    }

    public GalleryPlus(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
        inflate(getContext(), R.layout.cef_gallery_plus, this);
        galleryView = (Gallery) findViewById(R.id.gallery);
        arrowLeftView = (ImageView) findViewById(R.id.arrow_left);
        arrowRightView = (ImageView) findViewById(R.id.arrow_right);
        galleryView.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                setArrowsForPage(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    protected void setArrowsForPage(int position) {
        final int count = galleryView.getAdapter().getCount();
        if (count > 1) {
            if (position == 0 && arrowLeftView.getVisibility() == VISIBLE) {
                arrowLeftView.setVisibility(GONE);
            } else if (position > 0 && arrowLeftView.getVisibility() == GONE) {
                arrowLeftView.setVisibility(VISIBLE);
            }
            if (position == count - 1 && arrowRightView.getVisibility() == VISIBLE) {
                arrowRightView.setVisibility(GONE);
            } else if (position < count - 1 && arrowRightView.getVisibility() == GONE) {
                arrowRightView.setVisibility(VISIBLE);
            }
        } else {
            arrowLeftView.setVisibility(GONE);
            arrowRightView.setVisibility(GONE);
        }
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        if (aspectRatio != null) {
            final int h = (int) (getMeasuredWidth() * aspectRatio);
            galleryView.getLayoutParams().height = h;
            setMeasuredDimension(widthMeasureSpec, h);
        }
    }

    public boolean isEmpty() {
        return galleryView.getAdapter().getCount() == 0;
    }
{'fraction_non_alphanumeric': 0.09539976234934647, 'fraction_numerical': 0.002376506535392972, 'mean_word_length': 2.482269503546099, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '5935820', 'n_tokens_mistral': 1610, 'n_tokens_neox': 1537, 'n_words': 331}