Search in sources :

Example 1 with PendingDownload

use of net.rdrei.android.scdl2.api.PendingDownload in project scdl by passy.

the class ShareIntentResolver method resolvePendingDownload.

/**
	 * Resolves the intent to a PendingDownload describing the ID and type of the download.
	 *
	 * @return PendingDownload containing the resolved track or playlist ID together with its type.
	 * @throws ShareIntentResolverException
	 */
public PendingDownload resolvePendingDownload() throws ShareIntentResolverException {
    final String id;
    final String url = resolve();
    final Matcher idMatcher = URL_ID_PATTERN.matcher(url);
    final Matcher playlistMatcher = URL_PLAYLIST_PATTERN.matcher(url);
    if (!Config.Features.PLAYLIST_DOWNLOADS && playlistMatcher.find()) {
        throw new UnsupportedPlaylistUrlException(mActivity.getString(R.string.track_error_unsupported_playlist));
    }
    if (idMatcher.find()) {
        id = idMatcher.group(1);
    } else {
        throw new ShareIntentResolverException(String.format("Could not parse ID from URL '%s'.", url));
    }
    return new PendingDownload(id, MediaDownloadType.TRACK);
}
Also used : PendingDownload(net.rdrei.android.scdl2.api.PendingDownload) Matcher(java.util.regex.Matcher)

Example 2 with PendingDownload

use of net.rdrei.android.scdl2.api.PendingDownload in project scdl by passy.

the class AbstractMediaStateLoaderTaskTest method testCallForPlayList.

@Test
public void testCallForPlayList() throws Exception {
    final PendingDownload pendingDownload = new PendingDownload("1234", MediaDownloadType.PLAYLIST);
    final AbstractMediaStateLoaderTask task = new AbstractMediaStateLoaderTask(mContext, pendingDownload);
    task.call();
    verify(mPlaylistService).getPlaylist("1234");
    verifyZeroInteractions(mTrackService);
}
Also used : PendingDownload(net.rdrei.android.scdl2.api.PendingDownload) AbstractMediaStateLoaderTask(net.rdrei.android.scdl2.ui.AbstractMediaStateLoaderTask) Test(org.junit.Test)

Example 3 with PendingDownload

use of net.rdrei.android.scdl2.api.PendingDownload in project scdl by passy.

the class ShareIntentResolverTest method testResolveSoundcloudDataUrlToId.

@Test
public void testResolveSoundcloudDataUrlToId() throws ShareIntentResolverException {
    ShadowIntent intent = Robolectric.shadowOf(mIntent);
    intent.setData(Uri.parse("soundcloud://tracks/76738498"));
    final ShareIntentResolver resolver = TestHelper.getInjector().getInstance(ShareIntentResolver.class);
    final PendingDownload result = resolver.resolvePendingDownload();
    assertThat(result.getId(), equalTo("76738498"));
    assertThat(result.getType(), equalTo(MediaDownloadType.TRACK));
}
Also used : ShadowIntent(org.robolectric.shadows.ShadowIntent) PendingDownload(net.rdrei.android.scdl2.api.PendingDownload) ShareIntentResolver(net.rdrei.android.scdl2.ShareIntentResolver) Test(org.junit.Test)

Example 4 with PendingDownload

use of net.rdrei.android.scdl2.api.PendingDownload in project scdl by passy.

the class ShareIntentResolverTest method testResolveToId.

@Test
public void testResolveToId() throws ShareIntentResolverException {
    ShadowIntent intent = Robolectric.shadowOf(mIntent);
    intent.setData(Uri.parse("https://soundcloud.com/dj-newklear/newklear-contaminated-2"));
    final ShareIntentResolver resolver = TestHelper.getInjector().getInstance(ShareIntentResolver.class);
    final PendingDownload result = resolver.resolvePendingDownload();
    assertThat(result.getId(), equalTo("44276907"));
    assertThat(result.getType(), equalTo(MediaDownloadType.TRACK));
}
Also used : ShadowIntent(org.robolectric.shadows.ShadowIntent) PendingDownload(net.rdrei.android.scdl2.api.PendingDownload) ShareIntentResolver(net.rdrei.android.scdl2.ShareIntentResolver) Test(org.junit.Test)

Example 5 with PendingDownload

use of net.rdrei.android.scdl2.api.PendingDownload in project scdl by passy.

the class ShareIntentResolverTest method testNoSslResolveToId.

@Test
public void testNoSslResolveToId() throws ShareIntentResolverException {
    ShadowIntent intent = Robolectric.shadowOf(mIntent);
    intent.setData(Uri.parse("http://soundcloud.com/dj-newklear/newklear-contaminated-2"));
    final ShareIntentResolver resolver = TestHelper.getInjector().getInstance(ShareIntentResolver.class);
    final PendingDownload result = resolver.resolvePendingDownload();
    assertThat(result.getId(), equalTo("44276907"));
    assertThat(result.getType(), equalTo(MediaDownloadType.TRACK));
}
Also used : ShadowIntent(org.robolectric.shadows.ShadowIntent) PendingDownload(net.rdrei.android.scdl2.api.PendingDownload) ShareIntentResolver(net.rdrei.android.scdl2.ShareIntentResolver) Test(org.junit.Test)

Aggregations

PendingDownload (net.rdrei.android.scdl2.api.PendingDownload)6 Test (org.junit.Test)5 ShareIntentResolver (net.rdrei.android.scdl2.ShareIntentResolver)3 ShadowIntent (org.robolectric.shadows.ShadowIntent)3 AbstractMediaStateLoaderTask (net.rdrei.android.scdl2.ui.AbstractMediaStateLoaderTask)2 Matcher (java.util.regex.Matcher)1