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
5 changes: 4 additions & 1 deletion app/src/main/java/es/wolfi/app/passman/SettingValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ public enum SettingValues {
OFFLINE_STORAGE("offline_storage"),
ENABLE_OFFLINE_CACHE("enable_offline_cache"),
KEY_STORE_MIGRATION_STATE("key_store_migration_state"),
KEY_STORE_ENCRYPTION_KEY("key_store_encryption_key");
KEY_STORE_ENCRYPTION_KEY("key_store_encryption_key"),
CREDENTIAL_LABEL_SORT("credential_label_sort"),
CASE_INSENSITIVE_CREDENTIAL_LABEL_SORT("case_insensitive_credential_label_sort"),
RESTORE_CUSTOM_CREDENTIAL_SORT_ORDER("restore_custom_credential_sort_order");

private final String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package es.wolfi.app.passman.fragments;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
Expand Down Expand Up @@ -70,6 +71,8 @@ public class CredentialItemFragment extends Fragment {
private RecyclerView recyclerView;
private Vault customVault = null;
private boolean enableLimitedAutofillView = false;
private SharedPreferences sharedPreferences;
private boolean caseInsensitiveSort = false;

/**
* Mandatory empty constructor for the fragment manager to instantiate the
Expand Down Expand Up @@ -137,11 +140,12 @@ public void onClick(View view) {
sortMethod = (++sortMethod % 3);
updateToggleSortButtonImage(toggleSortButton);

vault.sort(sortMethod);
vault.sort(sortMethod, caseInsensitiveSort);
applyFilters(vault, searchInput);
sharedPreferences.edit().putInt(SettingValues.CREDENTIAL_LABEL_SORT.toString(), sortMethod).apply();
}
});
vault.sort(sortMethod);
vault.sort(sortMethod, caseInsensitiveSort);
recyclerView.setAdapter(new CredentialViewAdapter(vault.getCredentials(), mListener, PreferenceManager.getDefaultSharedPreferences(getContext())));
scrollToLastPosition();
updateToggleSortButtonImage(toggleSortButton);
Expand Down Expand Up @@ -206,6 +210,13 @@ public void onClick(View view) {
} else {
recyclerView.setLayoutManager(new GridLayoutManager(context, mColumnCount));
}

sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
caseInsensitiveSort = sharedPreferences.getBoolean(SettingValues.CASE_INSENSITIVE_CREDENTIAL_LABEL_SORT.toString(), false);
if (sharedPreferences.getBoolean(SettingValues.RESTORE_CUSTOM_CREDENTIAL_SORT_ORDER.toString(), true)) {
sortMethod = sharedPreferences.getInt(SettingValues.CREDENTIAL_LABEL_SORT.toString(), CredentialLabelSort.SortMethod.STANDARD.ordinal());
}

loadCredentialList(view);
}
return view;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ public class SettingsFragment extends Fragment {
MaterialCheckBox enable_autofill_manual_search_fallback;
Button open_autofill_android_settings_button;
EditText clear_clipboard_delay_value;
MaterialCheckBox settings_case_insensitive_credential_label_sort_switch;
MaterialCheckBox settings_restore_custom_credential_sort_order_switch;

EditText request_connect_timeout_value;
EditText request_response_timeout_value;
Expand Down Expand Up @@ -170,6 +172,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
open_autofill_android_settings_button = view.findViewById(R.id.open_autofill_android_settings_button);
clear_clipboard_delay_value = view.findViewById(R.id.clear_clipboard_delay_value);

settings_case_insensitive_credential_label_sort_switch = view.findViewById(R.id.settings_case_insensitive_credential_label_sort_switch);
settings_restore_custom_credential_sort_order_switch = view.findViewById(R.id.settings_restore_custom_credential_sort_order_switch);

request_connect_timeout_value = view.findViewById(R.id.request_connect_timeout_value);
request_response_timeout_value = view.findViewById(R.id.request_response_timeout_value);
clear_offline_cache_button = view.findViewById(R.id.clear_offline_cache_button);
Expand Down Expand Up @@ -281,6 +286,9 @@ public void onClick(View view) {

clear_clipboard_delay_value.setText(String.valueOf(settings.getInt(SettingValues.CLEAR_CLIPBOARD_DELAY.toString(), 0)));

settings_case_insensitive_credential_label_sort_switch.setChecked(settings.getBoolean(SettingValues.CASE_INSENSITIVE_CREDENTIAL_LABEL_SORT.toString(), false));
settings_restore_custom_credential_sort_order_switch.setChecked(settings.getBoolean(SettingValues.RESTORE_CUSTOM_CREDENTIAL_SORT_ORDER.toString(), true));

request_connect_timeout_value.setText(String.valueOf(settings.getInt(SettingValues.REQUEST_CONNECT_TIMEOUT.toString(), 15)));
request_response_timeout_value.setText(String.valueOf(settings.getInt(SettingValues.REQUEST_RESPONSE_TIMEOUT.toString(), 120)));
clear_offline_cache_button.setText(String.format("%s (%s)", getString(R.string.clear_offline_cache), OfflineStorage.getInstance().getSize()));
Expand Down Expand Up @@ -356,6 +364,9 @@ public void onClick(View view) {
settings.edit().putInt(SettingValues.CLEAR_CLIPBOARD_DELAY.toString(), Integer.parseInt(clear_clipboard_delay_value.getText().toString())).commit();
Objects.requireNonNull(((PasswordListActivity) getActivity())).attachClipboardListener();

settings.edit().putBoolean(SettingValues.CASE_INSENSITIVE_CREDENTIAL_LABEL_SORT.toString(), settings_case_insensitive_credential_label_sort_switch.isChecked()).commit();
settings.edit().putBoolean(SettingValues.RESTORE_CUSTOM_CREDENTIAL_SORT_ORDER.toString(), settings_restore_custom_credential_sort_order_switch.isChecked()).commit();

settings.edit().putInt(SettingValues.REQUEST_CONNECT_TIMEOUT.toString(), Integer.parseInt(request_connect_timeout_value.getText().toString())).commit();
settings.edit().putInt(SettingValues.REQUEST_RESPONSE_TIMEOUT.toString(), Integer.parseInt(request_response_timeout_value.getText().toString())).commit();

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/es/wolfi/passman/API/Vault.java
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,9 @@ public void onCompleted(Exception e, String result) {
});
}

public void sort(int method) {
public void sort(int method, boolean caseInsensitiveSort) {
credential_guid.clear();
Collections.sort(credentials, new CredentialLabelSort(method));
Collections.sort(credentials, new CredentialLabelSort(method, caseInsensitiveSort));
for (int i = 0; i < credentials.size(); i++) {
credential_guid.put(credentials.get(i).getGuid(), i);
}
Expand Down
12 changes: 9 additions & 3 deletions app/src/main/java/es/wolfi/utils/CredentialLabelSort.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,24 @@ public enum SortMethod {
}

private final int method;
private final boolean caseInsensitiveSort;

public CredentialLabelSort(int method) {
public CredentialLabelSort(int method, boolean caseInsensitiveSort) {
this.method = method;
this.caseInsensitiveSort = caseInsensitiveSort;
}

@Override
public int compare(Credential left, Credential right) {
if (method == SortMethod.ALPHABETICALLY_ASCENDING.ordinal()) {
return left.getLabel().compareTo(right.getLabel());
return this.caseInsensitiveSort
? left.getLabel().toLowerCase().compareTo(right.getLabel().toLowerCase())
: left.getLabel().compareTo(right.getLabel());
}
if (method == SortMethod.ALPHABETICALLY_DESCENDING.ordinal()) {
return right.getLabel().compareTo(left.getLabel());
return this.caseInsensitiveSort
? right.getLabel().toLowerCase().compareTo(left.getLabel().toLowerCase())
: right.getLabel().compareTo(left.getLabel());
}
return left.getId() - right.getId();
}
Expand Down
22 changes: 22 additions & 0 deletions app/src/main/res/layout/fragment_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,28 @@
android:inputType="number"
tools:ignore="LabelFor" />

<TextView
style="@style/Label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/credential_list_sort_settings" />

<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/settings_case_insensitive_credential_label_sort_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:checked="false"
android:text="@string/enable_case_insensitive_credential_label_sort" />

<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/settings_restore_custom_credential_sort_order_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:checked="false"
android:text="@string/restore_custom_credential_sort_order" />

<!--Expert settings-->

<TextView
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,7 @@
<string name="autofill_manual_search_fallback">Manual credential search as autofill fallback option</string>
<string name="set_as_autofill_service">Set as autofill service</string>
<string name="algorithm">Algorithm</string>
<string name="enable_case_insensitive_credential_label_sort">Enable case-insensitive credential sort</string>
<string name="credential_list_sort_settings">Credential list sort settings</string>
<string name="restore_custom_credential_sort_order">Restore custom credential sort order</string>
</resources>