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);
}
}
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);
}
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;
}
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;
}
}));
}
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);
}
Aggregations