Some progress toward a more generic org chooser / library spinner
authorkenstir <kenstir@gmail.com>
Tue, 1 Dec 2015 02:39:43 +0000 (21:39 -0500)
committerkenstir <kenstir@gmail.com>
Tue, 1 Dec 2015 02:39:43 +0000 (21:39 -0500)
* parse org tree from open-ils.actor.org_tree.retrieve not orgTree.js
* display orgs with left padding like the OPAC does

14 files changed:
Open-ILS/src/Android/.gitignore
Open-ILS/src/Android/core/res/layout/org_item_layout.xml [new file with mode: 0644]
Open-ILS/src/Android/core/res/layout/search_result_list.xml
Open-ILS/src/Android/core/src/org/evergreen_ils/accountAccess/AccountAccess.java
Open-ILS/src/Android/core/src/org/evergreen_ils/accountAccess/holds/HoldDetails.java
Open-ILS/src/Android/core/src/org/evergreen_ils/accountAccess/holds/PlaceHold.java
Open-ILS/src/Android/core/src/org/evergreen_ils/globals/EvergreenConstants.java
Open-ILS/src/Android/core/src/org/evergreen_ils/globals/GlobalConfigs.java
Open-ILS/src/Android/core/src/org/evergreen_ils/globals/Utils.java
Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/Organisation.java
Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/RecordInfo.java
Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SearchCatalog.java
Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SearchCatalogListView.java
Open-ILS/src/Android/core/src/org/evergreen_ils/views/splashscreen/LoadingTask.java

index 4bf775e..c13f219 100644 (file)
@@ -5,7 +5,7 @@
 .settings
 bin/
 gen/
-kc/
+kcxxx/
 out/
 proguard_logs/
 local.properties
diff --git a/Open-ILS/src/Android/core/res/layout/org_item_layout.xml b/Open-ILS/src/Android/core/res/layout/org_item_layout.xml
new file mode 100644 (file)
index 0000000..6e36404
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<TextView
+        xmlns:android="http://schemas.android.com/apk/res/android"
+        style="?android:attr/spinnerItemStyle"
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:gravity="left" />
index d3ef5db..a4ad387 100644 (file)
@@ -48,7 +48,7 @@
 
             <Spinner
                     android:id="@+id/chose_organisation"
-                    android:layout_width="0dp"
+                    android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:layout_gravity="left"
                     android:layout_weight="1"
index 6c1353e..d07d16c 100644 (file)
@@ -140,7 +140,7 @@ public class AccountAccess {
     private ArrayList<BookBag> bookBags = new ArrayList<BookBag>();
 
     /** The TAG. */
-    private final String TAG = AccountAccess.class.getSimpleName();
+    private final static String TAG = AccountAccess.class.getSimpleName();
 
     /**
      * The auth token. Sent with every request that needs authentication
@@ -512,16 +512,12 @@ public class AccountAccess {
     // ------------------------orgs Section
     // --------------------------------------//
 
-    public OSRFObject fetchOrgs() {
-        OSRFObject response = (OSRFObject) Utils.doRequest(conn(), SERVICE_ACTOR,
+    // todo: call service=open-ils.actor&method=open-ils.actor.org_types.retrieve
+
+    public OSRFObject fetchOrgTree() {
+        Object response = Utils.doRequest(conn(), SERVICE_ACTOR,
                 METHOD_ORG_TREE_RETRIEVE, new Object[]{});
-        try {
-            //List<OSRFObject> l = (List<OSRFObject>) response;
-            Log.d(TAG, "response="+response);
-        } catch (Exception e) {
-            Log.d(TAG, "caught exception", e);
-        }
-        return response;
+        return (OSRFObject) response;
     }
 
     /**
index eb5b41e..e6346c6 100644 (file)
@@ -23,7 +23,6 @@ import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
 
-import android.support.v7.app.ActionBar;
 import android.support.v7.app.ActionBarActivity;
 import android.util.Log;
 import android.view.MenuItem;
@@ -35,14 +34,12 @@ import org.evergreen_ils.utils.ui.ActionBarUtils;
 import org.evergreen_ils.utils.ui.CompatSpinnerAdapter;
 import org.evergreen_ils.views.splashscreen.SplashActivity;
 
-import android.app.Activity;
 import android.app.AlertDialog;
 import android.app.AlertDialog.Builder;
 import android.app.DatePickerDialog;
 import android.app.ProgressDialog;
 import android.content.Context;
 import android.content.DialogInterface;
-import android.content.Intent;
 import android.graphics.Color;
 import android.os.Bundle;
 import android.text.format.DateFormat;
@@ -361,7 +358,7 @@ public class HoldDetails extends ActionBarActivity {
 
         ArrayList<String> list = new ArrayList<String>();
         for (int i = 0; i < globalConfigs.organisations.size(); i++) {
-            list.add(globalConfigs.organisations.get(i).padding
+            list.add(globalConfigs.organisations.get(i).displayName
                     + globalConfigs.organisations.get(i).name);
 
             if (globalConfigs.organisations.get(i).id == record.pickup_lib)
index 9dc98f8..c1a616c 100644 (file)
@@ -23,7 +23,6 @@ import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
 
-import android.support.v7.app.ActionBar;
 import android.support.v7.app.ActionBarActivity;
 import android.util.Log;
 import android.view.MenuItem;
@@ -37,11 +36,9 @@ import org.evergreen_ils.utils.ui.ActionBarUtils;
 import org.evergreen_ils.utils.ui.CompatSpinnerAdapter;
 import org.evergreen_ils.views.splashscreen.SplashActivity;
 
-import android.app.Activity;
 import android.app.DatePickerDialog;
 import android.app.ProgressDialog;
 import android.content.Context;
-import android.content.Intent;
 import android.graphics.Color;
 import android.os.Bundle;
 import android.text.format.DateFormat;
@@ -333,7 +330,7 @@ public class PlaceHold extends ActionBarActivity {
         ArrayList<String> list = new ArrayList<String>();
         for (int i = 0; i < globalConfigs.organisations.size(); i++) {
             Organisation org = globalConfigs.organisations.get(i);
-            list.add(org.padding + org.name);
+            list.add(org.displayName + org.name);
             if (org.id == homeLibrary) {
                 selectedOrgPos = i;
             }
index 406c8d3..49dc2e3 100644 (file)
@@ -94,4 +94,11 @@ class EvergreenConstants {
     public static final int PENALTY_INVALID_PATRON_ADDRESS = 29;
 
     public static final int BILLING_TYPE_NOTIFICATION_FEE = 9;
+
+    // todo: fetch from service=open-ils.actor&method=open-ils.actor.org_types.retrieve
+    public static final int ORG_TYPE_CONSORTIUM = 1;
+    public static final int ORG_TYPE_SYSTEM = 2;
+    public static final int ORG_TYPE_BRANCH = 3;
+    public static final int ORG_TYPE_SUB_LIBRARY = 4;
+    public static final int ORG_TYPE_BOOKMOBILE = 5;
 }
index 55fb643..94e1d5c 100644 (file)
 package org.evergreen_ils.globals;
 
 import android.content.Context;
-import android.net.ConnectivityManager;
-import android.provider.Settings;
+import android.content.pm.ApplicationInfo;
 import android.text.TextUtils;
 import android.util.Log;
-import org.evergreen_ils.auth.Const;
 import org.evergreen_ils.searchCatalog.Organisation;
 import org.evergreen_ils.searchCatalog.SearchCatalog;
 import org.open_ils.idl.IDLParser;
 import org.opensrf.net.http.HttpConnection;
-import org.opensrf.util.JSONException;
-import org.opensrf.util.JSONReader;
+import org.opensrf.util.OSRFObject;
 
 import java.io.InputStream;
 import java.net.MalformedURLException;
@@ -47,7 +44,7 @@ public class GlobalConfigs {
 
     private static String TAG = "GlobalConfigs";
     
-    private static boolean debugMode = true;//todo get from boolean isDebuggable =  ( 0 != ( getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE ) );
+    private static Boolean isDebuggable = null;
 
     private static boolean loadedIDL = false;
 
@@ -65,7 +62,7 @@ public class GlobalConfigs {
     /** The locale. */
     public String locale = "en-US";
 
-    private static GlobalConfigs globalConfigSingleton = null;
+    private static GlobalConfigs instance = null;
 
     /** The organisations. */
     public ArrayList<Organisation> organisations;
@@ -79,9 +76,11 @@ public class GlobalConfigs {
 
     public static GlobalConfigs getGlobalConfigs(Context context) {
         Log.d(TAG, "getGlobalConfigs (url="+httpAddress+")");
-        if (globalConfigSingleton == null)
-            globalConfigSingleton = new GlobalConfigs();
-        return globalConfigSingleton;
+        if (instance == null)
+            instance = new GlobalConfigs();
+        if (context != null && isDebuggable == null)
+            isDebuggable = (0 != (context.getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE));
+        return instance;
     }
 
     public static GlobalConfigs getGlobalConfigs(Context context, String library_url) {
@@ -109,15 +108,16 @@ public class GlobalConfigs {
             httpAddress = library_url;
             conn = null; // must come before loadXXX()
             loadIDL();
-            loadOrganizations();
             loadCopyStatusesAvailable();
             return true;
         }
         return false;
     }
 
-    public static boolean isDebugMode() {
-        return debugMode;
+    public static boolean isDebuggable() {
+        if (isDebuggable == null)
+            return false;
+        return isDebuggable;
     }
 
     public static HttpConnection gatewayConnection() {
@@ -150,81 +150,31 @@ public class GlobalConfigs {
         loadedIDL = true;
     }
 
-    /**
-     * Fetch the OrgTree.js file, and from it parse the list of organisations.
-     */
-    public void loadOrganizations() {
-
-        String orgFile = null;
-
-        organisations = new ArrayList<Organisation>();
-
+    public void addOrganization(OSRFObject obj, int level) {
+        Organisation org = new Organisation();
+        org.level = level;
+        org.id = obj.getInt("id");
+        org.name = obj.getString("name");
+        org.shortname = obj.getString("shortname");
+        org.orgType = obj.getInt("ou_type");
+        //if (org.orgType < EvergreenConstants.ORG_TYPE_BRANCH) return;
+        org.displayName = new String(new char[level]).replace("\0", "  ");
+        organisations.add(org);
+
+        List<OSRFObject> children = null;
         try {
-            Log.d(TAG, "getOrg fetching "+httpAddress + collectionsRequest);
-            orgFile = Utils.getNetPageContent(httpAddress + collectionsRequest);
+            children = (List<OSRFObject>) obj.get("children");
+            for (OSRFObject child : children) {
+                addOrganization(child, level + 1);
+            }
         } catch (Exception e) {
+            Log.d(TAG, "addOrganization caught exception decoding children of "+org.name, e);
         }
+    }
 
-        if (orgFile != null) {
-            long start_ms = System.currentTimeMillis();
-            Log.d(TAG, "getOrg loading");
-            organisations = new ArrayList<Organisation>();
-
-            // in case of wrong file
-            if (orgFile.indexOf("=") == -1)
-                return;
-            String orgArray = orgFile.substring(orgFile.indexOf("=") + 1,
-                    orgFile.indexOf(";"));
-            Log.d(TAG, "getOrg array=" + orgArray.substring(0, orgArray.length()>50 ? 50 : -1));
-
-            // Parse javascript list
-            // Format: [[id, ou_type, parent_ou, name, opac_visible, shortname],...]
-            // Sample: [[149,3,146,"Agawam",0,"AGAWAM_MA"],
-            //          [150,4,149,"Agawam Public Library",1,"AGAWAM"],...]
-            // ou_type can be treated as hierarchical nesting level
-            List orgList;
-            try {
-                orgList = new JSONReader(orgArray).readArray();
-            } catch (JSONException e) {
-                Log.d(TAG, "getOrg failed parsing array", e);
-                return;
-            }
-
-            // Convert json list into array of Organisation
-            for (int i=0; i<orgList.size(); ++i) {
-                Organisation org = new Organisation();
-                List orgItem = (List) orgList.get(i);
-                org.id= (Integer)orgItem.get(0);
-                org.level = (Integer)orgItem.get(1);
-                org.parent = (Integer)orgItem.get(2);
-                org.name = (String)orgItem.get(3);
-                org.isVisible = (Integer)orgItem.get(4);
-                org.shortName = (String)orgItem.get(5);
-                if (org.isVisible == 0) {
-                    continue;
-                }
-
-                organisations.add(org);
-            }
-            
-            /*
-            for (int i=0; i<organisations.size(); ++i) {
-                Log.d(TAG, "getOrg presort org["+i+"]= id:"+organisations.get(i).id+" parent:"+organisations.get(i).parent+" name:"+organisations.get(i).name);
-            }
-            */
-            Collections.sort(organisations, new Comparator<Organisation>() {
-                @Override
-                public int compare(Organisation a, Organisation b) {
-                    if (a.parent == null)
-                        return -1; // root is always first
-                    return a.name.compareTo(b.name);
-                }
-            });
-
-            long duration_ms = System.currentTimeMillis() - start_ms;
-            Log.d(TAG, "getOrg took "+duration_ms+"ms");
-            loadedOrgTree = true;
-        }
+    public void loadOrganizations(OSRFObject orgTree) {
+        organisations = new ArrayList<Organisation>();
+        addOrganization(orgTree, 0);
     }
 
     public void loadCopyStatusesAvailable() {
index 5ab43cb..7268d48 100644 (file)
  */
 package org.evergreen_ils.globals;
 
-import java.io.BufferedInputStream;
 import java.io.BufferedReader;
-import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLConnection;
 import java.util.Map;
 
 import android.os.Looper;
@@ -42,12 +37,7 @@ import org.opensrf.net.http.GatewayRequest;
 import org.opensrf.net.http.HttpConnection;
 import org.opensrf.net.http.HttpRequest;
 
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.net.ConnectivityManager;
 import android.util.Log;
-import android.widget.ImageView;
 
 public class Utils {
     private static final String TAG = "osrf";
@@ -132,7 +122,7 @@ public class Utils {
         // this is what happens when the JSONReader tries to parse a response of an unregistered class.
         // Crash if debugMode, fail if not.
         Log.d(TAG, "NPE...unregistered type from service "+service+" method "+methodName, e);
-        if (GlobalConfigs.isDebugMode()) {
+        if (GlobalConfigs.isDebuggable()) {
             throw(e);
         }
     }
index 15ee726..3763432 100644 (file)
  */
 package org.evergreen_ils.searchCatalog;
 
-public class Organisation {
-
-    public String name = null;
+import org.evergreen_ils.barcodescan.Intents;
 
-    public String shortName = null;
-
-    public Integer id = null;
+public class Organisation {
 
     public Integer level = null;
+    public Integer id = null;
+    public String name = null;
+    public String shortname = null;
+    public Integer orgType = null;
+    public String displayName = "";
 
-    public Integer parent = null;
-
-    public Integer isVisible = null;
-
-    public Integer hiddenDepth = null;
-
-    // used for indent display
-    public String padding = "";
+    public Boolean opac_visible = null;
 
     public Organisation() {
-
     }
 }
index b0e2cdc..f2f85a2 100644 (file)
@@ -33,35 +33,20 @@ public class RecordInfo implements Serializable {
 
     private static final long serialVersionUID = 10123L;
 
-    private final String TAG = RecordInfo.class.getName();
+    private static final String TAG = RecordInfo.class.getSimpleName();
 
     public String title = null;
-
     public String author = null;
-
     public String pubdate = null;
-
     public String isbn = null;
-
     public Integer doc_id = null;
-
     public String publisher = null;
-
     public String subject = null;
-
     public String doc_type = null;
-
     public String online_loc = null;
-
     public String synopsis = null;
-
     public String physical_description = null;
-
     public String series = null;
-
-    // tcn field
-    public String image = null;
-
     public boolean dummy = false;
 
     public ArrayList<CopyCountInformation> copyCountListInfo = null;
@@ -100,8 +85,6 @@ public class RecordInfo implements Serializable {
             this.pubdate = safeString(info.getString("pubdate"));
             this.publisher = safeString(info.getString("publisher"));
             this.doc_id = info.getInt("doc_id");
-            this.image = safeString(info.getString("tcn"));
-            Log.d(TAG, "image=" + image);
             this.doc_type = safeString(info.getString("doc_type"));
         } catch (Exception e) {
             Log.d(TAG, "Exception basic info " + e.getMessage());
index 8abfe88..597e960 100644 (file)
@@ -86,8 +86,7 @@ public class SearchCatalog {
 
     public String TAG = SearchCatalog.class.getSimpleName();
 
-    // the org on witch the searches will be made
-    /** The selected organization. */
+    // the org on which the searches will be made
     public Organisation selectedOrganization = null;
 
     public Integer offset;
@@ -140,16 +139,12 @@ public class SearchCatalog {
                     complexParm.put("org_unit", this.selectedOrganization.id);
                 if (this.selectedOrganization.level != null)
                     complexParm.put("depth", this.selectedOrganization.level - 1);
-//                if (!this.searchFormat.isEmpty())
-//                    complexParm.put("format", this.searchFormat);
             }
             complexParm.put("limit", searchLimit);
             complexParm.put("offset", offset);
             if (searchClass != null) complexParm.put("default_class", searchClass);
-            /*
-             * complexParm.put("offset",0);
-             * complexParm.put("visibility_limit", 3000);
-             */
+//            complexParm.put("offset",0);
+//            complexParm.put("visibility_limit", 3000);
         } catch (Exception e) {
             Log.d(TAG, "Exception in JSON " + e.getMessage());
         }
@@ -182,11 +177,9 @@ public class SearchCatalog {
         for (int i = 0; i < result_ids.size(); i++) {
             ids.add(result_ids.get(i).get(0));
         }
-
         Log.d(TAG, "Ids " + ids);
 
         // request other info based on ids
-
         for (int i = 0; i < ids.size(); i++) {
             Integer record_id = Integer.parseInt(ids.get(i));
 
index 7e344cb..84bb10b 100644 (file)
@@ -21,7 +21,6 @@ package org.evergreen_ils.searchCatalog;
 
 import java.util.*;
 
-import android.support.v7.app.ActionBar;
 import android.support.v7.app.ActionBarActivity;
 import android.view.*;
 import org.evergreen_ils.R;
@@ -39,7 +38,6 @@ import android.app.AlertDialog;
 import android.app.ProgressDialog;
 import android.content.Context;
 import android.content.Intent;
-import android.net.ConnectivityManager;
 import android.os.Bundle;
 import android.util.Log;
 import android.view.ContextMenu.ContextMenuInfo;
@@ -199,7 +197,6 @@ public class SearchCatalogListView extends ActionBarActivity {
                 searchResults = search.getSearchResults(text, getSearchClass(), getSearchFormat(), 0);
 
                 runOnUiThread(new Runnable() {
-
                     @Override
                     public void run() {
 
@@ -432,12 +429,13 @@ public class SearchCatalogListView extends ActionBarActivity {
         ArrayList<String> list = new ArrayList<String>();
         for (int i = 0; i < globalConfigs.organisations.size(); i++) {
             Organisation org = globalConfigs.organisations.get(i);
-            list.add(org.padding + org.name);
+            list.add(org.displayName + org.name);
             if (org.id == homeLibrary) {
                 selectedOrgPos = i;
             }
         }
-        ArrayAdapter<String> adapter = CompatSpinnerAdapter.CreateCompatSpinnerAdapter(this, list);
+        //ArrayAdapter<String> adapter = CompatSpinnerAdapter.CreateCompatSpinnerAdapter(this, list);
+        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.org_item_layout, list);
         choseOrganisation = (Spinner) findViewById(R.id.chose_organisation);
         choseOrganisation.setAdapter(adapter);
         choseOrganisation.setSelection(selectedOrgPos);
index 3a98cfa..90cf5dc 100644 (file)
@@ -34,6 +34,8 @@ import android.util.Log;
 import org.evergreen_ils.searchCatalog.Library;
 import org.opensrf.util.OSRFObject;
 
+import java.util.Map;
+
 /** This is basically the same as an AsyncTask<String,String,String>, except that it uses
  * a Thread.  Starting with HONEYCOMB, tasks are executed on a single thread and the 2nd
  * AsyncTask doesn't start until the first finishes.
@@ -107,17 +109,11 @@ public class LoadingTask {
 
             Log.d(TAG, tag+"Loading resources from "+library.url);
             publishProgress("Loading resources");
-            GlobalConfigs.getGlobalConfigs(mCallingActivity, library.url);
-
             AccountAccess ac = AccountAccess.getAccountAccess();
+            GlobalConfigs gc = GlobalConfigs.getGlobalConfigs(mCallingActivity, library.url);
 
-            /* way to fetch org tree using OSRF rather than parsing JS
-            try {
-                OSRFObject o = ac.fetchOrgs();
-            } catch (Exception e) {
-                Log.d(TAG, tag+"caught exception", e);
-            }
-            */
+            /* fetch org tree using OSRF rather than parsing JS */
+            gc.loadOrganizations(ac.fetchOrgTree());
 
             // auth token zen: try once and if it fails, invalidate the token and try again
             Log.d(TAG, tag+"Starting session");