/**
   * Share the provided photo through other android apps
   *
   * <p>Will share the image as a image/jpg content type and include title and description as extra
   *
   * @param slideshowPhoto
   */
  public void actionSharePhoto(SlideshowPhoto slideshowPhoto) {
    Log.i(LOG_PREFIX, "Attempting to share photo " + slideshowPhoto);
    // TODO: Refactor this code.. rather ugly due to some GoogleTV related hacks

    if (slideshowPhoto != null) {
      Intent shareIntent = new Intent();
      shareIntent.setAction(Intent.ACTION_SEND);
      // we assume the type is image/jpg
      shareIntent.setType("image/jpg");

      String sharedText =
          slideshowPhoto.getTitle()
              + ": "
              + slideshowPhoto.getDescription()
              + "\n\n"
              + getResources().getString(R.string.share_footer);

      // if we have a cached file, add the stream and the sharedText
      // if not, add the url and the sharedText
      if (slideshowPhoto.isCacheExisting(rootFileDirectory)) {
        String path =
            "file://" + rootFileDirectory.getAbsolutePath() + "/" + slideshowPhoto.getFileName();
        Log.i(LOG_PREFIX, "Attempting to pass stream url " + path);
        shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(path));
        shareIntent.putExtra(Intent.EXTRA_TEXT, sharedText);
      } else {
        shareIntent.putExtra(
            Intent.EXTRA_TEXT, slideshowPhoto.getLargePhoto() + "\n\n" + sharedText);
      }

      shareIntent.putExtra(Intent.EXTRA_SUBJECT, slideshowPhoto.getTitle());

      // Start the actual sharing activity
      try {
        List<ResolveInfo> relevantActivities =
            getPackageManager().queryIntentActivities(shareIntent, 0);
        if (AndroidUtils.isGoogleTV(getApplicationContext())
            || relevantActivities == null
            || relevantActivities.size() == 0) {
          Log.i(
              LOG_PREFIX,
              "No activity found that can handle image/jpg. Performing simple text share");
          Intent backupShareIntent = new Intent();
          backupShareIntent.setAction(Intent.ACTION_SEND);
          backupShareIntent.setType("text/plain");
          String backupSharedText = slideshowPhoto.getLargePhoto() + "\n\n" + sharedText;
          backupShareIntent.putExtra(Intent.EXTRA_TEXT, backupSharedText);
          startActivity(backupShareIntent);
        } else {
          startActivity(shareIntent);
        }

      } catch (ActivityNotFoundException e) {
        notifyUser("Unable to share current photo");
      }

    } else {
      notifyUser("Unable to share current photo");
    }
  }
  /**
   * Called when the list of all photos have been downloaded from backend
   *
   * @param slideShowPhotos Photos in the feed, may not exist in cache yet
   */
  private void actionOnPhotoUrlsDownloaded(List<SlideshowPhoto> slideShowPhotos) {
    Log.i(LOG_PREFIX, "Photo gallery definition downloaded, now looking through the results");

    // Let's add the existing one to the adapter immediately, and send the other to the
    // FileDownloader
    ArrayList<DownloadableObject> notCachedPhotos = new ArrayList<DownloadableObject>(100);
    ArrayList<SlideshowPhoto> cachedPhotos = new ArrayList<SlideshowPhoto>(200);

    for (Iterator<SlideshowPhoto> iterator = slideShowPhotos.iterator(); iterator.hasNext(); ) {
      SlideshowPhoto slideshowPhoto = iterator.next();
      if (slideshowPhoto.isCacheExisting(rootFileDirectory)) {
        cachedPhotos.add(slideshowPhoto);
      } else {
        notCachedPhotos.add(slideshowPhoto);
      }
    }

    if (cachedPhotos.size() > 0) {
      // lets randomize all the cached photos
      long seed = System.nanoTime();
      Collections.shuffle(cachedPhotos, new Random(seed));

      addSlideshowPhoto(cachedPhotos);
    }

    if (notCachedPhotos.size() > 0) {
      // Rules for download
      // 1. Never download on roaming
      if (AndroidUtils.isConnectedRoaming(getApplicationContext())) {
        notifyUser(getString(R.string.msg_connected_roaming));
        return;
      }

      boolean connectOn3G = SlideshowPreferences.doDownloadOn3G(getApplicationContext());
      boolean isConnectedToWifi = AndroidUtils.isConnectedToWifi(getApplicationContext());
      boolean isConnectedToWired = AndroidUtils.isConnectedToWired(getApplicationContext());
      // 2. Do not download if not connected to Wifi and user has not changed connect to Wifi
      // setting
      if (isConnectedToWifi == false && isConnectedToWired == false && connectOn3G == false) {
        if (AndroidUtils.isGoogleTV(getApplicationContext())) {
          String msg =
              "On GoogleTV, but not connected to wifi or wired. Ignoring this. WifiCon="
                  + isConnectedToWifi
                  + " WiredCon="
                  + isConnectedToWired;
          Log.w(LOG_PREFIX, msg);
          isConnectedToWifi = true;
        } else {
          notifyUser(getString(R.string.msg_connected_mobile));
        }
      }

      // 3. Connect if on wifi or if not connected to wifi and wifi setting is changed
      if ((isConnectedToWifi == true || isConnectedToWired == true) || connectOn3G == true) {
        Log.i(
            LOG_PREFIX,
            "Downloading photos. ConnectedToWifi="
                + isConnectedToWifi
                + " ConnectOn3G="
                + connectOn3G);

        // lets randomize all the non-cached photos
        long seed = System.nanoTime();
        Collections.shuffle(notCachedPhotos, new Random(seed));
        fileDownloader =
            new FileDownloader(this.getBaseContext(), this, rootFileDirectory, notCachedPhotos);
        fileDownloader.execute();
      }

    } else {
      Log.i(LOG_PREFIX, "No new photos to download");
    }
  }