package com.live.mylivewallpaper.viewmode;

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.live.mylivewallpaper.data.LikeData;
import com.live.mylivewallpaper.paging.MyLikeSource;

import java.util.List;


public class VmLikeFragment extends ViewModel {

    public  Pager<Integer, LikeData> pager;



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

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

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


}
