Removed user id, name and email from Settings

This commit is contained in:
Kai S. K. Engelbart 2019-12-14 09:58:25 +01:00
parent 2b1ece1c48
commit 5b84578a0a
4 changed files with 20 additions and 130 deletions

View File

@ -38,9 +38,6 @@ public class Client {
this.config = config;
sender = getUser(userName);
// Update the user ID in the cache
Settings.getInstance().setUserID(sender.getID());
logger.info("Client user ID: " + sender.getID());
}
@ -100,11 +97,7 @@ public class Client {
return sync.getUsers().get(0);
} else throw new EnvoyException("Unexpected response from Envoy Server");
} catch (Exception e) {
logger.warning("Could not connect to server, trying offline mode.");
if (Settings.getInstance().getUserID() != -1) {
user.setID(Settings.getInstance().getUserID());
return user;
} else throw new EnvoyException("Could not enter offline mode.");
throw new EnvoyException("Could not connect to server", e);
}
}

View File

@ -26,9 +26,6 @@ import envoy.client.ui.Theme;
public class Settings {
// Actual settings accessible by the rest of the application
private String username;
private long userID;
private String email;
private boolean enterToSend = true;
private Map<String, Theme> themes;
private String currentTheme;
@ -66,9 +63,6 @@ public class Settings {
@SuppressWarnings("unchecked")
private void load() {
setUsername(prefs.get("username", ""));
setUserID(prefs.getLong("userID", -1));
setEmail(prefs.get("email", ""));
setEnterToSend(prefs.getBoolean("enterToSend", true));
setCurrentTheme(prefs.get("theme", "dark"));
@ -98,9 +92,6 @@ public class Settings {
* @since Envoy v0.2-alpha
*/
public void save() throws IOException {
prefs.put("username", getUsername());
prefs.putLong("userID", getUserID());
prefs.put("email", getEmail());
prefs.put("theme", currentTheme);
prefs.putBoolean("enterToSend", isEnterToSend());
@ -136,40 +127,6 @@ public class Settings {
*/
public void setCurrentTheme(String themeName) { currentTheme = themeName; }
/**
* @return the user name
* @since Envoy v0.2-alpha
*/
public String getUsername() { return username; }
/**
* @param username the user name to set
* @since Envoy v0.2-alpha
*/
public void setUsername(String username) { this.username = username; }
/**
* @return the userID
*/
public long getUserID() { return userID; }
/**
* @param userID the userID to set
*/
public void setUserID(long userID) { this.userID = userID; }
/**
* @return the email associated with that user.
* @since Envoy v0.2-alpha
*/
public String getEmail() { return email; }
/**
* @param email the email to set
* @since Envoy v0.2-alpha
*/
public void setEmail(String email) { this.email = email; }
/**
* @return true, if "enter" suffices to send a message, else it has to be "ctrl"
* + "enter"

View File

@ -101,8 +101,7 @@ public class SettingsScreen extends JDialog {
createNewThemeButton.setEnabled(false);
temporaryTheme = new Theme("temporaryTheme",
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
temporaryTheme = new Theme("temporaryTheme", Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
// Content pane
GridBagLayout gbl_contentPanel = new GridBagLayout();
@ -200,20 +199,8 @@ public class SettingsScreen extends JDialog {
colorsPanel.setLayout(new BoxLayout(colorsPanel, BoxLayout.Y_AXIS));
colorsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getBackgroundColor(),
"Background",
1);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getCellColor(),
"Cells",
2);
buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getBackgroundColor(), "Background", 1);
buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getCellColor(), "Cells", 2);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
@ -228,41 +215,11 @@ public class SettingsScreen extends JDialog {
theme.getInteractableBackgroundColor(),
"Interactable Background",
4);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getMessageColorChat(),
"Messages Chat",
5);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getDateColorChat(),
"Date Chat",
6);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getSelectionColor(),
"Selection",
7);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getTypingMessageColor(),
"Typing Message",
8);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getUserNameColor(),
"User Names",
9);
buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getMessageColorChat(), "Messages Chat", 5);
buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getDateColorChat(), "Date Chat", 6);
buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getSelectionColor(), "Selection", 7);
buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getTypingMessageColor(), "Typing Message", 8);
buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getUserNameColor(), "User Names", 9);
GridBagConstraints gbc_colorsPanel = new GridBagConstraints();
gbc_colorsPanel.fill = GridBagConstraints.HORIZONTAL;
@ -283,16 +240,14 @@ public class SettingsScreen extends JDialog {
String s = JOptionPane.showInputDialog("Enter a name for the new theme");
System.out.println(s);
Settings.getInstance()
.addNewThemeToMap(new Theme(s, temporaryTheme.getBackgroundColor(),
temporaryTheme.getCellColor(), temporaryTheme.getInteractableForegroundColor(),
temporaryTheme.getInteractableBackgroundColor(), temporaryTheme.getMessageColorChat(),
temporaryTheme.getDateColorChat(), temporaryTheme.getSelectionColor(),
.addNewThemeToMap(new Theme(s, temporaryTheme.getBackgroundColor(), temporaryTheme.getCellColor(),
temporaryTheme.getInteractableForegroundColor(), temporaryTheme.getInteractableBackgroundColor(),
temporaryTheme.getMessageColorChat(), temporaryTheme.getDateColorChat(), temporaryTheme.getSelectionColor(),
temporaryTheme.getTypingMessageColor(), temporaryTheme.getUserNameColor()));
themeArray = Arrays.copyOf(themeArray, themeArray.length + 1);
themeArray[themeArray.length - 1] = Settings.getInstance().getThemes().get(s).getThemeName();
temporaryTheme = new Theme("temporaryTheme",
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
temporaryTheme = new Theme("temporaryTheme", Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
createNewThemeButton.setEnabled(false);
themes.addItem(themeArray[themeArray.length - 1]);
@ -348,10 +303,6 @@ public class SettingsScreen extends JDialog {
getRootPane().setDefaultButton(okButton);
okButton.addActionListener((evt) -> {
try {
Settings.getInstance().setUsername(Settings.getInstance().getUsername());// still temporary
Settings.getInstance().setEmail(Settings.getInstance().getEmail());// still temporary value
Settings.getInstance().setEnterToSend(Settings.getInstance().isEnterToSend());// still temporary
Settings.getInstance().setCurrentTheme(selectedTheme.getThemeName());
@ -412,21 +363,12 @@ public class SettingsScreen extends JDialog {
temporaryTheme = new Theme("temporaryTheme",
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getBackgroundColor(),
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getCellColor(),
Settings.getInstance()
.getThemes()
.get(Settings.getInstance().getCurrentTheme())
.getInteractableForegroundColor(),
Settings.getInstance()
.getThemes()
.get(Settings.getInstance().getCurrentTheme())
.getInteractableBackgroundColor(),
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getInteractableForegroundColor(),
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getInteractableBackgroundColor(),
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getMessageColorChat(),
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getDateColorChat(),
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getSelectionColor(),
Settings.getInstance()
.getThemes()
.get(Settings.getInstance().getCurrentTheme())
.getTypingMessageColor(),
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getTypingMessageColor(),
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getUserNameColor());
colorsPanel.removeAll();
@ -513,8 +455,7 @@ public class SettingsScreen extends JDialog {
private void setContent(JPanel content, GridBagConstraints layout) { contentPanel.add(content, layout); }
private void buildCustomizeElement(JPanel panel, JButton button, JTextPane textPane, Theme theme, Color color,
String name, int yIndex) {
private void buildCustomizeElement(JPanel panel, JButton button, JTextPane textPane, Theme theme, Color color, String name, int yIndex) {
textPane.setFont(new Font("Arial", Font.PLAIN, 14));
textPane.setBackground(theme.getBackgroundColor());
textPane.setForeground(theme.getUserNameColor());

View File

@ -9,7 +9,6 @@ import javax.swing.JOptionPane;
import envoy.client.Client;
import envoy.client.Config;
import envoy.client.LocalDB;
import envoy.client.Settings;
import envoy.exception.EnvoyException;
/**
@ -43,7 +42,8 @@ public class Startup {
// Check if all configuration values have been initialized
if (!config.isInitialized()) throw new EnvoyException("Server or port are not defined");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Error loading configuration values: \n" + e.toString(), "Configuration error", JOptionPane.ERROR_MESSAGE);
JOptionPane
.showMessageDialog(null, "Error loading configuration values: \n" + e.toString(), "Configuration error", JOptionPane.ERROR_MESSAGE);
System.exit(1);
e.printStackTrace();
}
@ -56,7 +56,7 @@ public class Startup {
}
// Acquire the client user (with ID) either from the server or from the local
// cache (Preferences), which triggers offline mode
// database, which triggers offline mode
Client client;
try {
client = new Client(config, userName);
@ -79,7 +79,6 @@ public class Startup {
"Local DB error",
JOptionPane.WARNING_MESSAGE);
}
Settings.getInstance().setUsername(userName);
EventQueue.invokeLater(() -> {
try {