More changes to AppPrefs for generic app.
authorkenstir <kenstir@gmail.com>
Wed, 11 Nov 2015 23:22:04 +0000 (18:22 -0500)
committerkenstir <kenstir@gmail.com>
Wed, 11 Nov 2015 23:22:04 +0000 (18:22 -0500)
Open-ILS/src/Android/core/.classpath [deleted file]
Open-ILS/src/Android/core/.project [deleted file]
Open-ILS/src/Android/core/AndroidManifest.xml
Open-ILS/src/Android/core/src/org/evergreen_ils/auth/AuthenticatorActivity.java
Open-ILS/src/Android/core/src/org/evergreen_ils/auth/EvergreenAuthenticator.java
Open-ILS/src/Android/core/src/org/evergreen_ils/globals/AppPrefs.java
Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SearchCatalog.java
Open-ILS/src/Android/core/src/org/evergreen_ils/views/ChooseLibraryActivity.java
Open-ILS/src/Android/core/src/org/evergreen_ils/views/splashscreen/SplashActivity.java
Open-ILS/src/Android/support/v7/appcompat/.classpath [deleted file]
Open-ILS/src/Android/support/v7/appcompat/.project [deleted file]

diff --git a/Open-ILS/src/Android/core/.classpath b/Open-ILS/src/Android/core/.classpath
deleted file mode 100644 (file)
index 78f329b..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
-       <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
-       <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
-       <classpathentry kind="lib" path="libs/android-support-v4.jar">
-               <attributes>
-                       <attribute name="javadoc_location" value="file:/E:/tools/adt-bundle-windows-x86_64-20130917/sdk/extras/android/support/v4/docs/"/>
-               </attributes>
-       </classpathentry>
-       <classpathentry kind="lib" path="libs/org.opensrf2_serialized_reg.jar"/>
-       <classpathentry kind="lib" path="libs/zxing_barcode.jar"/>
-       <classpathentry kind="lib" path="libs/androwrapee-1.1.0.jar"/>
-       <classpathentry kind="src" path="src"/>
-       <classpathentry kind="src" path="gen"/>
-       <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
-       <classpathentry kind="output" path="bin/classes"/>
-</classpath>
diff --git a/Open-ILS/src/Android/core/.project b/Open-ILS/src/Android/core/.project
deleted file mode 100644 (file)
index b7991ed..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
-       <name>EvergreenApp</name>
-       <comment></comment>
-       <projects>
-       </projects>
-       <buildSpec>
-               <buildCommand>
-                       <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
-                       <arguments>
-                       </arguments>
-               </buildCommand>
-               <buildCommand>
-                       <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
-                       <arguments>
-                       </arguments>
-               </buildCommand>
-               <buildCommand>
-                       <name>org.eclipse.jdt.core.javabuilder</name>
-                       <arguments>
-                       </arguments>
-               </buildCommand>
-               <buildCommand>
-                       <name>com.android.ide.eclipse.adt.ApkBuilder</name>
-                       <arguments>
-                       </arguments>
-               </buildCommand>
-       </buildSpec>
-       <natures>
-               <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
-               <nature>org.eclipse.jdt.core.javanature</nature>
-       </natures>
-</projectDescription>
index a5dff60..5ea67ab 100644 (file)
@@ -9,6 +9,10 @@
             android:minSdkVersion="10"\r
             android:targetSdkVersion="19" />\r
 \r
+    <uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"/>\r
+\r
+    <uses-permission android:name="android.permission.MANAGE_ACCOUNTS"/>\r
+    <uses-permission android:name="android.permission.USE_CREDENTIALS"/>\r
     <application>\r
     </application>\r
 </manifest>\r
index eb8223d..3f46d44 100644 (file)
@@ -60,7 +60,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity {
 
         TextView signInText = (TextView) findViewById(R.id.account_sign_in_text);
         signInText.setText(String.format(getString(R.string.ou_account_sign_in_message),
-                AppPrefs.get(AppPrefs.LIBRARY_NAME)));
+                AppPrefs.getString(AppPrefs.LIBRARY_NAME)));
         if (accountName != null) {
             ((TextView) findViewById(R.id.accountName)).setText(accountName);
         }
@@ -72,17 +72,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity {
                         submit();
                     }
                 });
-        /*
-         * findViewById(R.id.signUp).setOnClickListener(new
-         * View.OnClickListener() {
-         * 
-         * @Override public void onClick(View v) { // Since there can only be
-         * one AuthenticatorActivity, we call the sign up activity, get his
-         * results, // and return them in setAccountAuthenticatorResult(). See
-         * finishLogin(). Intent signup = new Intent(getBaseContext(),
-         * SignUpActivity.class); signup.putExtras(getIntent().getExtras());
-         * startActivityForResult(signup, REQ_SIGNUP); } });
-         */
+
         if (savedInstanceState != null) {
             Log.d(TAG, "onCreate> savedInstanceState="+savedInstanceState);
             if (savedInstanceState.getString(STATE_ALERT_MESSAGE) != null) {
index 6725506..ddbb22c 100644 (file)
@@ -77,7 +77,7 @@ public class EvergreenAuthenticator {
 
         HttpConnection conn;
         try {
-            conn = new HttpConnection(AppPrefs.get(AppPrefs.LIBRARY_URL) + "/osrf-gateway-v1");
+            conn = new HttpConnection(AppPrefs.getString(AppPrefs.LIBRARY_URL) + "/osrf-gateway-v1");
         } catch (MalformedURLException e) {
             throw new AuthenticationException(e);
         }
@@ -107,6 +107,7 @@ public class EvergreenAuthenticator {
             Log.d(TAG, "authtoken: " + authtoken);
             Integer authtime = ((Map<String, Integer>) payload).get("authtime");
             Log.d(TAG, "authtime: " + authtime);
+            AppPrefs.setBoolean(AppPrefs.EVER_LOGGED_IN, true);
             return authtoken;
         } else if (textcode.equals("LOGIN_FAILED")) {
             String desc = ((Map<String, String>) resp).get("desc");
index 1ea1410..fa28a7f 100644 (file)
@@ -5,15 +5,18 @@ import android.content.SharedPreferences;
 import android.preference.PreferenceManager;
 import android.util.Log;
 import org.evergreen_ils.R;
+import org.evergreen_ils.accountAccess.bookbags.BookBag;
 
 /**
  * Created by kenstir on 11/8/2015.
  */
 public class AppPrefs {
+    public static final String EVER_LOGGED_IN = "ever_logged_in";
     public static final String LIBRARY_URL = "library_url";
     public static final String LIBRARY_NAME = "library_name";
     private static final String VERSION = "version";
-    private static final int PREFS_VERSION = 1;
+    // increment PREFS_VERSION every time you make a change to the persistent pref storage
+    private static final int PREFS_VERSION = 2;
     private static final String TAG = AppPrefs.class.getSimpleName();
     private static Context context;
     private static boolean initialized;
@@ -32,24 +35,37 @@ public class AppPrefs {
             SharedPreferences.Editor editor = prefs.edit();
             version = PREFS_VERSION;
             editor.putInt(VERSION, PREFS_VERSION);
-            editor.putString("library_url", context.getString(R.string.ou_library_url));
-            editor.putString("library_name", context.getString(R.string.ou_library_name));
+            editor.putBoolean(EVER_LOGGED_IN, false);
+            editor.putString(LIBRARY_URL, context.getString(R.string.ou_library_url));
+            editor.putString(LIBRARY_NAME, context.getString(R.string.ou_library_name));
             editor.commit();
         }
         Log.d(TAG, "version=" + version);
-        Log.d(TAG, "library_url=" + get(LIBRARY_URL));
-        Log.d(TAG, "library_name=" + get(LIBRARY_NAME));
+        Log.d(TAG, "library_url=" + getString(LIBRARY_URL));
+        Log.d(TAG, "library_name=" + getString(LIBRARY_NAME));
     }
 
-    public static String get(String key) {
+    public static String getString(String key) {
         SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
         return prefs.getString(key, null);
     }
 
-    public static void set(String key, String value) {
+    public static boolean getBoolean(String key) {
+        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+        return prefs.getBoolean(key, false);
+    }
+
+    public static void setString(String key, String value) {
         SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
         SharedPreferences.Editor editor = prefs.edit();
         editor.putString(key, value);
         editor.commit();
     }
+
+    public static void setBoolean(String key, boolean value) {
+        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+        SharedPreferences.Editor editor = prefs.edit();
+        editor.putBoolean(key, value);
+        editor.commit();
+    }
 }
index 9e0b7d9..53fcd8a 100644 (file)
@@ -132,7 +132,7 @@ public class SearchCatalog {
 
         try {
             // configure the connection
-            conn = new HttpConnection(AppPrefs.get(AppPrefs.LIBRARY_URL) + "/osrf-gateway-v1");
+            conn = new HttpConnection(AppPrefs.getString(AppPrefs.LIBRARY_URL) + "/osrf-gateway-v1");
 
         } catch (Exception e) {
             Log.d(TAG, "error", e);
index 282cf61..bac7f18 100644 (file)
@@ -98,8 +98,8 @@ public class ChooseLibraryActivity extends ActionBarActivity {
     private void selectLibrary() {
         if (selected_library != null) {
             Log.d(TAG, "selected library " + selected_library.directory_name);
-            AppPrefs.set(AppPrefs.LIBRARY_URL, selected_library.url);
-            AppPrefs.set(AppPrefs.LIBRARY_NAME, selected_library.short_name);
+            AppPrefs.setString(AppPrefs.LIBRARY_URL, selected_library.url);
+            AppPrefs.setString(AppPrefs.LIBRARY_NAME, selected_library.short_name);
 
             startSplashActivity();
         }
@@ -115,7 +115,7 @@ public class ChooseLibraryActivity extends ActionBarActivity {
     @Override
     protected void onStart() {
         super.onStart();
-        GlobalConfigs.httpAddress = AppPrefs.get(AppPrefs.LIBRARY_URL);// kenstir todo: replace all refs to GlobalConfigs.httpAddress
+        GlobalConfigs.httpAddress = AppPrefs.getString(AppPrefs.LIBRARY_URL);// kenstir todo: replace all refs to GlobalConfigs.httpAddress
         Log.d(TAG, "kcxxx: onstart: url=" + GlobalConfigs.httpAddress);
         if (!TextUtils.isEmpty(GlobalConfigs.httpAddress) && !restarted) {
             startSplashActivity();
@@ -148,16 +148,8 @@ public class ChooseLibraryActivity extends ActionBarActivity {
             }
             for (Map<String, ?> map : l) {
                 String url = (String) map.get("url");
-                String directory_name = (String) map.get("library_name");
+                String directory_name = (String) map.get("directory_name");
                 String short_name = (String) map.get("short_name");
-                if (short_name == null) {
-                    short_name = directory_name;
-                    try {
-                        short_name = short_name.replaceAll(".*\\((.*)\\).*", "$1");
-                    } catch (Exception e) {
-                        Log.d(TAG, "failed trimming short_name: " + short_name, e);
-                    }
-                }
                 Library library = new Library(url, short_name, directory_name);
                 libraries.add(library);
             }
index e398e0d..ac41b62 100644 (file)
@@ -22,7 +22,6 @@ package org.evergreen_ils.views.splashscreen;
 import android.content.SharedPreferences;
 import org.evergreen_ils.R;
 import org.evergreen_ils.globals.GlobalConfigs;
-import org.evergreen_ils.searchCatalog.Library;
 import org.evergreen_ils.globals.AppPrefs;
 import org.evergreen_ils.views.MainActivity;
 import org.evergreen_ils.views.splashscreen.LoadingTask.LoadingTaskListener;
@@ -32,7 +31,6 @@ import android.app.AlertDialog;
 import android.content.Context;
 import android.content.Intent;
 import android.os.Bundle;
-import android.preference.PreferenceManager;
 import android.text.TextUtils;
 import android.util.Log;
 import android.view.View;
@@ -113,9 +111,10 @@ public class SplashActivity extends Activity implements LoadingTaskListener {
     @Override
     protected void onStart() {
         super.onStart();
-        GlobalConfigs.httpAddress = AppPrefs.get(AppPrefs.LIBRARY_URL);// kenstir todo: replace all refs to GlobalConfigs.httpAddress
-        Log.d(TAG, "kcxxx: onstart: url=" + GlobalConfigs.httpAddress);
-        if (!TextUtils.isEmpty(GlobalConfigs.httpAddress) && !restarted) {
+        GlobalConfigs.httpAddress = AppPrefs.getString(AppPrefs.LIBRARY_URL);// kenstir todo: replace all refs to GlobalConfigs.httpAddress
+        boolean ever_logged_in = AppPrefs.getBoolean(AppPrefs.EVER_LOGGED_IN);
+        Log.d(TAG, "kcxxx: onstart: url=" + GlobalConfigs.httpAddress + " ever_logged_in=" + ever_logged_in);
+        if (!TextUtils.isEmpty(GlobalConfigs.httpAddress) && ever_logged_in && !restarted) {
             startTask();
         }
     }
diff --git a/Open-ILS/src/Android/support/v7/appcompat/.classpath b/Open-ILS/src/Android/support/v7/appcompat/.classpath
deleted file mode 100644 (file)
index a4763d1..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
-       <classpathentry kind="src" path="src"/>
-       <classpathentry kind="src" path="gen"/>
-       <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
-       <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
-       <classpathentry kind="output" path="bin/classes"/>
-</classpath>
diff --git a/Open-ILS/src/Android/support/v7/appcompat/.project b/Open-ILS/src/Android/support/v7/appcompat/.project
deleted file mode 100644 (file)
index 957d33d..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
-       <name>android-support-v7-appcompat</name>
-       <comment></comment>
-       <projects>
-       </projects>
-       <buildSpec>
-               <buildCommand>
-                       <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
-                       <arguments>
-                       </arguments>
-               </buildCommand>
-               <buildCommand>
-                       <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
-                       <arguments>
-                       </arguments>
-               </buildCommand>
-               <buildCommand>
-                       <name>org.eclipse.jdt.core.javabuilder</name>
-                       <arguments>
-                       </arguments>
-               </buildCommand>
-               <buildCommand>
-                       <name>com.android.ide.eclipse.adt.ApkBuilder</name>
-                       <arguments>
-                       </arguments>
-               </buildCommand>
-       </buildSpec>
-       <natures>
-               <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
-               <nature>org.eclipse.jdt.core.javanature</nature>
-       </natures>
-</projectDescription>