use of com.google.firebase.database.FirebaseDatabase in project SpotiQ by ZinoKader.
the class AppModule method providePartiesRepository.
@Provides
PartiesRepository providePartiesRepository() {
FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance();
DatabaseReference databaseReference = firebaseDatabase.getReference().child(FirebaseConstants.CHILD_PARTYLIST);
return new PartiesRepository(databaseReference);
}
use of com.google.firebase.database.FirebaseDatabase in project FirebaseUI-Android by firebase.
the class FirebaseIndexArrayTest method setUp.
@Before
public void setUp() throws Exception {
FirebaseDatabase databaseInstance = FirebaseDatabase.getInstance(getAppInstance(ApplicationProvider.getApplicationContext()));
mRef = databaseInstance.getReference().child("firebasearray");
mKeyRef = databaseInstance.getReference().child("firebaseindexarray");
mArray = new FirebaseIndexArray<>(mKeyRef, mRef, new ClassSnapshotParser<>(Integer.class));
mRef.removeValue();
mKeyRef.removeValue();
mListener = runAndWaitUntil(mArray, () -> {
for (int i = 1; i <= INITIAL_SIZE; i++) {
TestUtils.pushValue(mKeyRef, mRef, i, i);
}
}, () -> mArray.size() == INITIAL_SIZE);
}
use of com.google.firebase.database.FirebaseDatabase in project FirebaseUI-Android by firebase.
the class FirebaseIndexArrayOfObjectsTest method setUp.
@Before
public void setUp() throws Exception {
FirebaseDatabase databaseInstance = FirebaseDatabase.getInstance(getAppInstance(ApplicationProvider.getApplicationContext()));
mRef = databaseInstance.getReference().child("firebasearray").child("objects");
mKeyRef = databaseInstance.getReference().child("firebaseindexarray").child("objects");
mArray = new FirebaseIndexArray<>(mKeyRef, mRef, new ClassSnapshotParser<>(Bean.class));
mRef.removeValue();
mKeyRef.removeValue();
mListener = runAndWaitUntil(mArray, () -> {
for (int i = 1; i <= INITIAL_SIZE; i++) {
TestUtils.pushValue(mKeyRef, mRef, new Bean(i, "Text " + i, i % 2 == 0), i);
}
}, () -> mArray.size() == INITIAL_SIZE);
}
use of com.google.firebase.database.FirebaseDatabase in project NPSmiles by bmcglynn1.
the class NewsFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View viewer = inflater.inflate(R.layout.activity_news_feed, container, false);
View popupLayout = inflater.inflate(R.layout.popup_layout_logged_in, null);
final ListView list = (ListView) viewer.findViewById(R.id.list);
final ArrayList<NewsMessage> newsList = new ArrayList<>();
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("Reference");
mAuth = FirebaseAuth.getInstance();
if (mAuth.getCurrentUser() != null) {
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
PopupMenu popup = new PopupMenu(parent.getContext(), view);
popup.getMenuInflater().inflate(R.menu.popup_menu, popup.getMenu());
final TextView title = (TextView) view.findViewById(R.id.title);
final TextView message = (TextView) view.findViewById(R.id.information);
if (mAuth.getCurrentUser() != null) {
popup.show();
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch(item.getItemId()) {
case R.id.EditMenu:
// refresh view if needed
break;
case R.id.DeleteMenu:
// delete from firebase
// refresh view
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("Reference");
Query titleQuery = myRef.child(title.getText().toString());
titleQuery.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot titleSnapshot : dataSnapshot.getChildren()) {
dataSnapshot.getRef().removeValue();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
break;
}
return true;
}
});
}
}
});
}
myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
newsList.clear();
for (DataSnapshot newsItem : dataSnapshot.getChildren()) {
NewsMessage newsMessage = new NewsMessage();
for (DataSnapshot item : newsItem.getChildren()) {
if (item.getKey().equals("title")) {
newsMessage.setTitle((String) item.getValue());
} else if (item.getKey().equals("message")) {
newsMessage.setMessage((String) item.getValue());
} else {
newsMessage.setDate((String) item.getValue());
}
}
newsList.add(newsMessage);
}
Collections.sort(newsList);
CustomAdapter adapter = new CustomAdapter(context, newsList);
list.setAdapter(adapter);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
return viewer;
}
use of com.google.firebase.database.FirebaseDatabase in project NPSmiles by bmcglynn1.
the class CreatePost method addPost.
public void addPost() {
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("Reference");
DatabaseReference childRef = myRef.child(newsMessage.getTitle());
childRef.setValue(newsMessage);
}
Aggregations