In search results list and details page, indicate format type. This
authorkenstir <kenstir@gmail.com>
Sat, 17 Oct 2015 19:11:43 +0000 (15:11 -0400)
committerkenstir <kenstir@gmail.com>
Sat, 17 Oct 2015 19:11:43 +0000 (15:11 -0400)
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

Open-ILS/src/Android/core/AndroidManifest.xml
Open-ILS/src/Android/core/res/layout-land/search_result_list.xml
Open-ILS/src/Android/core/res/layout/record_details_basic_fragment.xml
Open-ILS/src/Android/core/res/layout/search_result_list.xml
Open-ILS/src/Android/core/res/raw/search_formats.json [new file with mode: 0644]
Open-ILS/src/Android/core/res/values/resources.xml
Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SearchCatalogListView.java
Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SearchFormat.java [new file with mode: 0644]
Open-ILS/src/Android/core/src/org/evergreen_ils/utils/ui/BasicDetailsFragment.java
Open-ILS/src/Android/cwmars_app/AndroidManifest.xml

index 2a49f76..cc7e7cf 100644 (file)
@@ -6,7 +6,7 @@
     android:versionName="1.0" >\r
 \r
     <uses-sdk\r
-            android:minSdkVersion="8"\r
+            android:minSdkVersion="9"\r
             android:targetSdkVersion="18" />\r
 \r
     <application>\r
index 525b118..777b528 100644 (file)
@@ -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"/>
         <Spinner
                 android:id="@+id/chose_organisation"
                 android:layout_width="fill_parent"
index 12d59ad..40729e1 100644 (file)
                        android:id="@+id/record_details_simple_title"
                        style="@style/textLarge" 
                        />
-                       
-                       <TextView
-                       android:id="@+id/record_details_simple_author"
-                       style="@style/textSmall" 
-                       android:layout_marginTop="5dip"
-                       />
-                       
+
+                    <TextView
+                            android:id="@+id/record_details_format"
+                            style="@style/textSmall"
+                            android:layout_marginTop="5dip"
+                            />
+
+                    <TextView
+                            android:id="@+id/record_details_simple_author"
+                            style="@style/textSmall"
+                            android:layout_marginTop="5dip"
+                            />
+
                        <TextView
                        android:id="@+id/record_details_simple_publisher"
                        style="@style/textSmall" 
index e6bd9df..d3ef5db 100644 (file)
@@ -37,8 +37,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"/>
         </LinearLayout>
 
         <LinearLayout
diff --git a/Open-ILS/src/Android/core/res/raw/search_formats.json b/Open-ILS/src/Android/core/res/raw/search_formats.json
new file mode 100644 (file)
index 0000000..30c56e3
--- /dev/null
@@ -0,0 +1,27 @@
+[
+  {"l":"All Formats", "f":""},
+  {"l":"All Books", "f":"book", "L":"Book"},
+  {"l":"All Music", "f":"music"},
+  {"l":"Audiocassette music recording", "f":"casmusic", "h":1},
+  {"l":"Blu-ray", "f":"blu-ray"},
+  {"l":"Braille", "f":"braille", "h":1},
+  {"l":"Cassette audiobook", "f":"casaudiobook", "h":1},
+  {"l":"CD Audiobook", "f":"cdaudiobook"},
+  {"l":"CD Music recording", "f":"cdmusic"},
+  {"l":"DVD", "f":"dvd"},
+  {"l":"E-audio", "f":"eaudio"},
+  {"l":"E-book", "f":"ebook"},
+  {"l":"E-video", "f":"evideo"},
+  {"l":"Equipment, games, toys", "f":"equip", "h":1},
+  {"l":"Kit", "f":"kit", "h":1},
+  {"l":"Large Print Book", "f":"lpbook"},
+  {"l":"Map", "f":"map", "h":1},
+  {"l":"Microform", "f":"microform", "h":1},
+  {"l":"Music Score", "f":"score", "h":1},
+  {"l":"Phonograph music recording", "f":"phonomusic", "h":1},
+  {"l":"Phonograph spoken recording", "f":"phonospoken", "h":1},
+  {"l":"Picture", "f":"picture"},
+  {"l":"Serials and magazines", "f":"serial"},
+  {"l":"Software and video games", "f":"software"},
+  {"l":"VHS", "f":"vhs", "h":1}
+]
index 9c5fcc0..3abbe9d 100644 (file)
                <item>Matches exactly</item>
     </string-array>
 
-    <string-array name="search_format_options">
-        <item>All Formats</item>
-        <item>All Books</item>
-        <item>All Music</item>
-        <!--<item>Audiocassette music recording</item>-->
-        <item>Blu-ray</item>
-        <!--<item>Braille</item>-->
-        <!--<item>Cassette audiobook</item>-->
-        <item>CD Audiobook</item>
-        <item>CD Music recording</item>
-        <item>DVD</item>
-        <item>E-audio</item>
-        <item>E-book</item>
-        <item>E-video</item>
-        <!--<item>Equipment, games, toys</item>-->
-        <!--<item>Kit</item>-->
-        <item>Large Print Book</item>
-        <!--<item>Map</item>-->
-        <!--<item>Microform</item>-->
-        <!--<item>Music Score</item>-->
-        <!--<item>Phonograph music recording</item>-->
-        <!--<item>Phonograph spoken recording</item>-->
-        <item>Picture</item>
-        <item>Serials and magazines</item>
-        <item>Software and video games</item>
-        <!--<item>VHS</item>-->
-    </string-array>
-    
     <string-array name="notification_preferences_list_values">
         <item>1</item>
         <item>2</item>
index 9a5f548..68b4d43 100644 (file)
@@ -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<RecordInfo> 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<String> labels = SearchFormat.getSpinnerLabels();
+        ArrayAdapter<String> adapter = new ArrayAdapter<String>(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 (file)
index 0000000..0e8b407
--- /dev/null
@@ -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<SearchFormatItem> searchFormats = new ArrayList<SearchFormatItem>();
+
+    public static void initFromJSON(String formats_json) {
+        searchFormats.clear();
+
+        List<Map<String,?>> formatsList;
+        try {
+            formatsList = (List<Map<String, ?>>) new JSONReader(formats_json).readArray();
+        } catch (JSONException e) {
+            Log.d(TAG, "failed parsing json: "+formats_json, e);
+            return;
+        }
+        for (int i=0; i<formatsList.size(); ++i) {
+            Map<String, ?> 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<String> getSpinnerLabels() {
+        ArrayList<String> labels = new ArrayList<String>();
+        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 "";
+    }
+}
index 5d1bdcd..96e5070 100644 (file)
@@ -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);
 
index cf47b38..3735bc7 100644 (file)
@@ -2,11 +2,11 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
           package="org.cwmars"
           android:installLocation="auto"
-          android:versionCode="7"
+          android:versionCode="9"
           android:versionName="1.3">
 
     <uses-sdk
-        android:minSdkVersion="8"
+        android:minSdkVersion="9"
         android:targetSdkVersion="18" />
 
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />