use of com.google.firebase.database.DataSnapshot in project MadMax by deviz92.
the class GroupDetailActivity method itemLongClicked.
//Apro popup menu quando ho tenuto premuto un friend o gruppo per 1 secondo
@Override
public void itemLongClicked(String fragmentName, final String itemID, View v) {
Log.i(TAG, "fragmentName " + fragmentName + " itemID " + itemID);
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
Bundle bundle = new Bundle();
Intent intent = null;
switch(fragmentName) {
case "FriendsFragment":
break;
case "GroupsFragment":
popup = new PopupMenu(GroupDetailActivity.this, v, Gravity.RIGHT);
popup.getMenuInflater().inflate(R.menu.longclick_popup_menu, popup.getMenu());
one = popup.getMenu().findItem(R.id.one);
one.setTitle("Remove friend");
popup.getMenu().findItem(R.id.two).setVisible(false);
popup.getMenu().findItem(R.id.three).setVisible(false);
//registering popup with OnMenuItemClickListener
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
Toast.makeText(GroupDetailActivity.this, "You Clicked : " + item.getTitle(), Toast.LENGTH_SHORT).show();
return true;
}
});
//showing popup menu
popup.show();
case "ExpensesFragment":
popup = new PopupMenu(GroupDetailActivity.this, v, Gravity.RIGHT);
popup.getMenuInflater().inflate(R.menu.longclick_popup_menu, popup.getMenu());
one = popup.getMenu().findItem(R.id.one);
one.setTitle("Remove expense");
popup.getMenu().findItem(R.id.two).setVisible(false);
popup.getMenu().findItem(R.id.three).setVisible(false);
//registering popup with OnMenuItemClickListener
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
//Toast.makeText(GroupDetailActivity.this,"You Clicked : " + item.getTitle(),Toast.LENGTH_SHORT).show();
FirebaseUtils.getInstance().removeExpenseFirebase(itemID, getApplicationContext());
// add event for EXPENSE_REMOVE
databaseReference.child("expenses").child(itemID).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
User currentUser = MainActivity.getCurrentUser();
Event event = new Event(groupID, Event.EventType.EXPENSE_REMOVE, currentUser.getName() + " " + currentUser.getSurname(), dataSnapshot.child("description").getValue(String.class));
event.setDate(new SimpleDateFormat("yyyy.MM.dd").format(new java.util.Date()));
event.setTime(new SimpleDateFormat("HH:mm").format(new java.util.Date()));
FirebaseUtils.getInstance().addEvent(event);
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.w(TAG, databaseError.toException());
}
});
return true;
}
});
//showing popup menu
popup.show();
break;
}
}
use of com.google.firebase.database.DataSnapshot in project MadMax by deviz92.
the class PendingExpensesFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
/*getSupportFragmentManager().beginTransaction()
.add(detailFragment, "detail")
// Add this transaction to the back stack
.addToBackStack()
.commit();*/
Log.d(TAG, "onCreateView");
setInterface((OnItemClickInterface) getActivity(), (OnItemLongClickInterface) getActivity());
View view = inflater.inflate(R.layout.skeleton_list, container, false);
RecyclerView.ItemDecoration divider = new InsetDivider.Builder(getContext()).orientation(InsetDivider.VERTICAL_LIST).dividerHeight(getResources().getDimensionPixelSize(R.dimen.divider_height)).color(ContextCompat.getColor(getContext(), R.color.colorDivider)).insets(getResources().getDimensionPixelSize(R.dimen.divider_inset), 0).overlay(true).build();
recyclerView = (RecyclerView) view.findViewById(R.id.rv_skeleton);
layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
recyclerView.setLayoutManager(layoutManager);
recyclerView.addItemDecoration(divider);
pendingExpenseViewAdapter = new PendingExpenseViewAdapter(this.getContext(), this, this, pendingExpensesMap);
recyclerView.setAdapter(pendingExpenseViewAdapter);
//Ascolto le pending expenses dello user
databaseReference.child("users").child(MainActivity.getCurrentUser().getID()).child("proposedExpenses").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//Per ogni pending expense dello user
for (DataSnapshot pendingExpenseSnap : dataSnapshot.getChildren()) {
//Se la pending expense non è stata eliminata (NELLO USER)
if (pendingExpenseSnap.getValue(Boolean.class)) {
FirebaseUtils.getInstance().getPendingExpense(pendingExpenseSnap.getKey(), pendingExpensesMap, pendingExpenseViewAdapter);
pendingExpenseViewAdapter.update(pendingExpensesMap);
pendingExpenseViewAdapter.notifyDataSetChanged();
} else {
//tolgo la spesa da quelle che verranno stampate, così la vedo sparire realtime
pendingExpensesMap.remove(pendingExpenseSnap.getKey());
pendingExpenseViewAdapter.update(pendingExpensesMap);
pendingExpenseViewAdapter.notifyDataSetChanged();
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
return view;
}
Aggregations