package com.wall.photography.wallpaper.fragment

//import com.wall.photography.wallpaper.paging.MySource
import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import androidx.paging.cachedIn
import com.wall.photography.wallpaper.MyApp
import com.wall.photography.wallpaper.data.Bean
import com.wall.photography.wallpaper.paging.MySource
import kotlinx.coroutines.flow.Flow
import java.util.Random


class HomeViewModel : ViewModel() {



    fun getPaging(cateName:String): Flow<PagingData<Bean>> {
        val nextInt = Random().nextInt(100)
        Log.d(MyApp.TAG,"----------nextInt=${nextInt}")
        return Pager(
            config = PagingConfig(pageSize = MyApp.pageSize, initialLoadSize = MyApp.pageSize),
            pagingSourceFactory = { MySource(cateName,nextInt) }
        ).flow
    }

    fun getPagingData(cateName:String): Flow<PagingData<Bean>> {

        return getPaging(cateName).cachedIn(viewModelScope)
    }



}