use of com.kabouzeid.gramophone.model.Song in project Phonograph by kabouzeid.
the class AppWidgetSmall method performUpdate.
/**
* Update all active widget instances by pushing changes
*/
public void performUpdate(final MusicService service, final int[] appWidgetIds) {
final RemoteViews appWidgetView = new RemoteViews(service.getPackageName(), R.layout.app_widget_small);
final boolean isPlaying = service.isPlaying();
final Song song = service.getCurrentSong();
// Set the titles and artwork
if (TextUtils.isEmpty(song.title) && TextUtils.isEmpty(song.artistName)) {
appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE);
} else {
if (TextUtils.isEmpty(song.title) || TextUtils.isEmpty(song.artistName)) {
appWidgetView.setTextViewText(R.id.text_separator, "");
} else {
appWidgetView.setTextViewText(R.id.text_separator, "•");
}
appWidgetView.setViewVisibility(R.id.media_titles, View.VISIBLE);
appWidgetView.setTextViewText(R.id.title, song.title);
appWidgetView.setTextViewText(R.id.text, song.artistName);
}
// Link actions buttons to intents
linkButtons(service, appWidgetView);
if (imageSize == 0)
imageSize = service.getResources().getDimensionPixelSize(R.dimen.app_widget_small_image_size);
if (cardRadius == 0f)
cardRadius = service.getResources().getDimension(R.dimen.app_widget_card_radius);
// Load the album cover async and push the update on completion
final Context appContext = service.getApplicationContext();
service.runOnUiThread(new Runnable() {
@Override
public void run() {
if (target != null) {
Glide.clear(target);
}
target = SongGlideRequest.Builder.from(Glide.with(appContext), song).checkIgnoreMediaStore(appContext).generatePalette(service).build().centerCrop().into(new SimpleTarget<BitmapPaletteWrapper>(imageSize, imageSize) {
@Override
public void onResourceReady(BitmapPaletteWrapper resource, GlideAnimation<? super BitmapPaletteWrapper> glideAnimation) {
Palette palette = resource.getPalette();
update(resource.getBitmap(), palette.getVibrantColor(palette.getMutedColor(MaterialValueHelper.getSecondaryTextColor(appContext, true))));
}
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
super.onLoadFailed(e, errorDrawable);
update(null, MaterialValueHelper.getSecondaryTextColor(appContext, true));
}
private void update(@Nullable Bitmap bitmap, int color) {
// Set correct drawable for pause state
int playPauseRes = isPlaying ? R.drawable.ic_pause_white_24dp : R.drawable.ic_play_arrow_white_24dp;
appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, playPauseRes, color)));
// Set prev/next button drawables
appWidgetView.setImageViewBitmap(R.id.button_next, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_next_white_24dp, color)));
appWidgetView.setImageViewBitmap(R.id.button_prev, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_previous_white_24dp, color)));
final Drawable image = getAlbumArtDrawable(service.getResources(), bitmap);
final Bitmap roundedBitmap = createRoundedBitmap(image, imageSize, imageSize, cardRadius, 0, 0, 0);
appWidgetView.setImageViewBitmap(R.id.image, roundedBitmap);
pushUpdate(appContext, appWidgetIds, appWidgetView);
}
});
}
});
}
use of com.kabouzeid.gramophone.model.Song in project Phonograph by kabouzeid.
the class AlbumSongAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(@NonNull SongAdapter.ViewHolder holder, int position) {
super.onBindViewHolder(holder, position);
final Song song = dataSet.get(position);
if (holder.imageText != null) {
final int trackNumber = MusicUtil.getFixedTrackNumber(song.trackNumber);
final String trackNumberString = trackNumber > 0 ? String.valueOf(trackNumber) : "-";
holder.imageText.setText(trackNumberString);
}
}
use of com.kabouzeid.gramophone.model.Song in project Phonograph by kabouzeid.
the class SongAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(@NonNull final ViewHolder holder, int position) {
final Song song = dataSet.get(position);
boolean isChecked = isChecked(song);
holder.itemView.setActivated(isChecked);
if (holder.getAdapterPosition() == getItemCount() - 1) {
if (holder.shortSeparator != null) {
holder.shortSeparator.setVisibility(View.GONE);
}
} else {
if (holder.shortSeparator != null) {
holder.shortSeparator.setVisibility(View.VISIBLE);
}
}
if (holder.title != null) {
holder.title.setText(getSongTitle(song));
}
if (holder.text != null) {
holder.text.setText(getSongText(song));
}
loadAlbumCover(song, holder);
}
use of com.kabouzeid.gramophone.model.Song in project Phonograph by kabouzeid.
the class ArtistSongAdapter method getView.
@Override
@NonNull
public View getView(final int position, View convertView, @NonNull ViewGroup parent) {
final Song song = getItem(position);
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_list, parent, false);
}
final TextView songTitle = convertView.findViewById(R.id.title);
final TextView songInfo = convertView.findViewById(R.id.text);
final ImageView albumArt = convertView.findViewById(R.id.image);
final View shortSeparator = convertView.findViewById(R.id.short_separator);
if (position == getCount() - 1) {
if (shortSeparator != null) {
shortSeparator.setVisibility(View.GONE);
}
} else {
if (shortSeparator != null) {
shortSeparator.setVisibility(View.VISIBLE);
}
}
songTitle.setText(song.title);
songInfo.setText(song.albumName);
SongGlideRequest.Builder.from(Glide.with(activity), song).checkIgnoreMediaStore(activity).build().into(albumArt);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
albumArt.setTransitionName(activity.getString(R.string.transition_album_art));
}
final ImageView overflowButton = convertView.findViewById(R.id.menu);
overflowButton.setOnClickListener(new SongMenuHelper.OnClickSongMenu(activity) {
@Override
public Song getSong() {
return song;
}
@Override
public boolean onMenuItemClick(MenuItem item) {
if (item.getItemId() == R.id.action_go_to_album) {
Pair[] albumPairs = new Pair[] { Pair.create(albumArt, activity.getResources().getString(R.string.transition_album_art)) };
NavigationUtil.goToAlbum(activity, song.albumId, albumPairs);
return true;
}
return super.onMenuItemClick(item);
}
});
convertView.setActivated(isChecked(song));
convertView.setOnClickListener(view -> {
if (isInQuickSelectMode()) {
toggleChecked(song);
} else {
MusicPlayerRemote.openQueue(dataSet, position, true);
}
});
convertView.setOnLongClickListener(view -> {
toggleChecked(song);
return true;
});
return convertView;
}
use of com.kabouzeid.gramophone.model.Song in project Phonograph by kabouzeid.
the class MusicUtil method deleteTracks.
public static void deleteTracks(@NonNull final Context context, @NonNull final List<Song> songs) {
final String[] projection = new String[] { BaseColumns._ID, MediaStore.MediaColumns.DATA };
final StringBuilder selection = new StringBuilder();
selection.append(BaseColumns._ID + " IN (");
for (int i = 0; i < songs.size(); i++) {
selection.append(songs.get(i).id);
if (i < songs.size() - 1) {
selection.append(",");
}
}
selection.append(")");
int deletedCount = 0;
try {
final Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection, selection.toString(), null, null);
if (cursor != null) {
// Step 1: Remove selected tracks from the current playlist, as well
// as from the album art cache
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
final long id = cursor.getLong(0);
final Song song = SongLoader.getSong(context, id);
MusicPlayerRemote.removeFromQueue(song);
cursor.moveToNext();
}
// Step 2: Remove files from card
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
final long id = cursor.getLong(0);
final String name = cursor.getString(1);
try {
// File.delete can throw a security exception
final File f = new File(name);
if (f.delete()) {
// Step 3: Remove selected track from the database
context.getContentResolver().delete(ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, id), null, null);
deletedCount++;
} else {
// I'm not sure if we'd ever get here (deletion would
// have to fail, but no exception thrown)
Log.e("MusicUtils", "Failed to delete file " + name);
}
cursor.moveToNext();
} catch (@NonNull final SecurityException ex) {
cursor.moveToNext();
} catch (NullPointerException e) {
Log.e("MusicUtils", "Failed to find file " + name);
}
}
cursor.close();
}
Toast.makeText(context, context.getString(R.string.deleted_x_songs, deletedCount), Toast.LENGTH_SHORT).show();
} catch (SecurityException ignored) {
}
}
Aggregations