lundi 28 septembre 2020

Best practices for prefetching data in repositories before its usage in android

I am trying to apply the repository pattern in my project, I have multiple of Repos for different data an example is shown below, I want the data to be ready before its usage, so what're the best practices for doing that... My thoughts are if for example if there's a transition between fragment 1 to fragment 2, if Fragment2 wants to access specific data, then Fragment1 has to make the data ready in the repo while making the transition,
but is there a specific guide for doing that? I feel that opposes the single responsibility principle.

object LanguageRepository {

    // make this ready before its usage
    lateinit var linguisticLanguages: List<Language>

    suspend fun loadAllLanguages() {
        withContext(Dispatchers.IO) {
            
            linguisticLanguages = Transformer.transform(LanguageService.getAvailableLanguages(true))
            // todo if sth happened fetch from cache
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire