use of com.polito.mad17.madmax.entities.User 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.User 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.User in project MadMax by deviz92.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i(TAG, "onCreate");
FirebaseUtils.getInstance().setUp();
firebaseDatabase = FirebaseUtils.getFirebaseDatabase();
databaseReference = FirebaseUtils.getDatabaseReference();
usersRef = databaseReference.child("users");
groupRef = databaseReference.child("groups");
auth = FirebaseAuth.getInstance();
// get data from firebase invite, if present
startingIntent = getIntent();
Uri data = startingIntent.getData();
if (data != null) {
inviterID = data.getQueryParameter("inviterID");
groupToBeAddedID = data.getQueryParameter("groupToBeAddedID");
} else {
// nretrieving data from the intent inviterID & groupToBeAddedID as the group ID where to add the current user
if (startingIntent.hasExtra("inviterID")) {
// to be used to set the current user as friend of the inviter
Log.d(TAG, "there is an invite");
inviterID = startingIntent.getStringExtra("inviterID");
startingIntent.removeExtra("inviterID");
} else
inviterID = null;
if (startingIntent.hasExtra("groupToBeAddedID")) {
groupToBeAddedID = startingIntent.getStringExtra("groupToBeAddedID");
startingIntent.removeExtra("groupToBeAddedID");
} else
groupToBeAddedID = null;
}
currentFragment = startingIntent.getIntExtra("currentFragment", 1);
if (auth.getCurrentUser() == null || !auth.getCurrentUser().isEmailVerified()) {
if (auth.getCurrentUser() != null) {
auth.signOut();
}
Intent doLogin = new Intent(getApplicationContext(), LoginSignUpActivity.class).setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
if (inviterID != null)
doLogin.putExtra("inviterID", inviterID);
if (groupToBeAddedID != null)
doLogin.putExtra("groupToBeAddedID", groupToBeAddedID);
startActivity(doLogin);
// 0 for no animation
overridePendingTransition(0, 0);
finish();
}
if (auth.getCurrentUser() != null) {
currentUID = auth.getCurrentUser().getUid();
}
// in the main we don't want an expansible bar
AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.app_bar);
appBarLayout.setExpanded(false);
// todo: capire come bloccare la barra nel main
// insert tabs and current fragment in the main layout
mainView.addView(getLayoutInflater().inflate(R.layout.skeleton_tab, null));
tabLayout = (TabLayout) findViewById(R.id.tab_layout);
tabLayout.addTab(tabLayout.newTab().setText(friends));
tabLayout.addTab(tabLayout.newTab().setText(R.string.groups));
tabLayout.addTab(tabLayout.newTab().setText(R.string.pending));
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
Log.d(TAG, String.valueOf(tab.getPosition()));
updateFab(tab.getPosition());
viewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
viewPager = (ViewPager) findViewById(R.id.main_view_pager);
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
adapter = new MainActivityPagerAdapter(getSupportFragmentManager(), tabLayout.getTabCount());
viewPager.setAdapter(adapter);
progressDialog = new ProgressDialog(this);
}
use of com.polito.mad17.madmax.entities.User 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();
}
use of com.polito.mad17.madmax.entities.User in project MadMax by deviz92.
the class PayGroupActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pay_group);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
String defaultCurrency = sharedPref.getString(SettingsFragment.DEFAULT_CURRENCY, "");
Intent intent = getIntent();
groupID = intent.getStringExtra("groupID");
userID = intent.getStringExtra("userID");
groupName = intent.getStringExtra("groupName");
groupImageURL = intent.getStringExtra("groupImage");
totBalances = (HashMap<String, Double>) intent.getSerializableExtra("totBalances");
shownCurrency = intent.getStringExtra("shownCurrency");
debt = totBalances.get(shownCurrency);
debt = abs(Math.floor(debt * 100) / 100);
currency = (Spinner) findViewById(R.id.currency);
amountEditText = (EditText) findViewById(R.id.amount);
amountEditText.setFilters(new InputFilter[] { new DecimalDigitsInputFilter(7, 2) });
groupNameTextView = (TextView) findViewById(R.id.tv_receiver);
groupNameTextView.setText(groupName);
amountEditText.setText(debt.toString());
// creating spinner for currencies
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.currencies, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
currency.setAdapter(adapter);
// set the defaultCurrency value for the spinner based on the user preferences
int spinnerPosition = adapter.getPosition(shownCurrency);
currency.setSelection(spinnerPosition);
userImage = (ImageView) findViewById(R.id.sender_photo);
groupImage = (ImageView) findViewById(R.id.receiver_photo);
userImageURL = MainActivity.getCurrentUser().getProfileImage();
userImage = (ImageView) findViewById(R.id.sender_photo);
if (userImageURL != null) {
Glide.with(getLayoutInflater().getContext()).load(userImageURL).centerCrop().bitmapTransform(new CropCircleTransformation(getLayoutInflater().getContext())).diskCacheStrategy(DiskCacheStrategy.ALL).into(userImage);
} else {
Glide.with(getLayoutInflater().getContext()).load(R.drawable.user_default).centerCrop().bitmapTransform(new CropCircleTransformation(getLayoutInflater().getContext())).diskCacheStrategy(DiskCacheStrategy.ALL).into(userImage);
}
groupImage = (ImageView) findViewById(R.id.receiver_photo);
if (groupImageURL != null) {
Glide.with(getLayoutInflater().getContext()).load(groupImageURL).centerCrop().bitmapTransform(new CropCircleTransformation(getLayoutInflater().getContext())).diskCacheStrategy(DiskCacheStrategy.ALL).into(groupImage);
} else {
Glide.with(getLayoutInflater().getContext()).load(R.drawable.group_default).centerCrop().bitmapTransform(new CropCircleTransformation(getLayoutInflater().getContext())).diskCacheStrategy(DiskCacheStrategy.ALL).into(groupImage);
}
}
Aggregations