package com.h.pixeldroid.fragments.feeds.uncachedFeeds import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import androidx.paging.* import com.h.pixeldroid.objects.FeedContent import kotlinx.coroutines.flow.Flow /** * ViewModel for the uncached feeds. * The ViewModel works with the different [UncachedContentRepository]s to get the data. */ class FeedViewModel(private val repository: UncachedContentRepository) : ViewModel() { private var currentResult: Flow>? = null fun flow(): Flow> { val lastResult = currentResult if (lastResult != null) { return lastResult } val newResult: Flow> = repository.getStream() .cachedIn(viewModelScope) currentResult = newResult return newResult } } /** * Common interface for the different uncached feeds */ interface UncachedContentRepository{ fun getStream(): Flow> }