Skip to content
This repository was archived by the owner on Jul 16, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.github.eb4j.ebview.data.DictionaryEntry;
import io.github.eb4j.ebview.data.IDictionary;
import io.github.eb4j.ebview.utils.CredentialsManager;
import io.github.eb4j.ebview.utils.Preferences;
import org.apache.commons.lang3.StringUtils;
import tokyo.northside.oxfordapi.OxfordClient;
import tokyo.northside.oxfordapi.OxfordClientException;
Expand Down Expand Up @@ -56,9 +57,12 @@ public List<DictionaryEntry> readArticlesPredictive(final String word) {
}

private List<DictionaryEntry> queryArticle(final String word, final boolean strict) {
String appId = CredentialsManager.getCredential(PROPERTY_API_ID);
String appId = Preferences.getPreferenceDefault(PROPERTY_API_ID, "");
if (StringUtils.isEmpty(appId)) {
return Collections.emptyList();
}
String appKey = CredentialsManager.getCredential(PROPERTY_API_KEY);
if (StringUtils.isEmpty(appId) || StringUtils.isEmpty(appKey)) {
if (StringUtils.isEmpty(appKey)) {
return Collections.emptyList();
}
OxfordClient client = new OxfordClient(appId, appKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import io.github.eb4j.ebview.dictionary.oxford.OxfordDriver;
import io.github.eb4j.ebview.utils.CredentialsManager;
import io.github.eb4j.ebview.utils.Preferences;
import org.apache.commons.lang3.StringUtils;

import javax.swing.JComponent;
Expand All @@ -37,16 +38,19 @@ public JComponent getGui() {
}

protected void initFromPrefs() {
CredentialsManager credentialsManager = CredentialsManager.getInstance();
panel.appIdTextField.setText(credentialsManager.retrieve(OxfordDriver.PROPERTY_API_ID).orElse(""));
panel.appKeyTextField.setText(credentialsManager.retrieve(OxfordDriver.PROPERTY_API_KEY).orElse(""));
String appId = Preferences.getPreferenceDefault(OxfordDriver.PROPERTY_API_ID, "");
panel.appIdTextField.setText(appId);
if (appId != null) {
CredentialsManager credentialsManager = CredentialsManager.getInstance();
panel.appKeyTextField.setText(credentialsManager.retrieve(OxfordDriver.PROPERTY_API_KEY).orElse(""));
}
}

public void persist() {
String appId = panel.appIdTextField.getText();
if (!StringUtils.isEmpty(appId)) {
Preferences.setPreference(OxfordDriver.PROPERTY_API_ID, appId);
CredentialsManager credentialsManager = CredentialsManager.getInstance();
credentialsManager.store(OxfordDriver.PROPERTY_API_ID, appId);
credentialsManager.store(OxfordDriver.PROPERTY_API_KEY, panel.appKeyTextField.getText());
}
}
Expand Down