@@ -418,33 +418,49 @@ public void onCancelled(FirebaseError firebaseError) {
418
418
@ Override
419
419
public void onChildChanged (DataSnapshot dataSnapshot , String s ) {
420
420
421
- /*
422
- // update the data of the quest
423
-
424
- // HOW TO DO IT
425
- // convert to quest card
426
- QuestCard updatedQuestCard = dataSnapshot.getValue(QuestCard.class);
427
- // get the keyy and index it into the map
428
- String key = updatedQuestCard.getQuestKey();
429
- //Log.e("indexes", "" + key);
430
- QuestCard oldQuest = map.get(key);
431
- //Log.e("indexes",""+oldQuest.getQuestKey());
432
- if(oldQuest == null){
433
- // not of interest to this user
434
- }else{
435
- // get the index of the oldQuest
436
- int index = questCards.indexOf(oldQuest);
437
- // use this index to update the quest
438
- //Log.e("indexes",""+index);
439
- //Log.e("indexes", "" + questCards.size());
440
- if(index >= 0){// because of the firebase issue of calling ondatachanged many times
441
- questCards.set(index,updatedQuestCard);
442
- // notify the adapter
443
- adapter.notifyDataSetChanged();
444
- }
445
421
446
- }
447
- */
422
+ QuestCard updatedQuestCard = dataSnapshot .getValue (QuestCard .class );
423
+
424
+
425
+ // loop through the questCard
426
+ // find the quest that matches the key of this quest
427
+ // get it's position and notify
428
+
429
+
430
+
431
+ for (int i = 0 ; i < questCards .size (); i ++){
432
+
433
+ QuestCard qc = questCards .get (i );
434
+
435
+ if (qc .getQuestKey ().equals (updatedQuestCard .getQuestKey ())){
436
+
437
+
438
+
439
+ QuestCard newConst = new QuestCard (updatedQuestCard .getQuestImage (),
440
+ updatedQuestCard .getQuestTitle (),
441
+ updatedQuestCard .getAuthorId (),
442
+ qc .getQuestUsername (),
443
+ qc .getQuestUserImage (),
444
+ updatedQuestCard .getQuestDescription (),
445
+ updatedQuestCard .getQuestCost (),
446
+ updatedQuestCard .getTodos (),
447
+ updatedQuestCard .getQuestKey (),
448
+ updatedQuestCard .getUsersWhoLiked (),
449
+ updatedQuestCard .getTakers (),
450
+ updatedQuestCard .getNumberOfLikes (),
451
+ updatedQuestCard .getNumberOfTakers (),
452
+ updatedQuestCard .getNumberOfFollowers (),
453
+ updatedQuestCard .getJoiners ()
454
+ );
455
+
456
+ // TAKE out the old quest and insert this one instead
457
+ questCards .set (i ,newConst );
458
+
459
+ }
460
+ }
461
+
462
+
463
+
448
464
449
465
}
450
466
0 commit comments