-
Notifications
You must be signed in to change notification settings - Fork 29
improve concurrent vault credential list access #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
binsky08
wants to merge
1
commit into
master
Choose a base branch
from
improve-concurrent-access
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 ([email protected]) | ||
| * @copyright Copyright (c) 2016, Marcos Zuriaga Miguel ([email protected]) | ||
| * @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; | ||
|
|
@@ -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()))); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 ([email protected]) | ||
| * @copyright Copyright (c) 2016, Marcos Zuriaga Miguel ([email protected]) | ||
| * @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; | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.