Search in sources :

Example 1 with PreviewPlayer

use of se.zinokader.spotiq.feature.search.preview.PreviewPlayer in project SpotiQ by ZinoKader.

the class PlaylistSearchPresenter method onCreate.

@Override
protected void onCreate(Bundle savedState) {
    super.onCreate(savedState);
    songPreviewPlayer = new PreviewPlayer();
    restartableLatestCache(LOAD_USER_RESTARTABLE_ID, () -> spotifyRepository.getMe(spotifyCommunicatorService.getWebApi()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).retryWhen(throwable -> throwable.delay(ApplicationConstants.REQUEST_RETRY_DELAY_SEC, TimeUnit.SECONDS)), (lobbyView, userPrivate) -> {
        user = new User(userPrivate.id, userPrivate.display_name, userPrivate.images);
    }, (lobbyView, throwable) -> {
        Log.d(LogTag.LOG_SEARCH, "Error when getting user Spotify data");
    });
    restartableReplay(LOAD_PLAYLISTS_RESTARTABLE_ID, () -> getUserPlaylists().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()), (playlistSearchView, playlistSimplePager) -> {
        playlistSearchView.updatePlaylists(playlistSimplePager.items);
    }, (playlistSearchView, throwable) -> {
        Log.d(LogTag.LOG_SEARCH, "Error when getting user Spotify data");
    });
    if (savedState == null) {
        start(LOAD_USER_RESTARTABLE_ID);
        start(LOAD_PLAYLISTS_RESTARTABLE_ID);
    }
}
Also used : PartiesRepository(se.zinokader.spotiq.repository.PartiesRepository) Bundle(android.os.Bundle) HashMap(java.util.HashMap) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) TrackMapper(se.zinokader.spotiq.util.mapper.TrackMapper) SpotifyService(kaaes.spotify.webapi.android.SpotifyService) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) SpotifyRepository(se.zinokader.spotiq.repository.SpotifyRepository) Map(java.util.Map) PreviewPlayer(se.zinokader.spotiq.feature.search.preview.PreviewPlayer) FirebaseConstants(se.zinokader.spotiq.constant.FirebaseConstants) Observable(io.reactivex.Observable) Schedulers(io.reactivex.schedulers.Schedulers) Log(android.util.Log) SpotifyConstants(se.zinokader.spotiq.constant.SpotifyConstants) Pager(kaaes.spotify.webapi.android.models.Pager) LogTag(se.zinokader.spotiq.constant.LogTag) BasePresenter(se.zinokader.spotiq.feature.base.BasePresenter) Party(se.zinokader.spotiq.model.Party) SpotifyAuthenticationService(se.zinokader.spotiq.service.authentication.SpotifyAuthenticationService) TimeUnit(java.util.concurrent.TimeUnit) ApplicationConstants(se.zinokader.spotiq.constant.ApplicationConstants) PlaylistSimple(kaaes.spotify.webapi.android.models.PlaylistSimple) List(java.util.List) TracklistRepository(se.zinokader.spotiq.repository.TracklistRepository) PlaylistTrack(kaaes.spotify.webapi.android.models.PlaylistTrack) User(se.zinokader.spotiq.model.User) User(se.zinokader.spotiq.model.User) PreviewPlayer(se.zinokader.spotiq.feature.search.preview.PreviewPlayer)

Example 2 with PreviewPlayer

use of se.zinokader.spotiq.feature.search.preview.PreviewPlayer in project SpotiQ by ZinoKader.

the class SongSearchPresenter method onCreate.

@Override
protected void onCreate(Bundle savedState) {
    super.onCreate(savedState);
    songPreviewPlayer = new PreviewPlayer();
    // load user data and user search suggestions
    restartableLatestCache(LOAD_USER_RESTARTABLE_ID, () -> spotifyRepository.getMe(spotifyCommunicatorService.getWebApi()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).retryWhen(throwable -> throwable.delay(ApplicationConstants.REQUEST_RETRY_DELAY_SEC, TimeUnit.SECONDS)), (songSearchView, userPrivate) -> {
        user = new User(userPrivate.id, userPrivate.display_name, userPrivate.images);
        // load personalized search suggestions
        Map<String, Object> searchOptions = new HashMap<>();
        searchOptions.put(SpotifyService.LIMIT, SpotifyConstants.TOP_TRACKS_QUERY_RESPONSE_LIMIT);
        searchOptions.put(SpotifyService.TIME_RANGE, SpotifyConstants.TIME_RANGE_SHORT);
        spotifyRepository.getMyTopTracks(searchOptions, spotifyCommunicatorService.getWebApi()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).retryWhen(throwable -> throwable.delay(ApplicationConstants.REQUEST_RETRY_DELAY_SEC, TimeUnit.SECONDS)).subscribe(tracks -> {
            List<Song> songSuggestions = TrackMapper.tracksToSongs(tracks, user);
            SongSearchSuggestionsBuilder suggestionsBuilder = new SongSearchSuggestionsBuilder(songSuggestions, ApplicationConstants.MAX_SONG_SUGGESTIONS);
            songSearchView.updateSearchSuggestions(suggestionsBuilder);
        });
    }, (songSearchView, throwable) -> {
        Log.d(LogTag.LOG_SEARCH, "Error when getting user Spotify data");
    });
    if (savedState == null) {
        start(LOAD_USER_RESTARTABLE_ID);
    }
}
Also used : PartiesRepository(se.zinokader.spotiq.repository.PartiesRepository) Bundle(android.os.Bundle) HashMap(java.util.HashMap) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) TrackMapper(se.zinokader.spotiq.util.mapper.TrackMapper) SpotifyService(kaaes.spotify.webapi.android.SpotifyService) Inject(javax.inject.Inject) SpotifyRepository(se.zinokader.spotiq.repository.SpotifyRepository) Map(java.util.Map) PreviewPlayer(se.zinokader.spotiq.feature.search.preview.PreviewPlayer) FirebaseConstants(se.zinokader.spotiq.constant.FirebaseConstants) Observable(io.reactivex.Observable) Schedulers(io.reactivex.schedulers.Schedulers) Log(android.util.Log) SpotifyConstants(se.zinokader.spotiq.constant.SpotifyConstants) LogTag(se.zinokader.spotiq.constant.LogTag) BasePresenter(se.zinokader.spotiq.feature.base.BasePresenter) Party(se.zinokader.spotiq.model.Party) SpotifyAuthenticationService(se.zinokader.spotiq.service.authentication.SpotifyAuthenticationService) TimeUnit(java.util.concurrent.TimeUnit) ApplicationConstants(se.zinokader.spotiq.constant.ApplicationConstants) List(java.util.List) TracksPager(kaaes.spotify.webapi.android.models.TracksPager) Song(se.zinokader.spotiq.model.Song) User(se.zinokader.spotiq.model.User) Song(se.zinokader.spotiq.model.Song) User(se.zinokader.spotiq.model.User) HashMap(java.util.HashMap) PreviewPlayer(se.zinokader.spotiq.feature.search.preview.PreviewPlayer)

Aggregations

Bundle (android.os.Bundle)2 Log (android.util.Log)2 Observable (io.reactivex.Observable)2 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)2 Schedulers (io.reactivex.schedulers.Schedulers)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 TimeUnit (java.util.concurrent.TimeUnit)2 Inject (javax.inject.Inject)2 SpotifyService (kaaes.spotify.webapi.android.SpotifyService)2 ApplicationConstants (se.zinokader.spotiq.constant.ApplicationConstants)2 FirebaseConstants (se.zinokader.spotiq.constant.FirebaseConstants)2 LogTag (se.zinokader.spotiq.constant.LogTag)2 SpotifyConstants (se.zinokader.spotiq.constant.SpotifyConstants)2 BasePresenter (se.zinokader.spotiq.feature.base.BasePresenter)2 PreviewPlayer (se.zinokader.spotiq.feature.search.preview.PreviewPlayer)2 Party (se.zinokader.spotiq.model.Party)2 User (se.zinokader.spotiq.model.User)2 PartiesRepository (se.zinokader.spotiq.repository.PartiesRepository)2