blob: 711e8c4ca61f20e4bda20ba12aa7bd689ffc49c9 [file] [log] [blame]
// Copyright 2016 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package io.v.todos.persistence;
import android.content.Context;
import com.firebase.client.ChildEventListener;
import com.firebase.client.Firebase;
import io.v.todos.TodoList;
public class FirebaseMain extends FirebasePersistence implements MainPersistence {
public static final String TODO_LISTS = "snackoos (TodoList)";
private final Firebase mTodoLists;
private final ChildEventListener mTodoListsListener;
public FirebaseMain(Context context, final ListEventListener<TodoList> listener) {
super(context);
mTodoLists = getFirebase().child(TODO_LISTS);
mTodoListsListener = mTodoLists.addChildEventListener(
new FirebaseChildEventListenerAdapter<>(TodoList.class, listener));
}
@Override
public void addTodoList(TodoList todoList) {
mTodoLists.push().setValue(todoList);
}
@Override
public void deleteTodoList(String key) {
mTodoLists.child(key).removeValue();
}
@Override
public void close() {
getFirebase().removeEventListener(mTodoListsListener);
}
}