Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;

import es.wolfi.app.ResponseHandlers.AutofillCredentialSaveResponseHandler;
import es.wolfi.app.passman.R;
Expand Down Expand Up @@ -115,7 +116,7 @@ public void onFillRequest(FillRequest request, CancellationSignal cancellationSi
CredentialAutofillService.WebDomainResult domain = getLikelyDomain(structures);

// Grab Credentials from vault
ArrayList<Credential> allCred = v.getCredentials();
CopyOnWriteArrayList<Credential> allCred = v.getCredentials();

if (allCred.isEmpty()) {
Toast.makeText(getApplicationContext(), getString(R.string.autofill_vaultempty), Toast.LENGTH_SHORT).show();
Expand Down Expand Up @@ -397,7 +398,7 @@ private String returnBestString(@NonNull String... usernameOptions) {
}

private List<Credential> findMatchingCredentials(
@NonNull ArrayList<Credential> credentialArrayList,
@NonNull CopyOnWriteArrayList<Credential> credentialArrayList,
@NonNull String packageName,
@NonNull CredentialAutofillService.WebDomainResult domain) {
ArrayList<Credential> matchingDomainCred = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.concurrent.CopyOnWriteArrayList;

import es.wolfi.app.passman.R;
import es.wolfi.app.passman.SettingValues;
Expand Down Expand Up @@ -134,7 +135,7 @@ public void applyFilters(Vault vault, EditText searchInput) {
filterTask.cancel(true);
}
filterTask = new FilterListAsyncTask(searchText, recyclerView, mListener);
ArrayList<Credential> input[] = new ArrayList[]{vault.getCredentials()};
CopyOnWriteArrayList<Credential> input[] = new CopyOnWriteArrayList[]{vault.getCredentials()};
filterTask.execute((Object[]) input);
}

Expand Down
20 changes: 14 additions & 6 deletions app/src/main/java/es/wolfi/passman/API/Vault.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.concurrent.CopyOnWriteArrayList;

import es.wolfi.app.passman.SJCLCrypto;
import es.wolfi.app.passman.SettingValues;
Expand All @@ -51,7 +52,7 @@ public class Vault extends Core implements Filterable {
public double last_access;
public String challenge_password;

ArrayList<Credential> credentials;
CopyOnWriteArrayList<Credential> credentials;
HashMap<String, Integer> credential_guid;

private String encryption_key = "";
Expand Down Expand Up @@ -162,7 +163,7 @@ public Date getLastAccessTime() {
return new Date((long) last_access * 1000);
}

public ArrayList<Credential> getCredentials() {
public CopyOnWriteArrayList<Credential> getCredentials() {
return credentials;
}

Expand Down Expand Up @@ -227,7 +228,7 @@ public static Vault fromJSON(JSONObject o) throws JSONException {

if (o.has("credentials")) {
JSONArray j = o.getJSONArray("credentials");
v.credentials = new ArrayList<Credential>();
v.credentials = new CopyOnWriteArrayList<Credential>();
v.credential_guid = new HashMap<>();

for (int i = 0; i < j.length(); i++) {
Expand All @@ -246,11 +247,16 @@ public static Vault fromJSON(JSONObject o) throws JSONException {
}

public void sort(int method) {
ArrayList<Credential> temp = new ArrayList<>(credentials);
credential_guid.clear();
Collections.sort(credentials, new CredentialLabelSort(method));
for (int i = 0; i < credentials.size(); i++) {
credential_guid.put(credentials.get(i).getGuid(), i);

Collections.sort(temp, new CredentialLabelSort(method));
for (int i = 0; i < temp.size(); i++) {
credential_guid.put(temp.get(i).getGuid(), i);
}

credentials.clear();
credentials.addAll(temp);
}

public void addCredential(Credential credential) {
Expand All @@ -271,6 +277,8 @@ public void deleteCredential(Credential updatedCredential) {
for (Credential credential : credentials) {
if (credential.getGuid().equals(updatedCredential.getGuid())) {
credentials.remove(credential);
credential_guid.remove(updatedCredential.getGuid());
break;
}
}
}
Expand Down
38 changes: 18 additions & 20 deletions app/src/main/java/es/wolfi/utils/FilterListAsyncTask.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
/**
* Passman Android App
* Passman Android App
*
* @copyright Copyright (c) 2016, Sander Brand (brantje@gmail.com)
* @copyright Copyright (c) 2016, Marcos Zuriaga Miguel (wolfi@wolfi.es)
* @license GNU AGPL version 3 or any later version
*
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* <p>
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

package es.wolfi.utils;
Expand All @@ -27,49 +26,48 @@

import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.concurrent.CopyOnWriteArrayList;

import es.wolfi.app.passman.fragments.CredentialItemFragment;
import es.wolfi.app.passman.adapters.CredentialViewAdapter;
import es.wolfi.app.passman.fragments.VaultFragment;
import es.wolfi.app.passman.adapters.VaultViewAdapter;
import es.wolfi.app.passman.fragments.CredentialItemFragment;
import es.wolfi.app.passman.fragments.VaultFragment;
import es.wolfi.passman.API.Credential;
import es.wolfi.passman.API.Vault;

public class FilterListAsyncTask <T extends Filterable> extends AsyncTask<ArrayList<T>, Integer, ArrayList<T>>{
public class FilterListAsyncTask<T extends Filterable> extends AsyncTask<CopyOnWriteArrayList<T>, Integer, CopyOnWriteArrayList<T>> {

private String filter;
private final String filter;
RecyclerView recyclerView;
CredentialItemFragment.OnListFragmentInteractionListener credentialMListener = null;
VaultFragment.OnListFragmentInteractionListener vaultMListener = null;
Boolean isVaultFragment;

public FilterListAsyncTask(String filter, RecyclerView recyclerView, CredentialItemFragment.OnListFragmentInteractionListener mListener){
public FilterListAsyncTask(String filter, RecyclerView recyclerView, CredentialItemFragment.OnListFragmentInteractionListener mListener) {
this.filter = filter;
this.recyclerView = recyclerView;
this.credentialMListener = mListener;
this.isVaultFragment = false;
}

public FilterListAsyncTask(String filter, RecyclerView recyclerView, VaultFragment.OnListFragmentInteractionListener mListener){
public FilterListAsyncTask(String filter, RecyclerView recyclerView, VaultFragment.OnListFragmentInteractionListener mListener) {
this.filter = filter;
this.recyclerView = recyclerView;
this.vaultMListener = mListener;
this.isVaultFragment = true;
}

@Override
protected ArrayList<T> doInBackground(ArrayList<T>... list) {
return new ListUtils().filterList(filter, list[0]);
protected CopyOnWriteArrayList<T> doInBackground(CopyOnWriteArrayList<T>... list) {
return ListUtils.filterList(filter, list[0]);
}

@Override
protected void onPostExecute(ArrayList<T> filteredList){
if(isVaultFragment){
recyclerView.setAdapter(new VaultViewAdapter((ArrayList<Vault>)filteredList, vaultMListener));
}
else {
recyclerView.setAdapter(new CredentialViewAdapter((ArrayList<Credential>) filteredList, credentialMListener, PreferenceManager.getDefaultSharedPreferences(recyclerView.getContext())));
protected void onPostExecute(CopyOnWriteArrayList<T> filteredList) {
if (isVaultFragment) {
recyclerView.setAdapter(new VaultViewAdapter((CopyOnWriteArrayList<Vault>) filteredList, vaultMListener));
} else {
recyclerView.setAdapter(new CredentialViewAdapter((CopyOnWriteArrayList<Credential>) filteredList, credentialMListener, PreferenceManager.getDefaultSharedPreferences(recyclerView.getContext())));
}
}
}
23 changes: 10 additions & 13 deletions app/src/main/java/es/wolfi/utils/ListUtils.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
/**
* Passman Android App
* Passman Android App
*
* @copyright Copyright (c) 2016, Sander Brand (brantje@gmail.com)
* @copyright Copyright (c) 2016, Marcos Zuriaga Miguel (wolfi@wolfi.es)
* @license GNU AGPL version 3 or any later version
*
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* <p>
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

package es.wolfi.utils;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.concurrent.CopyOnWriteArrayList;

public class ListUtils {
public static <T extends Filterable> ArrayList<T> filterList(String filter, ArrayList<T> list){
ArrayList<T> copiedList = new ArrayList<T>(list);
Iterator<T> it = copiedList.iterator();
while (it.hasNext()) {
if (!it.next().getFilterableAttribute().contains(filter)) {
it.remove();
public static <T extends Filterable> CopyOnWriteArrayList<T> filterList(String filter, CopyOnWriteArrayList<T> list) {
CopyOnWriteArrayList<T> copiedList = new CopyOnWriteArrayList<T>();
for (T item : list) {
if (item.getFilterableAttribute().contains(filter)) {
copiedList.add(item);
}
}
return copiedList;
Expand Down