Guest User

Untitled

a guest
May 22nd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. databaseReference = FirebaseDatabase.getInstance().getReference().child("Groups").child(mGroupUid).child("HomeFragment").child("FreezerItems");
  2. childEventListener = databaseReference.addChildEventListener(new ChildEventListener() {
  3. @Override
  4. public void onChildAdded(DataSnapshot dataSnapshot, String s) {
  5.  
  6. HashMap<String, String> value = (HashMap<String, String>) dataSnapshot.getValue();
  7. if (value != null) {
  8. String name = value.get("Name");
  9. String date = value.get("Date");
  10.  
  11. SimpleDateFormat sdf = new SimpleDateFormat("M/dd/yyyy", Locale.US);
  12.  
  13. try {
  14. dateFormat = sdf.parse(date);
  15.  
  16. } catch (ParseException e) {
  17. Log.wtf("FailedtoChangeDate", "Fail");
  18. }
  19.  
  20. Calendar cal = Calendar.getInstance();
  21. cal.add(Calendar.DAY_OF_MONTH, 1);
  22. Date tomorrow = cal.getTime();
  23.  
  24. if (dateFormat.equals(tomorrow)) {
  25.  
  26. GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(getApplicationContext());
  27. if (account != null) {
  28. String firstname = account.getGivenName();
  29. mContentTitle = "Your " + name + " is about to be expired!";
  30. mContentText = firstname + ", make sure to cook or eat your " + name + " by " + date;
  31. }
  32.  
  33. Intent openApp = new Intent(getApplicationContext(), MainActivity.class);
  34. PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 100, openApp, PendingIntent.FLAG_UPDATE_CURRENT);
  35.  
  36. notification = new NotificationCompat.Builder(getApplicationContext(), "Default")
  37. .setSmallIcon(R.drawable.ic_restaurant_black_24dp)
  38. .setContentTitle(mContentTitle)
  39. .setContentText(mContentText)
  40. .setLights(Color.GREEN, 2000, 1000)
  41. .setPriority(NotificationCompat.PRIORITY_MAX)
  42. .setStyle(new NotificationCompat.BigTextStyle().bigText(mContentText))
  43. .setContentIntent(contentIntent)
  44. .setAutoCancel(true);
  45. createNotificationChannel(getApplicationContext());
  46.  
  47. NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getApplicationContext());
  48. notificationManager.notify(uniqueID, notification.build());
  49.  
  50. }
  51.  
  52.  
  53. }
  54.  
  55. }
  56.  
  57. @Override
  58. public void onChildChanged(DataSnapshot dataSnapshot, String s) {
  59.  
  60. }
  61.  
  62. @Override
  63. public void onChildRemoved(DataSnapshot dataSnapshot) {
  64.  
  65. }
  66.  
  67. @Override
  68. public void onChildMoved(DataSnapshot dataSnapshot, String s) {
  69.  
  70. }
  71.  
  72. @Override
  73. public void onCancelled(DatabaseError databaseError) {
  74.  
  75. }
  76. });
Add Comment
Please, Sign In to add comment