Skip to content

Instantly share code, notes, and snippets.

@thatfiredev
Last active June 29, 2017 16:32
Show Gist options
  • Select an option

  • Save thatfiredev/eaa39ed03ddb6b4d254e174663b2bc6f to your computer and use it in GitHub Desktop.

Select an option

Save thatfiredev/eaa39ed03ddb6b4d254e174663b2bc6f to your computer and use it in GitHub Desktop.
Utilizado no artigo Android Architecture Components - LiveData: https://medium.com/@rosariopfernandes/aac5-9c56e6b4cffc
public LiveData<List<Tarefa>> getTarefas() {
if(tarefas == null) {
carregarDados();
}
if(tarefas.getValue().size()==0) {
//Transformations.map()
tarefas = Transformations.map(tarefas, new Function<List<Tarefa>,
List<Tarefa>>() {
@Override
public List<Tarefa> apply(List<Tarefa> novasTarefas) {
novasTarefas.add(new Tarefa(0, "Bem-vindo",
"Bem-vindo ao mundo dos Architecture Components"));
return novasTarefas;
}
});
}
return tarefas;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment