mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-04-21 08:06:33 -04:00
Change language as Locale to language code as String
This commit is contained in:
parent
d73a43271c
commit
486c83efaa
@ -82,7 +82,7 @@ public class Arbitrator implements Serializable {
|
||||
|
||||
// editable
|
||||
private ID_TYPE idType;
|
||||
private List<String> languages;
|
||||
private List<String> languageCodes;
|
||||
|
||||
private Coin fee;
|
||||
private List<METHOD> arbitrationMethods;
|
||||
@ -104,7 +104,7 @@ public class Arbitrator implements Serializable {
|
||||
p2pSigPubKey = persisted.getP2pSigPubKey();
|
||||
name = persisted.getName();
|
||||
idType = persisted.getIdType();
|
||||
languages = persisted.getLanguages();
|
||||
languageCodes = persisted.getLanguageCodes();
|
||||
reputation = persisted.getReputation();
|
||||
fee = persisted.getFee();
|
||||
arbitrationMethods = persisted.getArbitrationMethods();
|
||||
@ -119,7 +119,7 @@ public class Arbitrator implements Serializable {
|
||||
p2pSigPubKey = user.getP2PSigPubKey();
|
||||
name = "Mr. Default";
|
||||
idType = Arbitrator.ID_TYPE.REAL_LIFE_ID;
|
||||
languages = Arrays.asList(LanguageUtil.getDefaultLanguageLocale().getISO3Language());
|
||||
languageCodes = Arrays.asList(LanguageUtil.getDefaultLanguageLocaleAsCode());
|
||||
reputation = new Reputation();
|
||||
fee = Coin.parseCoin("0.1");
|
||||
arbitrationMethods = Arrays.asList(Arbitrator.METHOD.TLS_NOTARY);
|
||||
@ -173,8 +173,8 @@ public class Arbitrator implements Serializable {
|
||||
save();
|
||||
}
|
||||
|
||||
public void setLanguages(List<String> languages) {
|
||||
this.languages = languages;
|
||||
public void setLanguageCodes(List<String> languageCodes) {
|
||||
this.languageCodes = languageCodes;
|
||||
save();
|
||||
}
|
||||
|
||||
@ -223,8 +223,8 @@ public class Arbitrator implements Serializable {
|
||||
return idType;
|
||||
}
|
||||
|
||||
public List<String> getLanguages() {
|
||||
return languages;
|
||||
public List<String> getLanguageCodes() {
|
||||
return languageCodes;
|
||||
}
|
||||
|
||||
public Reputation getReputation() {
|
||||
|
@ -21,13 +21,11 @@ package io.bitsquare.arbitration;
|
||||
import io.bitsquare.arbitration.listeners.ArbitratorListener;
|
||||
import io.bitsquare.p2p.DHTService;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public interface ArbitratorService extends DHTService {
|
||||
void addArbitrator(Arbitrator arbitrator);
|
||||
|
||||
void addArbitratorListener(ArbitratorListener listener);
|
||||
|
||||
void getArbitrators(Locale defaultLanguageLocale);
|
||||
void getArbitrators(String defaultLanguageLocaleCode);
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,6 @@ import java.io.IOException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@ -134,7 +133,7 @@ public class TomP2PArbitratorService extends TomP2PDHTService implements Arbitra
|
||||
});
|
||||
}
|
||||
|
||||
public void getArbitrators(Locale languageLocale) {
|
||||
public void getArbitrators(String languageLocaleCode) {
|
||||
Number160 locationKey = Number160.createHash(ARBITRATORS_ROOT);
|
||||
FutureGet futureGet = getMap(locationKey);
|
||||
futureGet.addListener(new BaseFutureAdapter<BaseFuture>() {
|
||||
|
@ -66,7 +66,7 @@ public class ArbitratorBrowserView extends ActivatableView<Pane, Void> implement
|
||||
@Override
|
||||
public void initialize() {
|
||||
messageService.addArbitratorListener(this);
|
||||
messageService.getArbitrators(LanguageUtil.getDefaultLanguageLocale());
|
||||
messageService.getArbitrators(LanguageUtil.getDefaultLanguageLocaleAsCode());
|
||||
|
||||
View view = viewLoader.load(ArbitratorProfileView.class);
|
||||
root.getChildren().set(0, view.getRoot());
|
||||
|
@ -26,7 +26,6 @@ import io.bitsquare.gui.components.confidence.ConfidenceProgressIndicator;
|
||||
import io.bitsquare.gui.util.BSFormatter;
|
||||
import io.bitsquare.locale.BSResources;
|
||||
import io.bitsquare.locale.LanguageUtil;
|
||||
import io.bitsquare.user.User;
|
||||
import io.bitsquare.util.Utilities;
|
||||
|
||||
import org.bitcoinj.core.Coin;
|
||||
@ -39,7 +38,6 @@ import org.bitcoinj.script.Script;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@ -60,7 +58,7 @@ public class ArbitratorRegistrationView extends ActivatableView<AnchorPane, Void
|
||||
@FXML TextArea descriptionTextArea;
|
||||
@FXML Button saveProfileButton, paymentDoneButton;
|
||||
@FXML Label nameLabel, infoLabel, copyIcon, confirmationLabel;
|
||||
@FXML ComboBox<Locale> languageComboBox;
|
||||
@FXML ComboBox<String> languageComboBox;
|
||||
@FXML ComboBox<Arbitrator.ID_TYPE> idTypeComboBox;
|
||||
@FXML ComboBox<Arbitrator.METHOD> methodsComboBox;
|
||||
@FXML ConfidenceProgressIndicator progressIndicator;
|
||||
@ -74,23 +72,22 @@ public class ArbitratorRegistrationView extends ActivatableView<AnchorPane, Void
|
||||
private boolean isEditMode;
|
||||
private Arbitrator.ID_TYPE idType;
|
||||
|
||||
private List<Locale> languageList = new ArrayList<>();
|
||||
private List<String> languageCodes = new ArrayList<>();
|
||||
private List<Arbitrator.METHOD> methodList = new ArrayList<>();
|
||||
private List<Arbitrator.ID_VERIFICATION> idVerificationList = new ArrayList<>();
|
||||
|
||||
private final Arbitrator arbitrator;
|
||||
private final WalletService walletService;
|
||||
private final ArbitratorService messageService;
|
||||
private final User user;
|
||||
private final BSFormatter formatter;
|
||||
|
||||
|
||||
@Inject
|
||||
private ArbitratorRegistrationView(Arbitrator arbitrator, WalletService walletService,
|
||||
ArbitratorService messageService, User user, BSFormatter formatter) {
|
||||
ArbitratorService messageService, BSFormatter formatter) {
|
||||
this.arbitrator = arbitrator;
|
||||
this.walletService = walletService;
|
||||
this.messageService = messageService;
|
||||
this.user = user;
|
||||
this.formatter = formatter;
|
||||
}
|
||||
|
||||
@ -98,17 +95,17 @@ public class ArbitratorRegistrationView extends ActivatableView<AnchorPane, Void
|
||||
public void initialize() {
|
||||
accordion.setExpandedPane(profileTitledPane);
|
||||
|
||||
applyArbitrator();
|
||||
applyArbitrator();
|
||||
|
||||
languageComboBox.setItems(FXCollections.observableArrayList(LanguageUtil.getAllLanguageLocales()));
|
||||
languageComboBox.setConverter(new StringConverter<Locale>() {
|
||||
languageComboBox.setItems(FXCollections.observableArrayList(LanguageUtil.getAllLanguageLocaleCodes()));
|
||||
languageComboBox.setConverter(new StringConverter<String>() {
|
||||
@Override
|
||||
public String toString(Locale locale) {
|
||||
return locale.getDisplayLanguage();
|
||||
public String toString(String code) {
|
||||
return LanguageUtil.getDisplayName(code);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locale fromString(String s) {
|
||||
public String fromString(String s) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
@ -192,17 +189,17 @@ public class ArbitratorRegistrationView extends ActivatableView<AnchorPane, Void
|
||||
|
||||
@FXML
|
||||
public void onAddLanguage() {
|
||||
Locale item = languageComboBox.getSelectionModel().getSelectedItem();
|
||||
if (!languageList.contains(item) && item != null) {
|
||||
languageList.add(item);
|
||||
languagesTextField.setText(formatter.languageLocalesToString(languageList));
|
||||
String item = languageComboBox.getSelectionModel().getSelectedItem();
|
||||
if (!languageCodes.contains(item) && item != null) {
|
||||
languageCodes.add(item);
|
||||
languagesTextField.setText(formatter.languageCodesToString(languageCodes));
|
||||
languageComboBox.getSelectionModel().clearSelection();
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void onClearLanguages() {
|
||||
languageList.clear();
|
||||
languageCodes.clear();
|
||||
languagesTextField.setText("");
|
||||
}
|
||||
|
||||
@ -248,7 +245,7 @@ public class ArbitratorRegistrationView extends ActivatableView<AnchorPane, Void
|
||||
arbitrator.setFee(formatter.parseToCoin(arbitrationFeeTextField.getText()));
|
||||
arbitrator.setIdType(idType);
|
||||
arbitrator.setIdVerifications(idVerificationList);
|
||||
// arbitrator.setLanguages(languageList);
|
||||
arbitrator.setLanguageCodes(languageCodes);
|
||||
arbitrator.setArbitrationMethods(methodList);
|
||||
arbitrator.save();
|
||||
|
||||
@ -343,7 +340,7 @@ public class ArbitratorRegistrationView extends ActivatableView<AnchorPane, Void
|
||||
|
||||
nameTextField.setText(arbitrator.getName());
|
||||
idTypeTextField.setText(BSResources.get(arbitrator.getIdType().toString()));
|
||||
// languagesTextField.setText(formatter.languageLocalesToString(arbitrator.getLanguages()));
|
||||
// languagesTextField.setText(formatter.languageLocalesToString(arbitrator.getLanguages()));
|
||||
arbitrationFeeTextField.setText(String.valueOf(arbitrator.getFee()));
|
||||
methodsTextField.setText(formatter.arbitrationMethodsToString(arbitrator.getArbitrationMethods()));
|
||||
idVerificationsTextField.setText(
|
||||
@ -352,7 +349,7 @@ public class ArbitratorRegistrationView extends ActivatableView<AnchorPane, Void
|
||||
descriptionTextArea.setText(arbitrator.getDescription());
|
||||
|
||||
idType = arbitrator.getIdType();
|
||||
// languageList = arbitrator.getLanguages();
|
||||
languageCodes = arbitrator.getLanguageCodes();
|
||||
methodList = arbitrator.getArbitrationMethods();
|
||||
idVerificationList = arbitrator.getIdVerifications();
|
||||
}
|
||||
|
@ -28,8 +28,6 @@ import io.bitsquare.user.AccountSettings;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
|
||||
@ -37,11 +35,11 @@ class RestrictionsDataModel implements Activatable, DataModel {
|
||||
|
||||
private final AccountSettings accountSettings;
|
||||
|
||||
final ObservableList<Locale> languageList = FXCollections.observableArrayList();
|
||||
final ObservableList<Country> countryList = FXCollections.observableArrayList();
|
||||
final ObservableList<Arbitrator> arbitratorList = FXCollections.observableArrayList();
|
||||
final ObservableList<Locale> allLanguages = FXCollections.observableArrayList(LanguageUtil
|
||||
.getAllLanguageLocales());
|
||||
final ObservableList<String> languageCodes = FXCollections.observableArrayList();
|
||||
final ObservableList<Country> countries = FXCollections.observableArrayList();
|
||||
final ObservableList<Arbitrator> arbitrators = FXCollections.observableArrayList();
|
||||
final ObservableList<String> allLanguageCodes = FXCollections.observableArrayList(LanguageUtil
|
||||
.getAllLanguageLocaleCodes());
|
||||
final ObservableList<Region> allRegions = FXCollections.observableArrayList(CountryUtil.getAllRegions());
|
||||
|
||||
|
||||
@ -52,9 +50,9 @@ class RestrictionsDataModel implements Activatable, DataModel {
|
||||
|
||||
@Override
|
||||
public void activate() {
|
||||
countryList.setAll(accountSettings.getAcceptedCountries());
|
||||
languageList.setAll(accountSettings.getAcceptedLanguageLocales());
|
||||
arbitratorList.setAll(accountSettings.getAcceptedArbitrators());
|
||||
countries.setAll(accountSettings.getAcceptedCountries());
|
||||
languageCodes.setAll(accountSettings.getAcceptedLanguageLocaleCodes());
|
||||
arbitrators.setAll(accountSettings.getAcceptedArbitrators());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -66,24 +64,24 @@ class RestrictionsDataModel implements Activatable, DataModel {
|
||||
}
|
||||
|
||||
void updateArbitratorList() {
|
||||
arbitratorList.setAll(accountSettings.getAcceptedArbitrators());
|
||||
arbitrators.setAll(accountSettings.getAcceptedArbitrators());
|
||||
}
|
||||
|
||||
void addLanguage(Locale locale) {
|
||||
if (locale != null && !languageList.contains(locale)) {
|
||||
languageList.add(locale);
|
||||
accountSettings.addAcceptedLanguageLocale(locale);
|
||||
void addLanguageCode(String code) {
|
||||
if (code != null && !languageCodes.contains(code)) {
|
||||
languageCodes.add(code);
|
||||
accountSettings.addAcceptedLanguageLocale(code);
|
||||
}
|
||||
}
|
||||
|
||||
void removeLanguage(Locale locale) {
|
||||
languageList.remove(locale);
|
||||
accountSettings.removeAcceptedLanguageLocale(locale);
|
||||
void removeLanguage(String code) {
|
||||
languageCodes.remove(code);
|
||||
accountSettings.removeAcceptedLanguageLocale(code);
|
||||
}
|
||||
|
||||
void addCountry(Country country) {
|
||||
if (!countryList.contains(country) && country != null) {
|
||||
countryList.add(country);
|
||||
if (!countries.contains(country) && country != null) {
|
||||
countries.add(country);
|
||||
accountSettings.addAcceptedCountry(country);
|
||||
}
|
||||
}
|
||||
@ -92,17 +90,17 @@ class RestrictionsDataModel implements Activatable, DataModel {
|
||||
// TODO use Set instead of List
|
||||
// In addAcceptedCountry there is a check to no add duplicates, so it works correctly for now
|
||||
CountryUtil.getAllEuroCountries().stream().forEach(accountSettings::addAcceptedCountry);
|
||||
countryList.setAll(accountSettings.getAcceptedCountries());
|
||||
return countryList;
|
||||
countries.setAll(accountSettings.getAcceptedCountries());
|
||||
return countries;
|
||||
}
|
||||
|
||||
void removeCountry(Country country) {
|
||||
countryList.remove(country);
|
||||
countries.remove(country);
|
||||
accountSettings.removeAcceptedCountry(country);
|
||||
}
|
||||
|
||||
void removeArbitrator(Arbitrator arbitrator) {
|
||||
arbitratorList.remove(arbitrator);
|
||||
arbitrators.remove(arbitrator);
|
||||
accountSettings.removeAcceptedArbitrator(arbitrator);
|
||||
}
|
||||
}
|
||||
|
@ -29,10 +29,9 @@ import io.bitsquare.gui.main.help.Help;
|
||||
import io.bitsquare.gui.main.help.HelpId;
|
||||
import io.bitsquare.gui.util.ImageUtil;
|
||||
import io.bitsquare.locale.Country;
|
||||
import io.bitsquare.locale.LanguageUtil;
|
||||
import io.bitsquare.locale.Region;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
@ -48,10 +47,10 @@ import javafx.util.StringConverter;
|
||||
@FxmlView
|
||||
public class RestrictionsView extends ActivatableViewAndModel<GridPane, RestrictionsViewModel> implements Wizard.Step {
|
||||
|
||||
@FXML ListView<Locale> languagesListView;
|
||||
@FXML ListView<String> languagesListView;
|
||||
@FXML ListView<Country> countriesListView;
|
||||
@FXML ListView<Arbitrator> arbitratorsListView;
|
||||
@FXML ComboBox<Locale> languageComboBox;
|
||||
@FXML ComboBox<String> languageComboBox;
|
||||
@FXML ComboBox<Region> regionComboBox;
|
||||
@FXML ComboBox<Country> countryComboBox;
|
||||
@FXML Button completedButton, addAllEuroCountriesButton;
|
||||
@ -79,7 +78,7 @@ public class RestrictionsView extends ActivatableViewAndModel<GridPane, Restrict
|
||||
|
||||
@Override
|
||||
public void doActivate() {
|
||||
languagesListView.setItems(model.getLanguageList());
|
||||
languagesListView.setItems(model.getLanguageCodes());
|
||||
countriesListView.setItems(model.getCountryList());
|
||||
arbitratorsListView.setItems(model.getArbitratorList());
|
||||
}
|
||||
@ -174,10 +173,10 @@ public class RestrictionsView extends ActivatableViewAndModel<GridPane, Restrict
|
||||
}
|
||||
|
||||
private void initLanguage() {
|
||||
languagesListView.setCellFactory(new Callback<ListView<Locale>, ListCell<Locale>>() {
|
||||
languagesListView.setCellFactory(new Callback<ListView<String>, ListCell<String>>() {
|
||||
@Override
|
||||
public ListCell<Locale> call(ListView<Locale> list) {
|
||||
return new ListCell<Locale>() {
|
||||
public ListCell<String> call(ListView<String> list) {
|
||||
return new ListCell<String>() {
|
||||
final Label label = new Label();
|
||||
final ImageView icon = ImageUtil.getImageViewById(ImageUtil.REMOVE_ICON);
|
||||
final Button removeButton = new Button("", icon);
|
||||
@ -190,10 +189,10 @@ public class RestrictionsView extends ActivatableViewAndModel<GridPane, Restrict
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateItem(final Locale item, boolean empty) {
|
||||
public void updateItem(final String item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
if (item != null && !empty) {
|
||||
label.setText(item.getDisplayName());
|
||||
label.setText(LanguageUtil.getDisplayName(item));
|
||||
removeButton.setOnAction(actionEvent -> removeLanguage(item));
|
||||
setGraphic(pane);
|
||||
}
|
||||
@ -205,15 +204,15 @@ public class RestrictionsView extends ActivatableViewAndModel<GridPane, Restrict
|
||||
}
|
||||
});
|
||||
|
||||
languageComboBox.setItems(model.getAllLanguages());
|
||||
languageComboBox.setConverter(new StringConverter<Locale>() {
|
||||
languageComboBox.setItems(model.getAllLanguageCodes());
|
||||
languageComboBox.setConverter(new StringConverter<String>() {
|
||||
@Override
|
||||
public String toString(Locale locale) {
|
||||
return locale.getDisplayLanguage();
|
||||
public String toString(String code) {
|
||||
return LanguageUtil.getDisplayName(code);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locale fromString(String s) {
|
||||
public String fromString(String s) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
@ -310,7 +309,7 @@ public class RestrictionsView extends ActivatableViewAndModel<GridPane, Restrict
|
||||
});
|
||||
}
|
||||
|
||||
private void removeLanguage(Locale locale) {
|
||||
private void removeLanguage(String locale) {
|
||||
model.removeLanguage(locale);
|
||||
}
|
||||
|
||||
|
@ -25,8 +25,6 @@ import io.bitsquare.locale.Region;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.collections.ObservableList;
|
||||
@ -47,12 +45,12 @@ class RestrictionsViewModel extends ActivatableWithDataModel<RestrictionsDataMod
|
||||
updateDoneButtonDisableState();
|
||||
}
|
||||
|
||||
void addLanguage(Locale locale) {
|
||||
dataModel.addLanguage(locale);
|
||||
void addLanguage(String locale) {
|
||||
dataModel.addLanguageCode(locale);
|
||||
updateDoneButtonDisableState();
|
||||
}
|
||||
|
||||
void removeLanguage(Locale locale) {
|
||||
void removeLanguage(String locale) {
|
||||
dataModel.removeLanguage(locale);
|
||||
updateDoneButtonDisableState();
|
||||
}
|
||||
@ -86,32 +84,32 @@ class RestrictionsViewModel extends ActivatableWithDataModel<RestrictionsDataMod
|
||||
return dataModel.getAllCountriesFor(selectedRegion);
|
||||
}
|
||||
|
||||
ObservableList<Locale> getLanguageList() {
|
||||
return dataModel.languageList;
|
||||
ObservableList<String> getLanguageCodes() {
|
||||
return dataModel.languageCodes;
|
||||
}
|
||||
|
||||
ObservableList<Region> getAllRegions() {
|
||||
return dataModel.allRegions;
|
||||
}
|
||||
|
||||
ObservableList<Locale> getAllLanguages() {
|
||||
return dataModel.allLanguages;
|
||||
ObservableList<String> getAllLanguageCodes() {
|
||||
return dataModel.allLanguageCodes;
|
||||
}
|
||||
|
||||
ObservableList<Country> getCountryList() {
|
||||
return dataModel.countryList;
|
||||
return dataModel.countries;
|
||||
}
|
||||
|
||||
ObservableList<Arbitrator> getArbitratorList() {
|
||||
return dataModel.arbitratorList;
|
||||
return dataModel.arbitrators;
|
||||
}
|
||||
|
||||
|
||||
//TODO Revert size() > -1 to 0(2 later). For mock testing disabled arbitratorList test
|
||||
private void updateDoneButtonDisableState() {
|
||||
boolean isValid = dataModel.languageList != null && dataModel.languageList.size() > 0 &&
|
||||
dataModel.countryList != null && dataModel.countryList.size() > 0 &&
|
||||
dataModel.arbitratorList != null && dataModel.arbitratorList.size() > -1;
|
||||
boolean isValid = dataModel.languageCodes != null && dataModel.languageCodes.size() > 0 &&
|
||||
dataModel.countries != null && dataModel.countries.size() > 0 &&
|
||||
dataModel.arbitrators != null && dataModel.arbitrators.size() > -1;
|
||||
doneButtonDisable.set(!isValid);
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,6 @@ import org.bitcoinj.utils.Fiat;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
@ -100,7 +99,7 @@ class CreateOfferDataModel implements Activatable, DataModel {
|
||||
final ObjectProperty<Coin> securityDepositAsCoin = new SimpleObjectProperty<>();
|
||||
|
||||
final ObservableList<Country> acceptedCountries = FXCollections.observableArrayList();
|
||||
final ObservableList<Locale> acceptedLanguages = FXCollections.observableArrayList();
|
||||
final ObservableList<String> acceptedLanguageCodes = FXCollections.observableArrayList();
|
||||
final ObservableList<Arbitrator> acceptedArbitrators = FXCollections.observableArrayList();
|
||||
|
||||
|
||||
@ -154,7 +153,7 @@ class CreateOfferDataModel implements Activatable, DataModel {
|
||||
securityDepositAsCoin.set(accountSettings.getSecurityDeposit());
|
||||
|
||||
acceptedCountries.setAll(accountSettings.getAcceptedCountries());
|
||||
acceptedLanguages.setAll(accountSettings.getAcceptedLanguageLocales());
|
||||
acceptedLanguageCodes.setAll(accountSettings.getAcceptedLanguageLocaleCodes());
|
||||
acceptedArbitrators.setAll(accountSettings.getAcceptedArbitrators());
|
||||
}
|
||||
}
|
||||
|
@ -312,8 +312,8 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
||||
// ObservableLists
|
||||
dataModel.acceptedCountries.addListener((Observable o) -> acceptedCountries.set(formatter
|
||||
.countryLocalesToString(dataModel.acceptedCountries)));
|
||||
dataModel.acceptedLanguages.addListener((Observable o) -> acceptedLanguages.set(formatter
|
||||
.languageLocalesToString(dataModel.acceptedLanguages)));
|
||||
dataModel.acceptedLanguageCodes.addListener((Observable o) -> acceptedLanguages.set(formatter
|
||||
.languageCodesToString(dataModel.acceptedLanguageCodes)));
|
||||
dataModel.acceptedArbitrators.addListener((Observable o) -> acceptedArbitrators.set(formatter
|
||||
.arbitratorsToString(dataModel.acceptedArbitrators)));
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ class TakeOfferViewModel extends ActivatableWithDataModel<TakeOfferDataModel> im
|
||||
}
|
||||
|
||||
acceptedCountries = formatter.countryLocalesToString(offer.getAcceptedCountries());
|
||||
acceptedLanguages = formatter.languageLocalesToString(offer.getAcceptedLanguageLocales());
|
||||
acceptedLanguages = formatter.languageCodesToString(offer.getAcceptedLanguageCodes());
|
||||
acceptedArbitrators = formatter.arbitratorsToString(offer.getArbitrators());
|
||||
bankAccountType = BSResources.get(offer.getFiatAccountType().toString());
|
||||
bankAccountCurrency = BSResources.get(CurrencyUtil.getDisplayName(offer.getCurrencyCode()));
|
||||
|
@ -21,6 +21,7 @@ import io.bitsquare.arbitration.Arbitrator;
|
||||
import io.bitsquare.locale.BSResources;
|
||||
import io.bitsquare.locale.Country;
|
||||
import io.bitsquare.locale.CurrencyUtil;
|
||||
import io.bitsquare.locale.LanguageUtil;
|
||||
import io.bitsquare.offer.Offer;
|
||||
import io.bitsquare.user.User;
|
||||
|
||||
@ -316,8 +317,8 @@ public class BSFormatter {
|
||||
return arbitrators.stream().map(Arbitrator::getName).collect(Collectors.joining(", "));
|
||||
}
|
||||
|
||||
public String languageLocalesToString(List<Locale> languageLocales) {
|
||||
return languageLocales.stream().map(e -> e.getDisplayLanguage()).collect(Collectors.joining(", "));
|
||||
public String languageCodesToString(List<String> languageLocales) {
|
||||
return languageLocales.stream().map(e -> LanguageUtil.getDisplayName(e)).collect(Collectors.joining(", "));
|
||||
}
|
||||
|
||||
public String arbitrationMethodsToString(List<Arbitrator.METHOD> methods) {
|
||||
|
@ -29,27 +29,6 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class CountryUtil {
|
||||
|
||||
private static final String[] countryCodes = new String[]{"AE", "AL", "AR", "AT", "AU", "BA", "BE", "BG", "BH",
|
||||
"BO", "BR", "BY", "CA", "CH", "CL", "CN", "CO", "CR", "CS", "CU", "CY", "CZ", "DE", "DK", "DO", "DZ",
|
||||
"EC", "EE", "EG", "ES", "FI", "FR", "GB", "GR", "GT", "HK", "HN", "HR", "HU", "ID", "IE", "IL", "IN",
|
||||
"IQ", "IS", "IT", "JO", "JP", "KR", "KW", "LB", "LT", "LU", "LV", "LY", "MA", "ME", "MK", "MT", "MX",
|
||||
"MY", "NI", "NL", "NO", "NZ", "OM", "PA", "PE", "PH", "PL", "PR", "PT", "PY", "QA", "RO", "RS", "RU",
|
||||
"SA", "SD", "SE", "SG", "SI", "SK", "SV", "SY", "TH", "TN", "TR", "TW", "UA", "US", "UY", "VE", "VN",
|
||||
"YE", "ZA"};
|
||||
|
||||
private static final List<String> countryCodeList = Arrays.asList(countryCodes);
|
||||
private static final String[] regionCodes = new String[]{"AS", "EU", "SA", "EU", "OC", "EU", "EU", "EU", "AS",
|
||||
"SA", "SA", "EU", "NA", "EU", "SA", "AS", "SA", "NA", "EU", "NA", "EU", "EU", "EU", "EU", "NA", "AF",
|
||||
"SA", "EU", "AF", "EU", "EU", "EU", "EU", "EU", "NA", "AS", "NA", "EU", "EU", "AS", "EU", "AS", "AS",
|
||||
"AS", "EU", "EU", "AS", "AS", "AS", "AS", "AS", "EU", "EU", "EU", "AF", "AF", "EU", "EU", "EU", "NA",
|
||||
"AS", "NA", "EU", "EU", "OC", "AS", "NA", "SA", "AS", "EU", "NA", "EU", "SA", "AS", "EU", "EU", "EU",
|
||||
"AS", "AF", "EU", "AS", "EU", "EU", "NA", "AS", "AS", "AF", "AS", "AS", "EU", "NA", "SA", "SA", "AS",
|
||||
"AS", "AF"};
|
||||
private static final List<String> regionCodeList = Arrays.asList(regionCodes);
|
||||
private static final String[][] regionCodeToName = new String[][]{
|
||||
{"NA", "North America"}, {"SA", "South America"}, {"AF", "Africa"}, {"EU", "Europe"}, {"AS", "Asia"},
|
||||
{"OC", "Oceania"}};
|
||||
|
||||
public static List<Region> getAllRegions() {
|
||||
final List<Region> allRegions = new ArrayList<>();
|
||||
|
||||
@ -100,6 +79,14 @@ public class CountryUtil {
|
||||
selectedRegion != null && country != null && selectedRegion.equals(country.getRegion())));
|
||||
}
|
||||
|
||||
public static Country getDefaultCountry() {
|
||||
final Locale locale = new Locale("", Locale.getDefault().getCountry());
|
||||
String regionCode = getRegionCode(locale.getCountry());
|
||||
final Region region = new Region(regionCode, getRegionName(regionCode));
|
||||
return new Country(locale.getCountry(), locale.getDisplayCountry(), region);
|
||||
}
|
||||
|
||||
|
||||
private static List<Country> getAllCountries() {
|
||||
final List<Country> allCountries = new ArrayList<>();
|
||||
for (final Locale locale : getAllCountryLocales()) {
|
||||
@ -111,12 +98,26 @@ public class CountryUtil {
|
||||
return allCountries;
|
||||
}
|
||||
|
||||
public static Country getDefaultCountry() {
|
||||
final Locale locale = new Locale("", Locale.getDefault().getCountry());
|
||||
String regionCode = getRegionCode(locale.getCountry());
|
||||
final Region region = new Region(regionCode, getRegionName(regionCode));
|
||||
return new Country(locale.getCountry(), locale.getDisplayCountry(), region);
|
||||
}
|
||||
private static final String[] countryCodes = new String[]{"AE", "AL", "AR", "AT", "AU", "BA", "BE", "BG", "BH",
|
||||
"BO", "BR", "BY", "CA", "CH", "CL", "CN", "CO", "CR", "CS", "CU", "CY", "CZ", "DE", "DK", "DO", "DZ",
|
||||
"EC", "EE", "EG", "ES", "FI", "FR", "GB", "GR", "GT", "HK", "HN", "HR", "HU", "ID", "IE", "IL", "IN",
|
||||
"IQ", "IS", "IT", "JO", "JP", "KR", "KW", "LB", "LT", "LU", "LV", "LY", "MA", "ME", "MK", "MT", "MX",
|
||||
"MY", "NI", "NL", "NO", "NZ", "OM", "PA", "PE", "PH", "PL", "PR", "PT", "PY", "QA", "RO", "RS", "RU",
|
||||
"SA", "SD", "SE", "SG", "SI", "SK", "SV", "SY", "TH", "TN", "TR", "TW", "UA", "US", "UY", "VE", "VN",
|
||||
"YE", "ZA"};
|
||||
|
||||
private static final List<String> countryCodeList = Arrays.asList(countryCodes);
|
||||
private static final String[] regionCodes = new String[]{"AS", "EU", "SA", "EU", "OC", "EU", "EU", "EU", "AS",
|
||||
"SA", "SA", "EU", "NA", "EU", "SA", "AS", "SA", "NA", "EU", "NA", "EU", "EU", "EU", "EU", "NA", "AF",
|
||||
"SA", "EU", "AF", "EU", "EU", "EU", "EU", "EU", "NA", "AS", "NA", "EU", "EU", "AS", "EU", "AS", "AS",
|
||||
"AS", "EU", "EU", "AS", "AS", "AS", "AS", "AS", "EU", "EU", "EU", "AF", "AF", "EU", "EU", "EU", "NA",
|
||||
"AS", "NA", "EU", "EU", "OC", "AS", "NA", "SA", "AS", "EU", "NA", "EU", "SA", "AS", "EU", "EU", "EU",
|
||||
"AS", "AF", "EU", "AS", "EU", "EU", "NA", "AS", "AS", "AF", "AS", "AS", "EU", "NA", "SA", "SA", "AS",
|
||||
"AS", "AF"};
|
||||
private static final List<String> regionCodeList = Arrays.asList(regionCodes);
|
||||
private static final String[][] regionCodeToName = new String[][]{
|
||||
{"NA", "North America"}, {"SA", "South America"}, {"AF", "Africa"}, {"EU", "Europe"}, {"AS", "Asia"},
|
||||
{"OC", "Oceania"}};
|
||||
|
||||
private static String getRegionName(final String regionCode) {
|
||||
for (final String[] regionName : regionCodeToName) {
|
||||
|
@ -26,25 +26,29 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class LanguageUtil {
|
||||
|
||||
public static List<Locale> getAllLanguageLocales() {
|
||||
public static List<String> getAllLanguageLocaleCodes() {
|
||||
List<Locale> allLocales = Arrays.asList(Locale.getAvailableLocales());
|
||||
final Set<Locale> allLocalesAsSet =
|
||||
final Set<String> allLocaleCodesAsSet =
|
||||
allLocales.stream().filter(locale -> !"".equals(locale.getLanguage())).map(locale ->
|
||||
new Locale(locale.getLanguage(), "")).collect(Collectors.toSet());
|
||||
allLocales = new ArrayList<>();
|
||||
allLocales.addAll(allLocalesAsSet);
|
||||
allLocales.sort((locale1, locale2) -> locale1.getDisplayLanguage().compareTo(locale2.getDisplayLanguage()));
|
||||
return allLocales;
|
||||
new Locale(locale.getLanguage(), "").getISO3Language()).collect(Collectors.toSet());
|
||||
List<String> allLocaleCodes = new ArrayList<>();
|
||||
allLocaleCodes.addAll(allLocaleCodesAsSet);
|
||||
allLocaleCodes.sort((locale1, locale2) -> locale1.compareTo(locale2));
|
||||
return allLocaleCodes;
|
||||
}
|
||||
|
||||
public static Locale getDefaultLanguageLocale() {
|
||||
public static String getDefaultLanguageLocaleAsCode() {
|
||||
if (Locale.getDefault() != null)
|
||||
return new Locale(Locale.getDefault().getLanguage(), "");
|
||||
return new Locale(Locale.getDefault().getLanguage(), "").getISO3Language();
|
||||
else
|
||||
return getEnglishLanguageLocale();
|
||||
return getEnglishLanguageLocaleCode();
|
||||
}
|
||||
|
||||
public static Locale getEnglishLanguageLocale() {
|
||||
return new Locale(Locale.ENGLISH.getLanguage(), "");
|
||||
public static String getEnglishLanguageLocaleCode() {
|
||||
return new Locale(Locale.ENGLISH.getLanguage(), "").getISO3Language();
|
||||
}
|
||||
|
||||
public static String getDisplayName(String code) {
|
||||
return new Locale(code).getDisplayName();
|
||||
}
|
||||
}
|
||||
|
@ -24,9 +24,7 @@ import java.util.Objects;
|
||||
public class Region implements Serializable {
|
||||
private static final long serialVersionUID = -5930294199097793187L;
|
||||
|
||||
|
||||
private final String code;
|
||||
|
||||
private final String name;
|
||||
|
||||
public Region(String code, String name) {
|
||||
@ -55,7 +53,6 @@ public class Region implements Serializable {
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
@ -32,7 +32,6 @@ import java.security.PublicKey;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
@ -75,7 +74,7 @@ public class Offer implements Serializable {
|
||||
|
||||
private final Coin securityDeposit;
|
||||
private final List<Country> acceptedCountries;
|
||||
private final List<Locale> acceptedLanguageLocales;
|
||||
private final List<String> acceptedLanguageCodes;
|
||||
private final String bankAccountUID;
|
||||
private final List<Arbitrator> arbitrators;
|
||||
|
||||
@ -105,7 +104,7 @@ public class Offer implements Serializable {
|
||||
List<Arbitrator> arbitrators,
|
||||
Coin securityDeposit,
|
||||
List<Country> acceptedCountries,
|
||||
List<Locale> acceptedLanguageLocales) {
|
||||
List<String> acceptedLanguageCodes) {
|
||||
this.id = id;
|
||||
this.p2pSigPubKey = p2pSigPubKey;
|
||||
this.direction = direction;
|
||||
@ -120,7 +119,7 @@ public class Offer implements Serializable {
|
||||
this.securityDeposit = securityDeposit;
|
||||
this.acceptedCountries = acceptedCountries;
|
||||
|
||||
this.acceptedLanguageLocales = acceptedLanguageLocales;
|
||||
this.acceptedLanguageCodes = acceptedLanguageCodes;
|
||||
|
||||
creationDate = new Date();
|
||||
setState(State.UNKNOWN);
|
||||
@ -184,8 +183,8 @@ public class Offer implements Serializable {
|
||||
return acceptedCountries;
|
||||
}
|
||||
|
||||
public List<Locale> getAcceptedLanguageLocales() {
|
||||
return acceptedLanguageLocales;
|
||||
public List<String> getAcceptedLanguageCodes() {
|
||||
return acceptedLanguageCodes;
|
||||
}
|
||||
|
||||
public Fiat getVolumeByAmount(Coin amount) {
|
||||
@ -239,7 +238,7 @@ public class Offer implements Serializable {
|
||||
|
||||
public void validate() throws Exception {
|
||||
checkNotNull(getAcceptedCountries(), "AcceptedCountries is null");
|
||||
checkNotNull(getAcceptedLanguageLocales(), "AcceptedLanguageLocales is null");
|
||||
checkNotNull(getAcceptedLanguageCodes(), "AcceptedLanguageLocales is null");
|
||||
checkNotNull(getAmount(), "Amount is null");
|
||||
checkNotNull(getArbitrators(), "Arbitrator is null");
|
||||
checkNotNull(getBankAccountId(), "BankAccountId is null");
|
||||
@ -279,7 +278,7 @@ public class Offer implements Serializable {
|
||||
", bankAccountCountry=" + bankAccountCountry +
|
||||
", securityDeposit=" + securityDeposit +
|
||||
", acceptedCountries=" + acceptedCountries +
|
||||
", acceptedLanguageLocales=" + acceptedLanguageLocales +
|
||||
", acceptedLanguageLocales=" + acceptedLanguageCodes +
|
||||
", bankAccountUID='" + bankAccountUID + '\'' +
|
||||
", arbitrators=" + arbitrators +
|
||||
", offerFeePaymentTxID='" + offerFeePaymentTxID + '\'' +
|
||||
|
@ -176,7 +176,7 @@ public class TradeManager {
|
||||
accountSettings.getAcceptedArbitrators(),
|
||||
accountSettings.getSecurityDeposit(),
|
||||
accountSettings.getAcceptedCountries(),
|
||||
accountSettings.getAcceptedLanguageLocales());
|
||||
accountSettings.getAcceptedLanguageLocaleCodes());
|
||||
|
||||
try {
|
||||
Data offerData = new Data(offer);
|
||||
|
@ -30,7 +30,6 @@ import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.OptionalLong;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@ -41,10 +40,10 @@ public class AccountSettings implements Serializable {
|
||||
transient private Storage<AccountSettings> storage;
|
||||
|
||||
// Persisted fields
|
||||
private List<Locale> acceptedLanguageLocales = new ArrayList<>();
|
||||
private List<String> acceptedLanguageLocaleCodes = new ArrayList<>();
|
||||
private List<Country> acceptedCountryLocales = new ArrayList<>();
|
||||
private List<Arbitrator> acceptedArbitrators = new ArrayList<>();
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Constructor
|
||||
@ -56,12 +55,12 @@ public class AccountSettings implements Serializable {
|
||||
|
||||
AccountSettings persisted = storage.initAndGetPersisted(this);
|
||||
if (persisted != null) {
|
||||
acceptedLanguageLocales = persisted.getAcceptedLanguageLocales();
|
||||
acceptedLanguageLocaleCodes = persisted.getAcceptedLanguageLocaleCodes();
|
||||
acceptedCountryLocales = persisted.getAcceptedCountries();
|
||||
acceptedArbitrators = persisted.getAcceptedArbitrators();
|
||||
}
|
||||
else {
|
||||
acceptedLanguageLocales = Arrays.asList(LanguageUtil.getDefaultLanguageLocale(), LanguageUtil.getEnglishLanguageLocale());
|
||||
acceptedLanguageLocaleCodes = Arrays.asList(LanguageUtil.getDefaultLanguageLocaleAsCode(), LanguageUtil.getEnglishLanguageLocaleCode());
|
||||
acceptedCountryLocales = Arrays.asList(CountryUtil.getDefaultCountry());
|
||||
acceptedArbitrators = Arrays.asList(defaultArbitrator);
|
||||
}
|
||||
@ -73,15 +72,15 @@ public class AccountSettings implements Serializable {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
public void addAcceptedLanguageLocale(Locale locale) {
|
||||
if (!acceptedLanguageLocales.contains(locale)) {
|
||||
acceptedLanguageLocales.add(locale);
|
||||
public void addAcceptedLanguageLocale(String localeCode) {
|
||||
if (!acceptedLanguageLocaleCodes.contains(localeCode)) {
|
||||
acceptedLanguageLocaleCodes.add(localeCode);
|
||||
storage.save();
|
||||
}
|
||||
}
|
||||
|
||||
public void removeAcceptedLanguageLocale(Locale item) {
|
||||
acceptedLanguageLocales.remove(item);
|
||||
public void removeAcceptedLanguageLocale(String item) {
|
||||
acceptedLanguageLocaleCodes.remove(item);
|
||||
}
|
||||
|
||||
public void addAcceptedCountry(Country locale) {
|
||||
@ -107,7 +106,7 @@ public class AccountSettings implements Serializable {
|
||||
storage.save();
|
||||
}
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Getters
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -116,8 +115,8 @@ public class AccountSettings implements Serializable {
|
||||
return acceptedArbitrators;
|
||||
}
|
||||
|
||||
public List<Locale> getAcceptedLanguageLocales() {
|
||||
return acceptedLanguageLocales;
|
||||
public List<String> getAcceptedLanguageLocaleCodes() {
|
||||
return acceptedLanguageLocaleCodes;
|
||||
}
|
||||
|
||||
public List<Country> getAcceptedCountries() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user