package com.cartoon.live.wallpaper.myviewmode;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import androidx.paging.Pager;
import androidx.paging.PagingConfig;
import androidx.paging.PagingData;
import androidx.paging.PagingLiveData;

import com.cartoon.live.wallpaper.mydata.FavoriteData;
import com.cartoon.live.wallpaper.mypaging.MyLikeSource;

import java.util.List;


public class VmLikeFragment extends ViewModel {

    public  Pager<Integer, FavoriteData> pager;



    private MutableLiveData<PagingData<FavoriteData>> _likeLiveData = new MutableLiveData<>();
    public LiveData<PagingData<FavoriteData>> likeLiveData = _likeLiveData  ;

    public LiveData<PagingData<FavoriteData>> getPagingData() {
        Pager<Integer, FavoriteData> integerLikeDataPager = new Pager<>(
                new PagingConfig(10), // 每页加载 20 条数据
                MyLikeSource::new
        );

        return PagingLiveData.getLiveData(integerLikeDataPager);
    }
    public  void update(List<FavoriteData> data){
        PagingData<FavoriteData> from = PagingData.from(data);
        _likeLiveData.postValue(from);
    }


}
