package com.wall.photography.wallpaper.viewmode


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


class ListActivityViewModel : ViewModel() {

    fun getPaging(cateName:String): Flow<PagingData<Bean>> {
        return Pager(
            config = PagingConfig(pageSize = MyApp.pageSize, initialLoadSize = MyApp.pageSize),
            pagingSourceFactory = { MySource(cateName) }
        ).flow
    }

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

        return getPaging(cateName).cachedIn(viewModelScope)
    }



}