Android Open Source - tpblogr Flickr J Async Task Provider






From Project

Back to project page tpblogr.

License

The source code is released under:

MIT License

If you think the Android project tpblogr listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package blogr.vpm.fr.blogr.apis.flickr;
//w ww  .  ja  va  2 s.c o m
import android.app.Activity;
import android.app.DialogFragment;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.Toast;

import com.googlecode.flickrjandroid.photos.PhotoList;

import blogr.vpm.fr.blogr.R;
import blogr.vpm.fr.blogr.activity.FlickrDialogFragment;

/**
 * Created by vincent on 19/10/14.
 */
public class FlickrJAsyncTaskProvider extends AsyncTask<FlickrJAsyncTaskProvider.FlickrSearchBean, Integer, PhotoList> implements FlickrProvider {

  private final FlickrProvider delegate;

  private final Activity activity;

  public FlickrJAsyncTaskProvider(Activity activity, FlickrProvider delegate) {
    this.delegate = delegate;
    this.activity = activity;
  }

  @Override
  public PhotoList getUserPhotos(String username, int count) {
    this.execute(new FlickrSearchBean(username, count));
    return new PhotoList();
  }

  @Override
  protected PhotoList doInBackground(FlickrSearchBean... search) {
    return delegate.getUserPhotos(search[0].username, search[0].count);
  }

  @Override
  protected void onPostExecute(PhotoList pics) {
    if (pics.size() > 0) {
      ParcelableFlickrPhoto[] pPics = getParcelablePictureArray(pics);
      openFlickrDialog(pPics);
    } else {
      Toast.makeText(activity, activity.getResources().getString(R.string.no_access_flickr), Toast.LENGTH_SHORT).show();
    }
  }

  /**
   * Transforms the list of pictures into an array of parcelable (i.e. serializable) pictures
   *
   * @param pics the list of pictures from the Flickr API
   * @return an array of parcelable pictures
   */
  private ParcelableFlickrPhoto[] getParcelablePictureArray(PhotoList pics) {
    ParcelableFlickrPhoto[] pPics = new ParcelableFlickrPhoto[pics.size()];
    for (int i = 0; i < pics.size(); i++) {
      pPics[i] = new ParcelableFlickrPhoto(pics.get(i));
    }
    return pPics;
  }

  /**
   * Opens a dialog with the list of Flickr pictures
   *
   * @param pPics the array of parcelable (i.e. serializable) pictures
   */
  private void openFlickrDialog(ParcelableFlickrPhoto[] pPics) {
    DialogFragment flickrFragment = new FlickrDialogFragment();
    Bundle args = new Bundle();
    args.putParcelableArray(FlickrDialogFragment.ARG_PICS, pPics);
    flickrFragment.setArguments(args);
    flickrFragment.show(activity.getFragmentManager(), "flickrPicker");
  }

  public class FlickrSearchBean {
    String username;
    int count;

    private FlickrSearchBean(String username, int count) {
      this.username = username;
      this.count = count;
    }
  }
}




Java Source Code List

blogr.vpm.fr.blogr.activity.AllPreferencesActivity.java
blogr.vpm.fr.blogr.activity.BlogActivity.java
blogr.vpm.fr.blogr.activity.BlogListDialogFragment.java
blogr.vpm.fr.blogr.activity.DialogDismissedListener.java
blogr.vpm.fr.blogr.activity.EmailBlogEditionFragment.java
blogr.vpm.fr.blogr.activity.FlickrDialogFragment.java
blogr.vpm.fr.blogr.activity.GithubBlogEditionFragment.java
blogr.vpm.fr.blogr.activity.InvalidatedModelListener.java
blogr.vpm.fr.blogr.activity.PostEditionActivity.java
blogr.vpm.fr.blogr.activity.PostEditionFragment.java
blogr.vpm.fr.blogr.activity.PostListActivity.java
blogr.vpm.fr.blogr.activity.PostListChoiceModeListener.java
blogr.vpm.fr.blogr.activity.PostListFragment.java
blogr.vpm.fr.blogr.activity.PostSelectionListener.java
blogr.vpm.fr.blogr.activity.PreferenceCategoryFragment.java
blogr.vpm.fr.blogr.apis.flickr.FlickrJAndroidProvider.java
blogr.vpm.fr.blogr.apis.flickr.FlickrJAsyncTaskProvider.java
blogr.vpm.fr.blogr.apis.flickr.FlickrProvider.java
blogr.vpm.fr.blogr.apis.flickr.ParcelableFlickrPhoto.java
blogr.vpm.fr.blogr.bean.Blog.java
blogr.vpm.fr.blogr.bean.EmailBlog.java
blogr.vpm.fr.blogr.bean.GithubBlog.java
blogr.vpm.fr.blogr.bean.Post.java
blogr.vpm.fr.blogr.bean.TPBlog.java
blogr.vpm.fr.blogr.format.AlignCenterTagsProvider.java
blogr.vpm.fr.blogr.format.AlignLeftTagsProvider.java
blogr.vpm.fr.blogr.format.AlignRightTagsProvider.java
blogr.vpm.fr.blogr.insertion.DefaultInserter.java
blogr.vpm.fr.blogr.insertion.Inserter.java
blogr.vpm.fr.blogr.insertion.SingleTagProvider.java
blogr.vpm.fr.blogr.insertion.SurroundingTagsProvider.java
blogr.vpm.fr.blogr.location.AndroidLocationProvider.java
blogr.vpm.fr.blogr.location.LatLongTagProvider.java
blogr.vpm.fr.blogr.location.LocationProvider.java
blogr.vpm.fr.blogr.persistence.BlogRetriever.java
blogr.vpm.fr.blogr.persistence.BlogSaver.java
blogr.vpm.fr.blogr.persistence.FileBlogManager.java
blogr.vpm.fr.blogr.persistence.FilePostRetriever.java
blogr.vpm.fr.blogr.persistence.FilePostSaver.java
blogr.vpm.fr.blogr.persistence.PostRetriever.java
blogr.vpm.fr.blogr.persistence.PostSaver.java
blogr.vpm.fr.blogr.picture.AsyncPictureLoader.java
blogr.vpm.fr.blogr.picture.ImageViewLoader.java
blogr.vpm.fr.blogr.picture.PictureLoadedListener.java
blogr.vpm.fr.blogr.picture.PictureMdTagsProvider.java
blogr.vpm.fr.blogr.picture.PicturePickedListener.java
blogr.vpm.fr.blogr.picture.PictureTagProvider.java
blogr.vpm.fr.blogr.picture.PictureTpTagsProvider.java
blogr.vpm.fr.blogr.publish.Formatter.java
blogr.vpm.fr.blogr.publish.HtmlFormatter.java
blogr.vpm.fr.blogr.publish.IdentityFormatter.java
blogr.vpm.fr.blogr.publish.PostPublisher.java
blogr.vpm.fr.blogr.publish.StdEmailPostPublisher.java
blogr.vpm.fr.blogr.publish.TPJavaMailPostPublisher.java
blogr.vpm.fr.blogr.publish.TPPostPublisher.java
blogr.vpm.fr.blogr.service.PostPublishingPreferencesProvider.java
blogr.vpm.fr.blogr.service.PostPublishingServiceProvider.java