<commit_before>package com.charlesmadere.hummingbird.views;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.support.v4.app.FragmentActivity;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.charlesmadere.hummingbird.R;
import com.charlesmadere.hummingbird.adapters.AdapterView;
import com.charlesmadere.hummingbird.fragments.PostReactionsBottomSheetDialogFragment;
import com.charlesmadere.hummingbird.misc.MiscUtils;
import com.charlesmadere.hummingbird.models.CommentStory;
import com.charlesmadere.hummingbird.networking.Api;

import java.text.NumberFormat;

import butterknife.BindView;
import butterknife.ButterKnife;

public class LikesFeedButton extends FrameLayout implements AdapterView<CommentStory>,
        View.OnClickListener, View.OnLongClickListener {

    private CommentStory mCommentStory;
    private NumberFormat mNumberFormat;

    @BindView(R.id.tvLikesFeedButton)
    TextView mLabel;


    public LikesFeedButton(final Context context, final AttributeSet attrs) {
        super(context, attrs);
    }

    public LikesFeedButton(final Context context, final AttributeSet attrs,
            final int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public LikesFeedButton(final Context context, final AttributeSet attrs,
            final int defStyleAttr, final int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();

        if (isInEditMode()) {
            return;
        }

        update();
    }

    @Override
    public void onClick(final View v) {
        if (mCommentStory != null) {
            mCommentStory.toggleLiked();
            Api.likeStory(mCommentStory);
            update();
        }
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        ButterKnife.bind(this);
        setOnClickListener(this);
        setOnLongClickListener(this);
        mNumberFormat = NumberFormat.getInstance();
    }

    @Override
    public boolean onLongClick(final View v) {
        if (mCommentStory == null) {
            return false;
        }

        final Activity activity = MiscUtils.optActivity(getContext());

        if (activity instanceof FragmentActivity) {
            final FragmentActivity fragmentActivity = (FragmentActivity) activity;
            PostReactionsBottomSheetDialogFragment.create(mCommentStory.getId()).show(
                    fragmentActivity.getSupportFragmentManager(), null);
            return true;
        } else {
            return false;
        }
    }

    @Override
    public void setContent(final CommentStory content) {
        mCommentStory = content;
        update();
    }

    private void update() {
        final boolean liked;
        final int likes;

        if (mCommentStory != null) {
            liked = mCommentStory.isLiked();
            likes = mCommentStory.getTotalVotes();
        } else {<commit_msg>dont do long click action if the story has no votes<commit_after>package com.charlesmadere.hummingbird.views;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.support.v4.app.FragmentActivity;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.charlesmadere.hummingbird.R;
import com.charlesmadere.hummingbird.adapters.AdapterView;
import com.charlesmadere.hummingbird.fragments.PostReactionsBottomSheetDialogFragment;
import com.charlesmadere.hummingbird.misc.MiscUtils;
import com.charlesmadere.hummingbird.models.CommentStory;
import com.charlesmadere.hummingbird.networking.Api;

import java.text.NumberFormat;

import butterknife.BindView;
import butterknife.ButterKnife;

public class LikesFeedButton extends FrameLayout implements AdapterView<CommentStory>,
        View.OnClickListener, View.OnLongClickListener {

    private CommentStory mCommentStory;
    private NumberFormat mNumberFormat;

    @BindView(R.id.tvLikesFeedButton)
    TextView mLabel;


    public LikesFeedButton(final Context context, final AttributeSet attrs) {
        super(context, attrs);
    }

    public LikesFeedButton(final Context context, final AttributeSet attrs,
            final int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public LikesFeedButton(final Context context, final AttributeSet attrs,
            final int defStyleAttr, final int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();

        if (isInEditMode()) {
            return;
        }

        update();
    }

    @Override
    public void onClick(final View v) {
        if (mCommentStory != null) {
            mCommentStory.toggleLiked();
            Api.likeStory(mCommentStory);
            update();
        }
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        ButterKnife.bind(this);
        setOnClickListener(this);
        setOnLongClickListener(this);
        mNumberFormat = NumberFormat.getInstance();
    }

    @Override
    public boolean onLongClick(final View v) {
        if (mCommentStory == null || mCommentStory.getTotalVotes() < 1) {
            return false;
        }

        final Activity activity = MiscUtils.optActivity(getContext());

        if (activity instanceof FragmentActivity) {
            final FragmentActivity fragmentActivity = (FragmentActivity) activity;
            PostReactionsBottomSheetDialogFragment.create(mCommentStory.getId()).show(
                    fragmentActivity.getSupportFragmentManager(), null);
            return true;
        } else {
            return false;
        }
    }

    @Override
    public void setContent(final CommentStory content) {
        mCommentStory = content;
        update();
    }

    private void update() {
        final boolean liked;
        final int likes;

        if (mCommentStory != null) {
            liked = mCommentStory.isLiked();
            likes = mCommentStory.getTotalVotes();
        } else {
{'fraction_non_alphanumeric': 0.08283479061205706, 'fraction_numerical': 0.0004601932811780948, 'mean_word_length': 2.9611178614823817, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, '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': '379785', 'n_tokens_mistral': 1818, 'n_tokens_neox': 1741, 'n_words': 382}