}
}
- private class FetchConsortiumsTask extends AsyncTask<String, Integer, String> {
- protected String doInBackground(String... params) {
- String url = params[0];
- String result = null;
- try {
- Log.d(TAG, "fetching " + url);
- result = Utils.fetchUrl(url);
- //todo move json parsing to doInBackground
- } catch (Exception e) {
- Log.d(TAG, "error fetching", e);
- }
- return result;
- }
-
- protected void onPostExecute(String result) {
- long duration_ms = System.currentTimeMillis() - start_ms;
- Log.d(TAG, "task fetch took " + duration_ms + "ms");
- handleLibrariesJSON(result);
- }
- }
-
private void startTask() {
start_ms = System.currentTimeMillis();
- boolean use_volley = true;
- if (use_volley) {
- RequestQueue q = VolleyWrangler.getInstance(this).getRequestQueue();
- StringRequest stringRequest = new StringRequest(Request.Method.GET, libraries_directory_json_url,
- new Response.Listener<String>() {
- @Override
- public void onResponse(String response) {
- long duration_ms = System.currentTimeMillis() - start_ms;
- Log.d(TAG, "volley fetch took " + duration_ms + "ms");
- handleLibrariesJSON(response);
- }
- },
- new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- showAlert(error.getMessage());
- }
- });
- q.add(stringRequest);
- } else {
- new FetchConsortiumsTask().execute(libraries_directory_json_url);
- }
+ RequestQueue q = VolleyWrangler.getInstance(this).getRequestQueue();
+ StringRequest stringRequest = new StringRequest(Request.Method.GET, libraries_directory_json_url,
+ new Response.Listener<String>() {
+ @Override
+ public void onResponse(String response) {
+ long duration_ms = System.currentTimeMillis() - start_ms;
+ Log.d(TAG, "volley fetch took " + duration_ms + "ms");
+ handleLibrariesJSON(response);
+ }
+ },
+ new Response.ErrorListener() {
+ @Override
+ public void onErrorResponse(VolleyError error) {
+ showAlert(error.getMessage());
+ }
+ });
+ q.add(stringRequest);
}
// returns true if this is the generic app, which needs a library spinner etc.
import android.content.pm.ApplicationInfo;
import android.text.TextUtils;
import android.util.Log;
+import com.android.volley.Request;
+import com.android.volley.RequestQueue;
+import com.android.volley.Response;
+import com.android.volley.toolbox.StringRequest;
+import org.evergreen_ils.net.VolleyWrangler;
import org.evergreen_ils.searchCatalog.Organisation;
import org.evergreen_ils.searchCatalog.SearchCatalog;
+import org.open_ils.idl.IDLException;
import org.open_ils.idl.IDLParser;
import org.opensrf.net.http.HttpConnection;
import org.opensrf.util.OSRFObject;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.text.ParseException;
private String collectionsRequest = "/opac/common/js/" + locale
+ "/OrgTree.js";
+ private Context context = null;
+ private long start_ms;
+
private GlobalConfigs() {
}
Log.d(TAG, "getGlobalConfigs (url="+httpAddress+")");
if (instance == null)
instance = new GlobalConfigs();
+ if (context != null)
+ instance.context = context;
if (context != null && isDebuggable == null)
isDebuggable = (0 != (context.getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE));
return instance;
}
public void loadIDL() {
-
- try {
- Log.d(TAG, "loadIDL fetching " + httpAddress + IDL_FILE_FROM_ROOT);
- long start_ms = System.currentTimeMillis();
- InputStream in_IDL = Utils.getNetInputStream(GlobalConfigs.httpAddress + IDL_FILE_FROM_ROOT);
- IDLParser parser = new IDLParser(in_IDL);
- parser.setKeepIDLObjects(false);
- Log.d(TAG, "loadIDL parse");
- parser.parse();
- long duration_ms = System.currentTimeMillis() - start_ms;
- Log.d(TAG, "loadIDL parse took "+duration_ms+"ms");
- } catch (Exception e) {
- Log.w(TAG, "loadIDL parse error", e);
- }
-
- loadedIDL = true;
+ start_ms = System.currentTimeMillis();
+ RequestQueue q = VolleyWrangler.getInstance(context).getRequestQueue();
+ StringRequest stringRequest = new StringRequest(Request.Method.GET, httpAddress + IDL_FILE_FROM_ROOT,
+ new Response.Listener<String>() {
+ @Override
+ public void onResponse(String response) {
+ long duration_ms = System.currentTimeMillis() - start_ms;
+ Log.d(TAG, "volley fetch took " + duration_ms + "ms");
+ InputStream in = new ByteArrayInputStream(response.getBytes());
+ IDLParser parser = new IDLParser(in);
+ parser.setKeepIDLObjects(false);
+ Log.d(TAG, "loadIDL parse");
+ try {
+ parser.parse();
+ } catch (Exception e) {
+ Log.d(TAG, "loadIDL failed", e);
+ }
+ duration_ms = System.currentTimeMillis() - start_ms;
+ Log.d(TAG, "loadIDL parse took "+duration_ms+"ms");
+ }
+ },
+ null);
+ q.add(stringRequest);
}
public void addOrganization(OSRFObject obj, int level) {