Skip to content

Commit

Permalink
XmppProviders.getXmppProvidersModel(): return a List<String>
Browse files Browse the repository at this point in the history
  • Loading branch information
stokito committed Sep 1, 2024
1 parent dad6a61 commit 1f40d1c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import static org.jivesoftware.sparkimpl.certificates.SparkSSLContextCreator.Options.ONLY_SERVER_SIDE;

Expand Down Expand Up @@ -122,7 +123,13 @@ public FormPanel() {
public AccountCreationWizard() {
// Associate Mnemonics
serverField.setEditable(true);
serverField.setModel(XmppProviders.getXmppProvidersModel());
List<String> providers = XmppProviders.getXmppProvidersModel();
for (String provider : providers) {
serverField.addItem(provider);
}
// Randomly pre-select a provider
int randomProviderIdx = new Random().nextInt(providers.size());
serverField.setSelectedIndex(randomProviderIdx);

ResourceUtils.resButton(startRegistrationButton, Res.getString("button.start.registration"));
startRegistrationButton.addActionListener( actionEvent -> startRegistration() );
Expand Down
21 changes: 6 additions & 15 deletions core/src/main/java/org/jivesoftware/XmppProviders.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.jivesoftware.spark.util.log.Log;

import javax.swing.*;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import static java.util.Arrays.asList;

Expand Down Expand Up @@ -58,20 +55,14 @@ public class XmppProviders {
"yax.im",
};

public static ComboBoxModel<String> getXmppProvidersModel() {
DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>();
public static List<String> getXmppProvidersModel() {
List<String> providersList = downloadProvidersList();
if (providersList == null) {
// fallback to static list
providersList = asList(providers);
}
for (String provider : providersList) {
model.addElement(provider);
if (providersList != null) {
return providersList;
}
// Randomly pre-select a provider
int randomProviderIdx = new Random().nextInt(providersList.size());
model.setSelectedItem(providersList.get(randomProviderIdx));
return model;
// fallback to static list
providersList = asList(providers);
return providersList;
}

static List<String> downloadProvidersList() {
Expand Down

0 comments on commit 1f40d1c

Please sign in to comment.