mirror of
https://gitlab.com/openlp/android.git
synced 2024-12-22 11:52:49 +00:00
Fix up error handling if no OpenLP
This commit is contained in:
parent
4ad77c5e29
commit
9c073c42ec
@ -50,9 +50,8 @@ abstract public class OpenLPFragment extends ListFragment{
|
|||||||
private static AsyncHttpClient client = new AsyncHttpClient();
|
private static AsyncHttpClient client = new AsyncHttpClient();
|
||||||
|
|
||||||
protected void refreshDisplay(){}
|
protected void refreshDisplay(){}
|
||||||
protected void populateDisplay(String responseString) {}
|
protected void populateDisplay(String responseString, boolean inError) {}
|
||||||
protected void processUpdate(String responseString) {}
|
protected void processUpdate(String responseString, boolean inError) {}
|
||||||
protected void errorDisplay(int statusCode, String responseString) {}
|
|
||||||
|
|
||||||
protected void triggerTextRequest(String url) {
|
protected void triggerTextRequest(String url) {
|
||||||
calledURL = url;
|
calledURL = url;
|
||||||
@ -62,7 +61,7 @@ abstract public class OpenLPFragment extends ListFragment{
|
|||||||
@Override
|
@Override
|
||||||
public void onSuccess(int statusCode, Header[] headers, String responseString) {
|
public void onSuccess(int statusCode, Header[] headers, String responseString) {
|
||||||
// called when response HTTP status is "200 OK"
|
// called when response HTTP status is "200 OK"
|
||||||
manageResponse(responseString);
|
manageResponse(responseString, true);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
|
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
|
||||||
@ -72,16 +71,16 @@ abstract public class OpenLPFragment extends ListFragment{
|
|||||||
} else {
|
} else {
|
||||||
Toast.makeText(context, R.string.unable, Toast.LENGTH_LONG).show();
|
Toast.makeText(context, R.string.unable, Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
errorDisplay(statusCode, responseString);
|
manageResponse(responseString, false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void manageResponse(String response) {
|
public void manageResponse(String response, boolean notInError) {
|
||||||
if (calledURL.equals(updateUrl)) {
|
if (calledURL.equals(updateUrl)) {
|
||||||
populateDisplay(response);
|
populateDisplay(response, notInError);
|
||||||
}else {
|
}else {
|
||||||
processUpdate(response);
|
processUpdate(response, notInError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,26 +79,29 @@ public class LiveListFragment extends OpenLPFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void populateDisplay(String json) {
|
public void populateDisplay(String json, boolean notInError) {
|
||||||
Log.i(LOG_TAG, "populate_display - entry");
|
Log.i(LOG_TAG, "populate_display - entry");
|
||||||
List<HashMap<String, String>> aList = new ArrayList<HashMap<String, String>>();
|
List<HashMap<String, String>> aList = new ArrayList<HashMap<String, String>>();
|
||||||
selected = 0;
|
selected = 0;
|
||||||
|
|
||||||
try {
|
if (notInError) {
|
||||||
JSONArray items = new JSONObject(json).getJSONObject("results").getJSONArray("slides");
|
|
||||||
for (int i = 0; i < items.length(); ++i) {
|
|
||||||
JSONObject item = items.getJSONObject(i);
|
|
||||||
|
|
||||||
HashMap<String, String> hm = new HashMap<String, String>();
|
try {
|
||||||
hm.put("tag", item.getString("tag"));
|
JSONArray items = new JSONObject(json).getJSONObject("results").getJSONArray("slides");
|
||||||
if (item.getString("selected").equals("true")) {
|
for (int i = 0; i < items.length(); ++i) {
|
||||||
selected = i;
|
JSONObject item = items.getJSONObject(i);
|
||||||
|
|
||||||
|
HashMap<String, String> hm = new HashMap<String, String>();
|
||||||
|
hm.put("tag", item.getString("tag"));
|
||||||
|
if (item.getString("selected").equals("true")) {
|
||||||
|
selected = i;
|
||||||
|
}
|
||||||
|
hm.put("liveListNormal", Html.fromHtml(item.getString("html")).toString());
|
||||||
|
aList.add(hm);
|
||||||
}
|
}
|
||||||
hm.put("liveListNormal", Html.fromHtml(item.getString("html")).toString());
|
} catch (JSONException e) {
|
||||||
aList.add(hm);
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keys used in Hashmap
|
// Keys used in Hashmap
|
||||||
@ -163,7 +166,7 @@ public class LiveListFragment extends OpenLPFragment {
|
|||||||
triggerTextRequest(String.format("%s%s", Api.LIVE_SET, request));
|
triggerTextRequest(String.format("%s%s", Api.LIVE_SET, request));
|
||||||
Log.d(LOG_TAG, String.format("Setting list data. apiBase(%s), position(%s)",
|
Log.d(LOG_TAG, String.format("Setting list data. apiBase(%s), position(%s)",
|
||||||
Api.LIVE_SET, position));
|
Api.LIVE_SET, position));
|
||||||
Toast.makeText(getActivity().getBaseContext(), "Display Item selected", Toast.LENGTH_SHORT).show();
|
//Toast.makeText(getActivity().getBaseContext(), "Display Item selected", Toast.LENGTH_SHORT).show();
|
||||||
} catch (JsonHelpers.JSONHandlerException e) {
|
} catch (JsonHelpers.JSONHandlerException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Toast.makeText(getActivity().getBaseContext(), "Request Failed", Toast.LENGTH_SHORT).show();
|
Toast.makeText(getActivity().getBaseContext(), "Request Failed", Toast.LENGTH_SHORT).show();
|
||||||
|
@ -118,7 +118,7 @@ public class ServiceListFragment extends OpenLPFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void populateDisplay(String json) {
|
public void populateDisplay(String json, boolean notInError) {
|
||||||
Log.i(LOG_TAG, "populate_display - entry");
|
Log.i(LOG_TAG, "populate_display - entry");
|
||||||
if (noScreenUpdate || isDoubleClick) {
|
if (noScreenUpdate || isDoubleClick) {
|
||||||
noScreenUpdate = false;
|
noScreenUpdate = false;
|
||||||
@ -126,32 +126,34 @@ public class ServiceListFragment extends OpenLPFragment {
|
|||||||
}
|
}
|
||||||
List<HashMap<String, String>> aList = new ArrayList<HashMap<String, String>>();
|
List<HashMap<String, String>> aList = new ArrayList<HashMap<String, String>>();
|
||||||
|
|
||||||
try {
|
if (notInError) {
|
||||||
JSONArray items = new JSONObject(json).getJSONObject("results").getJSONArray("items");
|
try {
|
||||||
|
JSONArray items = new JSONObject(json).getJSONObject("results").getJSONArray("items");
|
||||||
|
|
||||||
for (int i = 0; i < items.length(); ++i) {
|
for (int i = 0; i < items.length(); ++i) {
|
||||||
JSONObject item = items.getJSONObject(i);
|
JSONObject item = items.getJSONObject(i);
|
||||||
|
|
||||||
HashMap<String, String> hm = new HashMap<String, String>();
|
HashMap<String, String> hm = new HashMap<String, String>();
|
||||||
if (item.getString("plugin").equals("songs")) {
|
if (item.getString("plugin").equals("songs")) {
|
||||||
hm.put("icon", Integer.toString(R.drawable.ic_my_library_music));
|
hm.put("icon", Integer.toString(R.drawable.ic_my_library_music));
|
||||||
} else if (item.getString("plugin").equals("bibles")) {
|
} else if (item.getString("plugin").equals("bibles")) {
|
||||||
hm.put("icon", Integer.toString(R.drawable.ic_my_library_books));
|
hm.put("icon", Integer.toString(R.drawable.ic_my_library_books));
|
||||||
} else if (item.getString("plugin").equals("media")) {
|
} else if (item.getString("plugin").equals("media")) {
|
||||||
hm.put("icon", Integer.toString(R.drawable.ic_local_movies));
|
hm.put("icon", Integer.toString(R.drawable.ic_local_movies));
|
||||||
} else if (item.getString("plugin").equals("presentations")) {
|
} else if (item.getString("plugin").equals("presentations")) {
|
||||||
hm.put("icon", Integer.toString(R.drawable.ic_video_collection));
|
hm.put("icon", Integer.toString(R.drawable.ic_video_collection));
|
||||||
} else if (item.getString("plugin").equals("images")) {
|
} else if (item.getString("plugin").equals("images")) {
|
||||||
hm.put("icon", Integer.toString(R.drawable.ic_image));
|
hm.put("icon", Integer.toString(R.drawable.ic_image));
|
||||||
} else {
|
} else {
|
||||||
hm.put("icon", Integer.toString(R.drawable.ic_edit));
|
hm.put("icon", Integer.toString(R.drawable.ic_edit));
|
||||||
|
}
|
||||||
|
|
||||||
|
hm.put("title", item.getString("title"));
|
||||||
|
aList.add(hm);
|
||||||
}
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
hm.put("title", item.getString("title"));
|
e.printStackTrace();
|
||||||
aList.add(hm);
|
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keys used in Hashmap
|
// Keys used in Hashmap
|
||||||
|
@ -11,4 +11,13 @@
|
|||||||
<item name="fragment_servicelist" type="layout">@layout/fragment_servicelist_list</item>
|
<item name="fragment_servicelist" type="layout">@layout/fragment_servicelist_list</item>
|
||||||
<item name="fragment_livelist" type="layout">@layout/fragment_livelist_list</item>
|
<item name="fragment_livelist" type="layout">@layout/fragment_livelist_list</item>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Layout alias to replace the single-pane version of the layout with a
|
||||||
|
two-pane version on Large screens.
|
||||||
|
|
||||||
|
For more on layout aliases, see:
|
||||||
|
http://developer.android.com/training/multiscreen/screensizes.html#TaskUseAliasFilters
|
||||||
|
-->
|
||||||
|
<item name="fragment_item" type="layout">@layout/fragment_item_list</item>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in New Issue
Block a user