kaaes.spotify.webapi.android.models.Track Java Examples

The following examples show how to use kaaes.spotify.webapi.android.models.Track. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpotifyPresenterImpl.java    From mirror with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void onViewResume(View view) {
    super.onViewResume(view);

    final List<String> trackIds = (List<String>) getParams().get(TRACK_IDS);
    mSpotifyManger.play(trackIds, new SpotifyManager.Listener() {
        @Override
        public void onTrackUpdate(Track track) {
            mView.updateTrack(track);
        }

        @Override
        public void onPlaylistEnd() {
            mEventManager.post(new ResetEvent(SpotifyPresenter.class));
        }
    });
}
 
Example #2
Source File: SearchResultsAdapter.java    From spotify-web-api-android with MIT License 6 votes vote down vote up
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    Track item = mItems.get(position);

    holder.title.setText(item.name);

    List<String> names = new ArrayList<>();
    for (ArtistSimple i : item.artists) {
        names.add(i.name);
    }
    Joiner joiner = Joiner.on(", ");
    holder.subtitle.setText(joiner.join(names));

    Image image = item.album.images.get(0);
    if (image != null) {
        Picasso.with(mContext).load(image.url).into(holder.image);
    }
}
 
Example #3
Source File: SearchPresenter.java    From spotify-web-api-android with MIT License 6 votes vote down vote up
@Override
public void selectTrack(Track item) {
    String previewUrl = item.preview_url;

    if (previewUrl == null) {
        logMessage("Track doesn't have a preview");
        return;
    }

    if (mPlayer == null) return;

    String currentTrackUrl = mPlayer.getCurrentTrack();

    if (currentTrackUrl == null || !currentTrackUrl.equals(previewUrl)) {
        mPlayer.play(previewUrl);
    } else if (mPlayer.isPlaying()) {
        mPlayer.pause();
    } else {
        mPlayer.resume();
    }
}
 
Example #4
Source File: SearchPresenter.java    From spotify-web-api-android with MIT License 6 votes vote down vote up
@Override
public void search(@Nullable String searchQuery) {
    if (searchQuery != null && !searchQuery.isEmpty() && !searchQuery.equals(mCurrentQuery)) {
        logMessage("query text submit " + searchQuery);
        mCurrentQuery = searchQuery;
        mView.reset();
        mSearchListener = new SearchPager.CompleteListener() {
            @Override
            public void onComplete(List<Track> items) {
                mView.addData(items);
            }

            @Override
            public void onError(Throwable error) {
                logError(error.getMessage());
            }
        };
        mSearchPager.getFirstPage(searchQuery, PAGE_SIZE, mSearchListener);
    }
}
 
Example #5
Source File: Pasta.java    From Pasta-for-Spotify with Apache License 2.0 6 votes vote down vote up
@Nullable
public ArrayList<TrackListData> getTracks(ArtistListData data) throws InterruptedException {
    Tracks tracks = null;
    for (int i = 0; tracks == null && i < PreferenceUtils.getRetryCount(this); i++) {
        try {
            tracks = spotifyService.getArtistTopTrack(data.artistId, Locale.getDefault().getCountry());
        } catch (Exception e) {
            e.printStackTrace();
            if (StaticUtils.shouldResendRequest(e)) Thread.sleep(200);
            else break;
        }
    }
    if (tracks == null) return null;

    ArrayList<TrackListData> trackList = new ArrayList<>();
    for (Track track : tracks.tracks) {
        trackList.add(new TrackListData(track));
    }
    return trackList;
}
 
Example #6
Source File: TrackListData.java    From Pasta-for-Spotify with Apache License 2.0 6 votes vote down vote up
public TrackListData(final Track track) {
    this.trackName = track.name;
    this.albumName = track.album.name;
    this.albumId = track.album.id;
    if (track.album.images.size() > 0) {
        if (track.album.images.size() > 1) this.trackImage = track.album.images.get(1).url;
        else this.trackImage = track.album.images.get(0).url;
        this.trackImageLarge = track.album.images.get(0).url;
    } else {
        this.trackImage = "";
        this.trackImageLarge = "";
    }
    this.trackDuration = String.valueOf(track.duration_ms);

    artists = new ArrayList<>();
    for (ArtistSimple artist : track.artists) {
        artists.add(new ArtistListData(artist));
    }

    this.trackUri = track.uri;
    this.trackId = track.id;
}
 
Example #7
Source File: SearchPager.java    From android-spotify-demo with MIT License 5 votes vote down vote up
public void getMyTopTracks(final onCompleteTopTrackListener listener){
    Map<String, Object> options = new HashMap<>();
    options.put(SpotifyService.LIMIT, 10);

    final ListManager listManager = ListManager.getInstance();

    spotifyService.getTopTracks(options, new SpotifyCallback<Pager<Track>>() {
        @Override
        public void failure(SpotifyError spotifyError) {
            Log.d("SearchPager", spotifyError.toString());

            if(listener != null)
                listener.onError(spotifyError);
        }

        @Override
        public void success(Pager<Track> trackPager, Response response) {
            List<Track> tracks = trackPager.items;

            for(Track track : tracks){
                Log.d("SearchPager", track.album.name);
                Log.d("SearchPager", track.album.images.get(1).url);

                listManager.addTopTrack(new TopTrack(track.album.name, track.album.images.get(1).url));

            }

            if(listener != null)
                listener.onComplete();
        }
    });
}
 
Example #8
Source File: SpotifyServiceTest.java    From spotify-web-api-android with MIT License 5 votes vote down vote up
@Test
public void shouldGetTrackData() throws IOException {
    String body = TestUtils.readTestData("track.json");
    Track fixture = mGson.fromJson(body, Track.class);

    Response response = TestUtils.getResponseFromModel(fixture, Track.class);
    when(mMockClient.execute(argThat(new MatchesId(fixture.id)))).thenReturn(response);

    Track track = mSpotifyService.getTrack(fixture.id);
    this.compareJSONWithoutNulls(body, track);
}
 
Example #9
Source File: SpotifyServiceAndroidTest.java    From spotify-web-api-android with MIT License 5 votes vote down vote up
@Test
public void getUserTopTracks() throws Exception {
    Pager<Track> payload = mService.getTopTracks();

    Request request = new Request.Builder()
            .get()
            .headers(mAuthHeader)
            .url("https://api.spotify.com/v1/me/top/tracks")
            .build();

    Response response = mClient.newCall(request).execute();
    assertEquals(200, response.code());

    assertThat(payload, JsonEquals.jsonEquals(response.body().string()));
}
 
Example #10
Source File: SpotifyServiceAndroidTest.java    From spotify-web-api-android with MIT License 5 votes vote down vote up
@Test
public void getTrack() throws Exception {
    Track payload = mService.getTrack("6Fer9IcKzs4G3nu0MYQmn4");

    Request request = new Request.Builder()
            .get()
            .url("https://api.spotify.com/v1/tracks/6Fer9IcKzs4G3nu0MYQmn4")
            .build();

    Response response = mClient.newCall(request).execute();
    assertEquals(200, response.code());

    assertThat(payload, JsonEquals.jsonEquals(response.body().string()));
}
 
Example #11
Source File: SpotifyFragment.java    From mirror with Apache License 2.0 5 votes vote down vote up
@Override
public void updateTrack(Track track) {
    if (mCurrentTrack == null || !mCurrentTrack.id.equals(track.id)) {
        mCurrentTrack = track;

        mSongTextView.setText(track.name);
        mSingerTextView.setText(artistNames(track.artists));
        mMusicPlayerView.setCoverURL(track.album.images.get(0).url);
        mMusicPlayerView.setProgress(0);
        mMusicPlayerView.setMax((int) (track.duration_ms / 1000));
        mMusicPlayerView.start();
    }
}
 
Example #12
Source File: SpotifyTrackEvent.java    From mirror with Apache License 2.0 4 votes vote down vote up
public SpotifyTrackEvent(Track track) {
    this.track = track;
}
 
Example #13
Source File: SpotifyTrackEvent.java    From mirror with Apache License 2.0 4 votes vote down vote up
public Track getTrack() {
    return track;
}
 
Example #14
Source File: SpotifyManagerImpl.java    From mirror with Apache License 2.0 4 votes vote down vote up
@Override
public void success(Track track, Response response) {
    if (mListener != null && track != null) {
        mListener.onTrackUpdate(track);
    }
}
 
Example #15
Source File: SearchResultsAdapter.java    From spotify-web-api-android with MIT License 4 votes vote down vote up
public void addData(List<Track> items) {
    mItems.addAll(items);
    notifyDataSetChanged();
}
 
Example #16
Source File: MainActivity.java    From spotify-web-api-android with MIT License 4 votes vote down vote up
@Override
public void addData(List<Track> items) {
    mAdapter.addData(items);
}
 
Example #17
Source File: MainActivity.java    From spotify-web-api-android with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Intent intent = getIntent();
    String token = intent.getStringExtra(EXTRA_TOKEN);

    mActionListener = new SearchPresenter(this, this);
    mActionListener.init(token);

    // Setup search field
    final SearchView searchView = (SearchView) findViewById(R.id.search_view);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            mActionListener.search(query);
            searchView.clearFocus();
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }
    });


    // Setup search results list
    mAdapter = new SearchResultsAdapter(this, new SearchResultsAdapter.ItemSelectedListener() {
        @Override
        public void onItemSelected(View itemView, Track item) {
            mActionListener.selectTrack(item);
        }
    });

    RecyclerView resultsList = (RecyclerView) findViewById(R.id.search_results);
    resultsList.setHasFixedSize(true);
    resultsList.setLayoutManager(mLayoutManager);
    resultsList.setAdapter(mAdapter);
    resultsList.addOnScrollListener(mScrollListener);

    // If Activity was recreated wit active search restore it
    if (savedInstanceState != null) {
        String currentQuery = savedInstanceState.getString(KEY_CURRENT_QUERY);
        mActionListener.search(currentQuery);
    }
}
 
Example #18
Source File: SearchResultFragment.java    From android-spotify-demo with MIT License 4 votes vote down vote up
private void queryData(){

        mSearchListener = new SearchPager.CompleteListener() {
            @Override
            public void onComplete(List<Track> items) {

                listManager.clearList();

                for(Track track : items){
                    //Log.d(TAG, "success! link: " + track.uri);                      // music link
                    //Log.d(TAG, "success! title: " + track.name);                        // title
                    //Log.d(TAG, "success! album: " + track.album.name);                  // album name
                    //Log.d(TAG, "success! album img: " + track.album.images.get(0).url); // album image
                    //Log.d(TAG, "success! duration: " + track.duration_ms);             // song duration
                    //Log.d(TAG, "success! artists: " + track.artists.get(0).name);     // artists

                    Music music = new Music(
                            track.id,
                            track.uri,
                            track.name,
                            track.album.name,
                            track.album.images.get(0).url,
                            track.duration_ms,
                            track.artists.get(0).name,
                            track.artists.get(0).id
                            );

                    listManager.addTrack(music);
                }

                Log.d(TAG, "query finished! Updating view...");
                updateView();
            }

            @Override
            public void onError(Throwable error) {
                Log.d(TAG, error.getMessage());
            }
        };

        mSearchPager.getTracksFromSearch(query, mSearchListener);
    }
 
Example #19
Source File: ParcelableModelsTest.java    From spotify-web-api-android with MIT License 4 votes vote down vote up
ArrayList<Class<? extends Parcelable>> getModelClasses() {
    return Lists.newArrayList(
            Album.class,
            Albums.class,
            AlbumSimple.class,
            AlbumsPager.class,
            Artist.class,
            Artists.class,
            ArtistSimple.class,
            ArtistsPager.class,
            AudioFeaturesTrack.class,
            AudioFeaturesTracks.class,
            CategoriesPager.class,
            Category.class,
            Copyright.class,
            ErrorDetails.class,
            ErrorResponse.class,
            FeaturedPlaylists.class,
            Followers.class,
            Image.class,
            LinkedTrack.class,
            NewReleases.class,
            Playlist.class,
            PlaylistFollowPrivacy.class,
            PlaylistSimple.class,
            PlaylistsPager.class,
            PlaylistTrack.class,
            PlaylistTracksInformation.class,
            Recommendations.class,
            Result.class,
            Seed.class,
            SeedsGenres.class,
            SavedTrack.class,
            SnapshotId.class,
            Track.class,
            Tracks.class,
            TrackSimple.class,
            TracksPager.class,
            TrackToRemove.class,
            TrackToRemoveWithPosition.class,
            TracksToRemove.class,
            TracksToRemoveWithPosition.class,
            UserPrivate.class,
            UserPublic.class
    );
}
 
Example #20
Source File: SpotifyService.java    From spotify-web-api-android with MIT License 2 votes vote down vote up
/**
 * Get the current user’s top tracks based on calculated affinity.
 *
 * @param options Optional parameters. For list of available parameters see
 *                <a href="https://developer.spotify.com/web-api/get-users-top-artists-and-tracks/">endpoint documentation</a>
 * @return The objects whose response body contains an artists or tracks object.
 * The object in turn contains a paging object of Artists or Tracks
 */
@GET("/me/top/tracks")
Pager<Track> getTopTracks(@QueryMap Map<String, Object> options);
 
Example #21
Source File: SpotifyService.java    From spotify-web-api-android with MIT License 2 votes vote down vote up
/**
 * Get the current user’s top tracks based on calculated affinity.
 *
 * @param options  Optional parameters. For list of available parameters see
 *                 <a href="https://developer.spotify.com/web-api/get-users-top-artists-and-tracks/">endpoint documentation</a>
 * @param callback Callback method
 */
@GET("/me/top/tracks")
void getTopTracks(@QueryMap Map<String, Object> options, Callback<Pager<Track>> callback);
 
Example #22
Source File: SpotifyService.java    From spotify-web-api-android with MIT License 2 votes vote down vote up
/**
 * Get the current user’s top tracks based on calculated affinity.
 *
 * @param callback callback method
 */
@GET("/me/top/tracks")
void getTopTracks(Callback<Pager<Track>> callback);
 
Example #23
Source File: SpotifyService.java    From spotify-web-api-android with MIT License 2 votes vote down vote up
/**
 * Get the current user’s top tracks based on calculated affinity.
 *
 * @return The objects whose response body contains an artists or tracks object.
 * The object in turn contains a paging object of Artists or Tracks
 */
@GET("/me/top/tracks")
Pager<Track> getTopTracks();
 
Example #24
Source File: SpotifyService.java    From spotify-web-api-android with MIT License 2 votes vote down vote up
/**
 * Get Spotify catalog information for a single track identified by their unique Spotify ID.
 *
 * @param trackId The Spotify ID for the track.
 * @param options Optional parameters. For list of supported parameters see
 *                <a href="https://developer.spotify.com/web-api/get-track/">endpoint documentation</a>
 * @return Requested track information
 * @see <a href="https://developer.spotify.com/web-api/get-track/">Get a Track</a>
 */
@GET("/tracks/{id}")
Track getTrack(@Path("id") String trackId, @QueryMap Map<String, Object> options);
 
Example #25
Source File: SpotifyService.java    From spotify-web-api-android with MIT License 2 votes vote down vote up
/**
 * Get Spotify catalog information about an album’s tracks.
 *
 * @param albumId  The Spotify ID for the album.
 * @param options  Optional parameters. For list of supported parameters see
 *                 <a href="https://developer.spotify.com/web-api/get-albums-tracks/">endpoint documentation</a>
 * @param callback Callback method
 * @see <a href="https://developer.spotify.com/web-api/get-albums-tracks/">Get an Album’s Tracks</a>
 */
@GET("/albums/{id}/tracks")
void getAlbumTracks(@Path("id") String albumId, @QueryMap Map<String, Object> options, Callback<Pager<Track>> callback);
 
Example #26
Source File: SpotifyService.java    From spotify-web-api-android with MIT License 2 votes vote down vote up
/**
 * Get Spotify catalog information for a single track identified by their unique Spotify ID.
 *
 * @param trackId  The Spotify ID for the track.
 * @param options  Optional parameters. For list of supported parameters see
 *                 <a href="https://developer.spotify.com/web-api/get-track/">endpoint documentation</a>
 * @param callback Callback method
 * @see <a href="https://developer.spotify.com/web-api/get-track/">Get a Track</a>
 */
@GET("/tracks/{id}")
void getTrack(@Path("id") String trackId, @QueryMap Map<String, Object> options, Callback<Track> callback);
 
Example #27
Source File: SpotifyService.java    From spotify-web-api-android with MIT License 2 votes vote down vote up
/**
 * Get Spotify catalog information for a single track identified by their unique Spotify ID.
 *
 * @param trackId The Spotify ID for the track.
 * @return Requested track information
 * @see <a href="https://developer.spotify.com/web-api/get-track/">Get a Track</a>
 */
@GET("/tracks/{id}")
Track getTrack(@Path("id") String trackId);
 
Example #28
Source File: SpotifyService.java    From spotify-web-api-android with MIT License 2 votes vote down vote up
/**
 * Get Spotify catalog information for a single track identified by their unique Spotify ID.
 *
 * @param trackId  The Spotify ID for the track.
 * @param callback Callback method
 * @see <a href="https://developer.spotify.com/web-api/get-track/">Get a Track</a>
 */
@GET("/tracks/{id}")
void getTrack(@Path("id") String trackId, Callback<Track> callback);
 
Example #29
Source File: SpotifyService.java    From spotify-web-api-android with MIT License 2 votes vote down vote up
/**
 * Get Spotify catalog information about an album’s tracks.
 *
 * @param albumId The Spotify ID for the album.
 * @param options Optional parameters. For list of supported parameters see
 *                <a href="https://developer.spotify.com/web-api/get-albums-tracks/">endpoint documentation</a>
 * @return List of simplified album objects wrapped in a Pager object
 * @see <a href="https://developer.spotify.com/web-api/get-albums-tracks/">Get an Album’s Tracks</a>
 */
@GET("/albums/{id}/tracks")
Pager<Track> getAlbumTracks(@Path("id") String albumId, @QueryMap Map<String, Object> options);
 
Example #30
Source File: SpotifyService.java    From spotify-web-api-android with MIT License 2 votes vote down vote up
/**
 * Get Spotify catalog information about an album’s tracks.
 *
 * @param albumId  The Spotify ID for the album.
 * @param callback Callback method
 * @see <a href="https://developer.spotify.com/web-api/get-albums-tracks/">Get an Album’s Tracks</a>
 */
@GET("/albums/{id}/tracks")
void getAlbumTracks(@Path("id") String albumId, Callback<Pager<Track>> callback);