Search in sources :

Example 1 with LoadFlickrActivityTask

use of com.bourke.glimmr.tasks.LoadFlickrActivityTask in project glimmr by brk3.

the class ActivityNotificationHandler method startTask.

@Override
public void startTask(OAuth oauth) {
    mOAuth = oauth;
    new LoadFlickrActivityTask(this).execute(oauth);
}
Also used : LoadFlickrActivityTask(com.bourke.glimmr.tasks.LoadFlickrActivityTask)

Example 2 with LoadFlickrActivityTask

use of com.bourke.glimmr.tasks.LoadFlickrActivityTask 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)

Aggregations

LoadFlickrActivityTask (com.bourke.glimmr.tasks.LoadFlickrActivityTask)2 MenuItem (android.view.MenuItem)1 IActivityItemsReadyListener (com.bourke.glimmr.event.Events.IActivityItemsReadyListener)1 Item (com.googlecode.flickrjandroid.activity.Item)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1