use of com.polito.mad17.madmax.entities.Event in project MadMax by deviz92.
the class PayGroupActivity method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
Log.d(TAG, "Clicked up button");
Intent intent = new Intent(this, GroupDetailActivity.class);
intent.putExtra("groupID", groupID);
intent.putExtra("userID", userID);
startActivity(intent);
return true;
case R.id.action_save:
Log.d(TAG, "Clicked pay");
Double money = null;
String text = amountEditText.getText().toString();
if (!text.isEmpty()) {
try {
// it means it is double
money = Double.parseDouble(text);
} catch (Exception e1) {
// this means it is not double
e1.printStackTrace();
}
}
// Retrieve selected currency and debt for that currency
shownCurrency = currency.getSelectedItem().toString();
debt = totBalances.get(shownCurrency);
// If you have no debts in that currency
if (debt == null || debt >= 0) {
Toast.makeText(PayGroupActivity.this, getString(R.string.no_debts_currency), Toast.LENGTH_SHORT).show();
return true;
}
debt = abs(Math.floor(debt * 100) / 100);
if (money != null) {
Log.d(TAG, "payed " + money);
if (money > debt) {
Toast.makeText(PayGroupActivity.this, getString(R.string.cannot_pay_more_currency), Toast.LENGTH_SHORT).show();
return true;
} else if (money <= 0) {
Toast.makeText(PayGroupActivity.this, getString(R.string.no_payment), Toast.LENGTH_SHORT).show();
return true;
} else {
// currency.getSelectedItem().toString()
payDebtForExpenses(userID, groupID, money, shownCurrency);
// add event for USER_PAY
User currentUser = MainActivity.getCurrentUser();
String userID = currentUser.getID();
Event event = new Event(groupID, Event.EventType.USER_PAY, userID, money + " " + shownCurrency);
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);
intent = new Intent(this, GroupDetailActivity.class);
intent.putExtra("groupID", groupID);
intent.putExtra("userID", userID);
finish();
startActivity(intent);
return true;
}
} else {
Log.d(TAG, "Error: money is null");
}
return true;
}
return super.onOptionsItemSelected(item);
}
use of com.polito.mad17.madmax.entities.Event in project MadMax by deviz92.
the class FirebaseUtils method removeExpenseFirebase.
public void removeExpenseFirebase(final String expenseID, final Context context) {
databaseReference.child("expenses").child(expenseID).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String groupID = dataSnapshot.child("groupID").getValue(String.class);
// aggiunto da riky per mandare la notifica a tutti tranne a chi ha eliminato la spesa
databaseReference.child("expenses").child(expenseID).child("deletedBy").setValue(MainActivity.getCurrentUID());
// Elimino spesa dal gruppo
databaseReference.child("groups").child(groupID).child("expenses").child(expenseID).setValue(false);
// Per ogni participant elimino la spesa dal suo elenco spese
for (DataSnapshot participantSnapshot : dataSnapshot.child("participants").getChildren()) {
String participantID = participantSnapshot.getKey();
databaseReference.child("users").child(participantID).child("expenses").child(expenseID).setValue(false);
}
// Elimino commenti sulla spesa
databaseReference.child("comments").child(groupID).removeValue();
// Elimino spesa
databaseReference.child("expenses").child(expenseID).child("deleted").setValue(true);
// Toast.makeText(context,context.getString(R.string.expense_removed),Toast.LENGTH_SHORT).show();
// add event for EXPENSE_REMOVE
databaseReference.child("expenses").child(expenseID).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
User currentUser = MainActivity.getCurrentUser();
Event event = new Event(dataSnapshot.child("groupID").getValue(String.class), 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());
}
});
/*Intent intent = new Intent(context, GroupDetailActivity.class);
intent.putExtra("groupID", groupID);
intent.putExtra("userID", MainActivity.getCurrentUID());
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);*/
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
use of com.polito.mad17.madmax.entities.Event in project MadMax by deviz92.
the class FirebaseUtils method removePendingExpenseFirebase.
public void removePendingExpenseFirebase(final String expenseID, final Context context) {
databaseReference.child("proposedExpenses").child(expenseID).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String groupID = dataSnapshot.child("groupID").getValue(String.class);
// Elimino spesa pending dal gruppo
databaseReference.child("groups").child(groupID).child("proposedExpenses").child(expenseID).setValue(false);
// Per ogni participant elimino la spesa pending dal suo elenco spese pending
for (DataSnapshot participantSnapshot : dataSnapshot.child("participants").getChildren()) {
String participantID = participantSnapshot.getKey();
databaseReference.child("users").child(participantID).child("proposedExpenses").child(expenseID).setValue(false);
}
// todo Elimino commenti sulla spesa pending
// databaseReference.child("comments").child(groupID).removeValue();
// Elimino spesa pending
databaseReference.child("proposedExpenses").child(expenseID).child("deleted").setValue(true);
// Toast.makeText(context, context.getString(R.string.expense_removed), Toast.LENGTH_SHORT).show();
// add event for PENDING_EXPENSE_REMOVE
databaseReference.child("proposedExpenses").child(expenseID).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
User currentUser = MainActivity.getCurrentUser();
Event event = new Event(dataSnapshot.child("groupID").getValue(String.class), Event.EventType.PENDING_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());
}
});
/*Intent intent = new Intent(context, MainActivity.class);
intent.putExtra("currentFragment", 2);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);*/
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
use of com.polito.mad17.madmax.entities.Event in project MadMax by deviz92.
the class DetailFragment method onActivityResult.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.i(TAG, "onActivityResult: requestCode=" + requestCode + ", resultCode=" + resultCode);
if (requestCode == MainActivity.REQUEST_INVITE_GROUP) {
if (resultCode == RESULT_OK) {
// Get the invitation IDs of all sent messages
String[] ids = AppInviteInvitation.getInvitationIds(resultCode, data);
for (String id : ids) {
Log.i(TAG, "onActivityResult: sent invitation " + id);
}
// add event for FRIEND_GROUP_INVITE
User currentUser = MainActivity.getCurrentUser();
Event event = new Event(groupID, Event.EventType.FRIEND_GROUP_INVITE, currentUser.getName() + " " + currentUser.getSurname());
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);
} else {
// Sending failed or it was canceled, show failure message to the user
Log.e(TAG, "onActivityResult: failed sent");
// Toast.makeText(getActivity(), "Unable to send invitation", Toast.LENGTH_SHORT).show();
}
}
}
use of com.polito.mad17.madmax.entities.Event in project MadMax by deviz92.
the class NewCommentDialogFragment method onCreateDialog.
@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
Bundle arguments = getArguments();
final String groupID = arguments.getString("groupID");
final String expenseID = arguments.getString("expenseID");
final String expenseName = arguments.getString("expenseName");
final Boolean isExpense = arguments.getBoolean("isExpense");
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.prompt_comment).setView(R.layout.new_comment_dialog).setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
User currentUser = MainActivity.getCurrentUser();
EditText message = (EditText) getDialog().findViewById(R.id.comment_message);
// add comment
Comment comment = new Comment(expenseID, currentUser.getName() + " " + currentUser.getSurname(), currentUser.getProfileImage(), message.getText().toString());
comment.setDate(new SimpleDateFormat("yyyy.MM.dd").format(new java.util.Date()));
comment.setTime(new SimpleDateFormat("HH:mm").format(new java.util.Date()));
FirebaseUtils.getInstance().addComment(comment, isExpense);
// add event for USER_COMMENT_ADD
Event event = new Event(groupID, Event.EventType.USER_COMMENT_ADD, // instead of the username the subject must be the ID of the user
currentUser.getID(), expenseName);
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);
// Send the positive button event back to the host activity
newCommentDialogListener.onDialogPositiveClick(NewCommentDialogFragment.this);
}
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User cancelled the dialog
// Send the negative button event back to the host activity
// newCommentDialogListener.onDialogNegativeClick(NewCommentDialogFragment.this);
}
});
// Create the AlertDialog object and return it
return builder.create();
}
Aggregations