use of com.polito.mad17.madmax.entities.Group 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