From bb67f7a7371bb9fedd26d3b52dd1b78a544437c8 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 21 Nov 2015 09:50:04 +0000 Subject: [PATCH] First call and ui started --- .../fragments/NavigationDrawerFragment.java | 5 +- .../android2/fragments/SearchFragment.java | 88 +++++++++---------- app/src/main/res/layout/fragment_search.xml | 64 ++++++++++---- app/src/main/res/values/strings.xml | 13 +-- 4 files changed, 94 insertions(+), 76 deletions(-) diff --git a/app/src/main/java/org/openlp/android2/fragments/NavigationDrawerFragment.java b/app/src/main/java/org/openlp/android2/fragments/NavigationDrawerFragment.java index 1a30a1e..132a2ed 100644 --- a/app/src/main/java/org/openlp/android2/fragments/NavigationDrawerFragment.java +++ b/app/src/main/java/org/openlp/android2/fragments/NavigationDrawerFragment.java @@ -42,7 +42,6 @@ import android.widget.AdapterView; import android.widget.ListAdapter; import android.widget.ListView; import android.widget.SimpleAdapter; -import android.widget.Toast; import org.openlp.android2.R; @@ -153,8 +152,8 @@ public class NavigationDrawerFragment extends Fragment { aList.add(hm4); HashMap hm5 = new HashMap(); - hm4.put("title", getString(R.string.action_search)); - hm4.put("icon", Integer.toString(R.drawable.ic_ondemand_video_black)); + hm5.put("title", getString(R.string.action_search)); + hm5.put("icon", Integer.toString(R.drawable.ic_ondemand_video_black)); aList.add(hm5); // Keys used in Hashmap 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 c231a29..14833b1 100644 --- a/app/src/main/java/org/openlp/android2/fragments/SearchFragment.java +++ b/app/src/main/java/org/openlp/android2/fragments/SearchFragment.java @@ -1,30 +1,28 @@ package org.openlp.android2.fragments; -import android.app.Activity; import android.net.Uri; import android.os.Bundle; -import android.app.Fragment; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.Toast; import org.openlp.android2.R; +import org.openlp.android2.api.Api; +import org.openlp.android2.common.JsonHelpers; +import org.openlp.android2.common.OpenLPFragment; +import org.openlp.android2.common.OpenLPHttpClient; /** - * A simple {@link Fragment} subclass. - * Activities that contain this fragment must implement the - * {@link SearchFragment.OnFragmentInteractionListener} interface - * to handle interaction events. - * Use the {@link SearchFragment#newInstance} factory method to - * create an instance of this fragment. + */ -public class SearchFragment extends Fragment { +public class SearchFragment extends OpenLPFragment { - - private OnFragmentInteractionListener mListener; + private final String LOG_TAG = SearchFragment.class.getName(); public SearchFragment() { - // Required empty public constructor + Log.d(LOG_TAG, "Constructor"); } public static SearchFragment newInstance() { @@ -37,51 +35,49 @@ public class SearchFragment extends Fragment { super.onCreate(savedInstanceState); } - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - // Inflate the layout for this fragment - return inflater.inflate(R.layout.fragment_search, container, false); - } - - // TODO: Rename method, update argument and hook method into UI event - public void onButtonPressed(Uri uri) { - if (mListener != null) { - mListener.onFragmentInteraction(uri); - } + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + context = getActivity(); + updateUrl = Api.SERVICE_LIST; + httpClient = new OpenLPHttpClient(context); + return super.onCreateView(inflater, container, savedInstanceState); } @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - try { - mListener = (OnFragmentInteractionListener) activity; - } catch (ClassCastException e) { - throw new ClassCastException(activity.toString() - + " must implement OnFragmentInteractionListener"); - } + public void onResume() { + super.onResume(); + Log.d(LOG_TAG, "Resuming..."); + triggerTextRequest(Api.SEARCHABLE_PLUGINS); + Log.d(LOG_TAG, "Resumed..."); } @Override public void onDetach() { super.onDetach(); - mListener = null; } - /** - * This interface must be implemented by activities that contain this - * fragment to allow an interaction in this fragment to be communicated - * to the activity and potentially other fragments contained in that - * activity. - *

- * See the Android Training lesson Communicating with Other Fragments for more information. - */ - public interface OnFragmentInteractionListener { - // TODO: Update argument type and name - public void onFragmentInteraction(Uri uri); + public void manageResponse(String response, boolean notInError) { + if (calledURL.equals(updateUrl)) { + populateTabDisplay(response); + }else { + processUpdate(response, notInError); + } + } + + private void populateTabDisplay(String response){ + int a = 1; + } + + public void itemClicked(int position) { + try { + String request = JsonHelpers.createRequestJSON("id", Integer.toString(position)); + triggerTextRequest(String.format("%s%s", Api.SERVICE_SET, request)); + Log.d(LOG_TAG, String.format("Setting list data. apiBase(%s), position(%s)", + Api.SERVICE_SET, position)); + } catch (JsonHelpers.JSONHandlerException e) { + e.printStackTrace(); + Toast.makeText(context, "Request Failed", Toast.LENGTH_SHORT).show(); + } } } diff --git a/app/src/main/res/layout/fragment_search.xml b/app/src/main/res/layout/fragment_search.xml index 81d79de..143cf4f 100644 --- a/app/src/main/res/layout/fragment_search.xml +++ b/app/src/main/res/layout/fragment_search.xml @@ -2,26 +2,37 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context="org.openlp.android2.fragments.SearchFragment"> + tools:context="org.openlp.android2.fragments.SearchFragment" + android:id="@+id/search_layout"> + android:layout_gravity="center_horizontal|top" + android:weightSum="1"> + + - + android:weightSum="1"> + + + + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5cd1ee9..d1fd299 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -29,7 +29,7 @@ Select the required display Display Desktop background Allow the selected item to scroll to the centre of the list - Show Live display + Live display Display Setting Display Black only Display Theme only @@ -45,14 +45,6 @@ Next None Port - - Songs - Bibles - Presentations - Images - Media - Custom - Previous Process Service List @@ -62,7 +54,4 @@ Settings Hostname or IP Unable to process request - check network settings - - - Hello blank fragment