diff --git a/app/build.gradle b/app/build.gradle index cb858be..830724a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,7 +10,7 @@ android { applicationId "org.openlp.android2" minSdkVersion 15 targetSdkVersion 22 - versionCode 4 + versionCode 5 versionName "2.0" } android { diff --git a/app/src/main/java/org/openlp/android2/fragments/SearchFragment.java b/app/src/main/java/org/openlp/android2/fragments/SearchFragment.java index 0003b19..018c766 100644 --- a/app/src/main/java/org/openlp/android2/fragments/SearchFragment.java +++ b/app/src/main/java/org/openlp/android2/fragments/SearchFragment.java @@ -94,9 +94,9 @@ public class SearchFragment extends Fragment { (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } - String text = spinner.getSelectedItem().toString(); - String text1 = v.getText().toString(); - Toast.makeText(context, "Search Called " + text + " " + text1, Toast.LENGTH_SHORT).show(); + //String text = spinner.getSelectedItem().toString(); + // String text1 = v.getText().toString(); + //Toast.makeText(context, "Search Called " + text + " " + text1, Toast.LENGTH_SHORT).show(); requestSearch(spinner.getSelectedItem().toString(), v.getText().toString()); return true; } @@ -163,6 +163,7 @@ public class SearchFragment extends Fragment { // called when response HTTP status is "200 OK" manageResponse(responseString, true); } + @Override public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) { // called when response HTTP status is "4XX" (eg. 401, 403, 404) @@ -191,19 +192,14 @@ public class SearchFragment extends Fragment { public void populateListDisplay(String json, boolean notInError) { Log.i(LOG_TAG, "populateListDisplay - entry"); - List> aList = new ArrayList>(); - + ListView list = (ListView)getActivity().findViewById(R.id.fragmentsearchresults); + final ArrayList listitems = new ArrayList(); if (notInError) { - try { JSONArray items = new JSONObject(json).getJSONObject("results").getJSONArray("items"); for (int i = 0; i < items.length(); ++i) { JSONArray item = items.getJSONArray(i); - - HashMap hm = new HashMap(); - //hm.put("tag", item.getString("tag")); - //hm.put("liveListNormal", Html.fromHtml(item.getString("html")).toString()); - aList.add(hm); + listitems.add(item); } } catch (JSONException e) { Log.e(LOG_TAG,json); @@ -211,41 +207,88 @@ public class SearchFragment extends Fragment { } } - // Keys used in Hashmap - String[] from = {"tag", "liveListNormal", "liveListSelected"}; + final StableArrayAdapter adapter = new StableArrayAdapter(context, + android.R.layout.simple_list_item_1, listitems); + list.setAdapter(adapter); - // Ids of views in live_list_fragment - int[] to = {R.id.tag, R.id.liveListNormal, R.id.liveListSelected}; - - - ListView list = (ListView)getActivity().findViewById(R.id.searchresultsdetails); - int a = 1; - -/* ArrayAdapter LTRadapter = new ArrayAdapter(getActivity(), - R.layout.spinner_list_item, categories); - - // Instantiating an adapter to store each items - ListAdapter adapter = new SimpleAdapter(getActivity().getBaseContext(), aList, - R.layout.fragment_s, from, to) { - public View getView(int position, View convertView, ViewGroup parent) { - View view = super.getView(position, convertView, parent); - TextView text1 = (TextView) view.findViewById(R.id.tag); - text1.setTextSize(TypedValue.COMPLEX_UNIT_SP, size); - TextView text2 = (TextView) view.findViewById(R.id.liveListNormal); - text2.setTextSize(TypedValue.COMPLEX_UNIT_SP, size); - if (selected == position) { - text2.setTextColor(Color.parseColor("#000000")); - text2.setTypeface(null, Typeface.BOLD_ITALIC); - } else{ - text2.setTypeface(null, Typeface.NORMAL); - } - return view; + list.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, final View view, + int position, long id) { + final String item = (String) parent.getItemAtPosition(position); + Toast.makeText(context, "Item Pressed " + String.valueOf(position), Toast.LENGTH_SHORT).show(); + /* view.animate().setDuration(2000).alpha(0) + .withEndAction(new Runnable() { + @Override + public void run() { + list.remove(item); + adapter.notifyDataSetChanged(); + view.setAlpha(1); + } + });*/ } - }; - setListAdapter(adapter);*/ + }); Log.i(LOG_TAG, "populateListDisplay - exit"); } + private class StableArrayAdapter extends ArrayAdapter { + + HashMap mIdMap = new HashMap(); + + public StableArrayAdapter(Context context, int textViewResourceId, + List objects) { + super(context, textViewResourceId, objects); + for (int i = 0; i < objects.size(); ++i) { + JSONArray item = objects.get(i); + try { + mIdMap.put(item.get(1).toString(), Integer.valueOf(item.get(0).toString())); + } catch (JSONException e) { + e.printStackTrace(); + } + } + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + // Get the data item for this position + //User user = getItem(position); + String item = null; + try { + item = getItem(position).get(1).toString(); + } catch (JSONException e) { + e.printStackTrace(); + } + // Check if an existing view is being reused, otherwise inflate the view + //if (convertView == null) { + // convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_user, parent, false); + //} + // Lookup view for data population + //TextView tvHome = (TextView) convertView.findViewById(R.id.searchresultsdetails); + // Populate the data into the template view using the data object + //tvName.setText(user.name); + //tvHome.setText(user.hometown); + // Return the completed view to render on screen + return convertView; + } + + @Override + public long getItemId(int position) { + String item = null; + try { + item = getItem(position).get(1).toString(); + } catch (JSONException e) { + e.printStackTrace(); + } + return mIdMap.get(item); + } + + @Override + public boolean hasStableIds() { + return true; + } + + } + } diff --git a/app/src/main/res/layout/blank_display_dialog.xml b/app/src/main/res/layout/blank_display_dialog.xml index 654dbf5..51c5bae 100644 --- a/app/src/main/res/layout/blank_display_dialog.xml +++ b/app/src/main/res/layout/blank_display_dialog.xml @@ -7,22 +7,26 @@ android:layout_height="fill_parent" android:weightSum="1"> + android:height="70px" + android:layout_marginTop="10dp" + android:layout_marginBottom="10dp"/> + android:height="30dp" + android:clickable="true" + android:layout_marginTop="20dp" + android:layout_marginBottom="20dp"/> + android:clickable="true" + android:layout_marginTop="20dp" + android:layout_marginBottom="20dp"/> + android:clickable="true" + android:layout_marginTop="20dp" + android:layout_marginBottom="20dp"/> + android:clickable="true" + android:layout_marginTop="20dp" + android:layout_marginBottom="20dp"/> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_search.xml b/app/src/main/res/layout/fragment_search.xml index fa1fc6f..98a6f32 100644 --- a/app/src/main/res/layout/fragment_search.xml +++ b/app/src/main/res/layout/fragment_search.xml @@ -69,7 +69,7 @@ android:id="@+id/fragmentsearchresults" android:weightSum="1"> -