use of com.polito.mad17.madmax.entities.User in project MadMax by deviz92.
the class HashMapFriendsAdapter method getView.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final View result;
if (convertView == null) {
result = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item, parent, false);
} else {
result = convertView;
}
Map.Entry<String, User> item = getItem(position);
TextView name = (TextView) result.findViewById(R.id.tv_sender);
TextView balanceText = (TextView) result.findViewById(R.id.tv_balance_text);
balanceText.setVisibility(View.INVISIBLE);
TextView balance = (TextView) result.findViewById(R.id.tv_balance);
balance.setVisibility(View.INVISIBLE);
name.setText(item.getValue().getName() + " " + item.getValue().getSurname());
ImageView photo = (ImageView) result.findViewById(R.id.img_photo);
// Loading profile image
Glide.with(parent.getContext()).load(item.getValue().getProfileImage()).placeholder(R.drawable.user_default).centerCrop().bitmapTransform(new CropCircleTransformation(parent.getContext())).diskCacheStrategy(DiskCacheStrategy.ALL).into(photo);
balance.setVisibility(View.GONE);
return result;
}
use of com.polito.mad17.madmax.entities.User in project MadMax by deviz92.
the class ProfileEdit method onCreate.
@Override
@TargetApi(23)
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.edit_profile);
nameView = (EditText) this.findViewById(R.id.name);
nameView.setText(currentUser.getName());
surnameView = (EditText) this.findViewById(R.id.surname);
surnameView.setText(currentUser.getSurname());
usernameView = (EditText) this.findViewById(R.id.sender_photo);
usernameView.setText(currentUser.getUsername());
// emailView = (EditText) this.findViewById(R.id.email);
// emailView.setText(currentUser.getEmail());
passwordView = (EditText) this.findViewById(R.id.password);
// progressDialog = new ProgressDialog(ProfileEdit.this);
profileImageView = (ImageView) this.findViewById(R.id.profile_image);
String profileImage = currentUser.getProfileImage();
if (profileImage != null && !profileImage.equals("")) {
// Loading image
Glide.with(this).load(profileImage).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL).into(profileImageView);
Log.d(TAG, "image url: " + MainActivity.getCurrentUser().getProfileImage());
} else {
// Loading image
Glide.with(this).load(R.drawable.user_default).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL).into(profileImageView);
}
profileImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i(TAG, "image clicked");
if (MainActivity.shouldAskPermission()) {
String[] perms = { "android.permission.READ_EXTERNAL_STORAGE" };
int permsRequestCode = 200;
requestPermissions(perms, permsRequestCode);
}
// allow to the user the choose his profile image
Intent intent = new Intent();
// Show only images, no videos or anything else
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
// Always show the chooser (if there are multiple options available)
startActivityForResult(Intent.createChooser(intent, "Select picture"), PICK_IMAGE_REQUEST);
// now see onActivityResult
}
});
saveButton = (Button) this.findViewById(R.id.btn_save);
saveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i(TAG, "save clicked");
if (updateAccount()) {
Toast.makeText(ProfileEdit.this, getString(R.string.saved), Toast.LENGTH_SHORT).show();
Intent i = new Intent(getApplicationContext(), MainActivity.class);
startActivity(i);
finish();
}
}
});
}
use of com.polito.mad17.madmax.entities.User in project MadMax by deviz92.
the class FirebaseServiceMessage method onMessageReceived.
/* @Override
public void onCreate() {
super.onCreate();
Log.d(TAG, "onCreate");
}*/
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
String body = remoteMessage.getNotification().getBody();
Map<String, String> data = remoteMessage.getData();
Log.d(TAG, "notification body: " + body);
String message[], messageContent = null;
// Creates an explicit intent for an Activity in the app
Intent resultIntent = null;
messageContent = body;
switch(data.get("notificationTitle")) {
case "notification_invite":
resultIntent = new Intent(getApplicationContext(), GroupDetailActivity.class);
resultIntent.putExtra("groupID", data.get("groupID"));
break;
case "notification_expense_added":
resultIntent = new Intent(getApplicationContext(), ExpenseDetailActivity.class);
resultIntent.putExtra("groupID", data.get("groupID"));
resultIntent.putExtra("expenseID", data.get("expenseID"));
break;
case "notification_expense_removed":
resultIntent = new Intent(getApplicationContext(), GroupDetailActivity.class);
resultIntent.putExtra("groupID", data.get("groupID"));
resultIntent.putExtra("expenseID", data.get("expenseID"));
break;
case "notification_proposalExpense_added":
resultIntent = new Intent(getApplicationContext(), PendingExpenseDetailActivity.class);
resultIntent.putExtra("expenseID", data.get("expenseID"));
break;
}
// User provaCurrent = MainActivity.getCurrentUser();
resultIntent.putExtra("userID", getCurrentUID());
NotificationCompat.Builder mBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(getApplicationContext()).setSmallIcon(R.mipmap.icon).setContentTitle(remoteMessage.getNotification().getTitle()).setContentText(messageContent);
// The stack builder object will contain an artificial back stack for the started Activity.
// This ensures that navigating backward from the Activity leads out of your application to the Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(getApplicationContext());
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(MainActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = mBuilder.build();
notification.flags = Notification.FLAG_AUTO_CANCEL;
// mId allows you to update the notification later on.
mNotificationManager.notify(1, notification);
/*String body = remoteMessage.getNotification().getBody();
Log.d(TAG, "notification body: "+body);
Map<String, String> data = remoteMessage.getData();
showNotification(remoteMessage.getNotification().getTitle(), body, data);*/
}
use of com.polito.mad17.madmax.entities.User 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.User in project MadMax by deviz92.
the class FirebaseUtils method leaveGroupFirebase.
public Integer leaveGroupFirebase(String userID, final String groupID) {
Group g = GroupsFragment.groups.get(groupID);
if (g != null) {
HashMap<String, Double> balances = g.getCurrencyBalances();
Boolean debt = false;
Log.d(TAG, g.getName() + " contains those balances: ");
if (balances != null) {
for (Map.Entry<String, Double> entry : balances.entrySet()) {
Log.d(TAG, entry.getKey() + " " + entry.getValue());
if (entry.getValue() < 0)
debt = true;
}
}
if (debt) {
Log.d(TAG, "Cannot leave group");
return 0;
} else {
Log.d(TAG, "Nessuno debito, abbandono in corso");
// Elimino gruppo da lista gruppi dello user
databaseReference.child("users").child(userID).child("groups").child(groupID).setValue(false);
// Elimino user dalla lista dei members del gruppo
databaseReference.child("groups").child(groupID).child("members").child(userID).child("deleted").setValue(true);
// Elimino gruppo da cache
GroupsFragment.groups.remove(groupID);
// Elimino gruppo dagli shared groups tra me e ogni membro del gruppo
deleteSharedGroup(MainActivity.getCurrentUID(), groupID);
return 2;
}
} else {
Log.d(TAG, "Bilancio del gruppo: " + groupID + " non disponibile adesso. Riprovare.");
return null;
}
}
Aggregations