package org.wikipedia.feed.view;

import android.content.Context;
import android.content.res.ColorStateList;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.v7.widget.AppCompatImageView;
import android.support.v7.widget.PopupMenu;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import org.wikipedia.R;
import org.wikipedia.feed.FeedViewCallback;
import org.wikipedia.feed.model.Card;

import butterknife.BindView;
import butterknife.ButterKnife;

public class CardHeaderView extends LinearLayout {
    @BindView(R.id.view_card_header_image) AppCompatImageView imageView;
    @BindView(R.id.view_card_header_title) TextView titleView;
    @BindView(R.id.view_card_header_subtitle) TextView subtitleView;
    @BindView(R.id.view_list_card_header_menu) View menuView;
    @Nullable private Card card;
    @Nullable private FeedViewCallback callback;

    public CardHeaderView(Context context) {
        super(context);

        inflate(getContext(), R.layout.view_card_header, this);
        ButterKnife.bind(this);
        menuView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                showOverflowMenu(v);
            }
        });
    }

    @NonNull public CardHeaderView setCard(@NonNull Card card) {
        this.card = card;
        return this;
    }

    @NonNull public CardHeaderView setCallback(@Nullable FeedViewCallback callback) {
        this.callback = callback;
        return this;
    }

    @NonNull public CardHeaderView setImage(@DrawableRes int resId) {
        imageView.setImageResource(resId);
        return this;
    }

    @NonNull public CardHeaderView setImageCircleColor(@ColorRes int color) {
        ColorStateList colorStateList = new ColorStateList(
                new int[][]{new int[]{}},
                new int[]{getResources().getColor(color)}
        );
        imageView.setSupportBackgroundTintList(colorStateList);
        return this;
    }

    @NonNull public CardHeaderView setTitle(@Nullable CharSequence title) {
        titleView.setText(title);
        return this;
    }

    @NonNull public CardHeaderView setTitle(@StringRes int id) {
        titleView.setText(id);
        return this;
    }

    @NonNull public CardHeaderView setSubtitle(@Nullable CharSequence subtitle) {
        subtitleView.setText(subtitle);
        return this;
    }

    private void showOverflowMenu(View anchorView) {
        PopupMenu menu = new PopupMenu(anchorView.getContext(), anchorView);
        menu.getMenuInflater().inflate(R.menu.menu_feed_card_header, menu.getMenu());
        menu.setOnMenuItemClickListener(new CardHeaderMenuClickListener());
        menu.show();
    }

    private class CardHeaderMenuClickListener implements PopupMenu.OnMenuItemClickListener {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
                case R.id.menu_feed_card_dismiss:
                    if (callback != null & card != null) {
                        return callback.onRequestDismissCard(card);
                    }
                    return false;
                default:
                    return false;
            }
        }
    }
}
@@ -714,16 +714,44 @@
 erKnife;
+%0Aimport butterknife.OnClick;
 %0A%0Apublic
@@ -1004,70 +1004,8 @@
 ew;%0A
-    @BindView(R.id.view_list_card_header_menu) View menuView;%0A
     
@@ -1152,17 +1152,16 @@
 ntext);%0A
-%0A
         
@@ -1168,28 +1168,23 @@
 inflate(
-getC
+c
 ontext
-()
 , R.layo
@@ -1247,195 +1247,8 @@
 s);%0A
-        menuView.setOnClickListener(new OnClickListener() %7B%0A            @Override%0A            public void onClick(View v) %7B%0A                showOverflowMenu(v);%0A            %7D%0A        %7D);%0A
     
@@ -2403,32 +2403,151 @@
 rn this;%0A    %7D%0A%0A
+    @OnClick(R.id.view_list_card_header_menu) protected void onMenuClick(View v) %7B%0A        showOverflowMenu(v);%0A    %7D%0A%0A
     private void

convert setOnClickListener() to @OnClick