예제 #1
0
  public void download(Context context, final Episode episode) {
    final Context applicationContext = context.getApplicationContext();
    try {
      Uri enclosure = episode.getEnclosure();
      if (enclosure == null) {
        return;
      }

      URL url = new URL(enclosure.toString());
      HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
      NetworkUtils.setUserAgent(context, urlConnection);
      String mediaLocalPath =
          MediaFileManager.saveMediaToFile(
              applicationContext, urlConnection.getInputStream(), episode);
      if (TextUtils.isEmpty(mediaLocalPath)) {
        Log.e(TAG, "Download failed: " + episode.getEnclosure());
      } else {
        episode.insertMediaLocalPath(mediaLocalPath);
      }
    } catch (MalformedURLException e) {
      Log.e(TAG, "Download failed: " + episode.getEnclosure(), e);
    } catch (IOException e) {
      Log.e(TAG, "Download failed: " + episode.getEnclosure(), e);
    }
  }
예제 #2
0
  public void testIsSameId() {
    Episode episode1 = Factory.build(Episode.class, "episode1");
    Episode episode2 = Factory.build(Episode.class, "episode2");
    Episode episode3 = Factory.build(Episode.class, "episode3");

    assertTrue(episode1.isSameEpisode(episode2));
    assertFalse(episode1.isSameEpisode(episode3));
    assertFalse(episode2.isSameEpisode(episode3));
  }