0

I am using the code below from the AQuery demo app and the xml is always null

How can I reteive the info related to the account I choose from the list of google accounts?

public void auth_specific_account(){


        String url = "https://www.google.com/reader/atom/user/-/state/com.google/reading-list?n=8";

        AjaxCallback<XmlDom> cb = new AjaxCallback<XmlDom>();

        cb.url(url).type(XmlDom.class).weakHandler(this, "readerCb");  
        cb.auth(this, AQuery.AUTH_READER, AQuery.ACTIVE_ACCOUNT);

        aq.progress(R.id.progress).ajax(cb);

    }

public void readerCb(String url, XmlDom xml, AjaxStatus status) {

        if(xml != null){

            List<XmlDom> entries = xml.tags("entry");           
            List<String> titles = new ArrayList<String>();

            for(XmlDom entry: entries){
                titles.add(entry.text("title"));
            }

            showTextResult(titles);         
        }

        AQUtility.debug("status:" + status);

        showResult(xml, status);
    }
124697
  • 22,097
  • 68
  • 188
  • 315

1 Answers1

0

You can use different approach, when weak handler is not necessary, by passing to aq.ajax() an object of extended AjaxCallback which gets information about item for which request should be used.

    private class AjaxCallbackAddingMarker extends AjaxCallback<Bitmap> {
        private final Item item;

        AjaxCallbackAddingMarker(Item item) {
            this.item = item;
        }

        @Override
        public synchronized void callback(String url, Bitmap object, AjaxStatus status) {
            // do something with item and downloaded Bitmap
        }
    };

If you want to use weakHandler, then this is my solution:

private void loadImage(final ImageView image, String url) {

    Bitmap bmp = aq.getCachedImage(url);

    if (bmp!= null) {
        image.setImageBitmap(bmp);
        return;
    }

    Object handler = new Object() {
        @SuppressWarnings("unused")
        public void callback(String url, Bitmap bmp, AjaxStatus status) {
            if (bmp != null) {
                image.setImageBitmap(bmp);
            }
        }
    };

    AjaxCallback<Bitmap> bmpCallback = new AjaxCallback<Bitmap>();
    bmpCallback.type(Bitmap.class).url(url).header("User-Agent", appPrefs.getUserAgent()).policy(AQuery.CACHE_PERSISTENT)
            .expire(GlobalVars.MARKERS_CACHE_EXPIRE).fileCache(true).weakHandler(handler, "callback");
    aq.ajax(bmpCallback);
}
Malachiasz
  • 7,126
  • 2
  • 35
  • 49