Skip to content

Instantly share code, notes, and snippets.

@ronbeltran
Created March 11, 2016 03:37
Show Gist options
  • Save ronbeltran/18c89d20785cd6d22225 to your computer and use it in GitHub Desktop.
Save ronbeltran/18c89d20785cd6d22225 to your computer and use it in GitHub Desktop.
package com.ronbeltran.projectname;
import android.content.Context;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class TaskLab {
/**
* Singleton class to hold task list
* */
private static TaskLab sTaskLab;
private List<Task> mTasks;
public static TaskLab get(Context context) {
if(sTaskLab == null){
sTaskLab = new TaskLab(context);
}
return sTaskLab;
}
private TaskLab(Context context) {
mTasks = new ArrayList<>();
// generate dummy tasks
for(int i=0; i<100; i++){
Task task = new Task();
task.setBody("Task #" + i);
task.setIsPublic(i % 2 == 0);
mTasks.add(task);
}
}
public List<Task> getTasks() {
return mTasks;
}
public Task getTask(UUID id) {
for(Task task: mTasks) {
if(task.getId().equals(id)){
return task;
}
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment