delight-im / Android-DDP

[UNMAINTAINED] Meteor's Distributed Data Protocol (DDP) for clients on Android
Apache License 2.0
274 stars 54 forks source link

Create MeteorSubscription.java #149

Open idelrich opened 6 years ago

idelrich commented 6 years ago

This new file adds a new class to the library that can handle "Multiple Subscriptions" and uses the existing SubscriptionListener class to notify the parent once all of the contained subscriptions are ready. It also adds a convenience getter to test if a subscription set is ready. The class can be used with a single subscription as well.

A sample of the "Multiple Subscriptions" might look like:

    mSubscription = new MeteorSubscription(mMeteor, new MeteorSubscription[]{
            new MeteorSubscription("activeCompetitions", null),
            new MeteorSubscription("recentGames", new Object[]{30}),
            new MeteorSubscription("recentGameScores", new Object[]{30}),
            new MeteorSubscription("activeGames", null),
            new MeteorSubscription("activeGameScores", new Object[]{true})

    }).start(new SubscribeListener() {
        @Override public void onSuccess() {
            Log.d("LS", "All subscriptions ready");
        }

        @Override public void onError(String error, String reason, String details) {
            Log.d("LS", "Error subscribing" + error + " [ " + reason + " ] ~> " + details);
        }
    });

All subscriptions can be stopped by calling mSubscription.stop();

Stephen (stephen@chatorr.ca)