more code refactoring
This commit is contained in:
parent
c6fa221a53
commit
a0e8db7f75
31 changed files with 78 additions and 153 deletions
|
|
@ -95,7 +95,6 @@ public class GenreAdapter extends RecyclerView.Adapter<GenreAdapter.ViewHolder>
|
|||
}
|
||||
|
||||
public class ViewHolder extends MediaEntryViewHolder {
|
||||
|
||||
public ViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -107,6 +107,7 @@ public class AlbumAdapter extends AbsMultiSelectAdapter<AlbumAdapter.ViewHolder,
|
|||
if (holder.title != null) {
|
||||
holder.title.setText(getAlbumTitle(album));
|
||||
}
|
||||
|
||||
if (holder.text != null) {
|
||||
holder.text.setText(getAlbumText(album));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ public abstract class AbsMultiSelectAdapter<VH extends RecyclerView.ViewHolder,
|
|||
updateCab();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -57,6 +58,7 @@ public abstract class AbsMultiSelectAdapter<VH extends RecyclerView.ViewHolder,
|
|||
checked.add(identifier);
|
||||
}
|
||||
}
|
||||
|
||||
notifyDataSetChanged();
|
||||
updateCab();
|
||||
}
|
||||
|
|
@ -67,6 +69,7 @@ public abstract class AbsMultiSelectAdapter<VH extends RecyclerView.ViewHolder,
|
|||
if (cab == null || !cab.isActive()) {
|
||||
cab = cabHolder.openCab(menuRes, this);
|
||||
}
|
||||
|
||||
final int size = checked.size();
|
||||
if (size <= 0) cab.finish();
|
||||
else if (size == 1) cab.setTitle(getName(checked.get(0)));
|
||||
|
|
@ -101,6 +104,7 @@ public abstract class AbsMultiSelectAdapter<VH extends RecyclerView.ViewHolder,
|
|||
cab.finish();
|
||||
clearChecked();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,12 +13,8 @@ import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
|||
import com.kabouzeid.gramophone.interfaces.CabHolder;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Eugene Cheung (arkon)
|
||||
*/
|
||||
public abstract class AbsOffsetSongAdapter extends SongAdapter {
|
||||
|
||||
protected static final int OFFSET_ITEM = 0;
|
||||
|
|
@ -80,6 +76,7 @@ public abstract class AbsOffsetSongAdapter extends SongAdapter {
|
|||
@Override
|
||||
public String getSectionName(int position) {
|
||||
position--;
|
||||
|
||||
if (position < 0) return "";
|
||||
return super.getSectionName(position);
|
||||
}
|
||||
|
|
@ -91,8 +88,8 @@ public abstract class AbsOffsetSongAdapter extends SongAdapter {
|
|||
|
||||
@Override
|
||||
protected Song getSong() {
|
||||
if (getItemViewType() == OFFSET_ITEM)
|
||||
return Song.EMPTY_SONG; // could also return null, just to be safe return empty song
|
||||
// return empty song just to be safe
|
||||
if (getItemViewType() == OFFSET_ITEM) return Song.EMPTY_SONG;
|
||||
return dataSet.get(getAdapterPosition() - 1);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,11 +13,7 @@ import com.kabouzeid.gramophone.util.MusicUtil;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class AlbumSongAdapter extends SongAdapter {
|
||||
|
||||
public AlbumSongAdapter(AppCompatActivity activity, List<Song> dataSet, @LayoutRes int itemLayoutRes, boolean usePalette, @Nullable CabHolder cabHolder) {
|
||||
super(activity, dataSet, itemLayoutRes, usePalette, cabHolder);
|
||||
}
|
||||
|
|
@ -61,6 +57,6 @@ public class AlbumSongAdapter extends SongAdapter {
|
|||
|
||||
@Override
|
||||
protected void loadAlbumCover(Song song, SongAdapter.ViewHolder holder) {
|
||||
// We don't want to load it in this adapter
|
||||
// don't want to load it in this adapter
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,9 +104,11 @@ public class ArtistSongAdapter extends ArrayAdapter<Song> implements MaterialCab
|
|||
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);
|
||||
}
|
||||
});
|
||||
|
|
@ -119,6 +121,7 @@ public class ArtistSongAdapter extends ArrayAdapter<Song> implements MaterialCab
|
|||
MusicPlayerRemote.openQueue(dataSet, position, true);
|
||||
}
|
||||
});
|
||||
|
||||
convertView.setOnLongClickListener(view -> {
|
||||
toggleChecked(song);
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -120,6 +120,7 @@ public class OrderablePlaylistSongAdapter extends PlaylistSongAdapter implements
|
|||
RemoveFromPlaylistDialog.create((PlaylistSong) getSong()).show(activity.getSupportFragmentManager(), "REMOVE_FROM_PLAYLIST");
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onSongMenuItemClick(item);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ public class PlayingQueueAdapter extends SongAdapter implements DraggableItemAda
|
|||
|
||||
@Override
|
||||
protected void loadAlbumCover(Song song, SongAdapter.ViewHolder holder) {
|
||||
// We don't want to load it in this adapter
|
||||
// don't want to load it in this adapter
|
||||
}
|
||||
|
||||
public void swapDataSet(List<Song> dataSet, int position) {
|
||||
|
|
@ -77,15 +77,19 @@ public class PlayingQueueAdapter extends SongAdapter implements DraggableItemAda
|
|||
if (holder.image != null) {
|
||||
holder.image.setAlpha(alpha);
|
||||
}
|
||||
|
||||
if (holder.title != null) {
|
||||
holder.title.setAlpha(alpha);
|
||||
}
|
||||
|
||||
if (holder.text != null) {
|
||||
holder.text.setAlpha(alpha);
|
||||
}
|
||||
|
||||
if (holder.imageText != null) {
|
||||
holder.imageText.setAlpha(alpha);
|
||||
}
|
||||
|
||||
if (holder.paletteColorContainer != null) {
|
||||
holder.paletteColorContainer.setAlpha(alpha);
|
||||
}
|
||||
|
|
@ -130,6 +134,7 @@ public class PlayingQueueAdapter extends SongAdapter implements DraggableItemAda
|
|||
if (imageText != null) {
|
||||
imageText.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
if (image != null) {
|
||||
image.setVisibility(View.GONE);
|
||||
}
|
||||
|
|
@ -147,6 +152,7 @@ public class PlayingQueueAdapter extends SongAdapter implements DraggableItemAda
|
|||
MusicPlayerRemote.removeFromQueue(getAdapterPosition());
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onSongMenuItemClick(item);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,24 +37,30 @@ public class PlaylistSongAdapter extends AbsOffsetSongAdapter {
|
|||
holder.title.setText(MusicUtil.getPlaylistInfoString(activity, dataSet));
|
||||
holder.title.setTextColor(textColor);
|
||||
}
|
||||
|
||||
if (holder.text != null) {
|
||||
holder.text.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (holder.menu != null) {
|
||||
holder.menu.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (holder.image != null) {
|
||||
final int padding = activity.getResources().getDimensionPixelSize(R.dimen.default_item_margin) / 2;
|
||||
holder.image.setPadding(padding, padding, padding, padding);
|
||||
holder.image.setColorFilter(textColor);
|
||||
holder.image.setImageResource(R.drawable.ic_timer_white_24dp);
|
||||
}
|
||||
|
||||
if (holder.dragView != null) {
|
||||
holder.dragView.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (holder.separator != null) {
|
||||
holder.separator.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
if (holder.shortSeparator != null) {
|
||||
holder.shortSeparator.setVisibility(View.GONE);
|
||||
}
|
||||
|
|
@ -79,9 +85,11 @@ public class PlaylistSongAdapter extends AbsOffsetSongAdapter {
|
|||
Pair[] albumPairs = new Pair[]{
|
||||
Pair.create(image, activity.getString(R.string.transition_album_art))
|
||||
};
|
||||
|
||||
NavigationUtil.goToAlbum(activity, dataSet.get(getAdapterPosition() - 1).albumId, albumPairs);
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onSongMenuItemClick(item);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,21 +36,26 @@ public class ShuffleButtonSongAdapter extends AbsOffsetSongAdapter {
|
|||
holder.title.setTextColor(accentColor);
|
||||
holder.title.setTypeface(Typeface.create("sans-serif-medium", Typeface.NORMAL));
|
||||
}
|
||||
|
||||
if (holder.text != null) {
|
||||
holder.text.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (holder.menu != null) {
|
||||
holder.menu.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (holder.image != null) {
|
||||
final int padding = activity.getResources().getDimensionPixelSize(R.dimen.default_item_margin) / 2;
|
||||
holder.image.setPadding(padding, padding, padding, padding);
|
||||
holder.image.setColorFilter(accentColor);
|
||||
holder.image.setImageResource(R.drawable.ic_shuffle_white_24dp);
|
||||
}
|
||||
|
||||
if (holder.separator != null) {
|
||||
holder.separator.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
if (holder.shortSeparator != null) {
|
||||
holder.shortSeparator.setVisibility(View.GONE);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ public class SongAdapter extends AbsMultiSelectAdapter<SongAdapter.ViewHolder, S
|
|||
|
||||
public SongAdapter(AppCompatActivity activity, List<Song> dataSet, @LayoutRes int itemLayoutRes, boolean usePalette, @Nullable CabHolder cabHolder, boolean showSectionName) {
|
||||
super(activity, cabHolder, R.menu.menu_media_selection);
|
||||
|
||||
this.activity = activity;
|
||||
this.dataSet = dataSet;
|
||||
this.itemLayoutRes = itemLayoutRes;
|
||||
|
|
@ -107,6 +108,7 @@ public class SongAdapter extends AbsMultiSelectAdapter<SongAdapter.ViewHolder, S
|
|||
if (holder.title != null) {
|
||||
holder.title.setText(getSongTitle(song));
|
||||
}
|
||||
|
||||
if (holder.text != null) {
|
||||
holder.text.setText(getSongText(song));
|
||||
}
|
||||
|
|
@ -245,9 +247,7 @@ public class SongAdapter extends AbsMultiSelectAdapter<SongAdapter.ViewHolder, S
|
|||
if (image != null && image.getVisibility() == View.VISIBLE) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_go_to_album:
|
||||
Pair[] albumPairs = new Pair[]{
|
||||
Pair.create(image, activity.getResources().getString(R.string.transition_album_art))
|
||||
};
|
||||
Pair[] albumPairs = new Pair[]{Pair.create(image, activity.getResources().getString(R.string.transition_album_art))};
|
||||
NavigationUtil.goToAlbum(activity, getSong().albumId, albumPairs);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,9 +15,6 @@ import com.kabouzeid.gramophone.util.PlaylistsUtil;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid), Aidan Follestad (afollestad)
|
||||
*/
|
||||
public class AddToPlaylistDialog extends DialogFragment {
|
||||
|
||||
@NonNull
|
||||
|
|
@ -50,9 +47,10 @@ public class AddToPlaylistDialog extends DialogFragment {
|
|||
.title(R.string.action_add_to_playlist)
|
||||
.items(playlistNames)
|
||||
.itemsCallback((materialDialog, view, i, charSequence) -> {
|
||||
//noinspection unchecked
|
||||
// noinspection unchecked
|
||||
final List<Song> songs = getArguments().getParcelableArrayList("songs");
|
||||
if (songs == null) return;
|
||||
|
||||
if (i == 0) {
|
||||
materialDialog.dismiss();
|
||||
CreatePlaylistDialog.create(songs).show(getActivity().getSupportFragmentManager(), "ADD_TO_PLAYLIST");
|
||||
|
|
|
|||
|
|
@ -10,9 +10,6 @@ import com.afollestad.materialdialogs.MaterialDialog;
|
|||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.model.playlist.AbsSmartPlaylist;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class ClearSmartPlaylistDialog extends DialogFragment {
|
||||
|
||||
@NonNull
|
||||
|
|
@ -27,10 +24,10 @@ public class ClearSmartPlaylistDialog extends DialogFragment {
|
|||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
//noinspection unchecked
|
||||
// noinspection unchecked
|
||||
final AbsSmartPlaylist playlist = getArguments().getParcelable("playlist");
|
||||
int title = R.string.clear_playlist_title;
|
||||
//noinspection ConstantConditions
|
||||
// noinspection ConstantConditions
|
||||
CharSequence content = Html.fromHtml(getString(R.string.clear_playlist_x, playlist.name));
|
||||
|
||||
return new MaterialDialog.Builder(getActivity())
|
||||
|
|
|
|||
|
|
@ -16,9 +16,6 @@ import com.kabouzeid.gramophone.util.PlaylistsUtil;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid), Aidan Follestad (afollestad)
|
||||
*/
|
||||
public class CreatePlaylistDialog extends DialogFragment {
|
||||
|
||||
private static final String SONGS = "songs";
|
||||
|
|
@ -63,7 +60,7 @@ public class CreatePlaylistDialog extends DialogFragment {
|
|||
if (!PlaylistsUtil.doesPlaylistExist(getActivity(), name)) {
|
||||
final int playlistId = PlaylistsUtil.createPlaylist(getActivity(), name);
|
||||
if (getActivity() != null) {
|
||||
//noinspection unchecked
|
||||
// noinspection unchecked
|
||||
List<Song> songs = getArguments().getParcelableArrayList(SONGS);
|
||||
if (songs != null && !songs.isEmpty()) {
|
||||
PlaylistsUtil.addToPlaylist(getActivity(), songs, playlistId, true);
|
||||
|
|
|
|||
|
|
@ -14,9 +14,6 @@ import com.kabouzeid.gramophone.util.PlaylistsUtil;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class DeletePlaylistDialog extends DialogFragment {
|
||||
|
||||
@NonNull
|
||||
|
|
@ -38,11 +35,10 @@ public class DeletePlaylistDialog extends DialogFragment {
|
|||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
//noinspection unchecked
|
||||
final List<Playlist> playlists = getArguments().getParcelableArrayList("playlists");
|
||||
int title;
|
||||
CharSequence content;
|
||||
//noinspection ConstantConditions
|
||||
// noinspection ConstantConditions
|
||||
if (playlists.size() > 1) {
|
||||
title = R.string.delete_playlists_title;
|
||||
content = Html.fromHtml(getString(R.string.delete_x_playlists, playlists.size()));
|
||||
|
|
@ -50,14 +46,14 @@ public class DeletePlaylistDialog extends DialogFragment {
|
|||
title = R.string.delete_playlist_title;
|
||||
content = Html.fromHtml(getString(R.string.delete_playlist_x, playlists.get(0).name));
|
||||
}
|
||||
|
||||
return new MaterialDialog.Builder(getActivity())
|
||||
.title(title)
|
||||
.content(content)
|
||||
.positiveText(R.string.delete_action)
|
||||
.negativeText(android.R.string.cancel)
|
||||
.onPositive((dialog, which) -> {
|
||||
if (getActivity() == null)
|
||||
return;
|
||||
if (getActivity() == null) return;
|
||||
PlaylistsUtil.deletePlaylists(getActivity(), playlists);
|
||||
})
|
||||
.build();
|
||||
|
|
|
|||
|
|
@ -14,9 +14,6 @@ import com.kabouzeid.gramophone.util.MusicUtil;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid), Aidan Follestad (afollestad)
|
||||
*/
|
||||
public class DeleteSongsDialog extends DialogFragment {
|
||||
|
||||
@NonNull
|
||||
|
|
@ -38,7 +35,6 @@ public class DeleteSongsDialog extends DialogFragment {
|
|||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
//noinspection unchecked
|
||||
final List<Song> songs = getArguments().getParcelableArrayList("songs");
|
||||
int title;
|
||||
CharSequence content;
|
||||
|
|
@ -49,14 +45,14 @@ public class DeleteSongsDialog extends DialogFragment {
|
|||
title = R.string.delete_song_title;
|
||||
content = Html.fromHtml(getString(R.string.delete_song_x, songs.get(0).title));
|
||||
}
|
||||
|
||||
return new MaterialDialog.Builder(getActivity())
|
||||
.title(title)
|
||||
.content(content)
|
||||
.positiveText(R.string.delete_action)
|
||||
.negativeText(android.R.string.cancel)
|
||||
.onPositive((dialog, which) -> {
|
||||
if (getActivity() == null)
|
||||
return;
|
||||
if (getActivity() == null) return;
|
||||
MusicUtil.deleteTracks(getActivity(), songs);
|
||||
})
|
||||
.build();
|
||||
|
|
|
|||
|
|
@ -38,9 +38,6 @@ import java.util.List;
|
|||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class DonationsDialog extends DialogFragment implements BillingProcessor.IBillingHandler {
|
||||
public static final String TAG = DonationsDialog.class.getSimpleName();
|
||||
|
||||
|
|
@ -111,6 +108,7 @@ public class DonationsDialog extends DialogFragment implements BillingProcessor.
|
|||
if (skuDetailsLoadAsyncTask != null) {
|
||||
skuDetailsLoadAsyncTask.cancel(true);
|
||||
}
|
||||
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
|
@ -118,6 +116,7 @@ public class DonationsDialog extends DialogFragment implements BillingProcessor.
|
|||
if (skuDetailsLoadAsyncTask != null) {
|
||||
skuDetailsLoadAsyncTask.cancel(false);
|
||||
}
|
||||
|
||||
skuDetailsLoadAsyncTask = new SkuDetailsLoadAsyncTask(this).execute();
|
||||
}
|
||||
|
||||
|
|
@ -147,6 +146,7 @@ public class DonationsDialog extends DialogFragment implements BillingProcessor.
|
|||
final String[] ids = dialog.getResources().getStringArray(DONATION_PRODUCT_IDS);
|
||||
return dialog.billingProcessor.getPurchaseListingDetails(new ArrayList<>(Arrays.asList(ids)));
|
||||
}
|
||||
|
||||
cancel(false);
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,9 +14,6 @@ import com.kabouzeid.gramophone.util.PlaylistsUtil;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class RemoveFromPlaylistDialog extends DialogFragment {
|
||||
|
||||
@NonNull
|
||||
|
|
@ -49,14 +46,14 @@ public class RemoveFromPlaylistDialog extends DialogFragment {
|
|||
title = R.string.remove_song_from_playlist_title;
|
||||
content = Html.fromHtml(getString(R.string.remove_song_x_from_playlist, songs.get(0).title));
|
||||
}
|
||||
|
||||
return new MaterialDialog.Builder(getActivity())
|
||||
.title(title)
|
||||
.content(content)
|
||||
.positiveText(R.string.remove_action)
|
||||
.negativeText(android.R.string.cancel)
|
||||
.onPositive((dialog, which) -> {
|
||||
if (getActivity() == null)
|
||||
return;
|
||||
if (getActivity() == null) return;
|
||||
PlaylistsUtil.removeFromPlaylist(getActivity(), songs);
|
||||
})
|
||||
.build();
|
||||
|
|
|
|||
|
|
@ -10,9 +10,6 @@ import com.afollestad.materialdialogs.MaterialDialog;
|
|||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.util.PlaylistsUtil;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid), Aidan Follestad (afollestad)
|
||||
*/
|
||||
public class RenamePlaylistDialog extends DialogFragment {
|
||||
|
||||
private static final String PLAYLIST_ID = "playlist_id";
|
||||
|
|
@ -40,6 +37,7 @@ public class RenamePlaylistDialog extends DialogFragment {
|
|||
.input(getString(R.string.playlist_name_empty), PlaylistsUtil.getNameForPlaylist(getActivity(), playlistId), false,
|
||||
(materialDialog, charSequence) -> {
|
||||
final String name = charSequence.toString().trim();
|
||||
|
||||
if (!name.isEmpty()) {
|
||||
long playlistId1 = getArguments().getLong(PLAYLIST_ID);
|
||||
PlaylistsUtil.renamePlaylist(getActivity(), playlistId1, name);
|
||||
|
|
|
|||
|
|
@ -29,9 +29,6 @@ import com.triggertrap.seekarc.SeekArc;
|
|||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class SleepTimerDialog extends DialogFragment {
|
||||
@BindView(R.id.seek_arc)
|
||||
SeekArc seekArc;
|
||||
|
|
@ -79,6 +76,7 @@ public class SleepTimerDialog extends DialogFragment {
|
|||
if (getActivity() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final PendingIntent previous = makeTimerPendingIntent(PendingIntent.FLAG_NO_CREATE);
|
||||
if (previous != null) {
|
||||
AlarmManager am = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
|
||||
|
|
@ -134,13 +132,13 @@ public class SleepTimerDialog extends DialogFragment {
|
|||
seekArc.setProgress(1);
|
||||
return;
|
||||
}
|
||||
|
||||
seekArcProgress = i;
|
||||
updateTimeDisplayTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekArc seekArc) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -165,6 +163,7 @@ public class SleepTimerDialog extends DialogFragment {
|
|||
if (shouldFinishLastSong.isChecked()) {
|
||||
return intent.setAction(MusicService.ACTION_PENDING_QUIT);
|
||||
}
|
||||
|
||||
return intent.setAction(MusicService.ACTION_QUIT);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,9 +28,6 @@ import org.jaudiotagger.tag.TagException;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid), Aidan Follestad (afollestad)
|
||||
*/
|
||||
public class SongDetailDialog extends DialogFragment {
|
||||
|
||||
public static final String TAG = SongDetailDialog.class.getSimpleName();
|
||||
|
|
@ -89,6 +86,7 @@ public class SongDetailDialog extends DialogFragment {
|
|||
fileName.setText(makeTextWithTitle(context, R.string.label_file_name, songFile.getName()));
|
||||
filePath.setText(makeTextWithTitle(context, R.string.label_file_path, songFile.getAbsolutePath()));
|
||||
fileSize.setText(makeTextWithTitle(context, R.string.label_file_size, getFileSizeString(songFile.length())));
|
||||
|
||||
try {
|
||||
AudioFile audioFile = AudioFileIO.read(songFile);
|
||||
AudioHeader audioHeader = audioFile.getAudioHeader();
|
||||
|
|
@ -99,11 +97,9 @@ public class SongDetailDialog extends DialogFragment {
|
|||
samplingRate.setText(makeTextWithTitle(context, R.string.label_sampling_rate, audioHeader.getSampleRate() + " Hz"));
|
||||
} catch (@NonNull CannotReadException | IOException | TagException | ReadOnlyFileException | InvalidAudioFrameException e) {
|
||||
Log.e(TAG, "error while reading the song file", e);
|
||||
// fallback
|
||||
trackLength.setText(makeTextWithTitle(context, R.string.label_track_length, MusicUtil.getReadableDurationString(song.duration)));
|
||||
}
|
||||
} else {
|
||||
// fallback
|
||||
fileName.setText(makeTextWithTitle(context, R.string.label_file_name, song.title));
|
||||
trackLength.setText(makeTextWithTitle(context, R.string.label_track_length, MusicUtil.getReadableDurationString(song.duration)));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,9 +11,6 @@ import com.kabouzeid.gramophone.R;
|
|||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.util.MusicUtil;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class SongShareDialog extends DialogFragment {
|
||||
@NonNull
|
||||
public static SongShareDialog create(final Song song) {
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ public class LibraryPreferenceDialog extends DialogFragment {
|
|||
} else {
|
||||
categoryInfos = PreferenceUtil.getInstance(getContext()).getLibraryCategories();
|
||||
}
|
||||
|
||||
adapter = new CategoryInfoAdapter(categoryInfos);
|
||||
|
||||
RecyclerView recyclerView = view.findViewById(R.id.recycler_view);
|
||||
|
|
@ -78,6 +79,7 @@ public class LibraryPreferenceDialog extends DialogFragment {
|
|||
if (categoryInfo.visible)
|
||||
selected++;
|
||||
}
|
||||
|
||||
return selected;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,9 +5,6 @@ import android.util.AttributeSet;
|
|||
|
||||
import com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEDialogPreference;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class NowPlayingScreenPreference extends ATEDialogPreference {
|
||||
public NowPlayingScreenPreference(Context context) {
|
||||
super(context);
|
||||
|
|
|
|||
|
|
@ -23,9 +23,6 @@ import com.kabouzeid.gramophone.ui.fragments.player.NowPlayingScreen;
|
|||
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
||||
import com.kabouzeid.gramophone.util.ViewUtil;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class NowPlayingScreenPreferenceDialog extends DialogFragment implements MaterialDialog.SingleButtonCallback, ViewPager.OnPageChangeListener {
|
||||
|
||||
private DialogAction whichButtonClicked;
|
||||
|
|
@ -73,7 +70,6 @@ public class NowPlayingScreenPreferenceDialog extends DialogFragment implements
|
|||
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -83,11 +79,9 @@ public class NowPlayingScreenPreferenceDialog extends DialogFragment implements
|
|||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state) {
|
||||
|
||||
}
|
||||
|
||||
private static class NowPlayingScreenAdapter extends PagerAdapter {
|
||||
|
||||
private Context context;
|
||||
|
||||
public NowPlayingScreenAdapter(Context context) {
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ public class MediaButtonIntentReceiver extends BroadcastReceiver {
|
|||
private static int mClickCounter = 0;
|
||||
private static long mLastClickTime = 0;
|
||||
|
||||
@SuppressLint("HandlerLeak") // false alarm, handler is already static
|
||||
@SuppressLint("HandlerLeak")
|
||||
private static Handler mHandler = new Handler() {
|
||||
|
||||
@Override
|
||||
|
|
@ -101,9 +101,10 @@ public class MediaButtonIntentReceiver extends BroadcastReceiver {
|
|||
|
||||
final int keycode = event.getKeyCode();
|
||||
final int action = event.getAction();
|
||||
|
||||
// fallback to system time if event time is not available
|
||||
final long eventTime = event.getEventTime() != 0 ?
|
||||
event.getEventTime() : System.currentTimeMillis();
|
||||
// Fallback to system time if event time was not available.
|
||||
|
||||
String command = null;
|
||||
switch (keycode) {
|
||||
|
|
@ -127,6 +128,7 @@ public class MediaButtonIntentReceiver extends BroadcastReceiver {
|
|||
command = MusicService.ACTION_PLAY;
|
||||
break;
|
||||
}
|
||||
|
||||
if (command != null) {
|
||||
if (action == KeyEvent.ACTION_DOWN) {
|
||||
if (event.getRepeatCount() == 0) {
|
||||
|
|
@ -153,16 +155,19 @@ public class MediaButtonIntentReceiver extends BroadcastReceiver {
|
|||
if (mClickCounter >= 3) {
|
||||
mClickCounter = 0;
|
||||
}
|
||||
|
||||
mLastClickTime = eventTime;
|
||||
acquireWakeLockAndSendMessage(context, msg, delay);
|
||||
} else {
|
||||
startService(context, command);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -189,6 +194,7 @@ public class MediaButtonIntentReceiver extends BroadcastReceiver {
|
|||
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Phonograph headset button");
|
||||
mWakeLock.setReferenceCounted(false);
|
||||
}
|
||||
|
||||
if (DEBUG) Log.v(TAG, "Acquiring wake lock and sending " + msg.what);
|
||||
// Make sure we don't indefinitely hold the wake lock under any circumstances
|
||||
mWakeLock.acquire(10000);
|
||||
|
|
|
|||
|
|
@ -16,9 +16,6 @@ import com.kabouzeid.gramophone.R;
|
|||
import com.kabouzeid.gramophone.service.playback.Playback;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
||||
|
||||
/**
|
||||
* @author Andrew Neal, Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class MultiPlayer implements Playback, MediaPlayer.OnErrorListener, MediaPlayer.OnCompletionListener {
|
||||
public static final String TAG = MultiPlayer.class.getSimpleName();
|
||||
|
||||
|
|
@ -31,9 +28,6 @@ public class MultiPlayer implements Playback, MediaPlayer.OnErrorListener, Media
|
|||
|
||||
private boolean mIsInitialized = false;
|
||||
|
||||
/**
|
||||
* Constructor of <code>MultiPlayer</code>
|
||||
*/
|
||||
public MultiPlayer(final Context context) {
|
||||
this.context = context;
|
||||
mCurrentMediaPlayer.setWakeMode(context, PowerManager.PARTIAL_WAKE_LOCK);
|
||||
|
|
@ -138,27 +132,16 @@ public class MultiPlayer implements Playback, MediaPlayer.OnErrorListener, Media
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the callbacks
|
||||
*
|
||||
* @param callbacks The callbacks to use
|
||||
*/
|
||||
@Override
|
||||
public void setCallbacks(@Nullable Playback.PlaybackCallbacks callbacks) {
|
||||
this.callbacks = callbacks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return True if the player is ready to go, false otherwise
|
||||
*/
|
||||
@Override
|
||||
public boolean isInitialized() {
|
||||
return mIsInitialized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts or resumes playback.
|
||||
*/
|
||||
@Override
|
||||
public boolean start() {
|
||||
try {
|
||||
|
|
@ -169,18 +152,12 @@ public class MultiPlayer implements Playback, MediaPlayer.OnErrorListener, Media
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the MediaPlayer to its uninitialized state.
|
||||
*/
|
||||
@Override
|
||||
public void stop() {
|
||||
mCurrentMediaPlayer.reset();
|
||||
mIsInitialized = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases resources associated with this MediaPlayer object.
|
||||
*/
|
||||
@Override
|
||||
public void release() {
|
||||
stop();
|
||||
|
|
@ -190,9 +167,6 @@ public class MultiPlayer implements Playback, MediaPlayer.OnErrorListener, Media
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pauses playback. Call start() to resume.
|
||||
*/
|
||||
@Override
|
||||
public boolean pause() {
|
||||
try {
|
||||
|
|
@ -203,24 +177,17 @@ public class MultiPlayer implements Playback, MediaPlayer.OnErrorListener, Media
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the MultiPlayer is playing.
|
||||
*/
|
||||
@Override
|
||||
public boolean isPlaying() {
|
||||
return mIsInitialized && mCurrentMediaPlayer.isPlaying();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the duration of the file.
|
||||
*
|
||||
* @return The duration in milliseconds
|
||||
*/
|
||||
@Override
|
||||
public int duration() {
|
||||
if (!mIsInitialized) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
try {
|
||||
return mCurrentMediaPlayer.getDuration();
|
||||
} catch (IllegalStateException e) {
|
||||
|
|
@ -228,16 +195,12 @@ public class MultiPlayer implements Playback, MediaPlayer.OnErrorListener, Media
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current playback position.
|
||||
*
|
||||
* @return The current position in milliseconds
|
||||
*/
|
||||
@Override
|
||||
public int position() {
|
||||
if (!mIsInitialized) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
try {
|
||||
return mCurrentMediaPlayer.getCurrentPosition();
|
||||
} catch (IllegalStateException e) {
|
||||
|
|
@ -245,12 +208,6 @@ public class MultiPlayer implements Playback, MediaPlayer.OnErrorListener, Media
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current playback position.
|
||||
*
|
||||
* @param whereto The offset in milliseconds from the start to seek to
|
||||
* @return The offset in milliseconds from the start to seek to
|
||||
*/
|
||||
@Override
|
||||
public int seek(final int whereto) {
|
||||
try {
|
||||
|
|
@ -271,11 +228,6 @@ public class MultiPlayer implements Playback, MediaPlayer.OnErrorListener, Media
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the audio session ID.
|
||||
*
|
||||
* @param sessionId The audio session ID
|
||||
*/
|
||||
@Override
|
||||
public boolean setAudioSessionId(final int sessionId) {
|
||||
try {
|
||||
|
|
@ -286,19 +238,11 @@ public class MultiPlayer implements Playback, MediaPlayer.OnErrorListener, Media
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the audio session ID.
|
||||
*
|
||||
* @return The current audio session ID.
|
||||
*/
|
||||
@Override
|
||||
public int getAudioSessionId() {
|
||||
return mCurrentMediaPlayer.getAudioSessionId();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean onError(final MediaPlayer mp, final int what, final int extra) {
|
||||
mIsInitialized = false;
|
||||
|
|
@ -308,12 +252,10 @@ public class MultiPlayer implements Playback, MediaPlayer.OnErrorListener, Media
|
|||
if (context != null) {
|
||||
Toast.makeText(context, context.getResources().getString(R.string.unplayable_file), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void onCompletion(final MediaPlayer mp) {
|
||||
if (mp == mCurrentMediaPlayer && mNextMediaPlayer != null) {
|
||||
|
|
|
|||
|
|
@ -66,11 +66,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid), Andrew Neal
|
||||
*/
|
||||
public class MusicService extends Service implements SharedPreferences.OnSharedPreferenceChangeListener, Playback.PlaybackCallbacks {
|
||||
|
||||
public static final String PHONOGRAPH_PACKAGE_NAME = "com.kabouzeid.gramophone";
|
||||
public static final String MUSIC_PACKAGE_NAME = "com.android.music";
|
||||
|
||||
|
|
@ -89,7 +85,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
public static final String APP_WIDGET_UPDATE = PHONOGRAPH_PACKAGE_NAME + ".appwidgetupdate";
|
||||
public static final String EXTRA_APP_WIDGET_NAME = PHONOGRAPH_PACKAGE_NAME + "app_widget_name";
|
||||
|
||||
// do not change these three strings as it will break support with other apps (e.g. last.fm scrobbling)
|
||||
// do not change these three strings as it will break support with other apps like last.fm
|
||||
public static final String META_CHANGED = PHONOGRAPH_PACKAGE_NAME + ".metachanged";
|
||||
public static final String QUEUE_CHANGED = PHONOGRAPH_PACKAGE_NAME + ".queuechanged";
|
||||
public static final String PLAY_STATE_CHANGED = PHONOGRAPH_PACKAGE_NAME + ".playstatechanged";
|
||||
|
|
@ -1013,7 +1009,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
sendChangeInternal(what);
|
||||
}
|
||||
|
||||
// to let other apps know whats playing. i.E. last.fm (scrobbling) or musixmatch
|
||||
// to let other apps know whats playing like last.fm
|
||||
private void sendPublicIntent(@NonNull final String what) {
|
||||
final Intent intent = new Intent(what.replace(PHONOGRAPH_PACKAGE_NAME, MUSIC_PACKAGE_NAME));
|
||||
|
||||
|
|
@ -1350,7 +1346,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
@Override
|
||||
public void run() {
|
||||
savePositionInTrack();
|
||||
sendPublicIntent(PLAY_STATE_CHANGED); // for musixmatch synced lyrics
|
||||
sendPublicIntent(PLAY_STATE_CHANGED);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -117,8 +117,9 @@ public class PlayingNotificationImpl extends PlayingNotification {
|
|||
setBackgroundColor(bgColor);
|
||||
setNotificationContent(ColorUtil.isColorLight(bgColor));
|
||||
|
||||
if (stopped)
|
||||
return; // notification has been stopped before loading was finished
|
||||
// notification has been stopped before loading was finished
|
||||
if (stopped) return;
|
||||
|
||||
updateNotifyModeAndPostNotification(notification);
|
||||
}
|
||||
|
||||
|
|
@ -179,5 +180,4 @@ public class PlayingNotificationImpl extends PlayingNotification {
|
|||
intent.setComponent(serviceName);
|
||||
return PendingIntent.getService(context, 0, intent, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,8 +97,9 @@ public class PlayingNotificationImpl24 extends PlayingNotification {
|
|||
builder.setColor(color);
|
||||
}
|
||||
|
||||
if (stopped)
|
||||
return; // notification has been stopped before loading was finished
|
||||
// notification has been stopped before loading was finished
|
||||
if (stopped) return;
|
||||
|
||||
updateNotifyModeAndPostNotification(builder.build());
|
||||
}
|
||||
}));
|
||||
|
|
|
|||
|
|
@ -2,11 +2,7 @@ package com.kabouzeid.gramophone.service.playback;
|
|||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public interface Playback {
|
||||
|
||||
boolean setDataSource(String path);
|
||||
|
||||
void setNextDataSource(@Nullable String path);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue