Search in sources :

Example 21 with Photo

use of com.googlecode.flickrjandroid.photos.Photo in project glimmr by brk3.

the class PhotoGridFragment method checkForNewPhotos.

/**
 * If we have a most recent id stored, see if it exists in the photo
 * list we just fetched. If so, all photos before that id in the list
 * are said to be new.
 */
protected void checkForNewPhotos(List<Photo> photos) {
    if (photos == null || photos.isEmpty()) {
        if (BuildConfig.DEBUG)
            Log.d(getLogTag(), "checkForNewPhotos: photos null or empty");
        return;
    }
    mNewPhotos = new ArrayList<Photo>();
    String newestId = getNewestPhotoId();
    if (newestId != null) {
        for (int i = 0; i < photos.size(); i++) {
            Photo p = photos.get(i);
            if (p.getId().equals(newestId)) {
                mNewPhotos = photos.subList(0, i);
                if (BuildConfig.DEBUG)
                    Log.d(getLogTag(), String.format("Found %d new photos", mNewPhotos.size()));
                break;
            }
        }
    }
    if (mNewPhotos != null && !mNewPhotos.isEmpty()) {
        storeNewestPhotoId(mNewPhotos.get(0));
    } else {
        if (BuildConfig.DEBUG)
            Log.d(getLogTag(), "mNewPhotos null or empty, using most " + "recent fetched photo as newest");
        storeNewestPhotoId(photos.get(0));
    }
}
Also used : Photo(com.googlecode.flickrjandroid.photos.Photo)

Example 22 with Photo

use of com.googlecode.flickrjandroid.photos.Photo in project glimmr by brk3.

the class ActivityNotificationHandler method showNotification.

private void showNotification(final Item item, final int eventOffset) {
    if (BuildConfig.DEBUG) {
        Log.d(TAG, "showNotification for " + item.getTitle() + ", starting ajax task to fetch the item image");
    }
    /* fetch the photo the item refers to */
    new LoadPhotoInfoTask(new IPhotoInfoReadyListener() {

        @Override
        public void onPhotoInfoReady(final Photo photo, Exception e) {
            /* fetch the photo bitmap to be shown in the notification */
            String url = photo.getMediumUrl();
            new DownloadPhotoTask(mContext, new Events.IPhotoDownloadedListener() {

                @Override
                public void onPhotoDownloaded(Bitmap bitmap, Exception e) {
                    onItemPhotoReady(item, photo, bitmap, eventOffset);
                }
            }, url).execute();
        }
    }, item.getId(), item.getSecret()).execute(mOAuth);
}
Also used : Bitmap(android.graphics.Bitmap) Photo(com.googlecode.flickrjandroid.photos.Photo) DownloadPhotoTask(com.bourke.glimmr.tasks.DownloadPhotoTask) LoadPhotoInfoTask(com.bourke.glimmr.tasks.LoadPhotoInfoTask) IPhotoInfoReadyListener(com.bourke.glimmr.event.Events.IPhotoInfoReadyListener)

Example 23 with Photo

use of com.googlecode.flickrjandroid.photos.Photo in project glimmr by brk3.

the class ContactsPhotosNotificationHandler method onPhotosReady.

/**
 * Once photos are ready check for new ones and notify the user.
 *
 * There are two conditions that must be satisfied for a notification to be
 * shown:
 * 1) The id must be newer than ones previously shown in the main app.
 * 2) The id must not equal the one previously notified about, to avoid
 *    duplicate notifications.
 */
@Override
public void onPhotosReady(List<Photo> photos, Exception e) {
    if (BuildConfig.DEBUG)
        Log.d(TAG, "onPhotosReady");
    if (photos != null) {
        List<Photo> newPhotos = checkForNewPhotos(photos);
        if (newPhotos != null && !newPhotos.isEmpty()) {
            String latestIdNotifiedAbout = getLatestIdNotifiedAbout();
            Photo latestPhoto = newPhotos.get(0);
            if (!latestIdNotifiedAbout.equals(latestPhoto.getId())) {
                showNewPhotosNotification(newPhotos);
                storeLatestIdNotifiedAbout(latestPhoto);
            }
        }
    } else {
        Log.e(TAG, "onPhotosReady: null photolist received");
    }
}
Also used : Photo(com.googlecode.flickrjandroid.photos.Photo)

Aggregations

Photo (com.googlecode.flickrjandroid.photos.Photo)23 ArrayList (java.util.ArrayList)5 Intent (android.content.Intent)3 LoadPhotoInfoTask (com.bourke.glimmr.tasks.LoadPhotoInfoTask)3 Bitmap (android.graphics.Bitmap)2 FragmentTransaction (android.support.v4.app.FragmentTransaction)2 View (android.view.View)2 ListView (android.widget.ListView)2 TextView (android.widget.TextView)2 SpannableBuilder (com.alexvasilkov.android.commons.texts.SpannableBuilder)2 Background (com.alexvasilkov.events.Events.Background)2 Subscribe (com.alexvasilkov.events.Events.Subscribe)2 IPhotoInfoReadyListener (com.bourke.glimmr.event.Events.IPhotoInfoReadyListener)2 PhotoStreamGridFragment (com.bourke.glimmr.fragments.home.PhotoStreamGridFragment)2 Flickr (com.googlecode.flickrjandroid.Flickr)2 PhotoList (com.googlecode.flickrjandroid.photos.PhotoList)2 SearchParameters (com.googlecode.flickrjandroid.photos.SearchParameters)2 List (java.util.List)2 Bundle (android.os.Bundle)1 Toolbar (android.support.v7.widget.Toolbar)1