use of com.polito.mad17.madmax.entities.Event in project MadMax by deviz92.
the class NewMemberActivity 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(this, "Unable to send invitation", Toast.LENGTH_SHORT).show();
}
}
}
use of com.polito.mad17.madmax.entities.Event in project MadMax by deviz92.
the class NewMemberActivity method onOptionsItemSelected.
// When I click SAVE
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int itemThatWasClickedId = item.getItemId();
if (itemThatWasClickedId == R.id.action_save) {
for (User newMemeber : alreadySelected.values()) {
FirebaseUtils.getInstance().joinGroupFirebase(newMemeber.getID(), groupID);
// add event for GROUP_MEMBER_ADD
User currentUser = MainActivity.getCurrentUser();
Event event = new Event(groupID, Event.EventType.GROUP_MEMBER_ADD, currentUser.getName() + " " + currentUser.getSurname(), newMemeber.getName() + " " + newMemeber.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);
}
for (User user : friends.values()) {
if (user.getIsInGroupForInvite().equals(groupID)) {
FirebaseUtils.getInstance().removeMemberFirebase(user.getID(), groupID);
// add event for GROUP_MEMBER_REMOVE
User currentUser = MainActivity.getCurrentUser();
Event event = new Event(groupID, Event.EventType.GROUP_MEMBER_REMOVE, currentUser.getName() + " " + currentUser.getSurname(), user.getName() + " " + user.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);
}
}
friends.clear();
alreadySelected.clear();
Toast.makeText(getApplicationContext(), getString(R.string.member_add), Toast.LENGTH_SHORT).show();
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
use of com.polito.mad17.madmax.entities.Event in project MadMax by deviz92.
the class PayExpenseActivity method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Intent intent;
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);
*/
onBackPressed();
return true;
case R.id.action_save:
Log.d(TAG, "Clicked pay expense");
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();
}
}
if (money != null) {
if (money > debt) {
Toast.makeText(PayExpenseActivity.this, getString(R.string.cannot_pay_more), Toast.LENGTH_SHORT).show();
return true;
} else if (money <= 0) {
Toast.makeText(PayExpenseActivity.this, getString(R.string.invalid_amount), Toast.LENGTH_SHORT).show();
return true;
} else {
Toast.makeText(PayExpenseActivity.this, getString(R.string.paid), Toast.LENGTH_SHORT).show();
payDebtForExpense(userID, expenseID, money);
// add event for USER_PAY
User currentUser = MainActivity.getCurrentUser();
String userID = currentUser.getID();
Event event = new Event(groupID, Event.EventType.USER_PAY, userID, money + " €");
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, ExpenseDetailActivity.class);
intent.putExtra("groupID", groupID);
intent.putExtra("userID", userID);
intent.putExtra("expenseID", expenseID);
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 EventsViewAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final EventViewHolder eventViewHolder, int position) {
final Event event = getItem(position).getValue();
User currentUser = MainActivity.getCurrentUser();
DatabaseReference databaseReference = FirebaseUtils.getDatabaseReference();
switch(event.getEventType()) {
case GROUP_ADD:
eventViewHolder.imageView.setImageResource(R.drawable.group_add);
event.setDescription(event.getSubject() + " " + context.getString(R.string.GROUP_ADD) + " \"" + event.getObject() + "\"");
break;
/*case GROUP_REMOVE:
eventViewHolder.imageView.setImageResource(R.drawable.group_remove);
event.setDescription("\"" + event.getSubject() + "\" " + context.getString(R.string.GROUP_REMOVE) + " \"" + event.getObject() + "\"");
break;*/
case GROUP_EDIT:
eventViewHolder.imageView.setImageResource(R.drawable.group_edit);
event.setDescription(event.getSubject() + " " + context.getString(R.string.GROUP_EDIT) + " \"" + event.getObject() + "\"");
break;
case GROUP_MEMBER_ADD:
eventViewHolder.imageView.setImageResource(R.drawable.user_add);
event.setDescription(event.getSubject() + " " + context.getString(R.string.GROUP_MEMBER_ADD) + " " + event.getObject());
break;
case GROUP_MEMBER_REMOVE:
eventViewHolder.imageView.setImageResource(R.drawable.user_remove);
event.setDescription(event.getSubject() + " " + context.getString(R.string.GROUP_MEMBER_REMOVE) + " " + event.getObject());
break;
case EXPENSE_ADD:
eventViewHolder.imageView.setImageResource(R.drawable.expense_add);
event.setDescription(event.getSubject() + " " + context.getString(R.string.EXPENSE_ADD) + " \"" + event.getObject() + "\"");
break;
case EXPENSE_REMOVE:
eventViewHolder.imageView.setImageResource(R.drawable.expense_remove);
event.setDescription(event.getSubject() + " " + context.getString(R.string.EXPENSE_REMOVE) + " \"" + event.getObject() + "\"");
break;
case EXPENSE_EDIT:
eventViewHolder.imageView.setImageResource(R.drawable.expense_edit);
event.setDescription(event.getSubject() + " " + context.getString(R.string.EXPENSE_EDIT) + " \"" + event.getObject() + "\"");
break;
case PENDING_EXPENSE_ADD:
eventViewHolder.imageView.setImageResource(R.drawable.expense_add);
event.setDescription(event.getSubject() + " " + context.getString(R.string.PENDING_EXPENSE_ADD) + " \"" + event.getObject() + "\"");
break;
case PENDING_EXPENSE_REMOVE:
eventViewHolder.imageView.setImageResource(R.drawable.expense_remove);
event.setDescription(event.getSubject() + " " + context.getString(R.string.PENDING_EXPENSE_REMOVE) + " \"" + event.getObject() + "\"");
break;
case PENDING_EXPENSE_EDIT:
eventViewHolder.imageView.setImageResource(R.drawable.expense_edit);
event.setDescription(event.getSubject() + " " + context.getString(R.string.PENDING_EXPENSE_EDIT) + " \"" + event.getObject() + "\"");
break;
case PENDING_EXPENSE_VOTE_UP:
eventViewHolder.imageView.setImageResource(R.drawable.thumb_up_black);
event.setDescription(event.getSubject() + " " + context.getString(R.string.PENDING_EXPENSE_VOTE) + " \"" + event.getObject() + "\"");
break;
case PENDING_EXPENSE_VOTE_DOWN:
eventViewHolder.imageView.setImageResource(R.drawable.thumb_down_black);
event.setDescription(event.getSubject() + " " + context.getString(R.string.PENDING_EXPENSE_VOTE) + " \"" + event.getObject() + "\"");
break;
case PENDING_EXPENSE_APPROVED:
eventViewHolder.imageView.setImageResource(R.drawable.expense_add);
event.setDescription(context.getString(R.string.PENDING_EXPENSE) + " \"" + event.getObject() + "\" " + context.getString(R.string.PENDING_EXPENSE_APPROVED));
break;
case PENDING_EXPENSE_NEGLECTED:
eventViewHolder.imageView.setImageResource(R.drawable.pending_expense_neglected);
event.setDescription(context.getString(R.string.PENDING_EXPENSE) + " \"" + event.getObject() + "\" " + context.getString(R.string.PENDING_EXPENSE_NEGLECTED));
break;
/*case FRIEND_INVITE:
eventViewHolder.imageView.setImageResource(R.drawable.user_add);
event.setDescription(context.getString(R.string.FRIEND_INVITE) + " \"" + event.getObject() + "\"");
break;*/
case FRIEND_GROUP_INVITE:
eventViewHolder.imageView.setImageResource(R.drawable.user_add);
event.setDescription(context.getString(R.string.FRIEND_GROUP_INVITE) + " " + event.getObject());
break;
case // instead of the username the subject must be the ID of the user
USER_PAY:
eventViewHolder.imageView.setImageResource(R.drawable.user_pay);
if (currentUser.getID().equals(event.getSubject())) {
event.setDescription(context.getString(R.string.ME_PAY) + " " + event.getObject());
} else {
databaseReference.child("users").child(event.getSubject()).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
event.setDescription(dataSnapshot.child("name").getValue(String.class) + " " + dataSnapshot.child("surname").getValue(String.class) + " " + context.getString(R.string.FRIEND_PAY) + " " + event.getObject());
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.w(TAG, databaseError.toException());
}
});
}
break;
case // instead of the username the subject must be the ID of the user
USER_COMMENT_ADD:
eventViewHolder.imageView.setImageResource(R.drawable.user_comment);
if (currentUser.getID().equals(event.getSubject())) {
event.setDescription(context.getString(R.string.ME_COMMENT_ADD) + " \"" + event.getObject() + "\"");
} else {
databaseReference.child("users").child(event.getSubject()).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
event.setDescription(dataSnapshot.child("name").getValue(String.class) + " " + dataSnapshot.child("surname").getValue(String.class) + " " + context.getString(R.string.FRIEND_COMMENT_ADD) + " \"" + event.getObject() + "\"");
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.w(TAG, databaseError.toException());
}
});
}
break;
default:
eventViewHolder.imageView.setImageResource(R.drawable.event_default);
event.setDescription("\"" + event.getSubject() + "\" " + context.getString(R.string.did) + " \"" + event.getObject() + "\"");
}
eventViewHolder.descriptionTextView.setText(event.getDescription());
eventViewHolder.timestampTextView.setText(context.getString(R.string.day) + " " + event.getDate() + " " + context.getString(R.string.at) + " " + event.getTime());
}
use of com.polito.mad17.madmax.entities.Event in project MadMax by deviz92.
the class NewGroupActivity method onOptionsItemSelected.
// When i click SAVE
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int itemThatWasClickedId = item.getItemId();
if (itemThatWasClickedId == R.id.action_save) {
// display message if text field is empty
if (TextUtils.isEmpty(nameGroup.getText().toString())) {
nameGroup.setError(getString(R.string.required));
return false;
}
Log.d(TAG, "Second step: invite members to group");
// String deepLink = getString(R.string.invitation_deep_link) + "?groupToBeAddedID=" + groupID+ "?inviterToGroupUID=" + MainActivity.getCurrentUID();
newgroup_id = databaseReference.child("groups").push().getKey();
String name = nameGroup.getText().toString();
String description = descriptionGroup.getText().toString();
// id is useless
final Group newGroup = new Group("0", name, "noImage", description, 1);
// for saving image
StorageReference uProfileImageFilenameRef = storageReference.child("groups").child(newgroup_id).child(newgroup_id + "_profileImage.jpg");
// Get the data from an ImageView as bytes
imageGroup.setDrawingCacheEnabled(true);
imageGroup.buildDrawingCache();
Bitmap bitmap = imageGroup.getDrawingCache();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] imageData = baos.toByteArray();
UploadTask uploadTask = uProfileImageFilenameRef.putBytes(imageData);
uploadTask.addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
@Override
public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
if (task.isSuccessful()) {
newGroup.setImage(task.getResult().getDownloadUrl().toString());
Log.d(TAG, "group img url: " + newGroup.getImage());
databaseReference.child("groups").child(newgroup_id).setValue(newGroup);
String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new java.util.Date());
databaseReference.child("groups").child(newgroup_id).child("timestamp").setValue(timeStamp);
databaseReference.child("groups").child(newgroup_id).child("numberMembers").setValue(1);
FirebaseUtils.getInstance().joinGroupFirebase(MainActivity.getCurrentUID(), newgroup_id);
Log.d(TAG, "group " + newgroup_id + " created");
// add event for GROUP_ADD
User currentUser = MainActivity.getCurrentUser();
Event event = new Event(newgroup_id, Event.EventType.GROUP_ADD, currentUser.getName() + " " + currentUser.getSurname(), newGroup.getName());
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 intent = new Intent(getApplicationContext(), NewMemberActivity.class);
intent.putExtra("groupID", newgroup_id);
intent.putExtra("groupName", name);
startActivity(intent);
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
Aggregations