Ejemplo n.º 1
0
 public synchronized String getFeedfileName(Feed feed) {
   String filename = feed.getDownload_url();
   if (feed.getTitle() != null && !feed.getTitle().isEmpty()) {
     filename = feed.getTitle();
   }
   return "feed-" + FileNameGenerator.generateFileName(filename);
 }
Ejemplo n.º 2
0
  private Feed queueTestSetupMultipleItems(final int NUM_ITEMS)
      throws InterruptedException, ExecutionException, TimeoutException {
    final Context context = getInstrumentation().getTargetContext();
    Feed feed = new Feed("url", null, "title");
    feed.setItems(new ArrayList<>());
    for (int i = 0; i < NUM_ITEMS; i++) {
      FeedItem item =
          new FeedItem(0, "title " + i, "id " + i, "link " + i, new Date(), FeedItem.PLAYED, feed);
      feed.getItems().add(item);
    }

    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    adapter.close();

    for (FeedItem item : feed.getItems()) {
      assertTrue(item.getId() != 0);
    }
    List<Future<?>> futures = new ArrayList<>();
    for (FeedItem item : feed.getItems()) {
      futures.add(DBWriter.addQueueItem(context, item));
    }
    for (Future<?> f : futures) {
      f.get(TIMEOUT, TimeUnit.SECONDS);
    }
    return feed;
  }
Ejemplo n.º 3
0
  public void testSetFeedMediaPlaybackInformation()
      throws IOException, ExecutionException, InterruptedException, TimeoutException {
    final int POSITION = 50;
    final long LAST_PLAYED_TIME = 1000;
    final int PLAYED_DURATION = 60;
    final int DURATION = 100;

    Feed feed = new Feed("url", null, "title");
    List<FeedItem> items = new ArrayList<>();
    feed.setItems(items);
    FeedItem item = new FeedItem(0, "Item", "Item", "url", new Date(), FeedItem.PLAYED, feed);
    items.add(item);
    FeedMedia media =
        new FeedMedia(
            0, item, DURATION, 1, 1, "mime_type", "dummy path", "download_url", true, null, 0, 0);
    item.setMedia(media);

    DBWriter.setFeedItem(item).get(TIMEOUT, TimeUnit.SECONDS);

    media.setPosition(POSITION);
    media.setLastPlayedTime(LAST_PLAYED_TIME);
    media.setPlayedDuration(PLAYED_DURATION);

    DBWriter.setFeedMediaPlaybackInformation(item.getMedia()).get(TIMEOUT, TimeUnit.SECONDS);

    FeedItem itemFromDb = DBReader.getFeedItem(item.getId());
    FeedMedia mediaFromDb = itemFromDb.getMedia();

    assertEquals(POSITION, mediaFromDb.getPosition());
    assertEquals(LAST_PLAYED_TIME, mediaFromDb.getLastPlayedTime());
    assertEquals(PLAYED_DURATION, mediaFromDb.getPlayedDuration());
    assertEquals(DURATION, mediaFromDb.getDuration());
  }
Ejemplo n.º 4
0
  public void testMarkAllItemsReadSameFeed()
      throws InterruptedException, ExecutionException, TimeoutException {
    final int NUM_ITEMS = 10;
    Feed feed = new Feed("url", null, "title");
    feed.setItems(new ArrayList<>());
    for (int i = 0; i < NUM_ITEMS; i++) {
      FeedItem item =
          new FeedItem(
              0, "title " + i, "id " + i, "link " + i, new Date(), FeedItem.UNPLAYED, feed);
      feed.getItems().add(item);
    }

    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    adapter.close();

    assertTrue(feed.getId() != 0);
    for (FeedItem item : feed.getItems()) {
      assertTrue(item.getId() != 0);
    }

    DBWriter.markAllItemsRead().get(TIMEOUT, TimeUnit.SECONDS);
    List<FeedItem> loadedItems = DBReader.getFeedItemList(feed);
    for (FeedItem item : loadedItems) {
      assertTrue(item.isPlayed());
    }
  }
Ejemplo n.º 5
0
  public void testAddQueueItemSingleItemAlreadyInQueue()
      throws InterruptedException, ExecutionException, TimeoutException {
    final Context context = getInstrumentation().getTargetContext();
    Feed feed = new Feed("url", null, "title");
    feed.setItems(new ArrayList<>());
    FeedItem item = new FeedItem(0, "title", "id", "link", new Date(), FeedItem.PLAYED, feed);
    feed.getItems().add(item);

    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    adapter.close();

    assertTrue(item.getId() != 0);
    DBWriter.addQueueItem(context, item).get(TIMEOUT, TimeUnit.SECONDS);

    adapter = PodDBAdapter.getInstance();
    adapter.open();
    Cursor cursor = adapter.getQueueIDCursor();
    assertTrue(cursor.moveToFirst());
    assertTrue(cursor.getLong(0) == item.getId());
    cursor.close();
    adapter.close();

    DBWriter.addQueueItem(context, item).get(TIMEOUT, TimeUnit.SECONDS);
    adapter = PodDBAdapter.getInstance();
    adapter.open();
    cursor = adapter.getQueueIDCursor();
    assertTrue(cursor.moveToFirst());
    assertTrue(cursor.getLong(0) == item.getId());
    assertTrue(cursor.getCount() == 1);
    cursor.close();
    adapter.close();
  }
 private boolean feedInFeedlist(Feed feed) {
   if (feeds == null || feed == null) return false;
   for (Feed f : feeds) {
     if (f.getIdentifyingValue().equals(feed.getIdentifyingValue())) {
       return true;
     }
   }
   return false;
 }
Ejemplo n.º 7
0
  public void testDeleteFeedNoFeedMedia()
      throws IOException, ExecutionException, InterruptedException, TimeoutException {
    File destFolder = getInstrumentation().getTargetContext().getExternalFilesDir(TEST_FOLDER);
    assertNotNull(destFolder);

    Feed feed = new Feed("url", null, "title");
    feed.setItems(new ArrayList<>());

    // create Feed image
    File imgFile = new File(destFolder, "image");
    assertTrue(imgFile.createNewFile());
    FeedImage image = new FeedImage(0, "image", imgFile.getAbsolutePath(), "url", true);
    image.setOwner(feed);
    feed.setImage(image);

    // create items
    for (int i = 0; i < 10; i++) {
      FeedItem item =
          new FeedItem(0, "Item " + i, "Item" + i, "url", new Date(), FeedItem.PLAYED, feed);
      feed.getItems().add(item);
    }

    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    adapter.close();

    assertTrue(feed.getId() != 0);
    assertTrue(feed.getImage().getId() != 0);
    for (FeedItem item : feed.getItems()) {
      assertTrue(item.getId() != 0);
    }

    DBWriter.deleteFeed(getInstrumentation().getTargetContext(), feed.getId())
        .get(TIMEOUT, TimeUnit.SECONDS);

    // check if files still exist
    assertFalse(imgFile.exists());

    adapter = PodDBAdapter.getInstance();
    adapter.open();
    Cursor c = adapter.getFeedCursor(feed.getId());
    assertTrue(c.getCount() == 0);
    c.close();
    c = adapter.getImageCursor(String.valueOf(image.getId()));
    assertTrue(c.getCount() == 0);
    c.close();
    for (FeedItem item : feed.getItems()) {
      c = adapter.getFeedItemCursor(String.valueOf(item.getId()));
      assertTrue(c.getCount() == 0);
      c.close();
    }
    adapter.close();
  }
Ejemplo n.º 8
0
 private FeedMedia playbackHistorySetup(Date playbackCompletionDate) {
   final Context context = getInstrumentation().getTargetContext();
   Feed feed = new Feed("url", null, "title");
   feed.setItems(new ArrayList<FeedItem>());
   FeedItem item = new FeedItem(0, "title", "id", "link", new Date(), FeedItem.PLAYED, feed);
   FeedMedia media =
       new FeedMedia(0, item, 10, 0, 1, "mime", null, "url", false, playbackCompletionDate, 0, 0);
   feed.getItems().add(item);
   item.setMedia(media);
   PodDBAdapter adapter = PodDBAdapter.getInstance();
   adapter.open();
   adapter.setCompleteFeed(feed);
   adapter.close();
   assertTrue(media.getId() != 0);
   return media;
 }
Ejemplo n.º 9
0
  public void testDeleteFeedMediaOfItemFileExists()
      throws IOException, ExecutionException, InterruptedException, TimeoutException {
    File dest =
        new File(
            getInstrumentation().getTargetContext().getExternalFilesDir(TEST_FOLDER), "testFile");

    assertTrue(dest.createNewFile());

    Feed feed = new Feed("url", null, "title");
    List<FeedItem> items = new ArrayList<>();
    feed.setItems(items);
    FeedItem item = new FeedItem(0, "Item", "Item", "url", new Date(), FeedItem.PLAYED, feed);

    FeedMedia media =
        new FeedMedia(
            0,
            item,
            1,
            1,
            1,
            "mime_type",
            dest.getAbsolutePath(),
            "download_url",
            true,
            null,
            0,
            0);
    item.setMedia(media);

    items.add(item);

    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    adapter.close();
    assertTrue(media.getId() != 0);
    assertTrue(item.getId() != 0);

    DBWriter.deleteFeedMediaOfItem(getInstrumentation().getTargetContext(), media.getId())
        .get(TIMEOUT, TimeUnit.SECONDS);
    media = DBReader.getFeedMedia(media.getId());
    assertNotNull(media);
    assertFalse(dest.exists());
    assertFalse(media.isDownloaded());
    assertNull(media.getFile_url());
  }
  @Override
  protected void beforeShowFeedInformation(Feed feed, Map<String, String> alternateFeedUrls) {
    super.beforeShowFeedInformation(feed, alternateFeedUrls);

    // remove HTML tags from descriptions

    if (BuildConfig.DEBUG) Log.d(TAG, "Removing HTML from shownotes");
    if (feed.getItems() != null) {
      HtmlToPlainText formatter = new HtmlToPlainText();
      for (FeedItem item : feed.getItems()) {
        if (item.getDescription() != null) {
          Document description = Jsoup.parse(item.getDescription());
          item.setDescription(StringUtils.trim(formatter.getPlainText(description)));
        }
      }
    }
  }
Ejemplo n.º 11
0
 public boolean compareWithOther(Feed other) {
   if (super.compareWithOther(other)) {
     return true;
   }
   if (!title.equals(other.title)) {
     return true;
   }
   if (other.feedIdentifier != null) {
     if (feedIdentifier == null || !feedIdentifier.equals(other.feedIdentifier)) {
       return true;
     }
   }
   if (other.link != null) {
     if (link == null || !link.equals(other.link)) {
       return true;
     }
   }
   if (other.description != null) {
     if (description == null || !description.equals(other.description)) {
       return true;
     }
   }
   if (other.language != null) {
     if (language == null || !language.equals(other.language)) {
       return true;
     }
   }
   if (other.author != null) {
     if (author == null || !author.equals(other.author)) {
       return true;
     }
   }
   if (other.paymentLink != null) {
     if (paymentLink == null || !paymentLink.equals(other.paymentLink)) {
       return true;
     }
   }
   if (other.isPaged() && !this.isPaged()) {
     return true;
   }
   if (!StringUtils.equals(other.getNextPageLink(), this.getNextPageLink())) {
     return true;
   }
   return false;
 }
Ejemplo n.º 12
0
  /**
   * Downloads a feed
   *
   * @param context The application's environment.
   * @param feed Feed to download
   * @param loadAllPages Set to true to download all pages
   */
  public synchronized void downloadFeed(Context context, Feed feed, boolean loadAllPages)
      throws DownloadRequestException {
    if (feedFileValid(feed)) {
      String username =
          (feed.getPreferences() != null) ? feed.getPreferences().getUsername() : null;
      String password =
          (feed.getPreferences() != null) ? feed.getPreferences().getPassword() : null;
      long ifModifiedSince = feed.isPaged() ? 0 : feed.getLastUpdate().getTime();

      Bundle args = new Bundle();
      args.putInt(REQUEST_ARG_PAGE_NR, feed.getPageNr());
      args.putBoolean(REQUEST_ARG_LOAD_ALL_PAGES, loadAllPages);

      download(
          context,
          feed,
          null,
          new File(getFeedfilePath(context), getFeedfileName(feed)),
          true,
          username,
          password,
          ifModifiedSince,
          true,
          args);
    }
  }
Ejemplo n.º 13
0
  public void testAddQueueItemMultipleItems()
      throws InterruptedException, ExecutionException, TimeoutException {
    final Context context = getInstrumentation().getTargetContext();
    final int NUM_ITEMS = 10;

    Feed feed = queueTestSetupMultipleItems(NUM_ITEMS);
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    Cursor cursor = adapter.getQueueIDCursor();
    assertTrue(cursor.moveToFirst());
    assertTrue(cursor.getCount() == NUM_ITEMS);
    for (int i = 0; i < NUM_ITEMS; i++) {
      assertTrue(cursor.moveToPosition(i));
      assertTrue(cursor.getLong(0) == feed.getItems().get(i).getId());
    }
    cursor.close();
    adapter.close();
  }
 private void setSubscribeButtonState(Feed feed) {
   if (subscribeButton != null && feed != null) {
     if (DownloadRequester.getInstance().isDownloadingFile(feed.getDownload_url())) {
       subscribeButton.setEnabled(false);
       subscribeButton.setText(R.string.downloading_label);
     } else if (feedInFeedlist(feed)) {
       subscribeButton.setEnabled(false);
       subscribeButton.setText(R.string.subscribed_label);
     } else {
       subscribeButton.setEnabled(true);
       subscribeButton.setText(R.string.subscribe_label);
     }
   }
 }
Ejemplo n.º 15
0
  public synchronized void downloadMedia(Context context, FeedMedia feedmedia)
      throws DownloadRequestException {
    if (feedFileValid(feedmedia)) {
      Feed feed = feedmedia.getItem().getFeed();
      String username;
      String password;
      if (feed != null && feed.getPreferences() != null) {
        username = feed.getPreferences().getUsername();
        password = feed.getPreferences().getPassword();
      } else {
        username = null;
        password = null;
      }

      File dest;
      if (feedmedia.getFile_url() != null) {
        dest = new File(feedmedia.getFile_url());
      } else {
        dest = new File(getMediafilePath(context, feedmedia), getMediafilename(feedmedia));
      }
      download(context, feedmedia, feed, dest, false, username, password, 0, false, null);
    }
  }
Ejemplo n.º 16
0
  public void testRemoveQueueItem()
      throws InterruptedException, ExecutionException, TimeoutException {
    final int NUM_ITEMS = 10;
    final Context context = getInstrumentation().getTargetContext();
    Feed feed = new Feed("url", null, "title");
    feed.setItems(new ArrayList<>());
    for (int i = 0; i < NUM_ITEMS; i++) {
      FeedItem item =
          new FeedItem(0, "title " + i, "id " + i, "link " + i, new Date(), FeedItem.PLAYED, feed);
      feed.getItems().add(item);
    }

    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    adapter.close();

    for (FeedItem item : feed.getItems()) {
      assertTrue(item.getId() != 0);
    }
    for (int removeIndex = 0; removeIndex < NUM_ITEMS; removeIndex++) {
      final FeedItem item = feed.getItems().get(removeIndex);
      adapter = PodDBAdapter.getInstance();
      adapter.open();
      adapter.setQueue(feed.getItems());
      adapter.close();

      DBWriter.removeQueueItem(context, item, false).get(TIMEOUT, TimeUnit.SECONDS);
      adapter = PodDBAdapter.getInstance();
      adapter.open();
      Cursor queue = adapter.getQueueIDCursor();
      assertTrue(queue.getCount() == NUM_ITEMS - 1);
      for (int i = 0; i < queue.getCount(); i++) {
        assertTrue(queue.moveToPosition(i));
        final long queueID = queue.getLong(0);
        assertTrue(queueID != item.getId()); // removed item is no longer in queue
        boolean idFound = false;
        for (FeedItem other :
            feed.getItems()) { // items that were not removed are still in the queue
          idFound = idFound | (other.getId() == queueID);
        }
        assertTrue(idFound);
      }
      queue.close();
      adapter.close();
    }
  }
Ejemplo n.º 17
0
  public void testMoveQueueItem()
      throws InterruptedException, ExecutionException, TimeoutException {
    final int NUM_ITEMS = 10;
    Feed feed = new Feed("url", null, "title");
    feed.setItems(new ArrayList<>());
    for (int i = 0; i < NUM_ITEMS; i++) {
      FeedItem item =
          new FeedItem(0, "title " + i, "id " + i, "link " + i, new Date(), FeedItem.PLAYED, feed);
      feed.getItems().add(item);
    }

    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    adapter.close();

    for (FeedItem item : feed.getItems()) {
      assertTrue(item.getId() != 0);
    }
    for (int from = 0; from < NUM_ITEMS; from++) {
      for (int to = 0; to < NUM_ITEMS; to++) {
        if (from == to) {
          continue;
        }
        Log.d(TAG, String.format("testMoveQueueItem: From=%d, To=%d", from, to));
        final long fromID = feed.getItems().get(from).getId();

        adapter = PodDBAdapter.getInstance();
        adapter.open();
        adapter.setQueue(feed.getItems());
        adapter.close();

        DBWriter.moveQueueItem(from, to, false).get(TIMEOUT, TimeUnit.SECONDS);
        adapter = PodDBAdapter.getInstance();
        adapter.open();
        Cursor queue = adapter.getQueueIDCursor();
        assertTrue(queue.getCount() == NUM_ITEMS);
        assertTrue(queue.moveToPosition(from));
        assertFalse(queue.getLong(0) == fromID);
        assertTrue(queue.moveToPosition(to));
        assertTrue(queue.getLong(0) == fromID);

        queue.close();
        adapter.close();
      }
    }
  }
  @Override
  protected void showFeedInformation(final Feed feed, final Map<String, String> alternateFeedUrls) {
    super.showFeedInformation(feed, alternateFeedUrls);
    setContentView(R.layout.listview_activity);

    this.feed = feed;
    this.selectedDownloadUrl = feed.getDownload_url();
    EventDistributor.getInstance().register(listener);
    ListView listView = (ListView) findViewById(R.id.listview);
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View header = inflater.inflate(R.layout.onlinefeedview_header, listView, false);
    listView.addHeaderView(header);

    listView.setAdapter(new FeedItemlistDescriptionAdapter(this, 0, feed.getItems()));

    ImageView cover = (ImageView) header.findViewById(R.id.imgvCover);
    TextView title = (TextView) header.findViewById(R.id.txtvTitle);
    TextView author = (TextView) header.findViewById(R.id.txtvAuthor);
    TextView description = (TextView) header.findViewById(R.id.txtvDescription);
    Spinner spAlternateUrls = (Spinner) header.findViewById(R.id.spinnerAlternateUrls);

    subscribeButton = (Button) header.findViewById(R.id.butSubscribe);

    if (feed.getImage() != null && StringUtils.isNotBlank(feed.getImage().getDownload_url())) {
      Glide.with(this)
          .load(feed.getImage().getDownload_url())
          .placeholder(R.color.light_gray)
          .error(R.color.light_gray)
          .diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
          .fitCenter()
          .dontAnimate()
          .into(cover);
    }

    title.setText(feed.getTitle());
    author.setText(feed.getAuthor());
    description.setText(feed.getDescription());

    subscribeButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            try {
              Feed f = new Feed(selectedDownloadUrl, new Date(0), feed.getTitle());
              f.setPreferences(feed.getPreferences());
              DefaultOnlineFeedViewActivity.this.feed = f;

              DownloadRequester.getInstance().downloadFeed(DefaultOnlineFeedViewActivity.this, f);
            } catch (DownloadRequestException e) {
              e.printStackTrace();
              DownloadRequestErrorDialogCreator.newRequestErrorDialog(
                  DefaultOnlineFeedViewActivity.this, e.getMessage());
            }
            setSubscribeButtonState(feed);
          }
        });

    if (alternateFeedUrls.isEmpty()) {
      spAlternateUrls.setVisibility(View.GONE);
    } else {
      spAlternateUrls.setVisibility(View.VISIBLE);

      final List<String> alternateUrlsList = new ArrayList<String>();
      final List<String> alternateUrlsTitleList = new ArrayList<String>();

      alternateUrlsList.add(feed.getDownload_url());
      alternateUrlsTitleList.add(feed.getTitle());

      alternateUrlsList.addAll(alternateFeedUrls.keySet());
      for (String url : alternateFeedUrls.keySet()) {
        alternateUrlsTitleList.add(alternateFeedUrls.get(url));
      }
      ArrayAdapter<String> adapter =
          new ArrayAdapter<String>(
              this, android.R.layout.simple_spinner_item, alternateUrlsTitleList);
      adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      spAlternateUrls.setAdapter(adapter);
      spAlternateUrls.setOnItemSelectedListener(
          new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
              selectedDownloadUrl = alternateUrlsList.get(position);
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {}
          });
    }
    setSubscribeButtonState(feed);
  }
Ejemplo n.º 19
0
  public void testDeleteFeedNoDownloadedFiles()
      throws ExecutionException, InterruptedException, TimeoutException {
    File destFolder = getInstrumentation().getTargetContext().getExternalFilesDir(TEST_FOLDER);
    assertNotNull(destFolder);

    Feed feed = new Feed("url", null, "title");
    feed.setItems(new ArrayList<>());

    // create Feed image
    File imgFile = new File(destFolder, "image");
    FeedImage image = new FeedImage(0, "image", imgFile.getAbsolutePath(), "url", true);
    image.setOwner(feed);
    feed.setImage(image);

    List<File> itemFiles = new ArrayList<>();
    // create items with downloaded media files
    for (int i = 0; i < 10; i++) {
      FeedItem item =
          new FeedItem(0, "Item " + i, "Item" + i, "url", new Date(), FeedItem.PLAYED, feed);
      feed.getItems().add(item);

      File enc = new File(destFolder, "file " + i);
      itemFiles.add(enc);

      FeedMedia media =
          new FeedMedia(
              0,
              item,
              1,
              1,
              1,
              "mime_type",
              enc.getAbsolutePath(),
              "download_url",
              false,
              null,
              0,
              0);
      item.setMedia(media);
    }

    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    adapter.close();

    assertTrue(feed.getId() != 0);
    assertTrue(feed.getImage().getId() != 0);
    for (FeedItem item : feed.getItems()) {
      assertTrue(item.getId() != 0);
      assertTrue(item.getMedia().getId() != 0);
    }

    DBWriter.deleteFeed(getInstrumentation().getTargetContext(), feed.getId())
        .get(TIMEOUT, TimeUnit.SECONDS);

    adapter = PodDBAdapter.getInstance();
    adapter.open();
    Cursor c = adapter.getFeedCursor(feed.getId());
    assertTrue(c.getCount() == 0);
    c.close();
    c = adapter.getImageCursor(String.valueOf(image.getId()));
    assertTrue(c.getCount() == 0);
    c.close();
    for (FeedItem item : feed.getItems()) {
      c = adapter.getFeedItemCursor(String.valueOf(item.getId()));
      assertTrue(c.getCount() == 0);
      c.close();
      c = adapter.getSingleFeedMediaCursor(item.getMedia().getId());
      assertTrue(c.getCount() == 0);
      c.close();
    }
    adapter.close();
  }