Search in sources :

Example 1 with Item

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

the class MainActivity method startViewerForActivityItem.

private void startViewerForActivityItem(int itemPos) {
    setProgressBarIndeterminateVisibility(Boolean.TRUE);
    List<Item> items = ActivityNotificationHandler.loadItemList(MainActivity.this);
    Item item = items.get(itemPos);
    new LoadPhotoInfoTask(new IPhotoInfoReadyListener() {

        @Override
        public void onPhotoInfoReady(final Photo photo, Exception e) {
            setProgressBarIndeterminateVisibility(Boolean.FALSE);
            if (FlickrHelper.getInstance().handleFlickrUnavailable(MainActivity.this, e)) {
                return;
            }
            if (photo == null) {
                Log.e(TAG, "onPhotoInfoReady: photo is null, " + "can't start viewer");
                return;
            }
            List<Photo> photos = new ArrayList<Photo>();
            photos.add(photo);
            setProgressBarIndeterminateVisibility(Boolean.FALSE);
            PhotoViewerActivity.startPhotoViewer(MainActivity.this, photos, 0);
        }
    }, item.getId(), item.getSecret()).execute(mOAuth);
}
Also used : MenuItem(android.view.MenuItem) Item(com.googlecode.flickrjandroid.activity.Item) ArrayList(java.util.ArrayList) Photo(com.googlecode.flickrjandroid.photos.Photo) LoadPhotoInfoTask(com.bourke.glimmr.tasks.LoadPhotoInfoTask) IPhotoInfoReadyListener(com.bourke.glimmr.event.Events.IPhotoInfoReadyListener)

Example 2 with Item

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

the class MainActivity method updateMenuListItems.

public void updateMenuListItems(boolean forceRefresh) {
    if (BuildConfig.DEBUG)
        Log.d(TAG, "updateMenuListItems");
    final List<Object> menuItems = new ArrayList<Object>();
    /* Add the standard page related items */
    for (PageItem page : mContent) {
        menuItems.add(new MenuDrawerItem(page.mTitle, page.mIconDrawable));
    }
    menuItems.add(new MenuDrawerCategory(getString(R.string.activity)));
    /* If the activity list file exists, add the contents to the menu
         * drawer area.  Otherwise start a task to fetch one. */
    File f = getFileStreamPath(ActivityNotificationHandler.ACTIVITY_ITEMLIST_FILE);
    if (f.exists() && !forceRefresh) {
        /* There is some duplicated code here.  Could move it into another
             * function but the task is fragmented enough as is */
        List<Item> items = ActivityNotificationHandler.loadItemList(this);
        menuItems.addAll(buildActivityStream(items));
        mActivityListVersion = mPrefs.getLong(ActivityNotificationHandler.KEY_TIME_ACTIVITY_ITEMS_LAST_UPDATED, -1);
        mMenuAdapter.setItems(menuItems);
        mMenuAdapter.notifyDataSetChanged();
    } else {
        setProgressBarIndeterminateVisibility(Boolean.TRUE);
        new LoadFlickrActivityTask(new IActivityItemsReadyListener() {

            @Override
            public void onItemListReady(List<Item> items, Exception e) {
                setProgressBarIndeterminateVisibility(Boolean.FALSE);
                if (items != null) {
                    ActivityNotificationHandler.storeItemList(MainActivity.this, items);
                    menuItems.addAll(buildActivityStream(items));
                    mActivityListVersion = mPrefs.getLong(ActivityNotificationHandler.KEY_TIME_ACTIVITY_ITEMS_LAST_UPDATED, -1);
                } else {
                    Log.e(TAG, "onItemListReady: Item list is null");
                }
                mMenuAdapter.setItems(menuItems);
                mMenuAdapter.notifyDataSetChanged();
            }
        }).execute(mOAuth);
    }
}
Also used : ArrayList(java.util.ArrayList) IActivityItemsReadyListener(com.bourke.glimmr.event.Events.IActivityItemsReadyListener) LoadFlickrActivityTask(com.bourke.glimmr.tasks.LoadFlickrActivityTask) MenuItem(android.view.MenuItem) Item(com.googlecode.flickrjandroid.activity.Item) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File)

Example 3 with Item

use of com.googlecode.flickrjandroid.activity.Item 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 4 with Item

use of com.googlecode.flickrjandroid.activity.Item 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)

Example 5 with Item

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

the class ActivityNotificationHandler method loadItemList.

public static List<Item> loadItemList(Context context) {
    List<Item> ret = new ArrayList<Item>();
    GsonHelper gson = new GsonHelper(context);
    String json = gson.loadJson(ACTIVITY_ITEMLIST_FILE);
    if (json.length() == 0) {
        Log.e(TAG, String.format("Error reading %s", ACTIVITY_ITEMLIST_FILE));
        return ret;
    }
    Type collectionType = new TypeToken<Collection<Item>>() {
    }.getType();
    ret = new Gson().fromJson(json, collectionType);
    if (BuildConfig.DEBUG) {
        Log.d(TAG, String.format("Sucessfully read %d items from %s", ret.size(), ACTIVITY_ITEMLIST_FILE));
    }
    return ret;
}
Also used : Item(com.googlecode.flickrjandroid.activity.Item) GsonHelper(com.bourke.glimmr.common.GsonHelper) Type(java.lang.reflect.Type) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Gson(com.google.gson.Gson)

Aggregations

Item (com.googlecode.flickrjandroid.activity.Item)5 ArrayList (java.util.ArrayList)5 MenuItem (android.view.MenuItem)3 List (java.util.List)3 Event (com.googlecode.flickrjandroid.activity.Event)2 GsonHelper (com.bourke.glimmr.common.GsonHelper)1 IActivityItemsReadyListener (com.bourke.glimmr.event.Events.IActivityItemsReadyListener)1 IPhotoInfoReadyListener (com.bourke.glimmr.event.Events.IPhotoInfoReadyListener)1 LoadFlickrActivityTask (com.bourke.glimmr.tasks.LoadFlickrActivityTask)1 LoadPhotoInfoTask (com.bourke.glimmr.tasks.LoadPhotoInfoTask)1 Gson (com.google.gson.Gson)1 Photo (com.googlecode.flickrjandroid.photos.Photo)1 File (java.io.File)1 Type (java.lang.reflect.Type)1 Collection (java.util.Collection)1 PrettyTime (org.ocpsoft.prettytime.PrettyTime)1