1

I have an application where a user is able to add passwords to a FireStore database which are encrypted. Then displayed in a "vault" bellow i have added my classes which are for data, Adapter and Fragment to call all of this. The problem I am facing is the RecyclerView is only displaying the title repeated 5 times rather than the 5 different entries.

FireStoreDatabase

Data

public class UpdatePassword {
    private String Title;
    private String Username;
    private String Password;
    private String WebAddress;
    private String Note;

    public UpdatePassword(){

    }

    public UpdatePassword(String title, String username, String password, String webAddress, String note){
        this.Title = title;
        this.Username = username;
        this.Password = password;
        this.WebAddress = webAddress;
        this.Note = note;
    }

    public String getTitle() {
        return Title;
    }

    public String getUsername() {
        return Username;
    }

    public String getPassword() {
        return Password;
    }

    public String getWebAddress() {
        return WebAddress;
    }

    public String getNote() {
        return Note;
    }
}

Adapter


    ArrayList<UpdatePassword> updateMessageList = new ArrayList<UpdatePassword>();

    private Context context;
    public String TAG = "PasswordUpdateAdapter";

    public PasswordUpdateAdapter(ArrayList<UpdatePassword> data, Context context) {
        this.updateMessageList = data;
        this.context = context;
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        cairoTextView textViewTitle;
        cairoTextView textViewUsername;
        cairoTextView textViewPassword;
        cairoTextView textViewWebAddress;
        cairoTextView textViewNote;


        public ViewHolder(View itemView) {
            super(itemView);
            this.textViewTitle = itemView.findViewById(R.id.title1);
            this.textViewUsername = itemView.findViewById(R.id.user1);
            this.textViewPassword = itemView.findViewById(R.id.password1);
            this.textViewWebAddress = itemView.findViewById(R.id.webAddress1);
            this.textViewNote = itemView.findViewById(R.id.Note1);

        }
    }

    @NonNull
    @Override
    public PasswordUpdateAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.password_update_item, parent, false);
        PasswordUpdateAdapter.ViewHolder viewHolder = new PasswordUpdateAdapter.ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull PasswordUpdateAdapter.ViewHolder holder, int position) {


        holder.textViewTitle.setText(updateMessageList.get(position).getTitle());
        holder.textViewUsername.setText(updateMessageList.get(position).getUsername());
        holder.textViewPassword.setText(updateMessageList.get(position).getPassword());
        holder.textViewWebAddress.setText(updateMessageList.get(position).getWebAddress());
        holder.textViewNote.setText(updateMessageList.get(position).getNote());
    }

    @Override
    public int getItemCount() {

        return updateMessageList.size();
    }

Main Fragment where everything is called I have only added my loadpasswords function as this is where everything is handled if you need to see the rest of the class I would be happy to add the rest of the class. The decrypt section is another class which is used to decrypt the encrypted strings.

 public void loadPasswords() {
        userID = firebaseAuthenti.getCurrentUser().getUid();
        fDatasebase.collection("Users")
       .whereEqualTo("uid", userID)
        .get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
            @Override
            public void onComplete(@NonNull Task<QuerySnapshot> task) {
                if (task.isSuccessful()) {
                    for(QueryDocumentSnapshot document : task.getResult()) {
                        Log.d(TAG, document.getId() + " => " + document.getData());
                        // Log.d(TAG, "DocumentSnapshot data: " + document.getData());

                        String title = (document.getString("title"));
                        String user = (document.getString("username"));
                        String pass = (document.getString("password"));
                        String web = (document.getString("webAddress"));
                        String note = (document.getString("note"));
                        String decrypt11 = null;
                        String decrypt12 = null;
                        String decrypt13 = null;
                        String decrypt14 = null;
                        String decrypt15 = null;

                        try {
                            decrypt13 = EncryptDecrypt.decryptString(title, EncryptDecrypt.Password);
                        } catch (NoSuchAlgorithmException | InvalidKeySpecException | InvalidKeyException | InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException | NoSuchPaddingException e) {
                            e.printStackTrace();
                        }
                        try {
                            decrypt14 = EncryptDecrypt.decryptString(user, EncryptDecrypt.Password);
                        } catch (NoSuchAlgorithmException | InvalidKeySpecException | InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException | NoSuchPaddingException | InvalidKeyException e) {
                            e.printStackTrace();
                        }
                        try {
                            decrypt15 = EncryptDecrypt.decryptString(pass, EncryptDecrypt.Password);
                        } catch (NoSuchAlgorithmException | InvalidKeySpecException | InvalidKeyException | InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException | NoSuchPaddingException e) {
                            e.printStackTrace();
                        }
                        try {
                            decrypt12 = EncryptDecrypt.decryptString(web, EncryptDecrypt.Password);
                        } catch (NoSuchAlgorithmException | InvalidKeySpecException | InvalidKeyException | InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException | NoSuchPaddingException e) {
                            e.printStackTrace();
                        }
                        try {
                            decrypt11 = EncryptDecrypt.decryptString(note, EncryptDecrypt.Password);
                        } catch (NoSuchAlgorithmException | InvalidKeySpecException | InvalidKeyException | InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException | NoSuchPaddingException e) {
                            e.printStackTrace();
                        }


                        UpdatePassword updatePassword = new UpdatePassword(

                                decrypt13,
                                decrypt14,
                                decrypt15,
                                decrypt12,
                                decrypt11
                        );


                       recyclerList.add(updatePassword);

                    }


                        Log.d(TAG, "onComplete: " + recyclerList.size());

                        PasswordUpdateAdapter adapter = null;

                        // init
                        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
                        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                        recyclerView.setLayoutManager(linearLayoutManager);

                        // show data
                        adapter = new PasswordUpdateAdapter(recyclerList, getContext());
                        recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL));
                        recyclerView.setAdapter(adapter);
                        adapter.notifyDataSetChanged();


                } else {
                    Log.d(TAG, "No such document");
                }
            }

        });


    }
dan1st
  • 12,568
  • 8
  • 34
  • 67
dawnofwar
  • 27
  • 6
  • Please edit your question and add your database structure as a screenshot. – Alex Mamo Mar 21 '20 at 16:51
  • @AlexMamo of course ill add that now – dawnofwar Mar 21 '20 at 16:52
  • @AlexMamo Are you able to see it? i took a screen shot and pasted it in but dont think its displayed? – dawnofwar Mar 21 '20 at 16:58
  • Did you try to print your recyclerList and see the data in there? – Gabriel Mar 21 '20 at 17:09
  • @AlexMamo That other question does not solve my problem, only the title is still displayed – dawnofwar Mar 21 '20 at 17:14
  • The name of the properties in your class are different than the name in the database. It's the exact same problem. – Alex Mamo Mar 21 '20 at 17:17
  • @AlexMamo i changed the names as suggested in the other question, no luck. Then added the annotations as well still no luck. – dawnofwar Mar 21 '20 at 17:23
  • @AlexMamo Could there be something else causing it? – dawnofwar Mar 21 '20 at 17:39
  • Your code will not work unless you have the correct names in both the class and the database. The fact that you are getting another error, means that there is another issue in your code but this sounds like a new issue which basically should be considered another question. So please post another fresh question using its own [MCVE](https://stackoverflow.com/help/mcve), so I and other Firebase developers can help you. – Alex Mamo Mar 21 '20 at 17:50
  • @AlexMamo Okay thank you, i can only post 1 question every 90 minutes so will have to post later this evening – dawnofwar Mar 21 '20 at 18:02

0 Answers0