package jcotter.listenmoe.adapters;

import android.graphics.Typeface;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import jcotter.listenmoe.R;
import jcotter.listenmoe.model.Song;

public class SongAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    public interface OnSongItemClickListener {
        void onSongItemClick(final Song song);
    }

    private List<Song> songs;
    private OnSongItemClickListener listener;

    public SongAdapter(OnSongItemClickListener listener) {
        this.songs = new ArrayList<>();
        this.listener = listener;
    }

    public void setSongs(List<Song> songs) {
        this.songs = songs;
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        final View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.song_item, parent, false);
        return new SongHolder(v, songs, listener);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Song song = songs.get(position);

        ((SongHolder) holder).mTitle.setText(song.getTitle());
        ((SongHolder) holder).mSubtitle.setText(song.getArtistAndAnime());
        ((SongHolder) holder).mFavorited.setVisibility(song.isFavorite() ? View.VISIBLE : View.GONE);

        if (!song.isEnabled()) {
            ((SongHolder) holder).mTitle.setTypeface(null, Typeface.ITALIC);
            ((SongHolder) holder).mSubtitle.setTypeface(null, Typeface.ITALIC);
        }
    }

    @Override
    public int getItemCount() {
        return songs.size();
    }

    public class SongHolder extends RecyclerView.ViewHolder {
        public TextView mTitle;
        public TextView mSubtitle;
        public LinearLayout mFavorited;

        public SongHolder(final View itemView, final List<Song> songs, final OnSongItemClickListener listener) {
            super(itemView);

            mTitle = (TextView) itemView.findViewById(R.id.title);
            mSubtitle = (TextView) itemView.findViewById(R.id.subtitle);
            mFavorited = (LinearLayout) itemView.findViewById(R.id.favorited);

            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (getAdapterPosition() != RecyclerView.NO_POSITION) {
                        final Song song = songs.get(getLayoutPosition());
                        listener.onSongItemClick(song);
                    }
                }
            });
        }
    }
}

@@ -1566,37 +1566,83 @@
     
-if (!song.isEnabled()) %7B%0A    
+final int typeface = song.isEnabled() ? Typeface.NORMAL : Typeface.ITALIC;%0A
     
@@ -1688,39 +1688,32 @@
 eface(null, 
-T
+t
 ypeface
-.ITALIC
 );%0A         
@@ -1707,28 +1707,24 @@
 e);%0A        
- 
-   
 ((SongHolder
@@ -1765,35 +1765,18 @@
 ll, 
-T
+t
 ypeface
-.ITALIC);%0A        %7D
+);
 %0A   

Fix songs being italicized incorrectly