1
0
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:
Tim Bentley 2015-03-08 11:36:29 +00:00
parent 4ad77c5e29
commit 9c073c42ec
4 changed files with 58 additions and 45 deletions

View File

@ -50,9 +50,8 @@ abstract public class OpenLPFragment extends ListFragment{
private static AsyncHttpClient client = new AsyncHttpClient();
protected void refreshDisplay(){}
protected void populateDisplay(String responseString) {}
protected void processUpdate(String responseString) {}
protected void errorDisplay(int statusCode, String responseString) {}
protected void populateDisplay(String responseString, boolean inError) {}
protected void processUpdate(String responseString, boolean inError) {}
protected void triggerTextRequest(String url) {
calledURL = url;
@ -62,7 +61,7 @@ abstract public class OpenLPFragment extends ListFragment{
@Override
public void onSuccess(int statusCode, Header[] headers, String responseString) {
// called when response HTTP status is "200 OK"
manageResponse(responseString);
manageResponse(responseString, true);
}
@Override
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
@ -72,16 +71,16 @@ abstract public class OpenLPFragment extends ListFragment{
} else {
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)) {
populateDisplay(response);
populateDisplay(response, notInError);
}else {
processUpdate(response);
processUpdate(response, notInError);
}
}
}

View File

@ -79,11 +79,13 @@ public class LiveListFragment extends OpenLPFragment {
}
@Override
public void populateDisplay(String json) {
public void populateDisplay(String json, boolean notInError) {
Log.i(LOG_TAG, "populate_display - entry");
List<HashMap<String, String>> aList = new ArrayList<HashMap<String, String>>();
selected = 0;
if (notInError) {
try {
JSONArray items = new JSONObject(json).getJSONObject("results").getJSONArray("slides");
for (int i = 0; i < items.length(); ++i) {
@ -100,6 +102,7 @@ public class LiveListFragment extends OpenLPFragment {
} catch (JSONException e) {
e.printStackTrace();
}
}
// Keys used in Hashmap
String[] from = {"tag", "liveListNormal", "liveListSelected"};
@ -163,7 +166,7 @@ public class LiveListFragment extends OpenLPFragment {
triggerTextRequest(String.format("%s%s", Api.LIVE_SET, request));
Log.d(LOG_TAG, String.format("Setting list data. apiBase(%s), position(%s)",
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) {
e.printStackTrace();
Toast.makeText(getActivity().getBaseContext(), "Request Failed", Toast.LENGTH_SHORT).show();

View File

@ -118,7 +118,7 @@ public class ServiceListFragment extends OpenLPFragment {
}
@Override
public void populateDisplay(String json) {
public void populateDisplay(String json, boolean notInError) {
Log.i(LOG_TAG, "populate_display - entry");
if (noScreenUpdate || isDoubleClick) {
noScreenUpdate = false;
@ -126,6 +126,7 @@ public class ServiceListFragment extends OpenLPFragment {
}
List<HashMap<String, String>> aList = new ArrayList<HashMap<String, String>>();
if (notInError) {
try {
JSONArray items = new JSONObject(json).getJSONObject("results").getJSONArray("items");
@ -153,6 +154,7 @@ public class ServiceListFragment extends OpenLPFragment {
} catch (JSONException e) {
e.printStackTrace();
}
}
// Keys used in Hashmap
String[] from = {"icon", "title"};

View File

@ -11,4 +11,13 @@
<item name="fragment_servicelist" type="layout">@layout/fragment_servicelist_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>