nihk/videopager

It is suggested that each line of code should be annotated for your convenience

nikolamakin opened this issue · 3 comments

It is suggested that each line of code should be annotated for your convenience, which is friendly to rookies

Are there any parts in particular you'd like more clarification on?

Are there any parts in particular you'd like more clarification on?

Hello, code God

Can you write some code logic of network request? Thank you

nihk commented

In this repo I've abstracted the video data source to an interface VideoDataRepository. Its implementation can be anything that returns a flow of video data. For example, if you wanted to do a one-shot network request for your video data using retrofit, an implementation could look like:

class OneShotNetworkVideoDataRepository(private val api: YourApi) : VideoDataRepository {
  override fun videoData(): Flow<List<VideoData>> = flow {
    val videos = api.fetchVideos() // be sure to map your API response type to List<VideoData>
    emit(videos)
  }
}

Note I haven't included error handling and made an assumption that api.fetchVideos() is a suspending function called on another dispatcher like DIspatchers.IO.

You could also change VideoDataRepository to return something like a Flow<State<List<VideoData>> if you want to better model states like loading/success/error.

Hope that helps. Let me know if you want more information on that.