Skip to content

Instantly share code, notes, and snippets.

@shyampurk
Last active August 29, 2015 14:17
Show Gist options
  • Save shyampurk/13b6e8a5aa87d1d10f60 to your computer and use it in GitHub Desktop.
Save shyampurk/13b6e8a5aa87d1d10f60 to your computer and use it in GitHub Desktop.
pubnub-todoapp-android-1
public void successCallback(String channel, Object message) {
// TODO Auto-generated method stub
super.successCallback(channel, message);
Log.i("Subscribe","SUCCESS"+message.getClass()+" "+message.toString());
try {
Globalvars.isSubscribed = true;
Log.i("Subscribe","SUCCESS sending message"+message.toString());
Intent intent = new Intent(MY_ACTION);
intent.putExtra("message", message.toString());
Log.i("PUBNUB", "Sending broadcast, message :"+message.toString());
sendBroadcast(intent);
} catch (Exception e) {
e.printStackTrace();
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (data!=null) {
// check if the request code is same as what is passed here it is 2
if(requestCode==2)
{
newtask=data.getParcelableExtra("edittask");
Callback callback = new Callback() {
public void successCallback(String channel, Object response) {
Log.d("PUBNUB","finished publishing" +response.toString());
}
public void errorCallback(String channel, PubnubError error) {
Log.d("PUBNUB",error.toString());
}
};
Log.d("PUBNUB","calling publish" + newtask.toString() );
pubnub.publish("newtodochannel", "NEW"+";"+newtask.getId()+";"+newtask.getDescription()+";"+newtask.getOwner()+";"+newtask.getUpdatetime()+";"+newtask.getStatus(), callback);
}
if (requestCode==1) {
if(resultCode==2){
edittask=data.getParcelableExtra("edittask");
Log.d(TAG,"Modifying task "+edittask.toString()+"at index"+index);
Callback callback = new Callback() {
public void successCallback(String channel, Object response) {
Log.d("PUBNUB","finished publishing MODIFY" +response.toString());
}
public void errorCallback(String channel, PubnubError error) {
Log.d("PUBNUB",error.toString());
}
};
Log.d("PUBNUB","calling publish for modify" + edittask.toString() );
pubnub.publish("newtodochannel", "MODIFY"+";"+edittask.getId()+";"+edittask.getDescription()+";"+edittask.getOwner()+";"+edittask.getUpdatetime()+";"+edittask.getStatus(), callback);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment