Giter Site home page Giter Site logo

How to use with remote data about videopager HOT 3 CLOSED

nihk avatar nihk commented on June 15, 2024
How to use with remote data

from videopager.

Comments (3)

heromiyo avatar heromiyo commented on June 15, 2024 1

Hey @nihk Thanks, i followed the steps and managed to fetch the videos, working on exoplayer caching (Preloading?/PreCaching?) .
Thanks for your help

from videopager.

nihk avatar nihk commented on June 15, 2024

Hey @heromiyo, great question. In this project, all MainViewModel cares about is the VideoDataRepository interface - it doesn't know anything about how it ultimately gets the List<VideoData>. That means you can pass in any custom implementation of VideoDataRepository to the ViewModel. For example, you could create a FirebaseVideoDataRepository implementation which uses Firebase to acquire the list of videos. VideoDataRepository has the one function which returns a Flow<List<VideoData>>; that represents a stream of data that could be anything on any thread.

In your case with Firebase you'll want to get a Flow of your relevant Firebase objects then map them to a List<VideoData>. I'm not familiar with the Firebase APIs, but here's the basic idea with some contrived classes:

class FirebaseVideoDataRepository(private val firebase: Firebase) : VideoDataRepository {
    override fun videoData(): Flow<List<VideoData>> {
        return firebase.getAllVideos()
            .map { videos -> videos.toVideoData() }
    }
    
    private fun List<FirebaseVideo>.toVideoData(): List<VideoData> {
        return map { firebaseVideo ->  VideoData(mediaUri = firebaseVideo.url) }
    }
}

interface Firebase {
    fun getAllVideos(): Flow<List<FirebaseVideo>>
}

data class FirebaseVideo(val url: String)

You could change the return type of VideoDataRepository's function to have some wrapper representing state, too. E.g. fun videoData(): Flow<MyState<List<VideoData>>>. That will facilitate the Success/Error states in your example.

Note that the current state of the app in this repository won't show image previews of remote videos (only local videos). This can be achieved by simply adding a new field to the VideoData object representing the image URL of a frame preview, then using it in the RecyclerView.ViewHolder. I'll check in a commit later to make that more clear.

from videopager.

nikolamakin avatar nikolamakin commented on June 15, 2024

hi, Have you solved it
Can I post part of the code of the response

from videopager.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.