Search in sources :

Example 1 with Event

use of com.googlecode.flickrjandroid.activity.Event in project glimmr by brk3.

the class ActivityNotificationHandler method onItemPhotoReady.

private void onItemPhotoReady(Item item, Photo photo, Bitmap bitmap, int eventOffset) {
    if (BuildConfig.DEBUG)
        Log.d(TAG, "onItemPhotoReady");
    String tickerText = String.format("%s %s", mContext.getString(R.string.new_activity), item.getTitle());
    String titleText = item.getTitle();
    /* build the notification content text from the item events */
    StringBuilder contentText = new StringBuilder();
    List<Event> events = (List<Event>) item.getEvents();
    List<Event> newEvents = events.subList(eventOffset, events.size());
    if (BuildConfig.DEBUG)
        Log.d(TAG, "newEvents.size: " + newEvents.size());
    for (int i = 0; i < newEvents.size(); i++) {
        Event e = newEvents.get(i);
        if ("comment".equals(e.getType())) {
            contentText.append(String.format("%s %s", e.getUsername(), mContext.getString(R.string.added_a_comment)));
            if (i < newEvents.size() - 1 && newEvents.size() > 1) {
                contentText.append(", ");
            }
        } else if ("fave".equals(e.getType())) {
            contentText.append(String.format("%s %s", e.getUsername(), mContext.getString(R.string.favorited)));
            if (i < newEvents.size() - 1 && newEvents.size() > 1) {
                contentText.append(", ");
            }
        }
        if (i == 1 && i < newEvents.size()) {
            contentText.append("+ ").append(newEvents.size() - 2).append(" others");
            break;
        }
    }
    /* finally, show the notification itself */
    int smallIcon = R.drawable.ic_social_chat_dark;
    if ("fave".equals(newEvents.get(0).getType())) {
        smallIcon = R.drawable.ic_action_rating_important_dark;
    }
    Notification n = getNotification(tickerText, titleText, contentText.toString(), newEvents.size(), smallIcon, bitmap, photo);
    final NotificationManager mgr = (NotificationManager) mContext.getSystemService(WakefulIntentService.NOTIFICATION_SERVICE);
    mgr.notify(Constants.NOTIFICATION_NEW_ACTIVITY, n);
}
Also used : NotificationManager(android.app.NotificationManager) Event(com.googlecode.flickrjandroid.activity.Event) ArrayList(java.util.ArrayList) List(java.util.List) Notification(android.app.Notification)

Example 2 with Event

use of com.googlecode.flickrjandroid.activity.Event in project glimmr by brk3.

the class MainActivity method buildActivityStream.

/**
     * An item can be a photo or photoset.
     * An event can be a comment, note, or fav on that item.
     */
private List<Object> buildActivityStream(List<Item> activityItems) {
    List<Object> ret = new ArrayList<Object>();
    if (activityItems == null) {
        return ret;
    }
    PrettyTime prettyTime = new PrettyTime(Locale.getDefault());
    String html = "<small><i>%s</i></small><br>" + "%s <font color=\"#ff0084\"><b>%s</b></font> <i>ā€˜%sā€™</i>";
    for (Item i : activityItems) {
        if ("photo".equals(i.getType())) {
            StringBuilder itemString = new StringBuilder();
            for (int j = i.getEvents().size() - 1; j >= 0; j--) {
                Event e = ((List<Event>) i.getEvents()).get(j);
                String pTime = prettyTime.format(e.getDateadded());
                String author = e.getUsername();
                if (mUser != null && mUser.getUsername().equals(author)) {
                    author = getString(R.string.you);
                }
                if ("comment".equals(e.getType())) {
                    itemString.append(String.format(html, pTime, author, getString(R.string.commented_on), i.getTitle()));
                } else if ("fave".equals(e.getType())) {
                    itemString.append(String.format(html, pTime, author, getString(R.string.favorited), i.getTitle()));
                } else {
                    Log.e(TAG, "unsupported Event type: " + e.getType());
                    continue;
                }
                if (j > 0) {
                    itemString.append("<br><br>");
                }
            }
            if (!itemString.toString().isEmpty()) {
                ret.add(new MenuDrawerActivityItem(itemString.toString(), -1));
            }
        }
    }
    return ret;
}
Also used : MenuItem(android.view.MenuItem) Item(com.googlecode.flickrjandroid.activity.Item) ArrayList(java.util.ArrayList) Event(com.googlecode.flickrjandroid.activity.Event) PrettyTime(org.ocpsoft.prettytime.PrettyTime) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with Event

use of com.googlecode.flickrjandroid.activity.Event in project glimmr by brk3.

the class ActivityNotificationHandler method checkForNewItemEvents.

/**
     * The item at the head of the list is the latest.  Check if it's
     * either new, or has updated events.
     */
private void checkForNewItemEvents(List<Item> fetchedItems) {
    if (BuildConfig.DEBUG) {
        Log.d(TAG, "Loading existing item list and comparing it against " + "the ones we just fetched");
    }
    if (fetchedItems == null || fetchedItems.isEmpty()) {
        Log.d(TAG, "fetchedItems null or empty, returning");
        return;
    }
    List<Item> currentItems = loadItemList(mContext);
    if (currentItems == null || currentItems.isEmpty()) {
        if (BuildConfig.DEBUG) {
            Log.d(TAG, "checkForNewItemEvents: couldn't load any " + "existing items to compare against");
        }
        return;
    }
    /* (NOTE: we could look at all the fetchedItems here to check for other
         * new or updated ones.  But would need to be careful that wouldn't
         * spam a lot of notifications so will just check the latest for now.)
         * */
    Item fetchedItem = fetchedItems.get(0);
    List<Event> newEvents = (List<Event>) fetchedItem.getEvents();
    Event latestEvent = newEvents.get(newEvents.size() - 1);
    String latestEventId = "" + latestEvent.getDateadded().getTime();
    String latestIdNotifiedAbout = getLatestIdNotifiedAbout();
    boolean isNewItem = true;
    for (Item curItem : currentItems) {
        if (fetchedItem.getId().equals(curItem.getId())) {
            isNewItem = false;
            List<Event> curEvents = (List<Event>) curItem.getEvents();
            if (newEvents.size() > curEvents.size()) {
                /* we have new events */
                if (BuildConfig.DEBUG) {
                    Log.d(TAG, "Found update to existing item " + fetchedItem.getTitle());
                }
                if (!latestIdNotifiedAbout.equals(latestEventId)) {
                    showNotification(fetchedItem, curEvents.size());
                    storeLatestIdNotifiedAbout(latestEventId);
                }
            }
            break;
        }
    }
    if (isNewItem) {
        if (BuildConfig.DEBUG) {
            Log.d(TAG, "Found new item " + fetchedItem.getTitle());
        }
        if (!latestIdNotifiedAbout.equals(latestEventId)) {
            showNotification(fetchedItem, 0);
            storeLatestIdNotifiedAbout(latestEventId);
        }
    }
}
Also used : Item(com.googlecode.flickrjandroid.activity.Item) Event(com.googlecode.flickrjandroid.activity.Event) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Event (com.googlecode.flickrjandroid.activity.Event)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Item (com.googlecode.flickrjandroid.activity.Item)2 Notification (android.app.Notification)1 NotificationManager (android.app.NotificationManager)1 MenuItem (android.view.MenuItem)1 PrettyTime (org.ocpsoft.prettytime.PrettyTime)1