From: kenstir Date: Sat, 17 Oct 2015 19:11:43 +0000 (-0400) Subject: In search results list and details page, indicate format type. This X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=d2b1c27b2394b31ca2d8a338b2c8f5b0fb42cc22;p=working%2FEvergreen.git In search results list and details page, indicate format type. This required moving the search formats out of a simple string resource and into a JSON resource, so we could distinguish between: * spinner label, e.g. "All Books" * item label, e.g. "Book" * search format text, e.g. "book" Incremented minimum android version to Gingerbread(8) so I could use String.isEmpty --- diff --git a/Open-ILS/src/Android/core/AndroidManifest.xml b/Open-ILS/src/Android/core/AndroidManifest.xml index 2a49f763a6..cc7e7cf778 100644 --- a/Open-ILS/src/Android/core/AndroidManifest.xml +++ b/Open-ILS/src/Android/core/AndroidManifest.xml @@ -6,7 +6,7 @@ android:versionName="1.0" > diff --git a/Open-ILS/src/Android/core/res/layout-land/search_result_list.xml b/Open-ILS/src/Android/core/res/layout-land/search_result_list.xml index 525b118e5c..777b528e98 100644 --- a/Open-ILS/src/Android/core/res/layout-land/search_result_list.xml +++ b/Open-ILS/src/Android/core/res/layout-land/search_result_list.xml @@ -32,8 +32,7 @@ android:id="@+id/search_format_spinner" android:layout_width="120dp" android:layout_height="wrap_content" - android:layout_gravity="right" - android:entries="@array/search_format_options"/> + android:layout_gravity="right"/> - - - + + + + + + android:layout_gravity="right"/> Matches exactly - - All Formats - All Books - All Music - - Blu-ray - - - CD Audiobook - CD Music recording - DVD - E-audio - E-book - E-video - - - Large Print Book - - - - - - Picture - Serials and magazines - Software and video games - - - 1 2 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 9a5f54855e..68b4d4331e 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 @@ -19,8 +19,8 @@ */ package org.evergreen_ils.searchCatalog; -import java.util.ArrayList; -import java.util.List; +import java.io.*; +import java.util.*; import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBarActivity; @@ -64,7 +64,7 @@ import android.widget.Toast; public class SearchCatalogListView extends ActionBarActivity { - private final String TAG = SearchCatalogListView.class.getName(); + private final String TAG = SearchCatalogListView.class.getSimpleName(); private ArrayList recordList; @@ -119,40 +119,8 @@ public class SearchCatalogListView extends ActionBarActivity { return searchClassSpinner.getSelectedItem().toString().toLowerCase(); } - // Sadly there is currently no way to get these programmatically. - // todo: instead of raw strings in the search_format_options string-array, - // store an array of search_key:printable_strings, e.g. "book:All Books", - // and dynamically construct the spinner. private String getSearchFormat() { - String value = ""; - String s = searchFormatSpinner.getSelectedItem().toString(); - if (!s.isEmpty()) value=s; - if (s.equalsIgnoreCase("All Formats")) value=""; - else if (s.equalsIgnoreCase("All Books")) value="book"; - else if (s.equalsIgnoreCase("All Music")) value="music"; - else if (s.equalsIgnoreCase("Audiocassette music recording")) value="casmusic"; - else if (s.equalsIgnoreCase("Blu-ray")) value="blu-ray"; - else if (s.equalsIgnoreCase("Braille")) value="braille"; - else if (s.equalsIgnoreCase("Cassette audiobook")) value="casaudiobook"; - else if (s.equalsIgnoreCase("CD Audiobook")) value="cdaudiobook"; - else if (s.equalsIgnoreCase("CD Music recording")) value="cdmusic"; - else if (s.equalsIgnoreCase("DVD")) value="dvd"; - else if (s.equalsIgnoreCase("E-audio")) value="eaudio"; - else if (s.equalsIgnoreCase("E-book")) value="ebook"; - else if (s.equalsIgnoreCase("E-video")) value="evideo"; - else if (s.equalsIgnoreCase("Equipment, games, toys")) value="equip"; - else if (s.equalsIgnoreCase("Kit")) value="kit"; - else if (s.equalsIgnoreCase("Large Print Book")) value="lpbook"; - else if (s.equalsIgnoreCase("Map")) value="map"; - else if (s.equalsIgnoreCase("Microform")) value="microform"; - else if (s.equalsIgnoreCase("Music Score")) value="score"; - else if (s.equalsIgnoreCase("Phonograph music recording")) value="phonomusic"; - else if (s.equalsIgnoreCase("Phonograph spoken recording")) value="phonospoken"; - else if (s.equalsIgnoreCase("Picture")) value="picture"; - else if (s.equalsIgnoreCase("Serials and magazines")) value="serial"; - else if (s.equalsIgnoreCase("Software and video games")) value="software"; - else if (s.equalsIgnoreCase("VHS")) value="vhs"; - return value; + return SearchFormat.getSearchFormatFromSpinnerLabel(searchFormatSpinner.getSelectedItem().toString()); } @Override @@ -189,6 +157,7 @@ public class SearchCatalogListView extends ActionBarActivity { searchClassSpinner = (Spinner) findViewById(R.id.search_class_spinner); searchFormatSpinner = (Spinner) findViewById(R.id.search_format_spinner); searchResultsNumber = (TextView) findViewById(R.id.search_result_number); + initSearchFormatSpinner(); // Get reference to ListView holder lv = (ListView) this.findViewById(R.id.search_results_list); @@ -337,8 +306,7 @@ public class SearchCatalogListView extends ActionBarActivity { } else { // start activity with book details - Intent intent = new Intent(getBaseContext(), - SampleUnderlinesNoFade.class); + Intent intent = new Intent(getBaseContext(), SampleUnderlinesNoFade.class); // serialize object and pass it to next activity intent.putExtra("recordInfo", info); intent.putExtra("orgID", search.selectedOrganization.id); @@ -491,6 +459,31 @@ 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 = new ArrayAdapter(this, android.R.layout.simple_spinner_item, labels); + searchFormatSpinner.setAdapter(adapter); + } + @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { @@ -742,7 +735,7 @@ public class SearchCatalogListView extends ActionBarActivity { // set text recordTitle.setText(record.title); recordAuthor.setText(record.author); - recordFormat.setText(record.search_format); + recordFormat.setText(SearchFormat.getLabelFromSearchFormat(record.search_format)); recordPublisher.setText(record.pubdate + " " + record.publisher); return row; 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 new file mode 100644 index 0000000000..0e8b407ce5 --- /dev/null +++ b/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SearchFormat.java @@ -0,0 +1,81 @@ +package org.evergreen_ils.searchCatalog; + +import android.util.Log; +import org.opensrf.util.JSONException; +import org.opensrf.util.JSONReader; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * Created by kenstir on 10/17/2015. + */ +public class SearchFormat { + + private static class SearchFormatItem { + public String spinnerLabel = null; + public String displayLabel = null; + public String searchFormat = null; + public boolean hidden; + } + + private final static String TAG = SearchFormat.class.getSimpleName(); + + static List searchFormats = new ArrayList(); + + public static void initFromJSON(String formats_json) { + searchFormats.clear(); + + List> formatsList; + try { + formatsList = (List>) new JSONReader(formats_json).readArray(); + } catch (JSONException e) { + Log.d(TAG, "failed parsing json: "+formats_json, e); + return; + } + for (int i=0; i m = formatsList.get(i); + Log.d(TAG, "item:"+m); + SearchFormatItem item = new SearchFormatItem(); + item.spinnerLabel = (String)m.get("l"); + item.displayLabel = (String)m.get("L"); + item.searchFormat = (String)m.get("f"); + item.hidden = m.containsKey("h"); + searchFormats.add(item); + } + } + + /// list of labels e.g. "All Formats", "All Books", ... + public static List getSpinnerLabels() { + ArrayList labels = new ArrayList(); + for (SearchFormatItem i : searchFormats) { + if (!i.hidden) { + labels.add(i.spinnerLabel); + } + } + return labels; + } + + /// get search format "music" from label "All Music" + public static String getSearchFormatFromSpinnerLabel(String label) { + for (SearchFormatItem i : searchFormats) { + if (i.spinnerLabel.equalsIgnoreCase(label)) { + return i.searchFormat; + } + } + Log.w(TAG, "label not found: "+label); + return ""; + } + + /// get label "CD Music recording" from search format "cdmusic" + public static String getLabelFromSearchFormat(String search_format) { + for (SearchFormatItem i : searchFormats) { + if (i.searchFormat.equalsIgnoreCase(search_format)) { + return (i.displayLabel != null) ? i.displayLabel : i.spinnerLabel; + } + } + Log.w(TAG, "search format not found: "+search_format); + return ""; + } +} diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/utils/ui/BasicDetailsFragment.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/utils/ui/BasicDetailsFragment.java index 5d1bdcd4ef..96e5070e37 100644 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/utils/ui/BasicDetailsFragment.java +++ b/Open-ILS/src/Android/core/src/org/evergreen_ils/utils/ui/BasicDetailsFragment.java @@ -31,11 +31,7 @@ import org.evergreen_ils.accountAccess.SessionNotFoundException; import org.evergreen_ils.accountAccess.bookbags.BookBag; import org.evergreen_ils.accountAccess.holds.PlaceHold; import org.evergreen_ils.globals.GlobalConfigs; -import org.evergreen_ils.searchCatalog.CopyInformation; -import org.evergreen_ils.searchCatalog.ImageDownloader; -import org.evergreen_ils.searchCatalog.MoreCopyInformation; -import org.evergreen_ils.searchCatalog.RecordInfo; -import org.evergreen_ils.searchCatalog.SearchCatalog; +import org.evergreen_ils.searchCatalog.*; import android.app.Dialog; import android.app.ProgressDialog; @@ -68,6 +64,7 @@ public class BasicDetailsFragment extends Fragment { private TextView record_header; private TextView titleTextView; + private TextView formatTextView; private TextView authorTextView; private TextView publisherTextView; @@ -144,33 +141,22 @@ public class BasicDetailsFragment extends Fragment { R.layout.record_details_basic_fragment, null); record_header = (TextView) layout.findViewById(R.id.record_header_text); - copyCountTextView = (TextView) layout - .findViewById(R.id.record_details_simple_copy_count); - showMore = (LinearLayout) layout - .findViewById(R.id.record_details_show_more); - titleTextView = (TextView) layout - .findViewById(R.id.record_details_simple_title); - authorTextView = (TextView) layout - .findViewById(R.id.record_details_simple_author); - publisherTextView = (TextView) layout - .findViewById(R.id.record_details_simple_publisher); - - seriesTextView = (TextView) layout - .findViewById(R.id.record_details_simple_series); - subjectTextView = (TextView) layout - .findViewById(R.id.record_details_simple_subject); - synopsisTextView = (TextView) layout - .findViewById(R.id.record_details_simple_synopsis); - isbnTextView = (TextView) layout - .findViewById(R.id.record_details_simple_isbn); - - recordImage = (ImageView) layout - .findViewById(R.id.record_details_simple_image); - - placeHoldButton = (Button) layout - .findViewById(R.id.simple_place_hold_button); - addToBookbagButton = (Button) layout - .findViewById(R.id.simple_add_to_bookbag_button); + copyCountTextView = (TextView) layout.findViewById(R.id.record_details_simple_copy_count); + showMore = (LinearLayout) layout.findViewById(R.id.record_details_show_more); + titleTextView = (TextView) layout.findViewById(R.id.record_details_simple_title); + formatTextView = (TextView) layout.findViewById(R.id.record_details_format); + authorTextView = (TextView) layout.findViewById(R.id.record_details_simple_author); + publisherTextView = (TextView) layout.findViewById(R.id.record_details_simple_publisher); + + seriesTextView = (TextView) layout.findViewById(R.id.record_details_simple_series); + subjectTextView = (TextView) layout.findViewById(R.id.record_details_simple_subject); + synopsisTextView = (TextView) layout.findViewById(R.id.record_details_simple_synopsis); + isbnTextView = (TextView) layout.findViewById(R.id.record_details_simple_isbn); + + recordImage = (ImageView) layout.findViewById(R.id.record_details_simple_image); + + placeHoldButton = (Button) layout.findViewById(R.id.simple_place_hold_button); + addToBookbagButton = (Button) layout.findViewById(R.id.simple_add_to_bookbag_button); placeHoldButton.setOnClickListener(new OnClickListener() { @@ -276,6 +262,7 @@ public class BasicDetailsFragment extends Fragment { record_header.setText(String.format(getString(R.string.record_of), position, total)); titleTextView.setText(record.title); + formatTextView.setText(SearchFormat.getLabelFromSearchFormat(record.search_format)); authorTextView.setText(record.author); publisherTextView.setText(record.pubdate + " " + record.publisher); diff --git a/Open-ILS/src/Android/cwmars_app/AndroidManifest.xml b/Open-ILS/src/Android/cwmars_app/AndroidManifest.xml index cf47b38a85..3735bc75fc 100644 --- a/Open-ILS/src/Android/cwmars_app/AndroidManifest.xml +++ b/Open-ILS/src/Android/cwmars_app/AndroidManifest.xml @@ -2,11 +2,11 @@