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

Callbacks not firing #18

Closed dwalintukan closed 9 years ago

dwalintukan commented 9 years ago

I'm logging in the console some text when these methods get fired, but they are not going off. I am signed in and subscribed correctly. I have also set the callback correctly. None of the callbacks are firing correctly. Could this be an issue with the singleton pattern?

public MeteorHelper(Context context) {
    mMeteor = new Meteor(context, context.getString(R.string.url_server));
    mMeteor.setCallback(this);
    mContext = context;
}

public static synchronized MeteorHelper getInstance(Context context) {
    if (mInstance == null) {
        mInstance = new MeteorHelper(context);
    }
    return mInstance;
}

@Override
public void onDataAdded(String collectionName, String documentID, String newValuesJson) {
    Log.v(TAG, "(onDataAdded) collection: " + collectionName + " documentId: " + documentID + " payload: " + newValuesJson);
}

@Override
public void onDataChanged(String collectionName, String documentID, String updatedValuesJson, String removedValuesJson) {
    Log.v(TAG, "(onDataChanged) collection: " + collectionName + " documentId: " + documentID + " payload: " + updatedValuesJson);
}

@Override
public void onDataRemoved(String collectionName, String documentID) {
    Log.v(TAG, "(onDataRemoved) collection: " + collectionName + " documentId: " + documentID);
}

Instead they are just going to my log like so:

06-12 16:19:39.146    6960-6960/com.walintukai.watchdog.debug I/System.out﹕ RECEIVE: {"msg":"added","collection":"assets","id":"cZCMZabRbPmEt3gk5","fields":{"name":"House 1","desc":{"country":"USA","city":"Emeryville","postal":"942828","street":"Christie Ave","year":2004}}}
06-12 16:19:39.146    6960-6960/com.walintukai.watchdog.debug I/System.out﹕ RECEIVE: {"msg":"ready","subs":["fff1d350-5270-490e-87dc-1f6b783e6ab1"]}
ocram commented 9 years ago

Sorry for the late reply!

We've checked your use case and code and it should work without any problems, actually.

The log statements that you saw was because this library had internal logging enabled by default. This has been fixed in https://github.com/delight-im/Android-DDP/commit/db19049f26e2440decab0e93ea83acf0569725f2 so that you won't see these statements anymore -- unless you explicitly enable this library's internal logging.

Could it be that you didn't see your Log.v(...) results due to a wrong filter set in your debugger/console?

Regarding the singleton pattern in general, you should change the constructor's visibility from public MeteorHelper(...) to private MeteorHelper(...) -- but this is not really that important, of course.

To save you from having to implement the singleton yourself, we've added a recommended singleton implementation in the MeteorSingleton class in https://github.com/delight-im/Android-DDP/commit/65a0b034e8de9aa9fbe3089eaac7742a1c818a36.

Please get one of the latest JARs and check the "Singleton access" section in the documentation.

Does that help?