Android Open Source - RobolectricSample Recent Activities






From Project

Back to project page RobolectricSample.

License

The source code is released under:

MIT License

If you think the Android project RobolectricSample listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.pivotallabs.tracker;
//from   w  ww  . ja v  a 2 s.co  m
import com.pivotallabs.Callbacks;
import com.pivotallabs.MultiCallbacks;
import com.pivotallabs.api.ApiGateway;
import com.pivotallabs.api.ApiResponse;
import com.pivotallabs.api.ApiResponseCallbacks;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.util.ArrayList;

public class RecentActivities extends ArrayList<RecentActivity> {
    private static final long serialVersionUID = 2810203342716301892L;
  
    private ApiGateway apiGateway;
    private AuthenticationGateway authenticationGateway;

    public RecentActivities(ApiGateway apiGateway, AuthenticationGateway authenticationGateway) {
        this.apiGateway = apiGateway;
        this.authenticationGateway = authenticationGateway;
    }

    public void update(Callbacks... callbacks) {
        MultiCallbacks multiCallbacks = new MultiCallbacks(callbacks);
        multiCallbacks.onStart();
        apiGateway.makeRequest(
                new RecentActivityRequest(authenticationGateway.getToken()),
                new RecentActivityApiResponseCallbacks(multiCallbacks));
    }

    private class RecentActivityApiResponseCallbacks implements ApiResponseCallbacks {
        private Callbacks callbacks;

        public RecentActivityApiResponseCallbacks(Callbacks callbacks) {
            this.callbacks = callbacks;
        }

        @Override
        public void onSuccess(ApiResponse response) {
            try {
                clear();
                NodeList activityNodeList = response.getResponseDocument().getElementsByTagName("activity");
                for (int i = 0; i < activityNodeList.getLength(); i++) {
                    add(new RecentActivity().apply((Element) activityNodeList.item(i)));
                }
                callbacks.onSuccess();
            } catch (ParserConfigurationException pce) {
                throw new RuntimeException(pce);
            } catch (SAXException se) {
                throw new RuntimeException(se);
            } catch (IOException ioe) {
                throw new RuntimeException(ioe);
            }
        }

        @Override
        public void onFailure(ApiResponse response) {
            callbacks.onFailure();
        }

        @Override
        public void onComplete() {
            callbacks.onComplete();
        }
    }
}




Java Source Code List

com.pivotallabs.AuthenticationCallbacks.java
com.pivotallabs.Callbacks.java
com.pivotallabs.EmptyOnClickListener.java
com.pivotallabs.GenericAdapter.java
com.pivotallabs.HomeActivity.java
com.pivotallabs.MultiCallbacks.java
com.pivotallabs.NamesActivity.java
com.pivotallabs.NamesAdapter.java
com.pivotallabs.NotifyDataSetChangedCallbacks.java
com.pivotallabs.OnChangeListener.java
com.pivotallabs.StubTextWatcher.java
com.pivotallabs.ViewEnablingTextWatcher.java
com.pivotallabs.ViewVisibleWhileOutstandingCallbacks.java
com.pivotallabs.api.ApiGateway.java
com.pivotallabs.api.ApiRequest.java
com.pivotallabs.api.ApiResponseCallbacks.java
com.pivotallabs.api.ApiResponse.java
com.pivotallabs.api.CertificateIgnoringSSLSocketFactory.java
com.pivotallabs.api.Http.java
com.pivotallabs.api.TrustingTrustManager.java
com.pivotallabs.api.Xmls.java
com.pivotallabs.injected.Counter.java
com.pivotallabs.injected.InjectedActivity.java
com.pivotallabs.injected.RobolectricSampleModule.java
com.pivotallabs.injected.SampleGuiceApplication.java
com.pivotallabs.tracker.AuthenticationGateway.java
com.pivotallabs.tracker.RecentActivities.java
com.pivotallabs.tracker.RecentActivityActivity.java
com.pivotallabs.tracker.RecentActivityAdapter.java
com.pivotallabs.tracker.RecentActivityRequest.java
com.pivotallabs.tracker.RecentActivity.java
com.pivotallabs.tracker.SignInDialog.java
com.pivotallabs.tracker.TrackerAuthenticationRequest.java
com.pivotallabs.util.Pair.java
com.pivotallabs.util.Strings.java