0

I am having some issues with the intent object. I already retrieved it with the new Activity but it doesn't work when passed to Firestore queries. The passed extra is for other users to get details of other users for a View. If I use the current user in auth and then pass it to a query it works but I need the details of other users for the View. It seems the intent string or items is not recognized when doing the query so I tried setting the TextView instead of getting the value of the text id and then doing the query, still doesn't work for me either way. Hope anyone can help with this. Thanks a lot.

                import androidx.appcompat.app.AppCompatActivity;
                import androidx.appcompat.widget.Toolbar;
                import androidx.recyclerview.widget.LinearLayoutManager;
                import androidx.recyclerview.widget.RecyclerView;
                
                import android.os.Bundle;
                import android.view.View;
                import android.widget.ImageView;
                import android.widget.TextView;
                import android.widget.Toast;
                
                
                import com.example.shopnshare.R;
                import com.example.shopnshare.activities.adapters.SliderAdapter;
                import com.example.shopnshare.activities.adapters.ViewAllAdapter;
                import com.example.shopnshare.activities.adapters.models.ImageModel;
                
                import com.google.android.gms.tasks.OnCompleteListener;
                import com.google.android.gms.tasks.OnSuccessListener;
                import com.google.android.gms.tasks.Task;
                import com.google.firebase.database.annotations.Nullable;
                import com.google.firebase.firestore.CollectionReference;
                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.QueryDocumentSnapshot;
                import com.google.firebase.firestore.QuerySnapshot;
                
                import org.checkerframework.checker.nullness.qual.NonNull;
                
                import java.util.ArrayList;
                import java.util.List;
                
                public class ShopPageActivity extends AppCompatActivity {
                
                    FirebaseFirestore firestore;
                    RecyclerView image_rec;
                
                    List<ImageModel> images;
                    Toolbar toolbar;
                    ImageView logo;
                
                    SliderAdapter sliderAdapter;
                
                    CollectionReference db;
                
                    //    ProgressBar pb;
                    TextView shop_page_id, uname, ucontact, ufacebook, uinstagram, udescription,uNewId;
                //    String finalId;
                
                        String sellDetail;
                    @Override
                    protected void onCreate(Bundle savedInstanceState) {
                        super.onCreate(savedInstanceState);
                        setContentView(R.layout.activity_shop_page);
                
                        firestore = FirebaseFirestore.getInstance();
                
                        uname = findViewById(R.id.shop_page_name);
                        ucontact = findViewById(R.id.shop_page_contact);
                
                        uNewId = findViewById(R.id.shop_page_id);
                        udescription = findViewById(R.id.shop_page_description);
                        ufacebook = findViewById(R.id.shop_page_description);
                        uinstagram = findViewById(R.id.shop_page_description);
                
                        uNewId.setText(getIntent().getStringExtra("seller"));
                
                
                        toolbar = findViewById(R.id.shop_page_toolbar);
                
                        setSupportActionBar(toolbar);
                        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
                
                        image_rec = findViewById(R.id.shop_page_slider_rec);
                
                        image_rec.setLayoutManager(new LinearLayoutManager(ShopPageActivity.this, RecyclerView.HORIZONTAL, false));
                        images = new ArrayList<>();
                        sliderAdapter = new SliderAdapter(this, images);
                        image_rec.setAdapter(sliderAdapter);
                        sliderAdapter.notifyDataSetChanged();
                    }
                
                
                    public  void getUserImages() {
                //            String newIds = sellDetail;
                            String newIds = String.valueOf(uNewId.getText());
                
                            firestore.collection("Images").document(String.valueOf(newIds)).collection("Images")
                                    .get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
                                        @Override
                                        public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
                                            for (QueryDocumentSnapshot document : queryDocumentSnapshots) {
                                                ImageModel image = document.toObject(ImageModel.class);
                                                Toast.makeText(ShopPageActivity.this, image.getUser_id(), Toast.LENGTH_SHORT).show();
                                                images.add(image);
                                                sliderAdapter.notifyDataSetChanged();
                //                                    pb.setVisibility(View.GONE);
                                                image_rec.setVisibility(View.VISIBLE);
                //                                    noProducts.setVisibility(View.GONE);
                                            }
                                        }
                                    });
                    }
                
                    @Override
                    protected void onStart() {
                        super.onStart();
                
                //            String sellDetail = getIntent().getStringExtra("seller");
                            firestore.collection("Users").document(String.valueOf(uNewId.getText())).addSnapshotListener(new EventListener<DocumentSnapshot>() {
                                @Override
                                public void onEvent(@Nullable DocumentSnapshot snapshot, @Nullable FirebaseFirestoreException error) {
                                Toast.makeText( ShopPageActivity.this,"ahaasddd"+uNewId.getText(),Toast.LENGTH_SHORT).show();
                                    if (error != null) {
                //                    Log.w(TAG, "Listen failed.", error);
                                        return;
                                    }
                
                                    if (snapshot != null && snapshot.exists()) {
                                        String seller_pic = snapshot.getString("user_images");
                                        String name = snapshot.getString("name");
                                        String id = snapshot.getString("id");
                                        String contact = snapshot.getString("contact");
                                        String facebook = snapshot.getString("facebook");
                                        String instagram = snapshot.getString("instagram");
                                        String description = snapshot.getString("description");
                //                    filePath = seller_pic;
                                        uname.setText(name);
                                        uNewId.setText(id);
                                        ucontact.setText(contact);
                                        ufacebook.setText(facebook);
                                        uinstagram.setText(instagram);
                                        udescription.setText(description);
                
                
                                    }
                                }
                
                
                            });
                
                        getUserImages();
                
                    }
                }

All variables/dependencies below are declared already here.

providerZ
  • 315
  • 11
Me Compu
  • 25
  • 6
  • I'm not sure I understand. What exactly in this code doesn't work the way you expect? Tell us what is wrong with shared code. Do you have any errors? – Alex Mamo Dec 27 '22 at 09:06

0 Answers0