Merge pull request #7251 from cparke2/sort-nonlatin-payment-methods-top

Sort foreign alphabet payment methods above the untranslated ones.
This commit is contained in:
HenrikJannsen 2024-09-26 18:35:18 +07:00 committed by GitHub
commit 1480fe2021
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -32,6 +32,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -51,6 +52,9 @@ public final class PaymentMethod implements PersistablePayload, Comparable<Payme
// Static // Static
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
// For sorting payment methods, we want names that contain only ASCII and Extended-ASCII to go *below* other languages
private static final Pattern ASCII_PATTERN = Pattern.compile("[\\x00-\\xFF]*");
// time in blocks (average 10 min for one block confirmation // time in blocks (average 10 min for one block confirmation
private static final long DAY = TimeUnit.HOURS.toMillis(24); private static final long DAY = TimeUnit.HOURS.toMillis(24);
@ -424,7 +428,14 @@ public final class PaymentMethod implements PersistablePayload, Comparable<Payme
@Override @Override
public int compareTo(@NotNull PaymentMethod other) { public int compareTo(@NotNull PaymentMethod other) {
// Not all accounts have translations into other languages, and when mixed with Latin they sort to the bottom.
// So we need some extra logic to get the Latin to sort separately underneath the non-Latin.
boolean isLatin = ASCII_PATTERN.matcher(Res.get(id)).matches();
boolean otherIsLatin = ASCII_PATTERN.matcher(Res.get(other.id)).matches();
if(isLatin == otherIsLatin)
return Res.get(id).compareTo(Res.get(other.id)); return Res.get(id).compareTo(Res.get(other.id));
else
return isLatin ? 1 : -1;
} }
public String getDisplayString() { public String getDisplayString() {