From 8fdeab3bb4de5d7447ae2da48b3d16b188997248 Mon Sep 17 00:00:00 2001 From: kenstir Date: Sun, 18 Oct 2015 22:43:47 -0400 Subject: [PATCH] Indicate item format in Checked Out activity. Factored out PCRUD code to be used by search results and checked out activity. --- .../Android/core/res/layout/checkout_list_item.xml | 6 +++ .../evergreen_ils/accountAccess/AccountAccess.java | 45 ++++++++++++++++++---- .../accountAccess/checkout/CircRecord.java | 11 +++++- .../checkout/ItemsCheckOutListView.java | 6 +++ .../evergreen_ils/searchCatalog/SearchCatalog.java | 34 ++-------------- .../searchCatalog/SearchCatalogListView.java | 29 ++------------ .../evergreen_ils/searchCatalog/SearchFormat.java | 30 +++++++++++++++ 7 files changed, 95 insertions(+), 66 deletions(-) diff --git a/Open-ILS/src/Android/core/res/layout/checkout_list_item.xml b/Open-ILS/src/Android/core/res/layout/checkout_list_item.xml index 516957d1cb..003539a092 100644 --- a/Open-ILS/src/Android/core/res/layout/checkout_list_item.xml +++ b/Open-ILS/src/Android/core/res/layout/checkout_list_item.xml @@ -27,6 +27,12 @@ android:layout_width="fill_parent" android:layout_height="wrap_content"/> + + "b", "conf"=>"0", "search_format"=>"ebook"'. + String attrs = resp.getString("attrs"); + Log.d(TAG, "attrs="+attrs); + String[] attr_arr = TextUtils.split(attrs, ", "); + String icon_format = ""; + String search_format = ""; + for (int i=0; i"); + String key = kv[0].replace("\"", ""); + if (key.equalsIgnoreCase("icon_format")) { + icon_format = kv[1].replace("\"", ""); + } else if (key.equalsIgnoreCase("search_format")) { + search_format = kv[1].replace("\"", ""); + } + } + if (!icon_format.isEmpty()) { + return icon_format; + } else { + return search_format; + } + } + /** * Fetch asset copy. * @@ -486,7 +520,6 @@ public class AccountAccess { * @return the oSRF object */ private OSRFObject fetchAssetCopy(Integer target_copy) { - OSRFObject acp = (OSRFObject) Utils.doRequest(conn, SERVICE_SEARCH, METHOD_FETCH_COPY, new Object[] { target_copy }); @@ -802,7 +835,6 @@ public class AccountAccess { * @throws SessionNotFoundException the session not found exception */ public boolean cancelHold(OSRFObject hold) throws SessionNotFoundException { - Integer hold_id = hold.getInt("id"); Object response = Utils.doRequest(conn, SERVICE_CIRC, @@ -814,7 +846,6 @@ public class AccountAccess { return true; return false; - } /** diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/accountAccess/checkout/CircRecord.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/accountAccess/checkout/CircRecord.java index b232ef570c..d071b04f92 100644 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/accountAccess/checkout/CircRecord.java +++ b/Open-ILS/src/Android/core/src/org/evergreen_ils/accountAccess/checkout/CircRecord.java @@ -24,6 +24,7 @@ import java.text.SimpleDateFormat; import java.util.Date; import org.evergreen_ils.globals.GlobalConfigs; +import org.evergreen_ils.searchCatalog.SearchFormat; import org.opensrf.util.OSRFObject; /** @@ -39,10 +40,9 @@ public class CircRecord { public static final int UNDEF_OBJ_TYPE = 0; public OSRFObject mvr = null; - public OSRFObject acp = null; - public OSRFObject circ = null; + public String format = null; public int circ_info_type = UNDEF_OBJ_TYPE; @@ -138,4 +138,11 @@ public class CircRecord { Date currentDate = new Date(System.currentTimeMillis()); return getDueDateObject().compareTo(currentDate) < 0; } + + public String getFormatLabel() { + if (format != null) { + return SearchFormat.getLabelFromSearchFormat(format); + } + return ""; + } } diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/accountAccess/checkout/ItemsCheckOutListView.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/accountAccess/checkout/ItemsCheckOutListView.java index 0ebc04c7a7..533d8b69b3 100644 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/accountAccess/checkout/ItemsCheckOutListView.java +++ b/Open-ILS/src/Android/core/src/org/evergreen_ils/accountAccess/checkout/ItemsCheckOutListView.java @@ -30,6 +30,7 @@ import org.evergreen_ils.accountAccess.AccountAccess; import org.evergreen_ils.accountAccess.MaxRenewalsException; import org.evergreen_ils.accountAccess.ServerErrorMessage; import org.evergreen_ils.accountAccess.SessionNotFoundException; +import org.evergreen_ils.searchCatalog.SearchFormat; import org.evergreen_ils.views.splashscreen.SplashActivity; import android.app.ProgressDialog; @@ -44,6 +45,7 @@ import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; +import org.w3c.dom.Text; public class ItemsCheckOutListView extends ActionBarActivity { @@ -74,6 +76,7 @@ public class ItemsCheckOutListView extends ActionBarActivity { SplashActivity.restartApp(this); return; } + SearchFormat.init(this); setContentView(R.layout.checkout_list); @@ -157,6 +160,7 @@ public class ItemsCheckOutListView extends ActionBarActivity { private TextView recordTitle; private TextView recordAuthor; + private TextView recordFormat; private TextView recordDueDate; private TextView recordIsOverdue; private TextView renewButton; @@ -194,6 +198,7 @@ public class ItemsCheckOutListView extends ActionBarActivity { // Get references to views recordTitle = (TextView) row.findViewById(R.id.checkout_record_title); recordAuthor = (TextView) row.findViewById(R.id.checkout_record_author); + recordFormat = (TextView) row.findViewById(R.id.checkout_record_format); recordDueDate = (TextView) row.findViewById(R.id.checkout_record_due_date); recordIsOverdue = (TextView) row.findViewById(R.id.checkout_record_overdue); renewButton = (TextView) row.findViewById(R.id.renew_button); @@ -298,6 +303,7 @@ public class ItemsCheckOutListView extends ActionBarActivity { // set text recordTitle.setText(record.getTitle()); recordAuthor.setText(record.getAuthor()); + recordFormat.setText(record.getFormatLabel()); recordDueDate.setText(getString(R.string.due) + " " + record.getDueDate()); recordIsOverdue.setText(record.isOverdue() ? getString(R.string.overdue) : ""); Log.d(TAG, "title: \"" + record.getTitle() + "\"" diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SearchCatalog.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SearchCatalog.java index d44834fd0a..d4cc9285ad 100644 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SearchCatalog.java +++ b/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SearchCatalog.java @@ -26,6 +26,7 @@ import java.util.List; import java.util.Map; import android.text.TextUtils; +import org.evergreen_ils.accountAccess.AccountAccess; import org.evergreen_ils.globals.GlobalConfigs; import org.evergreen_ils.globals.Utils; import org.opensrf.Method; @@ -44,8 +45,6 @@ import android.util.Log; public class SearchCatalog { public static String SERVICE = "open-ils.search"; - public static String PCRUD_SERVICE = "open-ils.pcrud"; - public static String PCRUD_METHOD_RETRIEVE_MRA = "open-ils.pcrud.retrieve.mra"; public static String METHOD_MULTICLASS_QUERY = "open-ils.search.biblio.multiclass.query"; public static String METHOD_SLIM_RETRIVE = "open-ils.search.biblio.record.mods_slim.retrieve"; @@ -220,7 +219,8 @@ public class SearchCatalog { RecordInfo record = new RecordInfo(getItemShortInfo(record_id)); resultsRecordInfo.add(record); - record.search_format = getFormat(record_id); + AccountAccess ac = AccountAccess.getAccountAccess(); + record.search_format = ac.fetchFormat(record_id.toString()); record.copyCountListInfo = getCopyCount(record_id, this.selectedOrganization.id); List> list = (List>) getLocationCount( @@ -255,34 +255,6 @@ public class SearchCatalog { return response; } - private String getFormat(Integer id) { - OSRFObject resp = (OSRFObject) Utils.doRequestSimple(conn, PCRUD_SERVICE, - PCRUD_METHOD_RETRIEVE_MRA, new Object[] { "ANONYMOUS", id }); - - // This is not beautiful. This MRA record comes back with an 'attrs' field that - // appears to have been serialized by perl Data::Dumper, e.g. - // '"biog"=>"b", "conf"=>"0", "search_format"=>"ebook"'. - String attrs = resp.getString("attrs"); - Log.d(TAG, "attrs="+attrs); - String[] attr_arr = TextUtils.split(attrs, ", "); - String icon_format = ""; - String search_format = ""; - for (int i=0; i"); - String key = kv[0].replace("\"", ""); - if (key.equalsIgnoreCase("icon_format")) { - icon_format = kv[1].replace("\"", ""); - } else if (key.equalsIgnoreCase("search_format")) { - search_format = kv[1].replace("\"", ""); - } - } - if (!icon_format.isEmpty()) { - return icon_format; - } else { - return search_format; - } - } - public Object getCopyStatuses() { List ccs_list = (List) Utils.doRequestSimple(conn, SERVICE, diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SearchCatalogListView.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SearchCatalogListView.java index 37bb5b7314..9815a8789a 100644 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SearchCatalogListView.java +++ b/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SearchCatalogListView.java @@ -130,6 +130,7 @@ public class SearchCatalogListView extends ActionBarActivity { SplashActivity.restartApp(this); return; } + SearchFormat.init(this); setContentView(R.layout.search_result_list); @@ -459,26 +460,8 @@ public class SearchCatalogListView extends ActionBarActivity { } - private String loadJSONFromResource(int r) { - String json = ""; - InputStream is = getResources().openRawResource(R.raw.search_formats); - int size = 0; - try { - size = is.available(); - byte[] buf = new byte[size]; - is.read(buf); - is.close(); - json = new String(buf, "UTF-8"); - } catch (IOException e) { - Log.d(TAG, "caught", e); - } - return json; - } - // unpack the json map to populate our spinner, and allow translation from search_format keyword <=> label private void initSearchFormatSpinner() { - String formats_json = loadJSONFromResource(R.raw.search_formats); - SearchFormat.initFromJSON(formats_json); List labels = SearchFormat.getSpinnerLabels(); //ArrayAdapter adapter = CompatSpinnerAdapter.CreateCompatSpinnerAdapter(this, labels); //ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item, labels); @@ -613,8 +596,7 @@ public class SearchCatalogListView extends ActionBarActivity { }); } else - Toast.makeText(context, "No bookbags", Toast.LENGTH_SHORT) - .show(); + Toast.makeText(context, "No bookbags", Toast.LENGTH_SHORT).show(); } break; } @@ -708,17 +690,12 @@ public class SearchCatalogListView extends ActionBarActivity { RecordInfo record = getItem(position); // if it is the right type of view - if (row == null - || row.findViewById(R.id.search_record_title) == null) { - - Log.d(tag, "Starting XML Row Inflation ... "); + if (row == null || row.findViewById(R.id.search_record_title) == null) { LayoutInflater inflater = (LayoutInflater) this .getContext().getSystemService( Context.LAYOUT_INFLATER_SERVICE); row = inflater.inflate(R.layout.search_result_item, parent, false); - Log.d(tag, "Successfully completed XML Row Inflation!"); - } // Get reference to ImageView diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SearchFormat.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SearchFormat.java index 0e8b407ce5..312eaea434 100644 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SearchFormat.java +++ b/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SearchFormat.java @@ -1,14 +1,21 @@ package org.evergreen_ils.searchCatalog; +import android.content.Context; import android.util.Log; +import org.evergreen_ils.R; import org.opensrf.util.JSONException; import org.opensrf.util.JSONReader; +import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; import java.util.List; import java.util.Map; /** + * Support translation between search_format strings ("book"), display labels as seen in the search format spinner + * ("All Books"), and display labels as shown on an item detail page ("Book"). + * * Created by kenstir on 10/17/2015. */ public class SearchFormat { @@ -22,8 +29,31 @@ public class SearchFormat { private final static String TAG = SearchFormat.class.getSimpleName(); + static boolean initialized = false; static List searchFormats = new ArrayList(); + public static void init(Context context) { + if (initialized) return; + String formats_json = loadJSONFromResource(context, R.raw.search_formats); + SearchFormat.initFromJSON(formats_json); + } + + private static String loadJSONFromResource(Context context, int r) { + String json = ""; + InputStream is = context.getResources().openRawResource(r); + int size = 0; + try { + size = is.available(); + byte[] buf = new byte[size]; + is.read(buf); + is.close(); + json = new String(buf, "UTF-8"); + } catch (IOException e) { + Log.d(TAG, "caught", e); + } + return json; + } + public static void initFromJSON(String formats_json) { searchFormats.clear(); -- 2.11.0