mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-24 15:10:44 +01:00
Sort foreign alphabet payment methods above the untranslated ones.
By default, JAVA sorts foreign characters below English characters. However, the payment methods that are translated are also more likely to be used by someone native to that language, so it makes better sense to sort as two separate sets and put the foreign language ones on top. This commit does that for payment methods.
This commit is contained in:
parent
c8c9251f2b
commit
c5ffb5c337
1 changed files with 12 additions and 1 deletions
|
@ -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) {
|
||||||
return Res.get(id).compareTo(Res.get(other.id));
|
// 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));
|
||||||
|
else
|
||||||
|
return isLatin ? 1 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDisplayString() {
|
public String getDisplayString() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue