package com.marverenic.music.instances.section;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.marverenic.music.databinding.InstanceSongBinding;
import com.marverenic.music.instances.Song;
import com.marverenic.music.view.EnhancedAdapters.EnhancedViewHolder;
import com.marverenic.music.view.EnhancedAdapters.HeterogeneousAdapter;
import com.marverenic.music.viewmodel.SongViewModel;

import java.util.List;

public class SongSection extends HeterogeneousAdapter.ListSection<Song> {

    public static final int ID = 9149;

    private FragmentManager mFragmentManager;

    public SongSection(AppCompatActivity activity, @NonNull List<Song> data) {
        this(activity.getSupportFragmentManager(), data);
    }

    public SongSection(Fragment fragment, @NonNull List<Song> data) {
        this(fragment.getFragmentManager(), data);
    }

    public SongSection(FragmentManager fragmentManager, @NonNull List<Song> data) {
        super(ID, data);
        mFragmentManager = fragmentManager;
    }

    @Override
    public EnhancedViewHolder<Song> createViewHolder(HeterogeneousAdapter adapter,
                                                                  ViewGroup parent) {
        InstanceSongBinding binding = InstanceSongBinding.inflate(
                LayoutInflater.from(parent.getContext()), parent, false);

        return new ViewHolder(binding, getData());
    }

    private class ViewHolder extends EnhancedViewHolder<Song> {

        private InstanceSongBinding mBinding;

        public ViewHolder(InstanceSongBinding binding, List<Song> songList) {
            super(binding.getRoot());
            mBinding = binding;

            Context context = itemView.getContext();
            binding.setViewModel(new SongViewModel(context, mFragmentManager, songList));
        }

        @Override
        public void update(Song s, int sectionPosition) {
            mBinding.getViewModel().setIndex(sectionPosition);
        }
    }
}

@@ -2157,14 +2157,24 @@
 .set
-Index(
+Song(getData(), 
 sect

Fix incorrect view population when data set changes