make search in uidList case insensitive in all places

This commit is contained in:
Vincent Breitmoser
2018-07-04 12:51:23 +02:00
parent b95c885aa0
commit 8a33fa8540
4 changed files with 19 additions and 10 deletions

View File

@@ -29,6 +29,7 @@ public abstract class SubKey implements KeysModel {
@AutoValue @AutoValue
public static abstract class UnifiedKeyInfo implements KeysModel.UnifiedKeyViewModel { public static abstract class UnifiedKeyInfo implements KeysModel.UnifiedKeyViewModel {
private List<String> autocryptPackageNames; private List<String> autocryptPackageNames;
private String cachedUidSearchString;
public boolean is_expired() { public boolean is_expired() {
Long expiry = expiry(); Long expiry = expiry();
@@ -64,5 +65,16 @@ public abstract class SubKey implements KeysModel {
public boolean has_encrypt_key() { public boolean has_encrypt_key() {
return has_encrypt_key_int() != 0; return has_encrypt_key_int() != 0;
} }
public String uidSearchString() {
if (cachedUidSearchString == null) {
cachedUidSearchString = user_id_list();
if (cachedUidSearchString == null) {
cachedUidSearchString = "";
}
cachedUidSearchString = cachedUidSearchString.toLowerCase();
}
return cachedUidSearchString;
}
} }
} }

View File

@@ -112,8 +112,8 @@ class RemoteSelectIdentityKeyPresenter {
} }
private void goToSelectLayout() { private void goToSelectLayout() {
List<UnifiedKeyInfo> filteredKeyInfoData = List<UnifiedKeyInfo> filteredKeyInfoData = viewModel.isListAllKeys() || TextUtils.isEmpty(userId.email) ?
viewModel.isListAllKeys() || TextUtils.isEmpty(userId.email) ? keyInfoData : getFilteredKeyInfo(); keyInfoData : getFilteredKeyInfo(userId.email.toLowerCase().trim());
if (filteredKeyInfoData == null) { if (filteredKeyInfoData == null) {
view.showLayoutEmpty(); view.showLayoutEmpty();
@@ -125,12 +125,11 @@ class RemoteSelectIdentityKeyPresenter {
} }
} }
private List<UnifiedKeyInfo> getFilteredKeyInfo() { private List<UnifiedKeyInfo> getFilteredKeyInfo(String filterString) {
if (viewModel.filteredKeyInfo == null) { if (viewModel.filteredKeyInfo == null) {
viewModel.filteredKeyInfo = new ArrayList<>(); viewModel.filteredKeyInfo = new ArrayList<>();
for (UnifiedKeyInfo unifiedKeyInfo : keyInfoData) { for (UnifiedKeyInfo unifiedKeyInfo : keyInfoData) {
String emailSearchList = unifiedKeyInfo.user_id_list(); if (unifiedKeyInfo.uidSearchString().contains(filterString)) {
if (emailSearchList == null || emailSearchList.contains(userId.email)) {
viewModel.filteredKeyInfo.add(unifiedKeyInfo); viewModel.filteredKeyInfo.add(unifiedKeyInfo);
} }
} }
@@ -185,7 +184,7 @@ class RemoteSelectIdentityKeyPresenter {
} }
void onKeyItemClick(int position) { void onKeyItemClick(int position) {
selectedMasterKeyId = getFilteredKeyInfo().get(position).master_key_id(); selectedMasterKeyId = getFilteredKeyInfo(userId.email.toLowerCase()).get(position).master_key_id();
view.highlightKey(position); view.highlightKey(position);
} }

View File

@@ -66,8 +66,7 @@ public class FlexibleKeyDetailsItem extends FlexibleSectionableKeyItem<FlexibleK
@Override @Override
public boolean filter(String constraint) { public boolean filter(String constraint) {
String uidList = keyInfo.user_id_list(); return constraint == null || keyInfo.uidSearchString().contains(constraint);
return constraint == null || (uidList != null && uidList.contains(constraint));
} }
class FlexibleKeyItemViewHolder extends FlexibleViewHolder { class FlexibleKeyItemViewHolder extends FlexibleViewHolder {

View File

@@ -42,8 +42,7 @@ public class EncryptRecipientChipsInput extends ChipsInput<EncryptRecipientChip>
@Override @Override
public boolean isKeptForConstraint(CharSequence constraint) { public boolean isKeptForConstraint(CharSequence constraint) {
String uidList = keyInfo.user_id_list(); return keyInfo.uidSearchString().contains(constraint);
return uidList == null || uidList.contains(constraint);
} }
} }