sandeep03edu

Whatsapp Status

Dec 21st, 2022 (edited)
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.78 KB | None | 0 0
  1.     public static void getStories(Context context, GetStatus getStatus){
  2.         UserDetails myUser = Constants.getUserDetails(context);
  3.  
  4.         getFriendsList(context, new GetList() {
  5.             @Override
  6.             public void getList(ArrayList<String> list) {
  7.                 // change this to arraylist of status
  8.                 ArrayList<ArrayList<String>> statusList = new ArrayList<>();
  9.  
  10.                 FirebaseFirestore.getInstance().collection(Constants.FIREBASE_STATUS)
  11.                         .whereGreaterThan("time", System.currentTimeMillis()-Constants.DATE_ONE_DAY)
  12.                         .orderBy("time", Query.Direction.DESCENDING)
  13.                         .get()
  14.                         .addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
  15.                             @Override
  16.                             public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
  17.                                 // map to count stories for each user
  18.                                 HashMap<String,Integer> hashMap=new HashMap<String,Integer>();
  19.                                 int count = 0;
  20.  
  21.                                 for(QueryDocumentSnapshot snapshot : queryDocumentSnapshots){
  22.                                     // Transform snapshot to Status object
  23.                                     // Get user id from status object
  24.                                     String userId= "121";
  25.                                     int userPosition;
  26.                                     if(hashMap.containsKey(userId)){
  27.                                         userPosition = hashMap.get(userId);
  28.                                     }
  29.                                     else{
  30.                                         hashMap.put(userId, count);
  31.                                         statusList.add(new ArrayList<>());
  32.                                         userPosition = count;
  33.                                     }
  34.                                     // Change this to status object obtained from snapshot object
  35.                                     String status = "121";
  36.                                     statusList.get(userPosition).add(status);
  37.  
  38.                                     getStatus.getStories(statusList);
  39.  
  40.                                 }
  41.                             }
  42.                         })
  43.                         .addOnFailureListener(new OnFailureListener() {
  44.                             @Override
  45.                             public void onFailure(@NonNull Exception e) {
  46.                                 getStatus.getFailure(e.getMessage());
  47.                             }
  48.                         });
  49.             }
  50.  
  51.             @Override
  52.             public void getError(String e) {
  53.                 getStatus.getFailure(e);
  54.             }
  55.         });
  56.  
  57.     }
  58.  
  59.     public static void getFriendsList(Context context, GetList getList){
  60.         UserDetails myUser = Constants.getUserDetails(context);
  61.  
  62.         FirebaseFirestore.getInstance()
  63.                 .collection(Constants.FIREBASE_USER_DETAILS +"/" + myUser.getMobile_no() + "/" + Constants.FIREBASE_FRIEND)
  64.                 .get()
  65.                 .addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
  66.                     @Override
  67.                     public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
  68.                         ArrayList<String> friendsList = new ArrayList<>();
  69.                         for(QueryDocumentSnapshot snapshot : queryDocumentSnapshots){
  70.                             Friend friend = snapshot.toObject(Friend.class);
  71.  
  72.                             String friend1 = friend.getFriend1();
  73.                             String friend2 = friend.getFriend2();
  74.  
  75.                             if(!friend1.equalsIgnoreCase(myUser.getMobile_no())){
  76.                                 if(!friendsList.contains(friend1)){
  77.                                     friendsList.add(friend1);
  78.                                 }
  79.                             }else if(!friend2.equalsIgnoreCase(myUser.getMobile_no())){
  80.                                 if(!friendsList.contains(friend2)){
  81.                                     friendsList.add(friend2);
  82.                                 }
  83.                             }
  84.  
  85.                             getList.getList(friendsList);
  86.  
  87.                         }
  88.                     }
  89.                 })
  90.                 .addOnFailureListener(new OnFailureListener() {
  91.                     @Override
  92.                     public void onFailure(@NonNull Exception e) {
  93.                         getList.getError(e.getMessage());
  94.                     }
  95.                 });
  96.     }
  97.  
  98.     interface GetStatus {
  99.         // Change arraylist of strings to Status object
  100.         void getStories(ArrayList<ArrayList<String>> list);
  101.         void getFailure(String e);
  102.     }
  103.  
  104.  
Advertisement
Add Comment
Please, Sign In to add comment