-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOtherUserProfileActivity.java
135 lines (101 loc) · 5.36 KB
/
OtherUserProfileActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package com.android.BloodBank;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import com.android.BloodBank.Adapter.HomePostAdapter;
import com.android.BloodBank.Adapter.OtherProfilePostAdapter;
import com.android.BloodBank.Model.Post;
import com.android.BloodBank.Model.UserProfileData;
import com.android.BloodBank.UI.Messaging.MessagingActivity;
import com.android.BloodBank.databinding.ActivityMessagingBinding;
import com.android.BloodBank.databinding.ActivityOtherUserProfileBinding;
import com.android.BloodBank.databinding.FragmentProfileBinding;
import com.bumptech.glide.Glide;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.firestore.CollectionReference;
import com.google.firebase.firestore.DocumentReference;
import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.EventListener;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.FirebaseFirestoreException;
import com.google.firebase.firestore.Query;
import com.google.firebase.firestore.QuerySnapshot;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class OtherUserProfileActivity extends AppCompatActivity {
ActivityOtherUserProfileBinding binding;
private HashMap<String,String> hashMap = new HashMap<>();
private FirebaseFirestore db = FirebaseFirestore.getInstance();
private List<Post> Posts;
private List<Post> tempPosts;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityOtherUserProfileBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
Intent intent = getIntent();
setUserInformation(intent.getStringExtra("selectedUserId"));
setPosts(intent.getStringExtra("selectedUserId"));
}
private void setPosts(String selectedUserId) {
tempPosts = new ArrayList<>();
Posts = new ArrayList<>();
db.collection("Posts").orderBy("time", Query.Direction.DESCENDING)
.addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot value, @Nullable FirebaseFirestoreException error) {
tempPosts.clear();
Posts.clear();
tempPosts = value.toObjects(Post.class);
for(Post post : tempPosts){
if(post.getId().equals(selectedUserId))
Posts.add(post);
//attach recycler for the other items that are being sold by the vendor
RecyclerView.LayoutManager manager = new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.VERTICAL, false);
OtherProfilePostAdapter adapter1 = new OtherProfilePostAdapter(Posts,getApplicationContext());
binding.postsRecyclerView.setLayoutManager(manager);
binding.postsRecyclerView.setAdapter(adapter1);
}
}
});
}
private void setUserInformation(String ID){
DocumentReference docRef = db.collection("Users").document(ID);
docRef.addSnapshotListener(new EventListener<DocumentSnapshot>() {
@SuppressLint("SetTextI18n")
@Override
public void onEvent(@Nullable DocumentSnapshot value, @Nullable FirebaseFirestoreException error) {
binding.userName.setText(value.getString("userName"));
Glide.with(getApplicationContext())
.asBitmap()
.load(value.getString("userImage"))
.into(binding.Dp);
binding.BloodGroup.setText(value.getString("userBloodGroup"));
binding.userWeight.setText(value.getString("userWeight") + " Kg");
binding.userLastBloodDonation.setText(value.getString("userLastBloodDonationDate"));
binding.phoneNumber.setText( "+91 " + value.getString("userPhoneNo"));
Log.d("address", String.valueOf(value.get("userAddress")));
hashMap = (HashMap<String, String>) value.get("userAddress");
binding.userAddress.setText(hashMap.get("Street") + ", " +hashMap.get("City") + ", " +hashMap.get("District") +", " +hashMap.get("State"));
binding.userPincode.setText(hashMap.get("PinCode"));
binding.message.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getApplicationContext(), MessagingActivity.class);
intent.putExtra("clickedUserName",value.getString("userName"));
intent.putExtra("clickedUserProfileImage",value.getString("userImage"));
intent.putExtra("clickedUserID",value.getString("userId"));
startActivity(intent);
}
});
}
});
}
}