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();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -79,26 +79,29 @@ 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;
|
||||
|
||||
try {
|
||||
JSONArray items = new JSONObject(json).getJSONObject("results").getJSONArray("slides");
|
||||
for (int i = 0; i < items.length(); ++i) {
|
||||
JSONObject item = items.getJSONObject(i);
|
||||
if (notInError) {
|
||||
|
||||
HashMap<String, String> hm = new HashMap<String, String>();
|
||||
hm.put("tag", item.getString("tag"));
|
||||
if (item.getString("selected").equals("true")) {
|
||||
selected = i;
|
||||
try {
|
||||
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>();
|
||||
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());
|
||||
aList.add(hm);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Keys used in Hashmap
|
||||
@ -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();
|
||||
|
@ -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,32 +126,34 @@ public class ServiceListFragment extends OpenLPFragment {
|
||||
}
|
||||
List<HashMap<String, String>> aList = new ArrayList<HashMap<String, String>>();
|
||||
|
||||
try {
|
||||
JSONArray items = new JSONObject(json).getJSONObject("results").getJSONArray("items");
|
||||
if (notInError) {
|
||||
try {
|
||||
JSONArray items = new JSONObject(json).getJSONObject("results").getJSONArray("items");
|
||||
|
||||
for (int i = 0; i < items.length(); ++i) {
|
||||
JSONObject item = items.getJSONObject(i);
|
||||
for (int i = 0; i < items.length(); ++i) {
|
||||
JSONObject item = items.getJSONObject(i);
|
||||
|
||||
HashMap<String, String> hm = new HashMap<String, String>();
|
||||
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_books));
|
||||
} 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_video_collection));
|
||||
} 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));
|
||||
HashMap<String, String> hm = new HashMap<String, String>();
|
||||
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_books));
|
||||
} 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_video_collection));
|
||||
} 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);
|
||||
}
|
||||
|
||||
hm.put("title", item.getString("title"));
|
||||
aList.add(hm);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Keys used in Hashmap
|
||||
|
@ -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>
|
Loading…
Reference in New Issue
Block a user