diff --git a/app/src/main/java/org/openlp/android2/OpenLP.java b/app/src/main/java/org/openlp/android2/OpenLP.java index 66dde80..ee1dad7 100644 --- a/app/src/main/java/org/openlp/android2/OpenLP.java +++ b/app/src/main/java/org/openlp/android2/OpenLP.java @@ -39,7 +39,7 @@ import org.openlp.android2.dialogs.AlertDisplayDialog; import org.openlp.android2.dialogs.BlankDisplayDialog; import org.openlp.android2.fragments.LiveListFragment; import org.openlp.android2.fragments.NavigationDrawerFragment; -import org.openlp.android2.fragments.ServicelistFragment; +import org.openlp.android2.fragments.ServiceListFragment; public class OpenLP extends Activity @@ -77,7 +77,7 @@ public class OpenLP extends Activity switch (position) { case 0: fragmentManager.beginTransaction() - .replace(R.id.container, ServicelistFragment.newInstance()) + .replace(R.id.container, ServiceListFragment.newInstance()) .commit(); mTitle = getString(R.string.service_list); break; diff --git a/app/src/main/java/org/openlp/android2/common/OpenLPFragment.java b/app/src/main/java/org/openlp/android2/common/OpenLPFragment.java new file mode 100644 index 0000000..71c6dd2 --- /dev/null +++ b/app/src/main/java/org/openlp/android2/common/OpenLPFragment.java @@ -0,0 +1,92 @@ +/****************************************************************************** + * OpenLP - Open Source Lyrics Projection * + * --------------------------------------------------------------------------- * + * Copyright (c) 2011-2014 Raoul Snyman * + * Portions copyright (c) 2011-2014 Tim Bentley, Johan Mynhardt * + * --------------------------------------------------------------------------- * + * This program is free software; you can redistribute it and/or modify it * + * under the terms of the GNU General Public License as published by the Free * + * Software Foundation; version 2 of the License. * + * * + * This program is distributed in the hope that it will be useful, but WITHOUT * + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * + * more details. * + * * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., 59 * + * Temple Place, Suite 330, Boston, MA 02111-1307 USA * + *******************************************************************************/ +package org.openlp.android2.common; + + +import android.app.ListFragment; +import android.content.Context; +import android.os.AsyncTask; +import android.util.Log; +import android.view.View; +import android.widget.AbsListView; +import android.widget.ListView; +import android.widget.Toast; +import com.loopj.android.http.AsyncHttpClient; +import com.loopj.android.http.TextHttpResponseHandler; +import org.apache.http.Header; +import org.openlp.android2.R; +import org.openlp.android2.api.Api; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URISyntaxException; + +abstract public class OpenLPFragment extends ListFragment{ + + private String LOG_TAG = OpenLPFragment.class.getName(); + public Context context; + protected String calledURL; + protected OpenLPHttpClient httpClient; + + abstract public void itemClicked(int position); + + @Override + public void onListItemClick(ListView l, View v, int position, long id) { + super.onListItemClick(l, v, position, id); + itemClicked(position); + } + + private static AsyncHttpClient client = new AsyncHttpClient(); + + protected void populateDisplay(String responseString) {} + protected void processUpdate(String responseString) {} + protected void errorDisplay(int statusCode, String responseString) {} + + protected void triggerTextRequest(String url) { + calledURL = url; + Log.d(LOG_TAG, "Trigger Request for url " + url); + String callurl = String.format("%s%s", httpClient.getAbsoluteUrl(client), url ); + client.get(callurl, null, new TextHttpResponseHandler() { + @Override + public void onSuccess(int statusCode, Header[] headers, String responseString) { + // called when response HTTP status is "200 OK" + manageResponse(responseString); + } + @Override + public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) { + // called when response HTTP status is "4XX" (eg. 401, 403, 404) + if (statusCode == 401) { + Toast.makeText(context, R.string.httpreturn_unauthorised, Toast.LENGTH_LONG).show(); + } else { + Toast.makeText(context, R.string.unable, Toast.LENGTH_LONG).show(); + } + errorDisplay(statusCode, responseString); + } + }); + } + + public void manageResponse(String response) { + if (calledURL.equals(Api.POLL_STATUS)) { + populateDisplay(response); + }else { + processUpdate(response); + } + } +} diff --git a/app/src/main/java/org/openlp/android2/fragments/ServiceListFragment.java b/app/src/main/java/org/openlp/android2/fragments/ServiceListFragment.java new file mode 100644 index 0000000..dc72484 --- /dev/null +++ b/app/src/main/java/org/openlp/android2/fragments/ServiceListFragment.java @@ -0,0 +1,226 @@ +/****************************************************************************** + * OpenLP - Open Source Lyrics Projection * + * --------------------------------------------------------------------------- * + * Copyright (c) 2011-2014 Raoul Snyman * + * Portions copyright (c) 2011-2014 Tim Bentley, Johan Mynhardt * + * * + * --------------------------------------------------------------------------- * + * This program is free software; you can redistribute it and/or modify it * + * under the terms of the GNU General Public License as published by the Free * + * Software Foundation; version 2 of the License. * + * * + * This program is distributed in the hope that it will be useful, but WITHOUT * + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * + * more details. * + * * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., 59 * + * Temple Place, Suite 330, Boston, MA 02111-1307 USA * + *******************************************************************************/ +package org.openlp.android2.fragments; + +import android.app.Activity; +import android.content.Context; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.util.Log; +import android.util.TypedValue; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.*; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +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.fragments.dummy.DummyContent; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + + +public class ServiceListFragment extends OpenLPFragment { + + private final String LOG_TAG = ServiceListFragment.class.getName(); + private boolean noScreenUpdate = false; + private boolean isDoubleClick = false; + + /** + * The fragment's ListView/GridView. + */ + private AbsListView mListView; + + /** + * The Adapter which will be used to populate the ListView/GridView with + * Views. + */ + private ListAdapter mAdapter; + + /** + * Mandatory empty constructor for the fragment manager to instantiate the + * fragment (e.g. upon screen orientation changes). + */ + public ServiceListFragment() { + } + + // TODO: Rename and change types of parameters + public static ServiceListFragment newInstance() { + ServiceListFragment fragment = new ServiceListFragment(); + Bundle args = new Bundle(); + //args.putString(ARG_PARAM1, param1); + //args.putString(ARG_PARAM2, param2); + fragment.setArguments(args); + return fragment; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + context = getActivity(); + noScreenUpdate = false; + isDoubleClick = false; + return super.onCreateView(inflater, container, savedInstanceState); + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + AdapterView.OnItemLongClickListener listener = new AdapterView.OnItemLongClickListener() { + @Override + public boolean onItemLongClick(AdapterView arg0, View arg1, int position, long id) { + Toast.makeText(getActivity().getBaseContext(), "Long Clicked ", Toast.LENGTH_SHORT).show(); + itemClicked(position); + noScreenUpdate = true; + isDoubleClick = true; + //((OpenLP) getActivity()).makeBackArrowVisible(true); + //((OpenLP) getActivity()).menuVisible(R.id.action_back); + //((OpenLP) getActivity()).selectItem(NavigationOptions.LiveList); + return false; + } + }; + getListView().setOnItemLongClickListener(listener); + } + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + } + + @Override + public void onDetach() { + super.onDetach(); + } + + @Override + public void onResume() { + super.onResume(); + Log.d(LOG_TAG, "Resuming..."); + triggerTextRequest(Api.SERVICE_LIST); + Log.d(LOG_TAG, "Resumed..."); + } + + @Override + public void populateDisplay(String json) { + Log.i(LOG_TAG, "populate_display - entry"); + if (noScreenUpdate || isDoubleClick) { + noScreenUpdate = false; + return; + } + List> aList = new ArrayList>(); + + try { + JSONArray items = new JSONObject(json).getJSONObject("results").getJSONArray("items"); + + for (int i = 0; i < items.length(); ++i) { + JSONObject item = items.getJSONObject(i); + + HashMap hm = new HashMap(); + if (item.getString("plugin").equals("songs")) { + hm.put("icon", Integer.toString(R.drawable.ic_my_library_music)); + } else if (item.getString("plugin").equals("bibles")) { + hm.put("icon", Integer.toString(R.drawable.ic_my_library_add)); + } else if (item.getString("plugin").equals("media")) { + hm.put("icon", Integer.toString(R.drawable.ic_local_movies)); + } else if (item.getString("plugin").equals("presentations")) { + hm.put("icon", Integer.toString(R.drawable.ic_dvr)); + } else if (item.getString("plugin").equals("images")) { + hm.put("icon", Integer.toString(R.drawable.ic_image)); + } else { + hm.put("icon", Integer.toString(R.drawable.ic_edit)); + } + + hm.put("title", item.getString("title")); + aList.add(hm); + } + } catch (JSONException e) { + e.printStackTrace(); + } + + // Keys used in Hashmap + String[] from = {"icon", "title"}; + + // Ids of views in service_list_fragment + int[] to = {R.id.icon, R.id.serviceListText}; + + SharedPreferences prefs = context.getSharedPreferences( + context.getString(R.string.keySharedPreferences), + Context.MODE_PRIVATE); + + final int size = Integer.parseInt(prefs.getString( + context.getString(R.string.keyTextSize), + String.valueOf(context.getResources().getInteger( + R.integer.textSizeDefaultValue)))); + + // Instantiating an adapter to store each items + ListAdapter adapter = new SimpleAdapter(getActivity().getBaseContext(), aList, + R.layout.fragment_service_list, 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.serviceListText); + text1.setTextSize(TypedValue.COMPLEX_UNIT_SP, size); + return view; + + } + + ; + }; + setListAdapter(adapter); + Log.i(LOG_TAG, "populate_display - exit"); + } + + /** + * The default content for this Fragment has a TextView that is shown when + * the list is empty. If you would like to change the text, call this method + * to supply the text it should use. + */ + public void setEmptyText(CharSequence emptyText) { + View emptyView = mListView.getEmptyView(); + + if (emptyText instanceof TextView) { + ((TextView) emptyView).setText(emptyText); + } + } + + public void itemClicked(int position) { + try { + noScreenUpdate = true; + String request = JsonHelpers.createRequestJSON("id", Integer.toString(position)); + triggerTextRequest(String.format("%s%s", Api.SERVICE_SET, request)); + String message = String.format("Setting list data. apiBase(%s), position(%s)", + Api.SERVICE_SET, position); + Log.d(LOG_TAG, message); + Toast.makeText(getActivity().getBaseContext(), "Service Item selected", Toast.LENGTH_SHORT).show(); + } catch (JsonHelpers.JSONHandlerException e) { + e.printStackTrace(); + Toast.makeText(getActivity().getBaseContext(), "Request Failed", Toast.LENGTH_SHORT).show(); + } + triggerTextRequest(Api.SERVICE_LIST); + } + +} diff --git a/app/src/main/java/org/openlp/android2/fragments/ServicelistFragment.java b/app/src/main/java/org/openlp/android2/fragments/ServicelistFragment.java deleted file mode 100644 index 7f29943..0000000 --- a/app/src/main/java/org/openlp/android2/fragments/ServicelistFragment.java +++ /dev/null @@ -1,172 +0,0 @@ -/****************************************************************************** - * OpenLP - Open Source Lyrics Projection * - * --------------------------------------------------------------------------- * - * Copyright (c) 2011-2014 Raoul Snyman * - * Portions copyright (c) 2011-2014 Tim Bentley, Johan Mynhardt * - * * - * --------------------------------------------------------------------------- * - * This program is free software; you can redistribute it and/or modify it * - * under the terms of the GNU General Public License as published by the Free * - * Software Foundation; version 2 of the License. * - * * - * This program is distributed in the hope that it will be useful, but WITHOUT * - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * - * more details. * - * * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., 59 * - * Temple Place, Suite 330, Boston, MA 02111-1307 USA * - *******************************************************************************/ -package org.openlp.android2.fragments; - -import android.app.Activity; -import android.os.Bundle; -import android.app.Fragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.AbsListView; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.ListAdapter; -import android.widget.TextView; -import org.openlp.android2.R; - -import org.openlp.android2.fragments.dummy.DummyContent; - -/** - * A fragment representing a list of Items. - *

- * Large screen devices (such as tablets) are supported by replacing the ListView - * with a GridView. - *

- * Activities containing this fragment MUST implement the {@link Callbacks} - * interface. - */ -public class ServicelistFragment extends Fragment implements AbsListView.OnItemClickListener { - - // TODO: Rename parameter arguments, choose names that match - // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER - private static final String ARG_PARAM1 = "param1"; - private static final String ARG_PARAM2 = "param2"; - - // TODO: Rename and change types of parameters - private String mParam1; - private String mParam2; - - private OnFragmentInteractionListener mListener; - - /** - * The fragment's ListView/GridView. - */ - private AbsListView mListView; - - /** - * The Adapter which will be used to populate the ListView/GridView with - * Views. - */ - private ListAdapter mAdapter; - - // TODO: Rename and change types of parameters - public static ServicelistFragment newInstance() { - ServicelistFragment fragment = new ServicelistFragment(); - Bundle args = new Bundle(); - //args.putString(ARG_PARAM1, param1); - //args.putString(ARG_PARAM2, param2); - fragment.setArguments(args); - return fragment; - } - - /** - * Mandatory empty constructor for the fragment manager to instantiate the - * fragment (e.g. upon screen orientation changes). - */ - public ServicelistFragment() { - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - if (getArguments() != null) { - mParam1 = getArguments().getString(ARG_PARAM1); - mParam2 = getArguments().getString(ARG_PARAM2); - } - - // TODO: Change Adapter to display your content - mAdapter = new ArrayAdapter(getActivity(), - android.R.layout.simple_list_item_1, android.R.id.text1, DummyContent.ITEMS); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.fragment_servicelist, container, false); - - // Set the adapter - mListView = (AbsListView) view.findViewById(android.R.id.list); - ((AdapterView) mListView).setAdapter(mAdapter); - - // Set OnItemClickListener so we can be notified on item clicks - mListView.setOnItemClickListener(this); - - return view; - } - - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - //try { - // mListener = (OnFragmentInteractionListener) activity; - //} catch (ClassCastException e) { - // throw new ClassCastException(activity.toString() - // + " must implement OnFragmentInteractionListener"); - // } - } - - @Override - public void onDetach() { - super.onDetach(); - mListener = null; - } - - - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - if (null != mListener) { - // Notify the active callbacks interface (the activity, if the - // fragment is attached to one) that an item has been selected. - mListener.onFragmentInteraction(DummyContent.ITEMS.get(position).id); - } - } - - /** - * The default content for this Fragment has a TextView that is shown when - * the list is empty. If you would like to change the text, call this method - * to supply the text it should use. - */ - public void setEmptyText(CharSequence emptyText) { - View emptyView = mListView.getEmptyView(); - - if (emptyText instanceof TextView) { - ((TextView) emptyView).setText(emptyText); - } - } - - /** - * 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(String id); - } - -} diff --git a/app/src/main/res/drawable-hdpi/ic_alarm_add.png b/app/src/main/res/drawable-hdpi/ic_alarm_add.png new file mode 100644 index 0000000..a4b163b Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_alarm_add.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_alarm_off.png b/app/src/main/res/drawable-hdpi/ic_alarm_off.png deleted file mode 100644 index b2ee3d2..0000000 Binary files a/app/src/main/res/drawable-hdpi/ic_alarm_off.png and /dev/null differ diff --git a/app/src/main/res/drawable-hdpi/ic_dvr.png b/app/src/main/res/drawable-hdpi/ic_dvr.png new file mode 100644 index 0000000..f779a4d Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_dvr.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_alarm_add.png b/app/src/main/res/drawable-mdpi/ic_alarm_add.png new file mode 100644 index 0000000..db26b2f Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_alarm_add.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_alarm_off.png b/app/src/main/res/drawable-mdpi/ic_alarm_off.png deleted file mode 100644 index b15af77..0000000 Binary files a/app/src/main/res/drawable-mdpi/ic_alarm_off.png and /dev/null differ diff --git a/app/src/main/res/drawable-mdpi/ic_dvr.png b/app/src/main/res/drawable-mdpi/ic_dvr.png new file mode 100644 index 0000000..d293521 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_dvr.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_alarm_add.png b/app/src/main/res/drawable-xhdpi/ic_alarm_add.png new file mode 100644 index 0000000..a287011 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_alarm_add.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_alarm_off.png b/app/src/main/res/drawable-xhdpi/ic_alarm_off.png deleted file mode 100644 index ca6dc28..0000000 Binary files a/app/src/main/res/drawable-xhdpi/ic_alarm_off.png and /dev/null differ diff --git a/app/src/main/res/drawable-xhdpi/ic_dvr.png b/app/src/main/res/drawable-xhdpi/ic_dvr.png new file mode 100644 index 0000000..d5778a4 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_dvr.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_alarm_add.png b/app/src/main/res/drawable-xxhdpi/ic_alarm_add.png new file mode 100644 index 0000000..4284c77 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_alarm_add.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_alarm_off.png b/app/src/main/res/drawable-xxhdpi/ic_alarm_off.png deleted file mode 100644 index 0f1e200..0000000 Binary files a/app/src/main/res/drawable-xxhdpi/ic_alarm_off.png and /dev/null differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_dvr_white.png b/app/src/main/res/drawable-xxhdpi/ic_dvr_white.png new file mode 100644 index 0000000..eaa1734 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_dvr_white.png differ diff --git a/app/src/main/res/layout/fragment_service_list.xml b/app/src/main/res/layout/fragment_service_list.xml index 1c8b4f7..508b724 100644 --- a/app/src/main/res/layout/fragment_service_list.xml +++ b/app/src/main/res/layout/fragment_service_list.xml @@ -1,16 +1,31 @@ - + + + - - + android:id="@+id/serviceListText" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:textStyle="bold" + android:textColor="#FFFFFF" + android:textSize="14dp" + android:paddingTop="10dp" + android:paddingRight="5dp" + android:paddingBottom="10dp" + /> + diff --git a/app/src/main/res/layout/fragment_servicelist_grid.xml b/app/src/main/res/layout/fragment_servicelist_grid.xml index bf17efc..ec42ccb 100644 --- a/app/src/main/res/layout/fragment_servicelist_grid.xml +++ b/app/src/main/res/layout/fragment_servicelist_grid.xml @@ -3,7 +3,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context="org.openlp.android2.fragments.ServicelistFragment"> + tools:context="org.openlp.android2.fragments.ServiceListFragment"> + tools:context="org.openlp.android2.fragments.ServiceListFragment">