0
votes

After a timeline card is updated by the Glassware, is it possible to have only the updated timeline card visible on Glass. Currently, I can see the old timeline card as well as updated timeline card on Glass, but obviously w/ differnt timestamp.

Here's more explanation w/ code:- There are two java classes, NewUserBootstrapper and NotifyServlet. The NewUserBootstrapper takes care of bootstrapping that includes authentication, inserting contact and inserting subscription. This is the code for inserting a timeline item as part of bootstrapping.

// Send a timeline item
TimelineItem timelineItem = new TimelineItem();
timelineItem.setText("Hello");
timelineItem.setNotification(new NotificationConfig().setLevel("DEFAULT"));
TimelineItem insertedItem = MirrorClient.insertTimelineItem(credential, timelineItem); 

Now in the NotifyServlet, after the Service is notified of changes to the timeline as part of "take a note" voice command, the NotifyServlet tries to update the text of the same timeline item.

  if (notification.getCollection().equals("timeline")) {
     // Get the impacted timeline item
     TimelineItem timelineItem =  
     mirrorClient.timeline().get(notification.getItemId()).execute();

 //Take a note
 if (notification.getUserActions().contains(new UserAction().setType("LAUNCH")))
 {
   final TimelineItem noteItem = mirrorClient.timeline()
                .get(notification.getItemId()).execute();

   final String spokenText = noteItem.getText();

   if ( spokenText.toUpperCase().contains("DONE") 
                  || spokenText.toUpperCase().contains("LIST"))
   {        
      noteItem.setText("Hello Glassware");
          MirrorClient.
              getMirror(credential).timeline().update(notification.getItemId(),  
              noteItem).execute();          
       }
}
 }

The update of the timeline card does happen, however I can see both the cards, one w/ "Hello" text and the other w/ "Hello Glassware" text but w/ different timestamp. I was expecting to see only the updated timeline card.

1
Can you show sample code for how you are doing the update? Typically, the "old" card is replaced completely by the updated card. Having both implies that you have ended up with two IDs. - Prisoner
There are two java classes, NewUserBootstrapper and NotifyServlet. The NewUserBootstrapper takes care of bootstrapping that includes authentication, inserting contact and inserting subscription. This is the code for inserting a timeline item as part of bootstrapping. // Send welcome timeline item TimelineItem timelineItem = new TimelineItem(); timelineItem.setText("Hello"); timelineItem.setNotification(new NotificationConfig().setLevel("DEFAULT")); TimelineItem insertedItem = MirrorClient.insertTimelineItem(credential, timelineItem); - Dev Srivastava
Now in the NotifyServlet, after the Service is notified of changes to the timeline as part of "take a note" voice command, the NotifyServlet tries to update the text of the same timeline item:- if (notification.getCollection().equals("timeline")) { // Get the impacted timeline item TimelineItem timelineItem = mirrorClient.timeline().get(notification.getItemId()).execute(); //Take a note if (notification.getUserActions().contains(new UserAction().setType("LAUNCH"))) { - Dev Srivastava
final TimelineItem noteItem = mirrorClient.timeline() .get(notification.getItemId()).execute(); final String spokenText = noteItem.getText(); if ( spokenText.toUpperCase().contains("DONE") || spokenText.toUpperCase().contains("LIST")) { noteItem.setText("Hello Glassware"); MirrorClient. getMirror(credential).timeline().update(notification.getItemId(), noteItem).execute(); } } } - Dev Srivastava
Thanks! edited the original post w/ more explanation and code. - Dev Srivastava

1 Answers

0
votes

I think the issue here is that you're trying to update the wrong card. Although you store the original card as insertedItem, you then post the update using notification's ID.

Remember that every action, either done by your Glassware or done by you on Glass, generates a card (and thus an ID). So your voice action generated a card which is stored on your timeline. It is common to either edit this card (to more nicely format it) or to delete the card from the Glassware as part of indicating you've received it and have acted on it.

So what is happening is that you're creating one card (insertedItem) from your Glassware, you're issuing a voice command (notification, which you then read into noteItem) which generates another card, and then updating the second card. It sounds like you really want to update the first card, so you should be updating insertedItem.