Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void getStories(Context context, GetStatus getStatus){
- UserDetails myUser = Constants.getUserDetails(context);
- getFriendsList(context, new GetList() {
- @Override
- public void getList(ArrayList<String> list) {
- // change this to arraylist of status
- ArrayList<ArrayList<String>> statusList = new ArrayList<>();
- FirebaseFirestore.getInstance().collection(Constants.FIREBASE_STATUS)
- .whereGreaterThan("time", System.currentTimeMillis()-Constants.DATE_ONE_DAY)
- .orderBy("time", Query.Direction.DESCENDING)
- .get()
- .addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
- @Override
- public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
- // map to count stories for each user
- HashMap<String,Integer> hashMap=new HashMap<String,Integer>();
- int count = 0;
- for(QueryDocumentSnapshot snapshot : queryDocumentSnapshots){
- // Transform snapshot to Status object
- // Get user id from status object
- String userId= "121";
- int userPosition;
- if(hashMap.containsKey(userId)){
- userPosition = hashMap.get(userId);
- }
- else{
- hashMap.put(userId, count);
- statusList.add(new ArrayList<>());
- userPosition = count;
- }
- // Change this to status object obtained from snapshot object
- String status = "121";
- statusList.get(userPosition).add(status);
- getStatus.getStories(statusList);
- }
- }
- })
- .addOnFailureListener(new OnFailureListener() {
- @Override
- public void onFailure(@NonNull Exception e) {
- getStatus.getFailure(e.getMessage());
- }
- });
- }
- @Override
- public void getError(String e) {
- getStatus.getFailure(e);
- }
- });
- }
- public static void getFriendsList(Context context, GetList getList){
- UserDetails myUser = Constants.getUserDetails(context);
- FirebaseFirestore.getInstance()
- .collection(Constants.FIREBASE_USER_DETAILS +"/" + myUser.getMobile_no() + "/" + Constants.FIREBASE_FRIEND)
- .get()
- .addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
- @Override
- public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
- ArrayList<String> friendsList = new ArrayList<>();
- for(QueryDocumentSnapshot snapshot : queryDocumentSnapshots){
- Friend friend = snapshot.toObject(Friend.class);
- String friend1 = friend.getFriend1();
- String friend2 = friend.getFriend2();
- if(!friend1.equalsIgnoreCase(myUser.getMobile_no())){
- if(!friendsList.contains(friend1)){
- friendsList.add(friend1);
- }
- }else if(!friend2.equalsIgnoreCase(myUser.getMobile_no())){
- if(!friendsList.contains(friend2)){
- friendsList.add(friend2);
- }
- }
- getList.getList(friendsList);
- }
- }
- })
- .addOnFailureListener(new OnFailureListener() {
- @Override
- public void onFailure(@NonNull Exception e) {
- getList.getError(e.getMessage());
- }
- });
- }
- interface GetStatus {
- // Change arraylist of strings to Status object
- void getStories(ArrayList<ArrayList<String>> list);
- void getFailure(String e);
- }
Advertisement
Add Comment
Please, Sign In to add comment