@@ -130,7 +130,11 @@ public void onAuthStateChanged(AuthData authData) {
130
130
headerImage = (ImageView ) headerView .findViewById (R .id .headerImage );
131
131
headerText = (TextView ) headerView .findViewById (R .id .headerText );
132
132
133
-
133
+ /*
134
+ Friend Request list of users pointers
135
+ */
136
+ usersPointers = new ArrayList <String >();
137
+ Log .e ("checker" , "users initialized" );
134
138
/**
135
139
* Lets inflate the very first fragment
136
140
* Here , we are inflating the TabFragment as the first Fragment
@@ -299,13 +303,17 @@ protected void onResume() {
299
303
}
300
304
301
305
306
+ public void fetchNotificationsFriendRequest (){
307
+
308
+ }
309
+
302
310
public void retrieveUser () {
303
311
if (mAuthData != null ) {
304
312
305
313
// listener for user key
306
314
userRef = ref .child ("users" ).child (mAuthData .getUid ());
307
315
uid = mAuthData .getUid ();
308
- userRef .addListenerForSingleValueEvent (new ValueEventListener () {
316
+ userRef .addValueEventListener (new ValueEventListener () {
309
317
@ Override
310
318
public void onDataChange (DataSnapshot dataSnapshot ) {
311
319
// convert snapshot to user class
@@ -394,23 +402,39 @@ public void done(ParseException e) {
394
402
get the users from pointers
395
403
activate icon
396
404
*/
405
+ // in a method otherwise we would have many listeners
406
+
397
407
// initialize the reference
398
- usersPointers = new ArrayList < String >();
408
+
399
409
friendsReqestReference = new Firebase ("https://quest1.firebaseio.com/users/" +uid +"/friends" );
400
410
Query query = friendsReqestReference .orderByValue ().equalTo (0 );
401
411
query .addChildEventListener (new ChildEventListener () {
402
412
@ Override
403
413
public void onChildAdded (DataSnapshot dataSnapshot , String s ) {
404
414
//Log.e("logmeThis",""+dataSnapshot.getKey());
405
- // save this pointer in usersPointers
406
- usersPointers .add (dataSnapshot .getKey ());
415
+ Log .e ("RequestMainActivity" , "onChildAdded" );
416
+
417
+
418
+ if (usersPointers .contains (dataSnapshot .getKey ())){
419
+ // it is already here
420
+ // do nothing
421
+ Log .e ("checker" ,"fail data is here" );
422
+ }else {
423
+ // save this pointer in usersPointers
424
+ usersPointers .add (dataSnapshot .getKey ());
425
+ Log .e ("checker" , "success data is nt here" );
426
+ for (String st : usersPointers ){
427
+ Log .e ("checkerData" ,"" +st );
428
+ }
407
429
430
+ // check the value
431
+ // only increment when it is 0
432
+ if (dataSnapshot .getValue (Integer .class ) == 0 ){
408
433
409
- // check the value
410
- // only increment when it is 0
411
- if (dataSnapshot .getValue (Integer .class ) == 0 ){
412
- badgeCount ++;
434
+ badgeCount ++;
435
+ }
413
436
}
437
+
414
438
// notify user by notification icon
415
439
416
440
@@ -440,7 +464,7 @@ public void onChildAdded(DataSnapshot dataSnapshot, String s) {
440
464
@ Override
441
465
public void onChildChanged (DataSnapshot dataSnapshot , String s ) {
442
466
// the user accepts
443
- Log .e ("MainActivityRequest " ,"onChildChanged" );
467
+ Log .e ("RequestMainActivity " ,"onChildChanged" );
444
468
// decrease the badgeCount and update the notification icon
445
469
// add the notification icon programmatically
446
470
//badgeCount--;
@@ -466,7 +490,7 @@ public void onChildRemoved(DataSnapshot dataSnapshot) {
466
490
usersPointers .remove (dataSnapshot .getKey ());
467
491
468
492
469
- // Log.e("MainActivityRequest", "onChildRemoved");
493
+ Log .e ("RequestMainActivity" , "onChildRemoved" );
470
494
// triggered when the user rejects or ignores the request
471
495
//badgeCount--;
472
496
if (android .os .Build .VERSION .SDK_INT >= android .os .Build .VERSION_CODES .LOLLIPOP ) {
@@ -584,6 +608,7 @@ public void onCancelled(FirebaseError firebaseError) {
584
608
585
609
}
586
610
611
+
587
612
public List <String > getKeysFromValues (Map <String , Object > map , int value ) {
588
613
List <String > list = new ArrayList <String >();
589
614
@@ -600,19 +625,8 @@ public List<String> getKeysFromValues(Map<String, Object> map, int value) {
600
625
return list ;
601
626
}
602
627
603
- // called after the List<User> is filled with data
604
- public void notificationStuff (List <User > users ){
605
- // adjust the badgeCount
606
- badgeCount = users .size ();
607
- // show the notification icon with appropriate number based on users.size()
608
- /*
609
- //If you want to add your ActionItem programmatically you can do this too. You do the following:
610
- new ActionItemBadgeAdder().act(this).menu(menu).title(R.string.sample_2).itemDetails(0, SAMPLE2_ID, 1).showAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS).add(bigStyle, 1);
611
- return true;
612
- */
613
- //
614
- }
615
628
629
+ /*
616
630
617
631
private class CheckFriendRequests extends AsyncTask<Map<String, Object>, Void, Void> {
618
632
@@ -676,6 +690,7 @@ public void onCancelled(FirebaseError firebaseError) {
676
690
677
691
678
692
}
693
+ */
679
694
680
695
681
696
0 commit comments