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.
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");
}
}
});
}