Search in sources :

Example 1 with Song

use of se.zinokader.spotiq.model.Song 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)

Example 2 with Song

use of se.zinokader.spotiq.model.Song in project SpotiQ by ZinoKader.

the class TracklistRecyclerAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(SongHolder songHolder, int position) {
    Song song = songs.get(position);
    Context context = songHolder.itemView.getContext();
    String artistsName = ArtistMapper.joinArtistNames(song.getArtists());
    String runTimeText = String.format(Locale.getDefault(), "%d minutes, %d seconds", TimeUnit.MILLISECONDS.toMinutes(song.getDurationMs()), TimeUnit.MILLISECONDS.toSeconds(song.getDurationMs()) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(song.getDurationMs())));
    songHolder.cropTransformation = new CropTransformation(context, ApplicationConstants.DEFAULT_TRACKLIST_CROP_WIDTH, ApplicationConstants.DEFAULT_TRACKLIST_CROP_HEIGHT, CropTransformation.CropType.CENTER);
    songHolder.blurTransformation = new BlurTransformation(context, ApplicationConstants.DEFAULT_TRACKLIST_BLUR_RADIUS);
    songHolder.colorFilterTransformation = new ColorFilterTransformation(context, R.color.colorPrimary);
    Glide.with(songHolder.itemView.getContext()).load(song.getAlbumArtUrl()).fitCenter().placeholder(R.drawable.image_album_placeholder).bitmapTransform(songHolder.blurTransformation, songHolder.cropTransformation, songHolder.colorFilterTransformation).into(new SimpleTarget<GlideDrawable>() {

        @Override
        public void onResourceReady(GlideDrawable drawable, GlideAnimation<? super GlideDrawable> glideAnimation) {
            songHolder.cardViewRoot.setBackground(drawable);
        }
    });
    Glide.with(context).load(song.getAlbumArtUrl()).placeholder(R.drawable.image_album_placeholder).fitCenter().into(songHolder.albumArt);
    songHolder.songName.setText(song.getName());
    songHolder.artistsName.setText(artistsName);
    songHolder.runTime.setText(runTimeText);
    songHolder.albumName.setText(song.getAlbum().name);
}
Also used : Context(android.content.Context) BlurTransformation(jp.wasabeef.glide.transformations.BlurTransformation) Song(se.zinokader.spotiq.model.Song) CropTransformation(jp.wasabeef.glide.transformations.CropTransformation) ColorFilterTransformation(jp.wasabeef.glide.transformations.ColorFilterTransformation) GlideDrawable(com.bumptech.glide.load.resource.drawable.GlideDrawable)

Example 3 with Song

use of se.zinokader.spotiq.model.Song in project SpotiQ by ZinoKader.

the class SongRequestArrayAdapter method getView.

@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
    Song song = getItem(position);
    // inflate the view if convertView is null (as in convertView is not being reused)
    if (convertView == null) {
        convertView = LayoutInflater.from(getContext()).inflate(R.layout.listview_row_requested_song, parent, false);
    }
    String artistsJoined = ArtistMapper.joinArtistNames(song.getArtists());
    ImageView albumArt = convertView.findViewById(R.id.albumArt);
    TextView songName = convertView.findViewById(R.id.songName);
    TextView artistsName = convertView.findViewById(R.id.artistsName);
    TextView albumName = convertView.findViewById(R.id.albumName);
    ImageButton closeButton = convertView.findViewById(R.id.closeButton);
    Glide.with(convertView.getContext()).load(song.getAlbumArtUrl()).diskCacheStrategy(DiskCacheStrategy.SOURCE).placeholder(R.drawable.image_album_placeholder).fitCenter().override(ApplicationConstants.LOW_QUALITY_ALBUM_ART_DIMENSION, ApplicationConstants.LOW_QUALITY_ALBUM_ART_DIMENSION).into(albumArt);
    songName.setText(song.getName());
    artistsName.setText(artistsJoined);
    albumName.setText(song.getAlbum().name);
    closeButton.setOnClickListener(view -> removalPublisher.onNext(song));
    return convertView;
}
Also used : Song(se.zinokader.spotiq.model.Song) ImageButton(android.widget.ImageButton) TextView(android.widget.TextView) ImageView(android.widget.ImageView) NonNull(android.support.annotation.NonNull)

Example 4 with Song

use of se.zinokader.spotiq.model.Song in project SpotiQ by ZinoKader.

the class TracklistFragment method onCreate.

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    ((Injector) getContext().getApplicationContext()).inject(this);
    super.onCreate(savedInstanceState);
    String partyTitle = getArguments().getString(ApplicationConstants.PARTY_NAME_EXTRA);
    itemAnimator.setInterpolator(new DecelerateInterpolator());
    itemAnimator.setAddDuration(ApplicationConstants.DEFAULT_ITEM_ADD_DURATION_MS);
    itemAnimator.setRemoveDuration(ApplicationConstants.DEFAULT_ITEM_REMOVE_DURATION_MS);
    itemAnimator.setMoveDuration(ApplicationConstants.DEFAULT_ITEM_MOVE_DURATION_MS);
    subscriptions.add(tracklistRepository.listenToTracklistChanges(partyTitle).delay(ApplicationConstants.DEFAULT_NEW_ITEM_DELAY_MS, TimeUnit.MILLISECONDS).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(childEvent -> {
        Song song = childEvent.getDataSnapshot().getValue(Song.class);
        switch(childEvent.getChangeType()) {
            case ADDED:
                addSong(song);
                break;
            case REMOVED:
                removeSong(song);
                break;
        }
    }));
}
Also used : DecelerateInterpolator(android.view.animation.DecelerateInterpolator) FragmentTracklistBinding(se.zinokader.spotiq.databinding.FragmentTracklistBinding) Bundle(android.os.Bundle) CustomDividerItemDecoration(se.zinokader.spotiq.util.view.CustomDividerItemDecoration) LayoutInflater(android.view.LayoutInflater) Fragment(android.support.v4.app.Fragment) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) R(se.zinokader.spotiq.R) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) ViewGroup(android.view.ViewGroup) ArrayList(java.util.ArrayList) TimeUnit(java.util.concurrent.TimeUnit) Inject(javax.inject.Inject) ApplicationConstants(se.zinokader.spotiq.constant.ApplicationConstants) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) TracklistRepository(se.zinokader.spotiq.repository.TracklistRepository) DataBindingUtil(android.databinding.DataBindingUtil) FadeInDownAnimator(jp.wasabeef.recyclerview.animators.FadeInDownAnimator) Song(se.zinokader.spotiq.model.Song) View(android.view.View) Schedulers(io.reactivex.schedulers.Schedulers) Nullable(android.support.annotation.Nullable) Injector(se.zinokader.spotiq.util.di.Injector) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) Song(se.zinokader.spotiq.model.Song) Injector(se.zinokader.spotiq.util.di.Injector)

Example 5 with Song

use of se.zinokader.spotiq.model.Song in project SpotiQ by ZinoKader.

the class SongRecyclerAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(SongHolder songHolder, int i) {
    Song song = songs.get(i);
    Context context = songHolder.itemView.getContext();
    songHolder.itemView.setOnClickListener(view -> onClickSubject.onNext(song));
    songHolder.itemView.setOnLongClickListener(view -> {
        curentlyLongClicking = true;
        onLongClickSubject.onNext(song);
        return true;
    });
    songHolder.itemView.setOnTouchListener((view, motionEvent) -> {
        view.onTouchEvent(motionEvent);
        if (motionEvent.getAction() == MotionEvent.ACTION_UP && curentlyLongClicking) {
            onLongClickEndSubject.onNext(new Empty());
            curentlyLongClicking = false;
        }
        return true;
    });
    String artistsName = ArtistMapper.joinArtistNames(song.getArtists());
    Glide.with(context).load(song.getAlbumArtUrl()).diskCacheStrategy(DiskCacheStrategy.SOURCE).placeholder(R.drawable.image_album_placeholder).fitCenter().override(ApplicationConstants.LOW_QUALITY_ALBUM_ART_DIMENSION, ApplicationConstants.LOW_QUALITY_ALBUM_ART_DIMENSION).into(songHolder.albumArt);
    songHolder.songName.setText(song.getName());
    songHolder.artistsName.setText(artistsName);
    songHolder.albumName.setText(song.getAlbum().name);
}
Also used : Context(android.content.Context) Song(se.zinokader.spotiq.model.Song) Empty(se.zinokader.spotiq.util.type.Empty)

Aggregations

Song (se.zinokader.spotiq.model.Song)6 Context (android.content.Context)2 Bundle (android.os.Bundle)2 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)2 Schedulers (io.reactivex.schedulers.Schedulers)2 List (java.util.List)2 TimeUnit (java.util.concurrent.TimeUnit)2 Inject (javax.inject.Inject)2 ApplicationConstants (se.zinokader.spotiq.constant.ApplicationConstants)2 DataBindingUtil (android.databinding.DataBindingUtil)1 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1 Fragment (android.support.v4.app.Fragment)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 Log (android.util.Log)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)1 ImageButton (android.widget.ImageButton)1