Я создал приложение для супружеских отношений, в котором все данные аутентифицированных пользователей в базе данных firebase извлекаются в карточку программы восстановления, но изображения с ним не извлекаются, изображение последнего аутентифицированного пользователя в базе данных применяется ко всем пользователям в recyclerview.
Изображение аутентифицированного пользователя в базе данных
Снимок mainImage (URL-адреса изображения), хранящийся в базе данных Firebase
![Image url stored in firebase database](https://i.stack.imgur.com/CpKUs.png)
Изображение хранится в подузле, потому что всякий раз, когда я обновляю изображение в это время, все данные в аутентифицированном узле удаляются, а узел mainImage обновляется.
Это код профиля поиска:
public class Search_Profile extends AppCompatActivity {
private SwipeRefreshLayout mSwipeRefreshLayout;
DatabaseReference databaseReference;
Firebase firebase;
List<User> list = new ArrayList<User>();
RecyclerView recyclerView;
Boolean isScrolling = false;
Context context;
public Search_Profile() {
}
FirebaseRecyclerPagingAdapter<User, UserViewHolder> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search__profile);
mSwipeRefreshLayout = findViewById(R.id.swipe_refresh_layout);
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
recyclerView.setLayoutManager(new LinearLayoutManager(Search_Profile.this));
databaseReference = FirebaseDatabase.getInstance().getReference().child(Dashboard.Database_Path);
PagedList.Config config = new PagedList.Config.Builder()
.setEnablePlaceholders(false)
.setPrefetchDistance(2)
.setPageSize(1)
.build();
DatabasePagingOptions<User> options = new DatabasePagingOptions.Builder<User>()
.setLifecycleOwner(this)
.setQuery(databaseReference, config, User.class)
.build();
adapter = new FirebaseRecyclerPagingAdapter<User, UserViewHolder>(options) {
@NonNull
@Override
public UserViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new UserViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler, parent, false),context) {
};
}
@Override
protected void onBindViewHolder(@NonNull UserViewHolder viewHolder, int i, @NonNull User user) {
viewHolder.setItem(user, i);
}
@Override
protected void onLoadingStateChanged(@NonNull LoadingState state) {
switch (state) {
case LOADING_INITIAL:
case LOADING_MORE:
// Do your loading animation
mSwipeRefreshLayout.setRefreshing(true);
break;
case LOADED:
// Stop Animation
mSwipeRefreshLayout.setRefreshing(false);
break;
case FINISHED:
//Reached end of Data set
mSwipeRefreshLayout.setRefreshing(false);
break;
case ERROR:
retry();
break;
}
}
@Override
protected void onError(@NonNull DatabaseError databaseError) {
super.onError(databaseError);
mSwipeRefreshLayout.setRefreshing(false);
databaseError.toException().printStackTrace();
// Handle Error
retry();
}
};
recyclerView.setAdapter(adapter);
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
adapter.refresh();
}
});
}
@Override
protected void onStart() {
super.onStart();
adapter.startListening();
}
//Stop Listening Adapter
@Override
protected void onStop() {
super.onStop();
adapter.stopListening();
}
}
Это код пользователя View Holder:
class UserViewHolder extends RecyclerView.ViewHolder {
DatabaseReference databaseReference;
Firebase firebase;
FirebaseAuth mAuth;
List<User> MainImageUploadInfoList;
ImageView imageView;
public TextView FirstNameTextView;
public TextView DateTextView;
public TextView HeightTextView;
public TextView EducationTextView;
public TextView OccupationTextView;
public TextView UserIDTextView;
public Button send_invitation,shortlist_profile;
public TextView income;
public TextView city_state;
public TextView hobbies;
public TextView marital_status;
public TextView family_members;
public TextView mothers_name;
public TextView fathers_name;
public TextView fathers_occupation;
public TextView mothers_occupation;
public CardView mCardView;
String sluidgl,sluidtemp;
public List<User> mUploads;
int flag=0;
HashSet<String> set=new HashSet<String>();
User user=new User();
private final Context context;
// private Object Context;
public UserViewHolder(@NonNull final View itemView, final Context context) {
super(itemView);
this.context=context;
itemView.setTag(user.getUser_id());
mCardView = (CardView) itemView.findViewById(R.id.cardview1);
FirstNameTextView = (TextView) itemView.findViewById(R.id.textView1);
DateTextView = (TextView) itemView.findViewById(R.id.textView3);
HeightTextView = (TextView) itemView.findViewById(R.id.textView4);
EducationTextView = (TextView) itemView.findViewById(R.id.textView5);
OccupationTextView = (TextView) itemView.findViewById(R.id.textView6);
UserIDTextView = (TextView) itemView.findViewById(R.id.textView7);
income = (TextView) itemView.findViewById(R.id.income);
city_state = (TextView) itemView.findViewById(R.id.city_state);
hobbies = (TextView) itemView.findViewById(R.id.hobbies);
marital_status = (TextView) itemView.findViewById(R.id.marital_status);
family_members = (TextView) itemView.findViewById(R.id.family_members);
mothers_name = (TextView) itemView.findViewById(R.id.mothers_name);
fathers_name = (TextView) itemView.findViewById(R.id.fathers_name);
fathers_occupation = (TextView) itemView.findViewById(R.id.fathers_occupation);
mothers_occupation = (TextView) itemView.findViewById(R.id.mothers_occupation);
send_invitation = (Button) itemView.findViewById(R.id.sendinvitation);
shortlist_profile=(Button)itemView.findViewById(R.id.shortlistprofile);
send_invitation=(Button)itemView.findViewById(R.id.sendinvitation);
shortlist_profile=(Button)itemView.findViewById(R.id.shortlistprofile);
imageView=(ImageView)itemView.findViewById(R.id.imageView2);
}
public void setItem(final User user, final int i){
mCardView.setTag(i);
FirstNameTextView.setText(user.getFirst_name() + " " + user.getLast_name());
DateTextView.setText(user.getDate());
HeightTextView.setText(user.getHeight());
EducationTextView.setText(user.getHighest_education());
OccupationTextView.setText(user.getOccupation());
UserIDTextView.setText(user.getUser_id());
income.setText(user.getIncome());
city_state.setText(user.getCity_state());
hobbies.setText(user.getHobbies());
marital_status.setText(user.getMarital_status());
family_members.setText(user.getFamily_members());
mothers_name.setText(user.getMothers_name());
fathers_name.setText(user.getFathers_name());
fathers_occupation.setText(user.getFathers_occupation());
mothers_occupation.setText(user.getMothers_occupation());
mAuth = FirebaseAuth.getInstance();
final FirebaseUser user1 = mAuth.getCurrentUser();
final String userId = user1.getUid();
databaseReference = FirebaseDatabase.getInstance().getReference().child("User");
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot:dataSnapshot.getChildren()) {
String user2 = snapshot.getKey();
System.out.println(user2 + "Auth Key");
databaseReference=FirebaseDatabase.getInstance().getReference().child("User").child(user2).child("images");
databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot ds:dataSnapshot.getChildren()){
User upload = ds.getValue(User.class);
upload.setKey(ds.getKey());
Picasso.get().load(upload.getMainImage()).placeholder(R.mipmap.ic_launcher).fit().into(imageView);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
}