package com.magnify.utils.ui.fragment.ui;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.yw.datautils.RandomUtil;
import com.yw.datautils.User;
import com.magnify.utils.R;
import com.yw.fastviewlibrary.fragment.BaseFragment;
import com.yw.fastviewlibrary.viewgroup.FavoriateLayout;

import adapter.abslistview.CommonAdapter;
import adapter.ViewHolders;


/**
 * Created by ${洒笑天涯} on 2016/11/13.
 */

public class HeartFormFragment extends BaseFragment {
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = LayoutInflater.from(getContext()).inflate(R.layout.activity_favoriate_layout, null);
        ListView mListView = (ListView) view.findViewById(R.id.mlistView);
        FavoriateLayout plFavoriate = (FavoriateLayout) view.findViewById(R.id.plFavoriate);
        mListView.setAdapter(new HeartFormAdapter(getContext(), plFavoriate));
        return view;
    }

    private class HeartFormAdapter extends CommonAdapter<User> {
        private FavoriateLayout mFl;

        public HeartFormAdapter(Context context, FavoriateLayout plFavoriate) {
            super(context, R.layout.item_heartform, RandomUtil.createRandomUser(100));
            mFl = plFavoriate;
        }

        @Override
        public void convert(ViewHolders holder, int position, User user) {
            holder.displayWithDefault(R.id.img, user.getImageAvator())
                    .setText(R.id.tv_text, user.getUserName())
                    .setOnClickListener(view -> mFl.startAnimation(view), R.id.img_favoriate);
        }
    }
}
