use of com.afollestad.aesthetic.Aesthetic in project Shuttle by timusus.
the class PlayerFragment method trackInfoChanged.
@Override
public void trackInfoChanged(@Nullable Song song) {
if (song == null)
return;
if (isExpanded && !snowfallView.isSnowing()) {
snowfallView.letItSnow();
} else {
snowfallView.removeSnow();
}
String totalTimeString = StringUtils.makeTimeString(this.getActivity(), song.duration / 1000);
if (!TextUtils.isEmpty(totalTimeString)) {
if (totalTime != null) {
totalTime.setText(totalTimeString);
}
}
if (track != null) {
track.setText(song.name);
track.setSelected(true);
}
if (album != null) {
album.setText(String.format("%s | %s", song.artistName, song.albumName));
}
if (isLandscape) {
toolbar.setTitle(song.name);
toolbar.setSubtitle(String.format("%s | %s", song.artistName, song.albumName));
target = Glide.with(this).load(song).diskCacheStrategy(DiskCacheStrategy.SOURCE).bitmapTransform(new BlurTransformation(getContext(), 15, 4)).error(PlaceholderProvider.getInstance().getPlaceHolderDrawable(song.name, true)).thumbnail(Glide.with(this).load(this.song).bitmapTransform(new BlurTransformation(getContext(), 15, 4))).crossFade(600).into(backgroundView);
this.song = song;
} else {
backgroundView.setImageDrawable(null);
toolbar.setTitle(null);
toolbar.setSubtitle(null);
}
if (SettingsManager.getInstance().getUsePalette()) {
// noinspection unchecked
Glide.with(this).load(song).asBitmap().transcode(new PaletteBitmapTranscoder(getContext()), PaletteBitmap.class).override(250, 250).diskCacheStrategy(DiskCacheStrategy.ALL).into(new SimpleTarget<PaletteBitmap>() {
@Override
public void onResourceReady(PaletteBitmap resource, GlideAnimation<? super PaletteBitmap> glideAnimation) {
if (!isAdded() || getContext() == null) {
return;
}
Palette.Swatch swatch = resource.palette.getDarkMutedSwatch();
if (swatch != null) {
if (SettingsManager.getInstance().getUsePalette()) {
if (SettingsManager.getInstance().getUsePaletteNowPlayingOnly()) {
animateColors(currentColor, swatch.getRgb(), color -> invalidateColors(color));
} else {
// Set Aesthetic colors globally, based on the current Palette swatch
disposables.add(Aesthetic.get(getContext()).colorPrimary().take(1).subscribe(integer -> animateColors(integer, swatch.getRgb(), color -> {
if (getContext() != null && isAdded()) {
Aesthetic aesthetic = Aesthetic.get(getContext()).colorPrimary(color).colorStatusBarAuto();
if (SettingsManager.getInstance().getTintNavBar()) {
aesthetic = aesthetic.colorNavigationBar(color);
}
aesthetic.apply();
}
})));
}
}
} else {
// Failed to generate the dark muted swatch, fall back to the primary theme colour.
Aesthetic.get(getContext()).colorPrimary().take(1).subscribe(primaryColor -> animateColors(currentColor, primaryColor, color -> invalidateColors(color)));
}
}
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
super.onLoadFailed(e, errorDrawable);
Aesthetic.get(getContext()).colorPrimary().take(1).subscribe(primaryColor -> animateColors(currentColor, primaryColor, color -> invalidateColors(color)));
}
});
}
}
Aggregations