centralized library url setting as preferences, only the default value is specified...
authorkenstir <kenstir@gmail.com>
Sun, 8 Dec 2013 00:38:09 +0000 (19:38 -0500)
committerkenstir <kenstir@gmail.com>
Sun, 8 Dec 2013 00:38:09 +0000 (19:38 -0500)
Open-ILS/src/Android/res/xml/application_preference_screen.xml [deleted file]
Open-ILS/src/Android/res/xml/preferences.xml [new file with mode: 0644]
Open-ILS/src/Android/src/org/evergreen/android/views/ApplicationPreferences.java
Open-ILS/src/Android/src/org/evergreen/android/views/splashscreen/SplashActivity.java
Open-ILS/src/Android/src/org/evergreen_ils/auth/AuthenticatorActivity.java
Open-ILS/src/Android/src/org/evergreen_ils/auth/Const.java
Open-ILS/src/Android/src/org/evergreen_ils/auth/EvergreenAuthenticator.java

diff --git a/Open-ILS/src/Android/res/xml/application_preference_screen.xml b/Open-ILS/src/Android/res/xml/application_preference_screen.xml
deleted file mode 100644 (file)
index da3f473..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<PreferenceScreen
-        xmlns:android="http://schemas.android.com/apk/res/android">
-
-        <PreferenceCategory
-          android:title="@string/preference_server_information_title" >
-               <EditTextPreference
-            android:key="library_url"
-            android:summary="@string/preference_library_url_address_summary"
-            android:title="@string/preference_library_url_address"
-         android:defaultValue="@string/ou_library_url"/>
-        </PreferenceCategory>
-  
-       <PreferenceCategory
-          android:title="@string/preference_notifications_title" >
-        <CheckBoxPreference
-            android:title="@string/preference_enable_notifications"
-            android:key="notifications_enabled"
-            android:summaryOn="@string/preference_enable_notifications_summary_on"
-            android:summaryOff="@string/preference_enable_notifications_summary_off"
-            />
-
-        <ListPreference
-            android:title="@string/preference_notifications_days_before"
-            android:key="notifications_days_before_expiration"
-            android:summary="@string/preference_notifications_days_before_summary"
-            android:entries="@array/notification_preferences_list_entries"
-            android:entryValues="@array/notification_preferences_list_values"
-            android:defaultValue="3"
-            />
-    </PreferenceCategory>
-</PreferenceScreen> 
\ No newline at end of file
diff --git a/Open-ILS/src/Android/res/xml/preferences.xml b/Open-ILS/src/Android/res/xml/preferences.xml
new file mode 100644 (file)
index 0000000..07f1785
--- /dev/null
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<PreferenceScreen
+        xmlns:android="http://schemas.android.com/apk/res/android">
+
+        <PreferenceCategory
+          android:title="@string/preference_server_information_title" >
+               <EditTextPreference
+            android:key="library_url"
+            android:summary="@string/preference_library_url_address_summary"
+            android:title="@string/preference_library_url_address"
+         android:defaultValue="@string/ou_library_url"/>
+        </PreferenceCategory>
+  
+       <PreferenceCategory
+          android:title="@string/preference_notifications_title" >
+        <CheckBoxPreference
+            android:title="@string/preference_enable_notifications"
+            android:key="notifications_enabled"
+            android:summaryOn="@string/preference_enable_notifications_summary_on"
+            android:summaryOff="@string/preference_enable_notifications_summary_off"
+            android:defaultValue="false"
+            />
+
+        <ListPreference
+            android:title="@string/preference_notifications_days_before"
+            android:key="notifications_days_before_expiration"
+            android:summary="@string/preference_notifications_days_before_summary"
+            android:entries="@array/notification_preferences_list_entries"
+            android:entryValues="@array/notification_preferences_list_values"
+            android:defaultValue="3"
+            />
+    </PreferenceCategory>
+</PreferenceScreen> 
\ No newline at end of file
index 9ed161c..6118564 100644 (file)
@@ -22,11 +22,11 @@ package org.evergreen.android.views;
 import java.util.Calendar;
 
 import org.evergreen.android.R;
-import org.evergreen.android.accountAccess.AccountAccess;
 import org.evergreen.android.globals.GlobalConfigs;
 import org.evergreen.android.services.NotificationAlert;
 import org.evergreen.android.services.PeriodicServiceBroadcastReceiver;
 import org.evergreen.android.services.ScheduledIntentService;
+import org.evergreen_ils.auth.Const;
 
 import android.app.AlarmManager;
 import android.app.PendingIntent;
@@ -46,14 +46,14 @@ import android.widget.Toast;
 public class ApplicationPreferences extends PreferenceActivity implements
         OnSharedPreferenceChangeListener {
 
+    private String TAG = ApplicationPreferences.class.getSimpleName();
+
     private ProgressDialog progressDialog;
 
     private ApplicationPreferences reference;
 
     private Context context;
 
-    private String TAG = "ApplicationPreferences";
-
     private Thread connectionThread = null;
 
     private Thread coreFilesDownload = null;
@@ -63,12 +63,11 @@ public class ApplicationPreferences extends PreferenceActivity implements
 
         super.onCreate(savedInstanceState);
 
-        addPreferencesFromResource(R.xml.application_preference_screen);
+        addPreferencesFromResource(R.xml.preferences);
 
         context = this;
         reference = this;
-        SharedPreferences prefs = PreferenceManager
-                .getDefaultSharedPreferences(context);
+        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
         // register preference listener
         prefs.registerOnSharedPreferenceChangeListener(this);
 
@@ -113,10 +112,9 @@ public class ApplicationPreferences extends PreferenceActivity implements
 
         boolean checkConnection = false;
 
-        if (key.equals("library_url")) {
+        if (key.equals(Const.KEY_LIBRARY_URL)) {
             checkConnection = true;
-            GlobalConfigs.httpAddress = sharedPreferences.getString(
-                    "library_url", "");
+            GlobalConfigs.httpAddress = sharedPreferences.getString(Const.KEY_LIBRARY_URL, "");
 
             httpAddressChange = true;
             System.out.println("Show dialog");
index 966403b..eb0b18f 100644 (file)
 package org.evergreen.android.views.splashscreen;
 
 import org.evergreen.android.R;
-import org.evergreen.android.accountAccess.AccountAccess;
 import org.evergreen.android.globals.GlobalConfigs;
 import org.evergreen.android.searchCatalog.SearchCatalogListView;
+import org.evergreen.android.views.ApplicationPreferences;
 import org.evergreen.android.views.splashscreen.LoadingTask.LoadingTaskListener;
 
 import android.app.Activity;
 import android.app.AlertDialog;
 import android.content.Context;
 import android.content.Intent;
-import android.content.SharedPreferences;
 import android.os.Bundle;
 import android.preference.PreferenceManager;
 import android.text.TextUtils;
@@ -39,6 +38,7 @@ import android.view.View.OnClickListener;
 import android.widget.Button;
 import android.widget.ProgressBar;
 import android.widget.TextView;
+import org.evergreen_ils.auth.Const;
 
 public class SplashActivity extends Activity implements LoadingTaskListener {
 
@@ -87,6 +87,9 @@ public class SplashActivity extends Activity implements LoadingTaskListener {
 
         this.mContext = this;
 
+        // make sure default values are set up for preferences, esp. library_url
+        PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
+
         mProgressText = (TextView) findViewById(R.id.action_in_progress);
         mProgressBar = (ProgressBar) findViewById(R.id.activity_splash_progress_bar);
         mRetryButton = (Button) findViewById(R.id.activity_splash_retry_button);
@@ -98,9 +101,7 @@ public class SplashActivity extends Activity implements LoadingTaskListener {
             }
         });
 
-        GlobalConfigs.httpAddress = mContext.getString(R.string.ou_library_url);
-        //prefs= PreferenceManager.getDefaultSharedPreferences(context);
-        //String username = prefs.getString("username", "");
+        GlobalConfigs.httpAddress = PreferenceManager.getDefaultSharedPreferences(this).getString(Const.KEY_LIBRARY_URL, "");
         startTask();
     }
     
index 1afa59b..051e4f9 100644 (file)
@@ -1,6 +1,8 @@
 package org.evergreen_ils.auth;
 
+import android.preference.PreferenceManager;
 import org.evergreen.android.R;
+import org.evergreen_ils.auth.Const;
 
 import android.accounts.Account;
 import android.accounts.AccountAuthenticatorActivity;
@@ -43,6 +45,10 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity {
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_login);
+
+        // make sure default values are set up for preferences, esp. library_url
+        PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
+
         accountManager = AccountManager.get(getBaseContext());
 
         String accountName = getIntent().getStringExtra(ARG_ACCOUNT_NAME);
index 9b9882e..60a402f 100644 (file)
@@ -4,4 +4,5 @@ public class Const {
     public static final String ACCOUNT_TYPE = "org.evergreen_ils";
     public static final String AUTHTOKEN_TYPE = "opac";
     public static final String AUTHTOKEN_TYPE_LABEL = "Online Public Access Catalog";
+    public static final String KEY_LIBRARY_URL = "library_url";
 }
index b10ebd2..3f8b9f8 100644 (file)
@@ -6,6 +6,7 @@ import java.security.NoSuchAlgorithmException;
 import java.util.HashMap;
 import java.util.Map;
 
+import android.preference.PreferenceManager;
 import org.opensrf.Method;
 import org.opensrf.net.http.GatewayRequest;
 import org.opensrf.net.http.HttpConnection;
@@ -73,9 +74,10 @@ public class EvergreenAuthenticator {
     public static String signIn(Context context, String username, String password) throws AuthenticationException {
         Log.d(TAG, "signIn> "+username);
 
+        final String library_url = PreferenceManager.getDefaultSharedPreferences(context).getString(Const.KEY_LIBRARY_URL,"");
         HttpConnection conn;
         try {
-            conn = new HttpConnection(context.getString(R.string.ou_library_url) + "/osrf-gateway-v1");
+            conn = new HttpConnection(library_url + "/osrf-gateway-v1");
         } catch (MalformedURLException e) {
             throw new AuthenticationException(e);
         }