- SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(this);
- Data.optShowOnlyStarred.set(p.getBoolean(PREF_KEY_SHOW_ONLY_STARRED_ACCOUNTS, false));
- SharedPreferences.OnSharedPreferenceChangeListener handler =
- (preference, value) -> Data.optShowOnlyStarred
- .set(preference.getBoolean(PREF_KEY_SHOW_ONLY_STARRED_ACCOUNTS, false));
- p.registerOnSharedPreferenceChangeListener(handler);
+ Data.refreshCurrencyData(Locale.getDefault());
+ Authenticator.setDefault(new Authenticator() {
+ @Override
+ protected PasswordAuthentication getPasswordAuthentication() {
+ MobileLedgerProfile p = Data.profile.getValue();
+ if ((p != null) && p.isAuthEnabled()) {
+ try {
+ final URL url = new URL(p.getUrl());
+ final String requestingHost = getRequestingHost();
+ final String expectedHost = url.getHost();
+ if (requestingHost.equalsIgnoreCase(expectedHost))
+ return new PasswordAuthentication(p.getAuthUserName(),
+ p.getAuthPassword().toCharArray());
+ else Log.w("http-auth",
+ String.format("Requesting host [%s] differs from expected [%s]",
+ requestingHost, expectedHost));
+ }
+ catch (MalformedURLException e) {
+ e.printStackTrace();
+ }
+ }
+
+ return super.getPasswordAuthentication();
+ }
+ });