Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- databaseReference = FirebaseDatabase.getInstance().getReference().child("Groups").child(mGroupUid).child("HomeFragment").child("FreezerItems");
- childEventListener = databaseReference.addChildEventListener(new ChildEventListener() {
- @Override
- public void onChildAdded(DataSnapshot dataSnapshot, String s) {
- HashMap<String, String> value = (HashMap<String, String>) dataSnapshot.getValue();
- if (value != null) {
- String name = value.get("Name");
- String date = value.get("Date");
- SimpleDateFormat sdf = new SimpleDateFormat("M/dd/yyyy", Locale.US);
- try {
- dateFormat = sdf.parse(date);
- } catch (ParseException e) {
- Log.wtf("FailedtoChangeDate", "Fail");
- }
- Calendar cal = Calendar.getInstance();
- cal.add(Calendar.DAY_OF_MONTH, 1);
- Date tomorrow = cal.getTime();
- if (dateFormat.equals(tomorrow)) {
- GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(getApplicationContext());
- if (account != null) {
- String firstname = account.getGivenName();
- mContentTitle = "Your " + name + " is about to be expired!";
- mContentText = firstname + ", make sure to cook or eat your " + name + " by " + date;
- }
- Intent openApp = new Intent(getApplicationContext(), MainActivity.class);
- PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 100, openApp, PendingIntent.FLAG_UPDATE_CURRENT);
- notification = new NotificationCompat.Builder(getApplicationContext(), "Default")
- .setSmallIcon(R.drawable.ic_restaurant_black_24dp)
- .setContentTitle(mContentTitle)
- .setContentText(mContentText)
- .setLights(Color.GREEN, 2000, 1000)
- .setPriority(NotificationCompat.PRIORITY_MAX)
- .setStyle(new NotificationCompat.BigTextStyle().bigText(mContentText))
- .setContentIntent(contentIntent)
- .setAutoCancel(true);
- createNotificationChannel(getApplicationContext());
- NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getApplicationContext());
- notificationManager.notify(uniqueID, notification.build());
- }
- }
- }
- @Override
- public void onChildChanged(DataSnapshot dataSnapshot, String s) {
- }
- @Override
- public void onChildRemoved(DataSnapshot dataSnapshot) {
- }
- @Override
- public void onChildMoved(DataSnapshot dataSnapshot, String s) {
- }
- @Override
- public void onCancelled(DatabaseError databaseError) {
- }
- });
Add Comment
Please, Sign In to add comment