* Fixed a NPE seen once when coercing results of getItemsCheckedOut().
authorkenstir <kenstir@gmail.com>
Tue, 17 Dec 2013 01:43:59 +0000 (20:43 -0500)
committerkenstir <kenstir@gmail.com>
Tue, 17 Dec 2013 01:43:59 +0000 (20:43 -0500)
* Make getItemsCheckedOut() sort by due date.
* Fixed a situation where session was non-null but was not valid; force reload
  of session in LoadingTask

Open-ILS/src/Android/core/res/layout/search_result_list.xml
Open-ILS/src/Android/core/res/values/strings.xml
Open-ILS/src/Android/core/src/org/evergreen/android/accountAccess/AccountAccess.java
Open-ILS/src/Android/core/src/org/evergreen/android/searchCatalog/AdvancedSearchActivity.java
Open-ILS/src/Android/core/src/org/evergreen/android/searchCatalog/SearchCatalogListView.java
Open-ILS/src/Android/core/src/org/evergreen/android/views/splashscreen/LoadingTask.java

index f4be2eb..bc82ae2 100644 (file)
@@ -56,7 +56,7 @@
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:hint="@string/search_hint"
-            android:singleLine="true" />
+            android:singleLine="true"/>
         
         <LinearLayout
         android:layout_width="fill_parent"
index 6376f58..13b1ee4 100644 (file)
@@ -37,7 +37,7 @@
 
     <!-- Search -->
 
-    <string name="browse_catalog">Browse catalog</string>
+    <string name="browse_catalog">Library catalog</string>
     <string name="search_hint">Search keywords</string>
     <string name="advanced_search">Advanced Search</string>
     <string name="loading_dialog_text"></string>
     <!-- Bookbag Activities -->
     <string name="delete_button">delete</string>
     <string name="bags_name">name</string>
-    <string name="bags_items">no items</string>
+    <string name="bags_items">items</string>
     <string name="bags_shared">shared</string>
     <string name="bags_action">action</string>
     <string name="details">details</string>
index 7d48cb5..b6e6298 100644 (file)
@@ -22,10 +22,7 @@ package org.evergreen.android.accountAccess;
 import java.io.IOException;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 import android.accounts.*;
 import android.app.Activity;
@@ -323,9 +320,9 @@ public class AccountAccess {
      * Retrieve session.
      * @throws SessionNotFoundException
      */
-    public boolean retrieveSession(String auth_token) throws SessionNotFoundException {
+    public boolean retrieveSession(String auth_token, boolean force) throws SessionNotFoundException {
 
-        if (this.haveSession && this.authToken.equals(auth_token))
+        if (!force && this.haveSession && this.authToken.equals(auth_token))
             return true;
         this.haveSession = false;
         this.authToken = auth_token;
@@ -365,7 +362,7 @@ public class AccountAccess {
         final String new_authToken = b.getString(AccountManager.KEY_AUTHTOKEN);
         if (TextUtils.isEmpty(new_authToken))
             return false;
-        return retrieveSession(new_authToken);
+        return retrieveSession(new_authToken, true);
     }
 
     // ------------------------Checked Out Items Section
@@ -376,79 +373,54 @@ public class AccountAccess {
      *
      * @return the items checked out
      * @throws SessionNotFoundException the session not found exception
-     * @throws NoNetworkAccessException the no network access exception
-     * @throws NoAccessToServer the no access to server
      */
     public ArrayList<CircRecord> getItemsCheckedOut()
             throws SessionNotFoundException {
 
         ArrayList<CircRecord> circRecords = new ArrayList<CircRecord>();
-        /*
-         * ArrayList<OSRFObject> long_overdue = new ArrayList<OSRFObject>();
-         * ArrayList<OSRFObject> claims_returned = new ArrayList<OSRFObject>();
-         * ArrayList<OSRFObject> lost = new ArrayList<OSRFObject>();
-         * ArrayList<OSRFObject> out = new ArrayList<OSRFObject>();
-         * ArrayList<OSRFObject> overdue = new ArrayList<OSRFObject>();
-         */
-
-        // fetch ids
-        List<String> long_overdue_id;
-        List<String> overdue_id;
-        List<String> claims_returned_id;
-        List<String> lost_id;
-        List<String> out_id;
 
         Object resp = Utils.doRequest(conn, SERVICE_ACTOR,
                 METHOD_FETCH_CHECKED_OUT_SUM, authToken, new Object[] {
                         authToken, userID });
+        if (resp == null)
+            return circRecords;
+        Map<String, ?> resp_map = ((Map<String, ?>) resp);
 
-        long_overdue_id = (List<String>) ((Map<String, ?>) resp)
-                .get("long_overdue");
-        claims_returned_id = (List<String>) ((Map<String, ?>) resp)
-                .get("claims_returned");
-        lost_id = (List<String>) ((Map<String, ?>) resp).get("lost");
-        out_id = (List<String>) ((Map<String, ?>) resp).get("out");
-        overdue_id = (List<String>) ((Map<String, ?>) resp).get("overdue");
-
-        // get all the record circ info
-        if (out_id != null)
+        if (resp_map.get("out") != null) {
+            List<String> out_id = (List<String>) resp_map.get("out");
             for (int i = 0; i < out_id.size(); i++) {
-                // get circ
                 OSRFObject circ = retrieveCircRecord(out_id.get(i));
                 CircRecord circRecord = new CircRecord(circ, CircRecord.OUT,
                         Integer.parseInt(out_id.get(i)));
-                // get info
-                fetchInfoForCheckedOutItem(circ.getInt("target_copy"),
-                        circRecord);
+                fetchInfoForCheckedOutItem(circ.getInt("target_copy"), circRecord);
                 circRecords.add(circRecord);
-
-                // Log.d(TAG, out.get(i).get("target_copy"));
-                // fetchInfoForCheckedOutItem(out.get(i).get("target_copy")+"");
             }
+        }
 
-        if (overdue_id != null)
+        if (resp_map.get("overdue") != null) {
+            List<String> overdue_id = (List<String>) resp_map.get("overdue");
             for (int i = 0; i < overdue_id.size(); i++) {
-                // get circ
                 OSRFObject circ = retrieveCircRecord(overdue_id.get(i));
-                CircRecord circRecord = new CircRecord(circ,
-                        CircRecord.OVERDUE, Integer.parseInt(overdue_id.get(i)));
-                // fetch info
-                fetchInfoForCheckedOutItem(circ.getInt("target_copy"),
-                        circRecord);
+                CircRecord circRecord = new CircRecord(circ, CircRecord.OVERDUE,
+                        Integer.parseInt(overdue_id.get(i)));
+                fetchInfoForCheckedOutItem(circ.getInt("target_copy"), circRecord);
                 circRecords.add(circRecord);
-
             }
+        }
+
         // TODO are we using this too? In the opac they are not used
         /*
-         * for(int i=0;i<lost_id.size();i++){ //Log.d(TAG, out.get(i));
-         * lost.add(retrieveCircRecord(lost_id.get(i))); } for(int
-         * i=0;i<claims_returned.size();i++){ //Log.d(TAG, out.get(i));
-         * claims_returned.add(retrieveCircRecord(claims_returned_id.get(i))); }
-         * for(int i=0;i<long_overdue_id.size();i++){
-         * //Log.d(TAG, out.get(i));
-         * long_overdue.add(retrieveCircRecord(long_overdue_id.get(i))); }
-         */
-
+        resp_map.get("claims_returned");
+        resp_map.get("long_overdue")
+        resp_map.get("lost");
+        */
+
+        Collections.sort(circRecords, new Comparator<CircRecord>() {
+            @Override
+            public int compare(CircRecord lhs, CircRecord rhs) {
+                return lhs.getDueDate().compareTo(rhs.getDueDate());
+            }
+        });
         return circRecords;
     }
 
index 61d251d..d0f8236 100644 (file)
@@ -71,7 +71,6 @@ public class AdvancedSearchActivity extends Activity {
 
         // header portion actions
         myAccountButton = (Button) findViewById(R.id.my_account_button);
-
         myAccountButton.setOnClickListener(new OnClickListener() {
             @Override
             public void onClick(View v) {
index 00a1642..cafda04 100644 (file)
@@ -163,7 +163,6 @@ public class SearchCatalogListView extends Activity {
         // end header portion actions
         
         advancedSearchButton = (Button) findViewById(R.id.menu_advanced_search_button);
-
         advancedSearchButton.setOnClickListener(new OnClickListener() {
             @Override
             public void onClick(View v) {
@@ -239,7 +238,6 @@ public class SearchCatalogListView extends Activity {
             public void run() {
 
                 final String text = searchText.getText().toString();
-
                 if (text.length() < 1)
                     return;
 
index f27c4d3..96a6cd4 100644 (file)
@@ -118,7 +118,7 @@ public class LoadingTask {
             boolean haveSession = false;
             boolean retry = false;
             try {
-                haveSession = ac.retrieveSession(auth_token);
+                haveSession = ac.retrieveSession(auth_token, true);
             } catch (SessionNotFoundException e) {
                 mAccountManager.invalidateAuthToken(accountType, auth_token);
                 retry = true;
@@ -133,7 +133,7 @@ public class LoadingTask {
                 Log.d(TAG, tag+"account_name="+account_name+" token="+auth_token);
                 if (account_name == null)
                     return "no account";
-                haveSession = ac.retrieveSession(auth_token);
+                haveSession = ac.retrieveSession(auth_token, true);
             }
             if (!haveSession)
                 return "no session";