Added Nullity Annotations
This commit is contained in:
parent
1dcc447e52
commit
5317c51400
102 changed files with 772 additions and 404 deletions
|
|
@ -16,6 +16,7 @@ import java.util.ArrayList;
|
||||||
* @author Karim Abou Zeid (kabouzeid)
|
* @author Karim Abou Zeid (kabouzeid)
|
||||||
*/
|
*/
|
||||||
public abstract class AbsMultiSelectAdapter<VH extends RecyclerView.ViewHolder, I> extends RecyclerView.Adapter<VH> implements MaterialCab.Callback {
|
public abstract class AbsMultiSelectAdapter<VH extends RecyclerView.ViewHolder, I> extends RecyclerView.Adapter<VH> implements MaterialCab.Callback {
|
||||||
|
@Nullable
|
||||||
private final CabHolder cabHolder;
|
private final CabHolder cabHolder;
|
||||||
private MaterialCab cab;
|
private MaterialCab cab;
|
||||||
private ArrayList<I> checked;
|
private ArrayList<I> checked;
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.kabouzeid.gramophone.adapter;
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.util.Pair;
|
import android.support.v4.util.Pair;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
|
@ -54,10 +55,12 @@ public class AlbumAdapter extends AbsMultiSelectAdapter<AlbumAdapter.ViewHolder,
|
||||||
public static final String TAG = AlbumAdapter.class.getSimpleName();
|
public static final String TAG = AlbumAdapter.class.getSimpleName();
|
||||||
private static final int FADE_IN_TIME = 500;
|
private static final int FADE_IN_TIME = 500;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final AppCompatActivity activity;
|
private final AppCompatActivity activity;
|
||||||
private boolean usePalette;
|
private boolean usePalette;
|
||||||
private List<Album> dataSet;
|
private List<Album> dataSet;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
View view = LayoutInflater.from(activity).inflate(R.layout.item_grid_album, parent, false);
|
View view = LayoutInflater.from(activity).inflate(R.layout.item_grid_album, parent, false);
|
||||||
|
|
@ -65,7 +68,7 @@ public class AlbumAdapter extends AbsMultiSelectAdapter<AlbumAdapter.ViewHolder,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(final ViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull final ViewHolder holder, int position) {
|
||||||
final Album album = dataSet.get(position);
|
final Album album = dataSet.get(position);
|
||||||
|
|
||||||
resetColors(holder.title, holder.artist, holder.footer);
|
resetColors(holder.title, holder.artist, holder.footer);
|
||||||
|
|
@ -114,7 +117,7 @@ public class AlbumAdapter extends AbsMultiSelectAdapter<AlbumAdapter.ViewHolder,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onMultipleItemAction(MenuItem menuItem, ArrayList<Album> selection) {
|
protected void onMultipleItemAction(@NonNull MenuItem menuItem, @NonNull ArrayList<Album> selection) {
|
||||||
switch (menuItem.getItemId()) {
|
switch (menuItem.getItemId()) {
|
||||||
case R.id.action_delete_from_disk:
|
case R.id.action_delete_from_disk:
|
||||||
DeleteSongsDialog.create(getSongList(selection)).show(activity.getSupportFragmentManager(), "DELETE_SONGS");
|
DeleteSongsDialog.create(getSongList(selection)).show(activity.getSupportFragmentManager(), "DELETE_SONGS");
|
||||||
|
|
@ -128,7 +131,8 @@ public class AlbumAdapter extends AbsMultiSelectAdapter<AlbumAdapter.ViewHolder,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArrayList<Song> getSongList(List<Album> albums) {
|
@NonNull
|
||||||
|
private ArrayList<Song> getSongList(@NonNull List<Album> albums) {
|
||||||
final ArrayList<Song> songs = new ArrayList<>();
|
final ArrayList<Song> songs = new ArrayList<>();
|
||||||
for (Album album : albums) {
|
for (Album album : albums) {
|
||||||
songs.addAll(AlbumSongLoader.getAlbumSongList(activity, album.id));
|
songs.addAll(AlbumSongLoader.getAlbumSongList(activity, album.id));
|
||||||
|
|
@ -137,14 +141,19 @@ public class AlbumAdapter extends AbsMultiSelectAdapter<AlbumAdapter.ViewHolder,
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||||
|
@NonNull
|
||||||
final ImageView albumArt;
|
final ImageView albumArt;
|
||||||
|
@NonNull
|
||||||
final TextView title;
|
final TextView title;
|
||||||
|
@NonNull
|
||||||
final TextView artist;
|
final TextView artist;
|
||||||
final View footer;
|
final View footer;
|
||||||
|
@NonNull
|
||||||
final ImageView checkMark;
|
final ImageView checkMark;
|
||||||
|
@NonNull
|
||||||
final View view;
|
final View view;
|
||||||
|
|
||||||
public ViewHolder(View itemView) {
|
public ViewHolder(@NonNull View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
view = itemView;
|
view = itemView;
|
||||||
albumArt = (ImageView) itemView.findViewById(R.id.album_art);
|
albumArt = (ImageView) itemView.findViewById(R.id.album_art);
|
||||||
|
|
@ -161,7 +170,7 @@ public class AlbumAdapter extends AbsMultiSelectAdapter<AlbumAdapter.ViewHolder,
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouch(View view, MotionEvent motionEvent) {
|
public boolean onTouch(@NonNull View view, @NonNull MotionEvent motionEvent) {
|
||||||
((FrameLayout) view.findViewById(R.id.content)).getForeground().setHotspot(motionEvent.getX(), motionEvent.getY());
|
((FrameLayout) view.findViewById(R.id.content)).getForeground().setHotspot(motionEvent.getX(), motionEvent.getY());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -191,7 +200,7 @@ public class AlbumAdapter extends AbsMultiSelectAdapter<AlbumAdapter.ViewHolder,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public AlbumAdapter(AppCompatActivity activity, @Nullable CabHolder cabHolder) {
|
public AlbumAdapter(@NonNull AppCompatActivity activity, @Nullable CabHolder cabHolder) {
|
||||||
super(activity, cabHolder, R.menu.menu_media_selection);
|
super(activity, cabHolder, R.menu.menu_media_selection);
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
usePalette = PreferenceUtils.getInstance(activity).coloredAlbumFooters();
|
usePalette = PreferenceUtils.getInstance(activity).coloredAlbumFooters();
|
||||||
|
|
@ -208,13 +217,13 @@ public class AlbumAdapter extends AbsMultiSelectAdapter<AlbumAdapter.ViewHolder,
|
||||||
dataSet = AlbumLoader.getAllAlbums(activity);
|
dataSet = AlbumLoader.getAllAlbums(activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyPalette(Bitmap bitmap, final TextView title, final TextView artist, final View footer) {
|
private void applyPalette(@Nullable Bitmap bitmap, @NonNull final TextView title, @NonNull final TextView artist, @NonNull final View footer) {
|
||||||
if (bitmap != null) {
|
if (bitmap != null) {
|
||||||
Palette.from(bitmap)
|
Palette.from(bitmap)
|
||||||
.resizeBitmapSize(100)
|
.resizeBitmapSize(100)
|
||||||
.generate(new Palette.PaletteAsyncListener() {
|
.generate(new Palette.PaletteAsyncListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onGenerated(Palette palette) {
|
public void onGenerated(@NonNull Palette palette) {
|
||||||
final Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();
|
final Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();
|
||||||
if (vibrantSwatch != null) {
|
if (vibrantSwatch != null) {
|
||||||
title.setTextColor(Util.getOpaqueColor(vibrantSwatch.getTitleTextColor()));
|
title.setTextColor(Util.getOpaqueColor(vibrantSwatch.getTitleTextColor()));
|
||||||
|
|
@ -230,14 +239,14 @@ public class AlbumAdapter extends AbsMultiSelectAdapter<AlbumAdapter.ViewHolder,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void paletteBlackAndWhite(final TextView title, final TextView artist, final View footer) {
|
private void paletteBlackAndWhite(@NonNull final TextView title, @NonNull final TextView artist, final View footer) {
|
||||||
title.setTextColor(Util.getOpaqueColor(DialogUtils.resolveColor(activity, R.attr.title_text_color)));
|
title.setTextColor(Util.getOpaqueColor(DialogUtils.resolveColor(activity, R.attr.title_text_color)));
|
||||||
artist.setTextColor(Util.getOpaqueColor(DialogUtils.resolveColor(activity, R.attr.caption_text_color)));
|
artist.setTextColor(Util.getOpaqueColor(DialogUtils.resolveColor(activity, R.attr.caption_text_color)));
|
||||||
int defaultBarColor = DialogUtils.resolveColor(activity, R.attr.default_bar_color);
|
int defaultBarColor = DialogUtils.resolveColor(activity, R.attr.default_bar_color);
|
||||||
ViewUtil.animateViewColor(footer, defaultBarColor, defaultBarColor);
|
ViewUtil.animateViewColor(footer, defaultBarColor, defaultBarColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetColors(final TextView title, final TextView artist, final View footer) {
|
private void resetColors(@NonNull final TextView title, @NonNull final TextView artist, @NonNull final View footer) {
|
||||||
title.setTextColor(DialogUtils.resolveColor(activity, R.attr.title_text_color));
|
title.setTextColor(DialogUtils.resolveColor(activity, R.attr.title_text_color));
|
||||||
artist.setTextColor(DialogUtils.resolveColor(activity, R.attr.caption_text_color));
|
artist.setTextColor(DialogUtils.resolveColor(activity, R.attr.caption_text_color));
|
||||||
int defaultBarColor = DialogUtils.resolveColor(activity, R.attr.default_bar_color);
|
int defaultBarColor = DialogUtils.resolveColor(activity, R.attr.default_bar_color);
|
||||||
|
|
@ -257,7 +266,7 @@ public class AlbumAdapter extends AbsMultiSelectAdapter<AlbumAdapter.ViewHolder,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onDataBaseEvent(DataBaseChangedEvent event) {
|
public void onDataBaseEvent(@NonNull DataBaseChangedEvent event) {
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
case DataBaseChangedEvent.ALBUMS_CHANGED:
|
case DataBaseChangedEvent.ALBUMS_CHANGED:
|
||||||
case DataBaseChangedEvent.DATABASE_CHANGED:
|
case DataBaseChangedEvent.DATABASE_CHANGED:
|
||||||
|
|
@ -268,7 +277,7 @@ public class AlbumAdapter extends AbsMultiSelectAdapter<AlbumAdapter.ViewHolder,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onUIChangeEvent(UIPreferenceChangedEvent event) {
|
public void onUIChangeEvent(@NonNull UIPreferenceChangedEvent event) {
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
case UIPreferenceChangedEvent.ALBUM_OVERVIEW_PALETTE_CHANGED:
|
case UIPreferenceChangedEvent.ALBUM_OVERVIEW_PALETTE_CHANGED:
|
||||||
usePalette = (boolean) event.getValue();
|
usePalette = (boolean) event.getValue();
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.kabouzeid.gramophone.adapter;
|
package com.kabouzeid.gramophone.adapter;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.util.Pair;
|
import android.support.v4.util.Pair;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
|
@ -43,11 +44,13 @@ import retrofit.client.Response;
|
||||||
* @author Karim Abou Zeid (kabouzeid)
|
* @author Karim Abou Zeid (kabouzeid)
|
||||||
*/
|
*/
|
||||||
public class ArtistAdapter extends AbsMultiSelectAdapter<ArtistAdapter.ViewHolder, Artist> {
|
public class ArtistAdapter extends AbsMultiSelectAdapter<ArtistAdapter.ViewHolder, Artist> {
|
||||||
|
@NonNull
|
||||||
protected final AppCompatActivity activity;
|
protected final AppCompatActivity activity;
|
||||||
protected List<Artist> dataSet;
|
protected List<Artist> dataSet;
|
||||||
|
@NonNull
|
||||||
protected final LastFMRestClient lastFMRestClient;
|
protected final LastFMRestClient lastFMRestClient;
|
||||||
|
|
||||||
public ArtistAdapter(AppCompatActivity activity, @Nullable CabHolder cabHolder) {
|
public ArtistAdapter(@NonNull AppCompatActivity activity, @Nullable CabHolder cabHolder) {
|
||||||
super(activity, cabHolder, R.menu.menu_media_selection);
|
super(activity, cabHolder, R.menu.menu_media_selection);
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
lastFMRestClient = new LastFMRestClient(activity);
|
lastFMRestClient = new LastFMRestClient(activity);
|
||||||
|
|
@ -64,6 +67,7 @@ public class ArtistAdapter extends AbsMultiSelectAdapter<ArtistAdapter.ViewHolde
|
||||||
dataSet = ArtistLoader.getAllArtists(activity);
|
dataSet = ArtistLoader.getAllArtists(activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
View view = LayoutInflater.from(activity).inflate(R.layout.item_list_artist, parent, false);
|
View view = LayoutInflater.from(activity).inflate(R.layout.item_list_artist, parent, false);
|
||||||
|
|
@ -71,7 +75,7 @@ public class ArtistAdapter extends AbsMultiSelectAdapter<ArtistAdapter.ViewHolde
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(final ViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull final ViewHolder holder, int position) {
|
||||||
final Artist artist = dataSet.get(position);
|
final Artist artist = dataSet.get(position);
|
||||||
|
|
||||||
holder.artistName.setText(artist.name);
|
holder.artistName.setText(artist.name);
|
||||||
|
|
@ -85,7 +89,7 @@ public class ArtistAdapter extends AbsMultiSelectAdapter<ArtistAdapter.ViewHolde
|
||||||
|
|
||||||
lastFMRestClient.getApiService().getArtistInfo(artist.name, null, new Callback<ArtistInfo>() {
|
lastFMRestClient.getApiService().getArtistInfo(artist.name, null, new Callback<ArtistInfo>() {
|
||||||
@Override
|
@Override
|
||||||
public void success(ArtistInfo artistInfo, Response response) {
|
public void success(@NonNull ArtistInfo artistInfo, Response response) {
|
||||||
if (artistInfo.getArtist() != null) {
|
if (artistInfo.getArtist() != null) {
|
||||||
int thumbnailIndex = 0;
|
int thumbnailIndex = 0;
|
||||||
List<Image> images = artistInfo.getArtist().getImage();
|
List<Image> images = artistInfo.getArtist().getImage();
|
||||||
|
|
@ -127,7 +131,7 @@ public class ArtistAdapter extends AbsMultiSelectAdapter<ArtistAdapter.ViewHolde
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onMultipleItemAction(MenuItem menuItem, ArrayList<Artist> selection) {
|
protected void onMultipleItemAction(@NonNull MenuItem menuItem, @NonNull ArrayList<Artist> selection) {
|
||||||
switch (menuItem.getItemId()) {
|
switch (menuItem.getItemId()) {
|
||||||
case R.id.action_delete_from_disk:
|
case R.id.action_delete_from_disk:
|
||||||
DeleteSongsDialog.create(getSongList(selection)).show(activity.getSupportFragmentManager(), "DELETE_SONGS");
|
DeleteSongsDialog.create(getSongList(selection)).show(activity.getSupportFragmentManager(), "DELETE_SONGS");
|
||||||
|
|
@ -141,7 +145,8 @@ public class ArtistAdapter extends AbsMultiSelectAdapter<ArtistAdapter.ViewHolde
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArrayList<Song> getSongList(List<Artist> artists) {
|
@NonNull
|
||||||
|
private ArrayList<Song> getSongList(@NonNull List<Artist> artists) {
|
||||||
final ArrayList<Song> songs = new ArrayList<>();
|
final ArrayList<Song> songs = new ArrayList<>();
|
||||||
for (Artist artist : artists) {
|
for (Artist artist : artists) {
|
||||||
songs.addAll(ArtistSongLoader.getArtistSongList(activity, artist.id));
|
songs.addAll(ArtistSongLoader.getArtistSongList(activity, artist.id));
|
||||||
|
|
@ -150,12 +155,16 @@ public class ArtistAdapter extends AbsMultiSelectAdapter<ArtistAdapter.ViewHolde
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||||
|
@NonNull
|
||||||
final TextView artistName;
|
final TextView artistName;
|
||||||
|
@NonNull
|
||||||
final TextView artistInfo;
|
final TextView artistInfo;
|
||||||
|
@NonNull
|
||||||
final ImageView artistImage;
|
final ImageView artistImage;
|
||||||
|
@NonNull
|
||||||
final View view;
|
final View view;
|
||||||
|
|
||||||
public ViewHolder(View itemView) {
|
public ViewHolder(@NonNull View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
view = itemView;
|
view = itemView;
|
||||||
artistName = (TextView) itemView.findViewById(R.id.artist_name);
|
artistName = (TextView) itemView.findViewById(R.id.artist_name);
|
||||||
|
|
@ -200,7 +209,7 @@ public class ArtistAdapter extends AbsMultiSelectAdapter<ArtistAdapter.ViewHolde
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onDataBaseEvent(DataBaseChangedEvent event) {
|
public void onDataBaseEvent(@NonNull DataBaseChangedEvent event) {
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
case DataBaseChangedEvent.ARTISTS_CHANGED:
|
case DataBaseChangedEvent.ARTISTS_CHANGED:
|
||||||
case DataBaseChangedEvent.DATABASE_CHANGED:
|
case DataBaseChangedEvent.DATABASE_CHANGED:
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.kabouzeid.gramophone.adapter;
|
package com.kabouzeid.gramophone.adapter;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.util.Pair;
|
import android.support.v4.util.Pair;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
|
@ -38,11 +39,12 @@ public class ArtistAlbumAdapter extends AbsMultiSelectAdapter<ArtistAlbumAdapter
|
||||||
private static final int TYPE_MIDDLE = 2;
|
private static final int TYPE_MIDDLE = 2;
|
||||||
private static final int TYPE_LAST = 3;
|
private static final int TYPE_LAST = 3;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final AppCompatActivity activity;
|
private final AppCompatActivity activity;
|
||||||
private ArrayList<Album> dataSet;
|
private ArrayList<Album> dataSet;
|
||||||
private final int listMargin;
|
private final int listMargin;
|
||||||
|
|
||||||
public ArtistAlbumAdapter(AppCompatActivity activity, ArrayList<Album> objects, @Nullable CabHolder cabHolder) {
|
public ArtistAlbumAdapter(@NonNull AppCompatActivity activity, ArrayList<Album> objects, @Nullable CabHolder cabHolder) {
|
||||||
super(activity, cabHolder, R.menu.menu_media_selection);
|
super(activity, cabHolder, R.menu.menu_media_selection);
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
dataSet = objects;
|
dataSet = objects;
|
||||||
|
|
@ -60,6 +62,7 @@ public class ArtistAlbumAdapter extends AbsMultiSelectAdapter<ArtistAlbumAdapter
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
View view = LayoutInflater.from(activity).inflate(R.layout.item_grid_artist_album, parent, false);
|
View view = LayoutInflater.from(activity).inflate(R.layout.item_grid_artist_album, parent, false);
|
||||||
|
|
@ -73,7 +76,7 @@ public class ArtistAlbumAdapter extends AbsMultiSelectAdapter<ArtistAlbumAdapter
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(final ViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull final ViewHolder holder, int position) {
|
||||||
final Album album = dataSet.get(position);
|
final Album album = dataSet.get(position);
|
||||||
|
|
||||||
ImageLoader.getInstance().displayImage(
|
ImageLoader.getInstance().displayImage(
|
||||||
|
|
@ -111,7 +114,7 @@ public class ArtistAlbumAdapter extends AbsMultiSelectAdapter<ArtistAlbumAdapter
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onMultipleItemAction(MenuItem menuItem, ArrayList<Album> selection) {
|
protected void onMultipleItemAction(@NonNull MenuItem menuItem, @NonNull ArrayList<Album> selection) {
|
||||||
switch (menuItem.getItemId()) {
|
switch (menuItem.getItemId()) {
|
||||||
case R.id.action_delete_from_disk:
|
case R.id.action_delete_from_disk:
|
||||||
DeleteSongsDialog.create(getSongList(selection)).show(activity.getSupportFragmentManager(), "DELETE_SONGS");
|
DeleteSongsDialog.create(getSongList(selection)).show(activity.getSupportFragmentManager(), "DELETE_SONGS");
|
||||||
|
|
@ -125,7 +128,8 @@ public class ArtistAlbumAdapter extends AbsMultiSelectAdapter<ArtistAlbumAdapter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArrayList<Song> getSongList(List<Album> albums) {
|
@NonNull
|
||||||
|
private ArrayList<Song> getSongList(@NonNull List<Album> albums) {
|
||||||
final ArrayList<Song> songs = new ArrayList<>();
|
final ArrayList<Song> songs = new ArrayList<>();
|
||||||
for (Album album : albums) {
|
for (Album album : albums) {
|
||||||
songs.addAll(AlbumSongLoader.getAlbumSongList(activity, album.id));
|
songs.addAll(AlbumSongLoader.getAlbumSongList(activity, album.id));
|
||||||
|
|
@ -134,12 +138,16 @@ public class ArtistAlbumAdapter extends AbsMultiSelectAdapter<ArtistAlbumAdapter
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||||
|
@NonNull
|
||||||
final ImageView albumArt;
|
final ImageView albumArt;
|
||||||
|
@NonNull
|
||||||
final TextView title;
|
final TextView title;
|
||||||
|
@NonNull
|
||||||
final TextView year;
|
final TextView year;
|
||||||
|
@NonNull
|
||||||
final View view;
|
final View view;
|
||||||
|
|
||||||
public ViewHolder(View itemView) {
|
public ViewHolder(@NonNull View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
view = itemView;
|
view = itemView;
|
||||||
albumArt = (ImageView) itemView.findViewById(R.id.album_art);
|
albumArt = (ImageView) itemView.findViewById(R.id.album_art);
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.kabouzeid.gramophone.adapter;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.app.FragmentPagerAdapter;
|
import android.support.v4.app.FragmentPagerAdapter;
|
||||||
|
|
@ -25,13 +26,15 @@ public class PagerAdapter extends FragmentPagerAdapter {
|
||||||
|
|
||||||
private final List<Holder> mHolderList = new ArrayList<>();
|
private final List<Holder> mHolderList = new ArrayList<>();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
|
||||||
private int mCurrentPage;
|
private int mCurrentPage;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final String[] titles;
|
private final String[] titles;
|
||||||
|
|
||||||
public PagerAdapter(final Context context, final FragmentManager fragmentManager) {
|
public PagerAdapter(@NonNull final Context context, final FragmentManager fragmentManager) {
|
||||||
super(fragmentManager);
|
super(fragmentManager);
|
||||||
mContext = context;
|
mContext = context;
|
||||||
titles = new String[]{
|
titles = new String[]{
|
||||||
|
|
@ -43,7 +46,7 @@ public class PagerAdapter extends FragmentPagerAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("synthetic-access")
|
@SuppressWarnings("synthetic-access")
|
||||||
public void add(final Class<? extends Fragment> className, final Bundle params) {
|
public void add(@NonNull final Class<? extends Fragment> className, final Bundle params) {
|
||||||
final Holder mHolder = new Holder();
|
final Holder mHolder = new Holder();
|
||||||
mHolder.mClassName = className.getName();
|
mHolder.mClassName = className.getName();
|
||||||
mHolder.mParams = params;
|
mHolder.mParams = params;
|
||||||
|
|
@ -61,8 +64,9 @@ public class PagerAdapter extends FragmentPagerAdapter {
|
||||||
return getItem(position);
|
return getItem(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Object instantiateItem(final ViewGroup container, final int position) {
|
public Object instantiateItem(@NonNull final ViewGroup container, final int position) {
|
||||||
final Fragment mFragment = (Fragment) super.instantiateItem(container, position);
|
final Fragment mFragment = (Fragment) super.instantiateItem(container, position);
|
||||||
final WeakReference<Fragment> mWeakFragment = mFragmentArray.get(position);
|
final WeakReference<Fragment> mWeakFragment = mFragmentArray.get(position);
|
||||||
if (mWeakFragment != null) {
|
if (mWeakFragment != null) {
|
||||||
|
|
@ -93,6 +97,7 @@ public class PagerAdapter extends FragmentPagerAdapter {
|
||||||
return mHolderList.size();
|
return mHolderList.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getPageTitle(final int position) {
|
public CharSequence getPageTitle(final int position) {
|
||||||
return titles[position]
|
return titles[position]
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package com.kabouzeid.gramophone.adapter;
|
package com.kabouzeid.gramophone.adapter;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
@ -24,15 +26,17 @@ import java.util.ArrayList;
|
||||||
*/
|
*/
|
||||||
public class PlayingQueueAdapter extends ArrayAdapter<Song> {
|
public class PlayingQueueAdapter extends ArrayAdapter<Song> {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final AppCompatActivity activity;
|
private final AppCompatActivity activity;
|
||||||
|
|
||||||
public PlayingQueueAdapter(AppCompatActivity activity, ArrayList<Song> playList) {
|
public PlayingQueueAdapter(@NonNull AppCompatActivity activity, @NonNull ArrayList<Song> playList) {
|
||||||
super(activity, R.layout.item_list_playlist_song, playList);
|
super(activity, R.layout.item_list_playlist_song, playList);
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
public View getView(final int position, @Nullable View convertView, ViewGroup parent) {
|
||||||
final Song song = getItem(position);
|
final Song song = getItem(position);
|
||||||
if (convertView == null) {
|
if (convertView == null) {
|
||||||
convertView = LayoutInflater.from(activity).inflate(R.layout.item_list_playlist_song, parent, false);
|
convertView = LayoutInflater.from(activity).inflate(R.layout.item_list_playlist_song, parent, false);
|
||||||
|
|
@ -56,7 +60,7 @@ public class PlayingQueueAdapter extends ArrayAdapter<Song> {
|
||||||
popupMenu.inflate(R.menu.menu_item_playing_queue_song);
|
popupMenu.inflate(R.menu.menu_item_playing_queue_song);
|
||||||
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
public boolean onMenuItemClick(@NonNull MenuItem item) {
|
||||||
if (item.getItemId() == R.id.action_remove_from_playing_queue) {
|
if (item.getItemId() == R.id.action_remove_from_playing_queue) {
|
||||||
MusicPlayerRemote.removeFromQueue(position);
|
MusicPlayerRemote.removeFromQueue(position);
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.kabouzeid.gramophone.adapter;
|
package com.kabouzeid.gramophone.adapter;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.util.Pair;
|
import android.support.v4.util.Pair;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
|
@ -72,6 +73,7 @@ public class PlaylistAdapter extends AbsMultiSelectAdapter<PlaylistAdapter.ViewH
|
||||||
dataSet.addAll(PlaylistLoader.getAllPlaylists(activity));
|
dataSet.addAll(PlaylistLoader.getAllPlaylists(activity));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
int layoutRes = viewType == VIEW_TYPE_DEFAULT ? R.layout.item_list_playlist : R.layout.item_list_smart_playlist;
|
int layoutRes = viewType == VIEW_TYPE_DEFAULT ? R.layout.item_list_playlist : R.layout.item_list_smart_playlist;
|
||||||
|
|
@ -80,7 +82,7 @@ public class PlaylistAdapter extends AbsMultiSelectAdapter<PlaylistAdapter.ViewH
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(ViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||||
final Playlist playlist = dataSet.get(position);
|
final Playlist playlist = dataSet.get(position);
|
||||||
holder.playlistName.setText(playlist.name);
|
holder.playlistName.setText(playlist.name);
|
||||||
holder.view.setActivated(isChecked(playlist));
|
holder.view.setActivated(isChecked(playlist));
|
||||||
|
|
@ -110,7 +112,7 @@ public class PlaylistAdapter extends AbsMultiSelectAdapter<PlaylistAdapter.ViewH
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onMultipleItemAction(MenuItem menuItem, ArrayList<Playlist> selection) {
|
protected void onMultipleItemAction(@NonNull MenuItem menuItem, @NonNull ArrayList<Playlist> selection) {
|
||||||
switch (menuItem.getItemId()) {
|
switch (menuItem.getItemId()) {
|
||||||
case R.id.action_delete_playlist:
|
case R.id.action_delete_playlist:
|
||||||
for (int i = 0; i < selection.size(); i++) {
|
for (int i = 0; i < selection.size(); i++) {
|
||||||
|
|
@ -135,7 +137,8 @@ public class PlaylistAdapter extends AbsMultiSelectAdapter<PlaylistAdapter.ViewH
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArrayList<Song> getSongList(List<Playlist> playlists) {
|
@NonNull
|
||||||
|
private ArrayList<Song> getSongList(@NonNull List<Playlist> playlists) {
|
||||||
final ArrayList<Song> songs = new ArrayList<>();
|
final ArrayList<Song> songs = new ArrayList<>();
|
||||||
for (Playlist playlist : playlists) {
|
for (Playlist playlist : playlists) {
|
||||||
if (playlist instanceof AbsSmartPlaylist) {
|
if (playlist instanceof AbsSmartPlaylist) {
|
||||||
|
|
@ -156,7 +159,7 @@ public class PlaylistAdapter extends AbsMultiSelectAdapter<PlaylistAdapter.ViewH
|
||||||
ImageView icon;
|
ImageView icon;
|
||||||
View view;
|
View view;
|
||||||
|
|
||||||
public ViewHolder(View itemView) {
|
public ViewHolder(@NonNull View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
ButterKnife.inject(this, itemView);
|
ButterKnife.inject(this, itemView);
|
||||||
view = itemView;
|
view = itemView;
|
||||||
|
|
@ -169,7 +172,7 @@ public class PlaylistAdapter extends AbsMultiSelectAdapter<PlaylistAdapter.ViewH
|
||||||
popupMenu.inflate(getItemViewType() == VIEW_TYPE_SMART ? R.menu.menu_item_smart_playlist : R.menu.menu_item_playlist);
|
popupMenu.inflate(getItemViewType() == VIEW_TYPE_SMART ? R.menu.menu_item_smart_playlist : R.menu.menu_item_playlist);
|
||||||
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
public boolean onMenuItemClick(@NonNull MenuItem item) {
|
||||||
if (item.getItemId() == R.id.action_clear_playlist) {
|
if (item.getItemId() == R.id.action_clear_playlist) {
|
||||||
Playlist playlist = dataSet.get(getAdapterPosition());
|
Playlist playlist = dataSet.get(getAdapterPosition());
|
||||||
if (playlist instanceof AbsSmartPlaylist) {
|
if (playlist instanceof AbsSmartPlaylist) {
|
||||||
|
|
@ -219,7 +222,7 @@ public class PlaylistAdapter extends AbsMultiSelectAdapter<PlaylistAdapter.ViewH
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onDataBaseEvent(DataBaseChangedEvent event) {
|
public void onDataBaseEvent(@NonNull DataBaseChangedEvent event) {
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
case DataBaseChangedEvent.PLAYLISTS_CHANGED:
|
case DataBaseChangedEvent.PLAYLISTS_CHANGED:
|
||||||
case DataBaseChangedEvent.DATABASE_CHANGED:
|
case DataBaseChangedEvent.DATABASE_CHANGED:
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package com.kabouzeid.gramophone.adapter;
|
package com.kabouzeid.gramophone.adapter;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.util.Pair;
|
import android.support.v4.util.Pair;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
|
@ -48,18 +50,21 @@ public class SearchAdapter extends RecyclerView.Adapter<SearchAdapter.ViewHolder
|
||||||
private static final int ARTIST = 2;
|
private static final int ARTIST = 2;
|
||||||
private static final int SONG = 3;
|
private static final int SONG = 3;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final AppCompatActivity activity;
|
private final AppCompatActivity activity;
|
||||||
|
@NonNull
|
||||||
private List results = Collections.emptyList();
|
private List results = Collections.emptyList();
|
||||||
private String query;
|
private String query;
|
||||||
|
@NonNull
|
||||||
private final LastFMRestClient lastFMRestClient;
|
private final LastFMRestClient lastFMRestClient;
|
||||||
|
|
||||||
public SearchAdapter(AppCompatActivity activity) {
|
public SearchAdapter(@NonNull AppCompatActivity activity) {
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
lastFMRestClient = new LastFMRestClient(activity);
|
lastFMRestClient = new LastFMRestClient(activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void search(String query) {
|
public void search(@NonNull String query) {
|
||||||
this.query = query;
|
this.query = query;
|
||||||
results = new ArrayList();
|
results = new ArrayList();
|
||||||
if (!query.trim().equals("")) {
|
if (!query.trim().equals("")) {
|
||||||
|
|
@ -92,6 +97,7 @@ public class SearchAdapter extends RecyclerView.Adapter<SearchAdapter.ViewHolder
|
||||||
return HEADER;
|
return HEADER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
if (viewType == ALBUM)
|
if (viewType == ALBUM)
|
||||||
|
|
@ -104,7 +110,7 @@ public class SearchAdapter extends RecyclerView.Adapter<SearchAdapter.ViewHolder
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(final ViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull final ViewHolder holder, int position) {
|
||||||
switch (getItemViewType(position)) {
|
switch (getItemViewType(position)) {
|
||||||
case ALBUM:
|
case ALBUM:
|
||||||
final Album album = (Album) results.get(position);
|
final Album album = (Album) results.get(position);
|
||||||
|
|
@ -130,7 +136,7 @@ public class SearchAdapter extends RecyclerView.Adapter<SearchAdapter.ViewHolder
|
||||||
}
|
}
|
||||||
lastFMRestClient.getApiService().getArtistInfo(artist.name, null, new Callback<ArtistInfo>() {
|
lastFMRestClient.getApiService().getArtistInfo(artist.name, null, new Callback<ArtistInfo>() {
|
||||||
@Override
|
@Override
|
||||||
public void success(ArtistInfo artistInfo, Response response) {
|
public void success(@NonNull ArtistInfo artistInfo, Response response) {
|
||||||
if (artistInfo.getArtist() != null) {
|
if (artistInfo.getArtist() != null) {
|
||||||
int thumbnailIndex = 0;
|
int thumbnailIndex = 0;
|
||||||
List<Image> images = artistInfo.getArtist().getImage();
|
List<Image> images = artistInfo.getArtist().getImage();
|
||||||
|
|
@ -177,12 +183,15 @@ public class SearchAdapter extends RecyclerView.Adapter<SearchAdapter.ViewHolder
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||||
|
@Nullable
|
||||||
private final ImageView image;
|
private final ImageView image;
|
||||||
|
@NonNull
|
||||||
public final TextView title;
|
public final TextView title;
|
||||||
|
@Nullable
|
||||||
public final TextView subTitle;
|
public final TextView subTitle;
|
||||||
private final int viewType;
|
private final int viewType;
|
||||||
|
|
||||||
public ViewHolder(View itemView, int viewType) {
|
public ViewHolder(@NonNull View itemView, int viewType) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
itemView.setOnClickListener(this);
|
itemView.setOnClickListener(this);
|
||||||
this.viewType = viewType;
|
this.viewType = viewType;
|
||||||
|
|
@ -208,7 +217,7 @@ public class SearchAdapter extends RecyclerView.Adapter<SearchAdapter.ViewHolder
|
||||||
popupMenu.inflate(R.menu.menu_item_song);
|
popupMenu.inflate(R.menu.menu_item_song);
|
||||||
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemClick(MenuItem menuItem) {
|
public boolean onMenuItemClick(@NonNull MenuItem menuItem) {
|
||||||
return MenuItemClickHelper.handleSongMenuClick(activity, (Song) results.get(getAdapterPosition()), menuItem);
|
return MenuItemClickHelper.handleSongMenuClick(activity, (Song) results.get(getAdapterPosition()), menuItem);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -269,7 +278,7 @@ public class SearchAdapter extends RecyclerView.Adapter<SearchAdapter.ViewHolder
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onDataBaseEvent(DataBaseChangedEvent event) {
|
public void onDataBaseEvent(@NonNull DataBaseChangedEvent event) {
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
case DataBaseChangedEvent.ALBUMS_CHANGED:
|
case DataBaseChangedEvent.ALBUMS_CHANGED:
|
||||||
case DataBaseChangedEvent.DATABASE_CHANGED:
|
case DataBaseChangedEvent.DATABASE_CHANGED:
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.kabouzeid.gramophone.adapter.songadapter;
|
package com.kabouzeid.gramophone.adapter.songadapter;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
|
@ -49,6 +50,7 @@ public class AlbumSongAdapter extends AbsMultiSelectAdapter<AlbumSongAdapter.Vie
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
View view = LayoutInflater.from(activity).inflate(R.layout.item_list_album_song, parent, false);
|
View view = LayoutInflater.from(activity).inflate(R.layout.item_list_album_song, parent, false);
|
||||||
|
|
@ -56,7 +58,7 @@ public class AlbumSongAdapter extends AbsMultiSelectAdapter<AlbumSongAdapter.Vie
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(ViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||||
final Song song = dataSet.get(position);
|
final Song song = dataSet.get(position);
|
||||||
|
|
||||||
final int trackNumber = MusicUtil.getFixedTrackNumber(song.trackNumber);
|
final int trackNumber = MusicUtil.getFixedTrackNumber(song.trackNumber);
|
||||||
|
|
@ -78,7 +80,7 @@ public class AlbumSongAdapter extends AbsMultiSelectAdapter<AlbumSongAdapter.Vie
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onMultipleItemAction(MenuItem menuItem, ArrayList<Song> selection) {
|
protected void onMultipleItemAction(@NonNull MenuItem menuItem, @NonNull ArrayList<Song> selection) {
|
||||||
switch (menuItem.getItemId()) {
|
switch (menuItem.getItemId()) {
|
||||||
case R.id.action_delete_from_disk:
|
case R.id.action_delete_from_disk:
|
||||||
DeleteSongsDialog.create(selection).show(activity.getSupportFragmentManager(), "DELETE_SONGS");
|
DeleteSongsDialog.create(selection).show(activity.getSupportFragmentManager(), "DELETE_SONGS");
|
||||||
|
|
@ -93,13 +95,18 @@ public class AlbumSongAdapter extends AbsMultiSelectAdapter<AlbumSongAdapter.Vie
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||||
|
@NonNull
|
||||||
final TextView songTitle;
|
final TextView songTitle;
|
||||||
|
@NonNull
|
||||||
final TextView trackNumber;
|
final TextView trackNumber;
|
||||||
|
@NonNull
|
||||||
final TextView artistName;
|
final TextView artistName;
|
||||||
|
@NonNull
|
||||||
final ImageView overflowButton;
|
final ImageView overflowButton;
|
||||||
|
@NonNull
|
||||||
final View view;
|
final View view;
|
||||||
|
|
||||||
public ViewHolder(View itemView) {
|
public ViewHolder(@NonNull View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
view = itemView;
|
view = itemView;
|
||||||
songTitle = (TextView) itemView.findViewById(R.id.song_title);
|
songTitle = (TextView) itemView.findViewById(R.id.song_title);
|
||||||
|
|
@ -115,7 +122,7 @@ public class AlbumSongAdapter extends AbsMultiSelectAdapter<AlbumSongAdapter.Vie
|
||||||
popupMenu.inflate(R.menu.menu_item_song);
|
popupMenu.inflate(R.menu.menu_item_song);
|
||||||
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
public boolean onMenuItemClick(@NonNull MenuItem item) {
|
||||||
return MenuItemClickHelper.handleSongMenuClick(activity, dataSet.get(getAdapterPosition()), item);
|
return MenuItemClickHelper.handleSongMenuClick(activity, dataSet.get(getAdapterPosition()), item);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.kabouzeid.gramophone.adapter.songadapter;
|
package com.kabouzeid.gramophone.adapter.songadapter;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.util.Pair;
|
import android.support.v4.util.Pair;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
|
@ -34,14 +35,16 @@ import java.util.ArrayList;
|
||||||
*/
|
*/
|
||||||
public class ArtistSongAdapter extends ArrayAdapter<Song> implements MaterialCab.Callback {
|
public class ArtistSongAdapter extends ArrayAdapter<Song> implements MaterialCab.Callback {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private final CabHolder cabHolder;
|
private final CabHolder cabHolder;
|
||||||
private MaterialCab cab;
|
private MaterialCab cab;
|
||||||
private ArrayList<Song> dataSet;
|
private ArrayList<Song> dataSet;
|
||||||
private ArrayList<Song> checked;
|
private ArrayList<Song> checked;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final AppCompatActivity activity;
|
private final AppCompatActivity activity;
|
||||||
|
|
||||||
public ArtistSongAdapter(AppCompatActivity activity, ArrayList<Song> songs, @Nullable CabHolder cabHolder) {
|
public ArtistSongAdapter(@NonNull AppCompatActivity activity, @NonNull ArrayList<Song> songs, @Nullable CabHolder cabHolder) {
|
||||||
super(activity, R.layout.item_list_song, songs);
|
super(activity, R.layout.item_list_song, songs);
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
this.cabHolder = cabHolder;
|
this.cabHolder = cabHolder;
|
||||||
|
|
@ -55,8 +58,9 @@ public class ArtistSongAdapter extends ArrayAdapter<Song> implements MaterialCab
|
||||||
addAll(dataSet);
|
addAll(dataSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
public View getView(final int position, @Nullable View convertView, ViewGroup parent) {
|
||||||
final Song song = getItem(position);
|
final Song song = getItem(position);
|
||||||
if (convertView == null) {
|
if (convertView == null) {
|
||||||
convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_list_artist_song, parent, false);
|
convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_list_artist_song, parent, false);
|
||||||
|
|
@ -87,7 +91,7 @@ public class ArtistSongAdapter extends ArrayAdapter<Song> implements MaterialCab
|
||||||
popupMenu.inflate(R.menu.menu_item_song);
|
popupMenu.inflate(R.menu.menu_item_song);
|
||||||
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
public boolean onMenuItemClick(@NonNull MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.action_go_to_album:
|
case R.id.action_go_to_album:
|
||||||
Pair[] albumPairs = new Pair[]{
|
Pair[] albumPairs = new Pair[]{
|
||||||
|
|
@ -127,7 +131,7 @@ public class ArtistSongAdapter extends ArrayAdapter<Song> implements MaterialCab
|
||||||
return convertView;
|
return convertView;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onMultipleItemAction(MenuItem menuItem, ArrayList<Song> selection) {
|
private void onMultipleItemAction(@NonNull MenuItem menuItem, @NonNull ArrayList<Song> selection) {
|
||||||
switch (menuItem.getItemId()) {
|
switch (menuItem.getItemId()) {
|
||||||
case R.id.action_delete_from_disk:
|
case R.id.action_delete_from_disk:
|
||||||
DeleteSongsDialog.create(selection).show(activity.getSupportFragmentManager(), "DELETE_SONGS");
|
DeleteSongsDialog.create(selection).show(activity.getSupportFragmentManager(), "DELETE_SONGS");
|
||||||
|
|
@ -182,7 +186,7 @@ public class ArtistSongAdapter extends ArrayAdapter<Song> implements MaterialCab
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCabItemClicked(MenuItem menuItem) {
|
public boolean onCabItemClicked(@NonNull MenuItem menuItem) {
|
||||||
onMultipleItemAction(menuItem, new ArrayList<>(checked));
|
onMultipleItemAction(menuItem, new ArrayList<>(checked));
|
||||||
cab.finish();
|
cab.finish();
|
||||||
uncheckAll();
|
uncheckAll();
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.kabouzeid.gramophone.adapter.songadapter;
|
package com.kabouzeid.gramophone.adapter.songadapter;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.util.Pair;
|
import android.support.v4.util.Pair;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
|
@ -39,11 +40,12 @@ import java.util.List;
|
||||||
public class PlaylistSongAdapter extends AbsPlaylistSongAdapter<PlaylistSongAdapter.ViewHolder, PlaylistSong> {
|
public class PlaylistSongAdapter extends AbsPlaylistSongAdapter<PlaylistSongAdapter.ViewHolder, PlaylistSong> {
|
||||||
|
|
||||||
public static final String TAG = PlaylistSongAdapter.class.getSimpleName();
|
public static final String TAG = PlaylistSongAdapter.class.getSimpleName();
|
||||||
|
@NonNull
|
||||||
protected final AppCompatActivity activity;
|
protected final AppCompatActivity activity;
|
||||||
protected ArrayList<PlaylistSong> dataSet;
|
protected ArrayList<PlaylistSong> dataSet;
|
||||||
private Playlist playlist;
|
private Playlist playlist;
|
||||||
|
|
||||||
public PlaylistSongAdapter(AppCompatActivity activity, Playlist playlist, @Nullable CabHolder cabHolder) {
|
public PlaylistSongAdapter(@NonNull AppCompatActivity activity, @NonNull Playlist playlist, @Nullable CabHolder cabHolder) {
|
||||||
super(activity, cabHolder, R.menu.menu_playlists_songs_selection);
|
super(activity, cabHolder, R.menu.menu_playlists_songs_selection);
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
this.playlist = playlist;
|
this.playlist = playlist;
|
||||||
|
|
@ -67,6 +69,7 @@ public class PlaylistSongAdapter extends AbsPlaylistSongAdapter<PlaylistSongAdap
|
||||||
return dataSet;
|
return dataSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
View view = LayoutInflater.from(activity).inflate(R.layout.item_list_song, parent, false);
|
View view = LayoutInflater.from(activity).inflate(R.layout.item_list_song, parent, false);
|
||||||
|
|
@ -74,7 +77,7 @@ public class PlaylistSongAdapter extends AbsPlaylistSongAdapter<PlaylistSongAdap
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(final ViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull final ViewHolder holder, int position) {
|
||||||
final PlaylistSong song = dataSet.get(position);
|
final PlaylistSong song = dataSet.get(position);
|
||||||
|
|
||||||
holder.itemView.setActivated(isChecked(song));
|
holder.itemView.setActivated(isChecked(song));
|
||||||
|
|
@ -102,7 +105,7 @@ public class PlaylistSongAdapter extends AbsPlaylistSongAdapter<PlaylistSongAdap
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onMultipleItemAction(MenuItem menuItem, ArrayList<PlaylistSong> selection) {
|
protected void onMultipleItemAction(@NonNull MenuItem menuItem, ArrayList<PlaylistSong> selection) {
|
||||||
switch (menuItem.getItemId()) {
|
switch (menuItem.getItemId()) {
|
||||||
case R.id.action_delete_from_playlist:
|
case R.id.action_delete_from_playlist:
|
||||||
RemoveFromPlaylistDialog.create(selection).show(activity.getSupportFragmentManager(), "ADD_PLAYLIST");
|
RemoveFromPlaylistDialog.create(selection).show(activity.getSupportFragmentManager(), "ADD_PLAYLIST");
|
||||||
|
|
@ -129,12 +132,16 @@ public class PlaylistSongAdapter extends AbsPlaylistSongAdapter<PlaylistSongAdap
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||||
|
@NonNull
|
||||||
final TextView songTitle;
|
final TextView songTitle;
|
||||||
|
@NonNull
|
||||||
final TextView songInfo;
|
final TextView songInfo;
|
||||||
|
@NonNull
|
||||||
final ImageView overflowButton;
|
final ImageView overflowButton;
|
||||||
|
@NonNull
|
||||||
final ImageView albumArt;
|
final ImageView albumArt;
|
||||||
|
|
||||||
public ViewHolder(View itemView, final int songMenu) {
|
public ViewHolder(@NonNull View itemView, final int songMenu) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
songTitle = (TextView) itemView.findViewById(R.id.song_title);
|
songTitle = (TextView) itemView.findViewById(R.id.song_title);
|
||||||
songInfo = (TextView) itemView.findViewById(R.id.song_info);
|
songInfo = (TextView) itemView.findViewById(R.id.song_info);
|
||||||
|
|
@ -149,7 +156,7 @@ public class PlaylistSongAdapter extends AbsPlaylistSongAdapter<PlaylistSongAdap
|
||||||
popupMenu.inflate(songMenu);
|
popupMenu.inflate(songMenu);
|
||||||
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
public boolean onMenuItemClick(@NonNull MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.action_delete_from_playlist:
|
case R.id.action_delete_from_playlist:
|
||||||
RemoveFromPlaylistDialog.create(dataSet.get(getAdapterPosition())).show(activity.getSupportFragmentManager(), "ADD_PLAYLIST");
|
RemoveFromPlaylistDialog.create(dataSet.get(getAdapterPosition())).show(activity.getSupportFragmentManager(), "ADD_PLAYLIST");
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.kabouzeid.gramophone.adapter.songadapter;
|
package com.kabouzeid.gramophone.adapter.songadapter;
|
||||||
|
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.util.Pair;
|
import android.support.v4.util.Pair;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
|
@ -63,6 +64,7 @@ public class SongAdapter extends AbsMultiSelectAdapter<SongAdapter.ViewHolder, S
|
||||||
dataSet = SongLoader.getAllSongs(activity);
|
dataSet = SongLoader.getAllSongs(activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
View view = LayoutInflater.from(activity).inflate(R.layout.item_list_song, parent, false);
|
View view = LayoutInflater.from(activity).inflate(R.layout.item_list_song, parent, false);
|
||||||
|
|
@ -75,7 +77,7 @@ public class SongAdapter extends AbsMultiSelectAdapter<SongAdapter.ViewHolder, S
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(final ViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull final ViewHolder holder, int position) {
|
||||||
if (getItemViewType(position) == SONG) {
|
if (getItemViewType(position) == SONG) {
|
||||||
final Song song = dataSet.get(position - 1);
|
final Song song = dataSet.get(position - 1);
|
||||||
|
|
||||||
|
|
@ -118,7 +120,7 @@ public class SongAdapter extends AbsMultiSelectAdapter<SongAdapter.ViewHolder, S
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onMultipleItemAction(MenuItem menuItem, ArrayList<Song> selection) {
|
protected void onMultipleItemAction(@NonNull MenuItem menuItem, @NonNull ArrayList<Song> selection) {
|
||||||
switch (menuItem.getItemId()) {
|
switch (menuItem.getItemId()) {
|
||||||
case R.id.action_delete_from_disk:
|
case R.id.action_delete_from_disk:
|
||||||
DeleteSongsDialog.create(selection).show(activity.getSupportFragmentManager(), "DELETE_SONGS");
|
DeleteSongsDialog.create(selection).show(activity.getSupportFragmentManager(), "DELETE_SONGS");
|
||||||
|
|
@ -133,15 +135,20 @@ public class SongAdapter extends AbsMultiSelectAdapter<SongAdapter.ViewHolder, S
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||||
|
@NonNull
|
||||||
final TextView songTitle;
|
final TextView songTitle;
|
||||||
|
@NonNull
|
||||||
final TextView songInfo;
|
final TextView songInfo;
|
||||||
|
@NonNull
|
||||||
final ImageView overflowButton;
|
final ImageView overflowButton;
|
||||||
|
@NonNull
|
||||||
final ImageView albumArt;
|
final ImageView albumArt;
|
||||||
final View separator;
|
final View separator;
|
||||||
final View short_separator;
|
final View short_separator;
|
||||||
|
@NonNull
|
||||||
final View view;
|
final View view;
|
||||||
|
|
||||||
public ViewHolder(View itemView) {
|
public ViewHolder(@NonNull View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
view = itemView;
|
view = itemView;
|
||||||
songTitle = (TextView) itemView.findViewById(R.id.song_title);
|
songTitle = (TextView) itemView.findViewById(R.id.song_title);
|
||||||
|
|
@ -159,7 +166,7 @@ public class SongAdapter extends AbsMultiSelectAdapter<SongAdapter.ViewHolder, S
|
||||||
popupMenu.inflate(R.menu.menu_item_song);
|
popupMenu.inflate(R.menu.menu_item_song);
|
||||||
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
public boolean onMenuItemClick(@NonNull MenuItem item) {
|
||||||
final int position = getAdapterPosition() - 1;
|
final int position = getAdapterPosition() - 1;
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.action_go_to_album:
|
case R.id.action_go_to_album:
|
||||||
|
|
@ -212,7 +219,7 @@ public class SongAdapter extends AbsMultiSelectAdapter<SongAdapter.ViewHolder, S
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onDataBaseEvent(DataBaseChangedEvent event) {
|
public void onDataBaseEvent(@NonNull DataBaseChangedEvent event) {
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
case DataBaseChangedEvent.SONGS_CHANGED:
|
case DataBaseChangedEvent.SONGS_CHANGED:
|
||||||
case DataBaseChangedEvent.DATABASE_CHANGED:
|
case DataBaseChangedEvent.DATABASE_CHANGED:
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.kabouzeid.gramophone.adapter.songadapter.smartplaylist;
|
package com.kabouzeid.gramophone.adapter.songadapter.smartplaylist;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.util.Pair;
|
import android.support.v4.util.Pair;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
|
@ -51,7 +52,7 @@ public class SmartPlaylistSongAdapter extends AbsPlaylistSongAdapter<SmartPlayli
|
||||||
return dataSet.get(position).id;
|
return dataSet.get(position).id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SmartPlaylistSongAdapter(AppCompatActivity activity, AbsSmartPlaylist playlist, @Nullable CabHolder cabHolder) {
|
public SmartPlaylistSongAdapter(AppCompatActivity activity, @NonNull AbsSmartPlaylist playlist, @Nullable CabHolder cabHolder) {
|
||||||
super(activity, cabHolder, R.menu.menu_cannot_delete_single_songs_playlist_songs_selection);
|
super(activity, cabHolder, R.menu.menu_cannot_delete_single_songs_playlist_songs_selection);
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
this.playlist = playlist;
|
this.playlist = playlist;
|
||||||
|
|
@ -63,6 +64,7 @@ public class SmartPlaylistSongAdapter extends AbsPlaylistSongAdapter<SmartPlayli
|
||||||
return dataSet;
|
return dataSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
View view = LayoutInflater.from(activity).inflate(R.layout.item_list_song, parent, false);
|
View view = LayoutInflater.from(activity).inflate(R.layout.item_list_song, parent, false);
|
||||||
|
|
@ -70,7 +72,7 @@ public class SmartPlaylistSongAdapter extends AbsPlaylistSongAdapter<SmartPlayli
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(final ViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull final ViewHolder holder, int position) {
|
||||||
final Song song = dataSet.get(position);
|
final Song song = dataSet.get(position);
|
||||||
|
|
||||||
holder.itemView.setActivated(isChecked(song));
|
holder.itemView.setActivated(isChecked(song));
|
||||||
|
|
@ -98,7 +100,7 @@ public class SmartPlaylistSongAdapter extends AbsPlaylistSongAdapter<SmartPlayli
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onMultipleItemAction(MenuItem menuItem, ArrayList<Song> selection) {
|
protected void onMultipleItemAction(@NonNull MenuItem menuItem, @NonNull ArrayList<Song> selection) {
|
||||||
switch (menuItem.getItemId()) {
|
switch (menuItem.getItemId()) {
|
||||||
case R.id.action_add_to_playlist:
|
case R.id.action_add_to_playlist:
|
||||||
onAddToPlaylist(selection);
|
onAddToPlaylist(selection);
|
||||||
|
|
@ -113,17 +115,21 @@ public class SmartPlaylistSongAdapter extends AbsPlaylistSongAdapter<SmartPlayli
|
||||||
AddToPlaylistDialog.create(songs).show(activity.getSupportFragmentManager(), "ADD_PLAYLIST");
|
AddToPlaylistDialog.create(songs).show(activity.getSupportFragmentManager(), "ADD_PLAYLIST");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onAddToCurrentPlaying(ArrayList<Song> songs) {
|
protected void onAddToCurrentPlaying(@NonNull ArrayList<Song> songs) {
|
||||||
MusicPlayerRemote.enqueue(songs);
|
MusicPlayerRemote.enqueue(songs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||||
|
@NonNull
|
||||||
final TextView songTitle;
|
final TextView songTitle;
|
||||||
|
@NonNull
|
||||||
final TextView songInfo;
|
final TextView songInfo;
|
||||||
|
@NonNull
|
||||||
final ImageView overflowButton;
|
final ImageView overflowButton;
|
||||||
|
@NonNull
|
||||||
final ImageView albumArt;
|
final ImageView albumArt;
|
||||||
|
|
||||||
public ViewHolder(View itemView, final int songMenu) {
|
public ViewHolder(@NonNull View itemView, final int songMenu) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
songTitle = (TextView) itemView.findViewById(R.id.song_title);
|
songTitle = (TextView) itemView.findViewById(R.id.song_title);
|
||||||
songInfo = (TextView) itemView.findViewById(R.id.song_info);
|
songInfo = (TextView) itemView.findViewById(R.id.song_info);
|
||||||
|
|
@ -138,7 +144,7 @@ public class SmartPlaylistSongAdapter extends AbsPlaylistSongAdapter<SmartPlayli
|
||||||
popupMenu.inflate(songMenu);
|
popupMenu.inflate(songMenu);
|
||||||
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
public boolean onMenuItemClick(@NonNull MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.action_go_to_album:
|
case R.id.action_go_to_album:
|
||||||
Pair[] albumPairs = new Pair[]{
|
Pair[] albumPairs = new Pair[]{
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.RemoteViews;
|
import android.widget.RemoteViews;
|
||||||
|
|
||||||
|
|
@ -28,14 +30,14 @@ public class WidgetMedium extends AppWidgetProvider {
|
||||||
private static String currentAlbumArtUri;
|
private static String currentAlbumArtUri;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
public void onUpdate(@NonNull Context context, @NonNull AppWidgetManager appWidgetManager, @NonNull int[] appWidgetIds) {
|
||||||
updateWidgets(context, MusicPlayerRemote.getCurrentSong(), MusicPlayerRemote.isPlaying());
|
updateWidgets(context, MusicPlayerRemote.getCurrentSong(), MusicPlayerRemote.isPlaying());
|
||||||
for (int widgetId : appWidgetIds) {
|
for (int widgetId : appWidgetIds) {
|
||||||
appWidgetManager.updateAppWidget(widgetId, widgetLayout);
|
appWidgetManager.updateAppWidget(widgetId, widgetLayout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateWidgets(final Context context, final Song song, boolean isPlaying) {
|
public static void updateWidgets(@NonNull final Context context, @NonNull final Song song, boolean isPlaying) {
|
||||||
if (song.id == -1) return;
|
if (song.id == -1) return;
|
||||||
widgetLayout = new RemoteViews(context.getPackageName(), R.layout.widget_medium);
|
widgetLayout = new RemoteViews(context.getPackageName(), R.layout.widget_medium);
|
||||||
linkButtons(context, widgetLayout);
|
linkButtons(context, widgetLayout);
|
||||||
|
|
@ -45,7 +47,7 @@ public class WidgetMedium extends AppWidgetProvider {
|
||||||
loadAlbumArt(context, song);
|
loadAlbumArt(context, song);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateWidgetsPlayState(final Context context, boolean isPlaying) {
|
public static void updateWidgetsPlayState(@NonNull final Context context, boolean isPlaying) {
|
||||||
if (widgetLayout == null)
|
if (widgetLayout == null)
|
||||||
widgetLayout = new RemoteViews(context.getPackageName(), R.layout.widget_medium);
|
widgetLayout = new RemoteViews(context.getPackageName(), R.layout.widget_medium);
|
||||||
int playPauseRes = isPlaying ? R.drawable.ic_pause_black_36dp : R.drawable.ic_play_arrow_black_36dp;
|
int playPauseRes = isPlaying ? R.drawable.ic_pause_black_36dp : R.drawable.ic_play_arrow_black_36dp;
|
||||||
|
|
@ -53,7 +55,7 @@ public class WidgetMedium extends AppWidgetProvider {
|
||||||
updateWidgets(context);
|
updateWidgets(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void updateWidgets(final Context context) {
|
private static void updateWidgets(@NonNull final Context context) {
|
||||||
AppWidgetManager man = AppWidgetManager.getInstance(context);
|
AppWidgetManager man = AppWidgetManager.getInstance(context);
|
||||||
int[] ids = man.getAppWidgetIds(
|
int[] ids = man.getAppWidgetIds(
|
||||||
new ComponentName(context, WidgetMedium.class));
|
new ComponentName(context, WidgetMedium.class));
|
||||||
|
|
@ -62,12 +64,12 @@ public class WidgetMedium extends AppWidgetProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void loadAlbumArt(final Context context, final Song song) {
|
private static void loadAlbumArt(@NonNull final Context context, @Nullable final Song song) {
|
||||||
if (song != null) {
|
if (song != null) {
|
||||||
currentAlbumArtUri = MusicUtil.getSongImageLoaderString(song);
|
currentAlbumArtUri = MusicUtil.getSongImageLoaderString(song);
|
||||||
ImageLoader.getInstance().displayImage(currentAlbumArtUri, new NonViewAware(new ImageSize(-1, -1), ViewScaleType.CROP), new SimpleImageLoadingListener() {
|
ImageLoader.getInstance().displayImage(currentAlbumArtUri, new NonViewAware(new ImageSize(-1, -1), ViewScaleType.CROP), new SimpleImageLoadingListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
|
public void onLoadingComplete(String imageUri, View view, @Nullable Bitmap loadedImage) {
|
||||||
if (currentAlbumArtUri.equals(imageUri)) {
|
if (currentAlbumArtUri.equals(imageUri)) {
|
||||||
if (loadedImage != null) {
|
if (loadedImage != null) {
|
||||||
// The RemoteViews might wants to recycle the bitmaps thrown at it, so we need
|
// The RemoteViews might wants to recycle the bitmaps thrown at it, so we need
|
||||||
|
|
@ -94,7 +96,7 @@ public class WidgetMedium extends AppWidgetProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setAlbumArt(final Context context, final Bitmap albumArt) {
|
private static void setAlbumArt(@NonNull final Context context, @Nullable final Bitmap albumArt) {
|
||||||
if (albumArt != null) {
|
if (albumArt != null) {
|
||||||
widgetLayout.setImageViewBitmap(R.id.album_art, albumArt);
|
widgetLayout.setImageViewBitmap(R.id.album_art, albumArt);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -103,7 +105,7 @@ public class WidgetMedium extends AppWidgetProvider {
|
||||||
updateWidgets(context);
|
updateWidgets(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void linkButtons(final Context context, final RemoteViews views) {
|
private static void linkButtons(@NonNull final Context context, @NonNull final RemoteViews views) {
|
||||||
views.setOnClickPendingIntent(R.id.album_art, retrievePlaybackActions(context, 0));
|
views.setOnClickPendingIntent(R.id.album_art, retrievePlaybackActions(context, 0));
|
||||||
views.setOnClickPendingIntent(R.id.media_titles, retrievePlaybackActions(context, 0));
|
views.setOnClickPendingIntent(R.id.media_titles, retrievePlaybackActions(context, 0));
|
||||||
views.setOnClickPendingIntent(R.id.button_toggle_play_pause, retrievePlaybackActions(context, 1));
|
views.setOnClickPendingIntent(R.id.button_toggle_play_pause, retrievePlaybackActions(context, 1));
|
||||||
|
|
@ -111,7 +113,7 @@ public class WidgetMedium extends AppWidgetProvider {
|
||||||
views.setOnClickPendingIntent(R.id.button_prev, retrievePlaybackActions(context, 3));
|
views.setOnClickPendingIntent(R.id.button_prev, retrievePlaybackActions(context, 3));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PendingIntent retrievePlaybackActions(final Context context, final int which) {
|
private static PendingIntent retrievePlaybackActions(@NonNull final Context context, final int which) {
|
||||||
Intent action;
|
Intent action;
|
||||||
PendingIntent pendingIntent;
|
PendingIntent pendingIntent;
|
||||||
final ComponentName serviceName = new ComponentName(context, MusicService.class);
|
final ComponentName serviceName = new ComponentName(context, MusicService.class);
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ public class AboutDialog extends DialogFragment {
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getCurrentVersionName(final Context context) {
|
private static String getCurrentVersionName(@NonNull final Context context) {
|
||||||
String versionName;
|
String versionName;
|
||||||
try {
|
try {
|
||||||
versionName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
|
versionName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
|
||||||
|
|
|
||||||
|
|
@ -21,12 +21,14 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public class AddToPlaylistDialog extends DialogFragment {
|
public class AddToPlaylistDialog extends DialogFragment {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public static AddToPlaylistDialog create(Song song) {
|
public static AddToPlaylistDialog create(Song song) {
|
||||||
ArrayList<Song> list = new ArrayList<>();
|
ArrayList<Song> list = new ArrayList<>();
|
||||||
list.add(song);
|
list.add(song);
|
||||||
return create(list);
|
return create(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public static AddToPlaylistDialog create(ArrayList<Song> songs) {
|
public static AddToPlaylistDialog create(ArrayList<Song> songs) {
|
||||||
AddToPlaylistDialog dialog = new AddToPlaylistDialog();
|
AddToPlaylistDialog dialog = new AddToPlaylistDialog();
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
|
|
@ -49,7 +51,7 @@ public class AddToPlaylistDialog extends DialogFragment {
|
||||||
.items(playlistNames)
|
.items(playlistNames)
|
||||||
.itemsCallback(new MaterialDialog.ListCallback() {
|
.itemsCallback(new MaterialDialog.ListCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onSelection(MaterialDialog materialDialog, View view, int i, CharSequence charSequence) {
|
public void onSelection(@NonNull MaterialDialog materialDialog, View view, int i, CharSequence charSequence) {
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
final ArrayList<Song> songs = (ArrayList<Song>) getArguments().getSerializable("songs");
|
final ArrayList<Song> songs = (ArrayList<Song>) getArguments().getSerializable("songs");
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import com.kabouzeid.gramophone.model.smartplaylist.AbsSmartPlaylist;
|
||||||
*/
|
*/
|
||||||
public class ClearSmartPlaylistDialog extends DialogFragment {
|
public class ClearSmartPlaylistDialog extends DialogFragment {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public static ClearSmartPlaylistDialog create(AbsSmartPlaylist playlist) {
|
public static ClearSmartPlaylistDialog create(AbsSmartPlaylist playlist) {
|
||||||
ClearSmartPlaylistDialog dialog = new ClearSmartPlaylistDialog();
|
ClearSmartPlaylistDialog dialog = new ClearSmartPlaylistDialog();
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ import android.graphics.drawable.StateListDrawable;
|
||||||
import android.graphics.drawable.shapes.OvalShape;
|
import android.graphics.drawable.shapes.OvalShape;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.content.res.ResourcesCompat;
|
import android.support.v4.content.res.ResourcesCompat;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
@ -31,6 +33,7 @@ public class ColorChooserDialog extends DialogFragment implements View.OnClickLi
|
||||||
|
|
||||||
private ColorCallback mCallback;
|
private ColorCallback mCallback;
|
||||||
private int[] mColors;
|
private int[] mColors;
|
||||||
|
@Nullable
|
||||||
private GridView mGrid;
|
private GridView mGrid;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -40,7 +43,7 @@ public class ColorChooserDialog extends DialogFragment implements View.OnClickLi
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(@NonNull View v) {
|
||||||
if (v.getTag() != null) {
|
if (v.getTag() != null) {
|
||||||
final int index = (Integer) v.getTag();
|
final int index = (Integer) v.getTag();
|
||||||
getArguments().putInt("preselect", mColors[index]);
|
getArguments().putInt("preselect", mColors[index]);
|
||||||
|
|
@ -128,8 +131,9 @@ public class ColorChooserDialog extends DialogFragment implements View.OnClickLi
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, @Nullable View convertView, ViewGroup parent) {
|
||||||
if (convertView == null)
|
if (convertView == null)
|
||||||
convertView = LayoutInflater.from(getActivity()).inflate(R.layout.griditem_color_chooser, parent, false);
|
convertView = LayoutInflater.from(getActivity()).inflate(R.layout.griditem_color_chooser, parent, false);
|
||||||
|
|
||||||
|
|
@ -156,7 +160,7 @@ public class ColorChooserDialog extends DialogFragment implements View.OnClickLi
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(@NonNull View v) {
|
||||||
final int index = (Integer) v.getTag();
|
final int index = (Integer) v.getTag();
|
||||||
getArguments().putInt("preselect", mColors[index]);
|
getArguments().putInt("preselect", mColors[index]);
|
||||||
invalidateGrid();
|
invalidateGrid();
|
||||||
|
|
@ -180,6 +184,7 @@ public class ColorChooserDialog extends DialogFragment implements View.OnClickLi
|
||||||
return Color.argb(alpha, red, green, blue);
|
return Color.argb(alpha, red, green, blue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private static Drawable createSelector(int color) {
|
private static Drawable createSelector(int color) {
|
||||||
ShapeDrawable darkerCircle = new ShapeDrawable(new OvalShape());
|
ShapeDrawable darkerCircle = new ShapeDrawable(new OvalShape());
|
||||||
darkerCircle.getPaint().setColor(translucentColor(shiftColorDown(color)));
|
darkerCircle.getPaint().setColor(translucentColor(shiftColorDown(color)));
|
||||||
|
|
@ -188,7 +193,7 @@ public class ColorChooserDialog extends DialogFragment implements View.OnClickLi
|
||||||
return stateListDrawable;
|
return stateListDrawable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void show(Activity context, int title, int preselect) {
|
public void show(@NonNull Activity context, int title, int preselect) {
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putInt("preselect", preselect);
|
args.putInt("preselect", preselect);
|
||||||
args.putInt("title", title);
|
args.putInt("title", title);
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.kabouzeid.gramophone.dialogs;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
import android.text.InputType;
|
import android.text.InputType;
|
||||||
|
|
||||||
|
|
@ -18,17 +19,20 @@ import java.util.ArrayList;
|
||||||
*/
|
*/
|
||||||
public class CreatePlaylistDialog extends DialogFragment {
|
public class CreatePlaylistDialog extends DialogFragment {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public static CreatePlaylistDialog create() {
|
public static CreatePlaylistDialog create() {
|
||||||
return create((Song) null);
|
return create((Song) null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CreatePlaylistDialog create(Song song) {
|
@NonNull
|
||||||
|
public static CreatePlaylistDialog create(@Nullable Song song) {
|
||||||
ArrayList<Song> list = new ArrayList<>();
|
ArrayList<Song> list = new ArrayList<>();
|
||||||
if (song != null)
|
if (song != null)
|
||||||
list.add(song);
|
list.add(song);
|
||||||
return create(list);
|
return create(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public static CreatePlaylistDialog create(ArrayList<Song> songs) {
|
public static CreatePlaylistDialog create(ArrayList<Song> songs) {
|
||||||
CreatePlaylistDialog dialog = new CreatePlaylistDialog();
|
CreatePlaylistDialog dialog = new CreatePlaylistDialog();
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
|
|
@ -49,7 +53,7 @@ public class CreatePlaylistDialog extends DialogFragment {
|
||||||
InputType.TYPE_TEXT_FLAG_CAP_WORDS)
|
InputType.TYPE_TEXT_FLAG_CAP_WORDS)
|
||||||
.input(R.string.playlist_name_empty, 0, false, new MaterialDialog.InputCallback() {
|
.input(R.string.playlist_name_empty, 0, false, new MaterialDialog.InputCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onInput(MaterialDialog materialDialog, CharSequence charSequence) {
|
public void onInput(MaterialDialog materialDialog, @NonNull CharSequence charSequence) {
|
||||||
if (getActivity() == null)
|
if (getActivity() == null)
|
||||||
return;
|
return;
|
||||||
if (!charSequence.toString().trim().isEmpty()) {
|
if (!charSequence.toString().trim().isEmpty()) {
|
||||||
|
|
|
||||||
|
|
@ -18,12 +18,14 @@ import java.util.ArrayList;
|
||||||
*/
|
*/
|
||||||
public class DeletePlaylistDialog extends DialogFragment {
|
public class DeletePlaylistDialog extends DialogFragment {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public static DeletePlaylistDialog create(Playlist playlist) {
|
public static DeletePlaylistDialog create(Playlist playlist) {
|
||||||
ArrayList<Playlist> list = new ArrayList<>();
|
ArrayList<Playlist> list = new ArrayList<>();
|
||||||
list.add(playlist);
|
list.add(playlist);
|
||||||
return create(list);
|
return create(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public static DeletePlaylistDialog create(ArrayList<Playlist> playlists) {
|
public static DeletePlaylistDialog create(ArrayList<Playlist> playlists) {
|
||||||
DeletePlaylistDialog dialog = new DeletePlaylistDialog();
|
DeletePlaylistDialog dialog = new DeletePlaylistDialog();
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
|
|
|
||||||
|
|
@ -18,12 +18,14 @@ import java.util.ArrayList;
|
||||||
*/
|
*/
|
||||||
public class DeleteSongsDialog extends DialogFragment {
|
public class DeleteSongsDialog extends DialogFragment {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public static DeleteSongsDialog create(Song song) {
|
public static DeleteSongsDialog create(Song song) {
|
||||||
ArrayList<Song> list = new ArrayList<>();
|
ArrayList<Song> list = new ArrayList<>();
|
||||||
list.add(song);
|
list.add(song);
|
||||||
return create(list);
|
return create(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public static DeleteSongsDialog create(ArrayList<Song> songs) {
|
public static DeleteSongsDialog create(ArrayList<Song> songs) {
|
||||||
DeleteSongsDialog dialog = new DeleteSongsDialog();
|
DeleteSongsDialog dialog = new DeleteSongsDialog();
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
|
|
|
||||||
|
|
@ -18,12 +18,14 @@ import java.util.ArrayList;
|
||||||
*/
|
*/
|
||||||
public class RemoveFromPlaylistDialog extends DialogFragment {
|
public class RemoveFromPlaylistDialog extends DialogFragment {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public static RemoveFromPlaylistDialog create(PlaylistSong song) {
|
public static RemoveFromPlaylistDialog create(PlaylistSong song) {
|
||||||
ArrayList<PlaylistSong> list = new ArrayList<>();
|
ArrayList<PlaylistSong> list = new ArrayList<>();
|
||||||
list.add(song);
|
list.add(song);
|
||||||
return create(list);
|
return create(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public static RemoveFromPlaylistDialog create(ArrayList<PlaylistSong> songs) {
|
public static RemoveFromPlaylistDialog create(ArrayList<PlaylistSong> songs) {
|
||||||
RemoveFromPlaylistDialog dialog = new RemoveFromPlaylistDialog();
|
RemoveFromPlaylistDialog dialog = new RemoveFromPlaylistDialog();
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import com.kabouzeid.gramophone.util.PlaylistsUtil;
|
||||||
*/
|
*/
|
||||||
public class RenamePlaylistDialog extends DialogFragment {
|
public class RenamePlaylistDialog extends DialogFragment {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public static RenamePlaylistDialog create(long playlistId) {
|
public static RenamePlaylistDialog create(long playlistId) {
|
||||||
RenamePlaylistDialog dialog = new RenamePlaylistDialog();
|
RenamePlaylistDialog dialog = new RenamePlaylistDialog();
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
|
|
@ -37,7 +38,7 @@ public class RenamePlaylistDialog extends DialogFragment {
|
||||||
.input(getString(R.string.playlist_name_empty), PlaylistsUtil.getNameForPlaylist(getActivity(), playlistId), false,
|
.input(getString(R.string.playlist_name_empty), PlaylistsUtil.getNameForPlaylist(getActivity(), playlistId), false,
|
||||||
new MaterialDialog.InputCallback() {
|
new MaterialDialog.InputCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onInput(MaterialDialog materialDialog, CharSequence charSequence) {
|
public void onInput(MaterialDialog materialDialog, @NonNull CharSequence charSequence) {
|
||||||
if (!charSequence.toString().trim().equals("")) {
|
if (!charSequence.toString().trim().equals("")) {
|
||||||
long playlistId = getArguments().getLong("playlist_id");
|
long playlistId = getArguments().getLong("playlist_id");
|
||||||
PlaylistsUtil.renamePlaylist(getActivity(), playlistId, charSequence.toString());
|
PlaylistsUtil.renamePlaylist(getActivity(), playlistId, charSequence.toString());
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ public class SleepTimerDialog extends DialogFragment {
|
||||||
|
|
||||||
seekArc.setOnSeekArcChangeListener(new SeekArc.OnSeekArcChangeListener() {
|
seekArc.setOnSeekArcChangeListener(new SeekArc.OnSeekArcChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onProgressChanged(SeekArc seekArc, int i, boolean b) {
|
public void onProgressChanged(@NonNull SeekArc seekArc, int i, boolean b) {
|
||||||
if (i < 1) {
|
if (i < 1) {
|
||||||
seekArc.setProgress(1);
|
seekArc.setProgress(1);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ public class SongDetailDialog extends DialogFragment {
|
||||||
|
|
||||||
public static final String TAG = SongDetailDialog.class.getSimpleName();
|
public static final String TAG = SongDetailDialog.class.getSimpleName();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public static SongDetailDialog create(File songFile) {
|
public static SongDetailDialog create(File songFile) {
|
||||||
SongDetailDialog dialog = new SongDetailDialog();
|
SongDetailDialog dialog = new SongDetailDialog();
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
|
|
@ -85,13 +86,13 @@ public class SongDetailDialog extends DialogFragment {
|
||||||
bitRate.setText(makeTextWithTitle(context, R.string.label_bit_rate, audioHeader.getBitRate() + " kb/s"));
|
bitRate.setText(makeTextWithTitle(context, R.string.label_bit_rate, audioHeader.getBitRate() + " kb/s"));
|
||||||
samplingRate.setText(makeTextWithTitle(context, R.string.label_sampling_rate, audioHeader.getSampleRate() + " Hz"));
|
samplingRate.setText(makeTextWithTitle(context, R.string.label_sampling_rate, audioHeader.getSampleRate() + " Hz"));
|
||||||
}
|
}
|
||||||
} catch (CannotReadException | IOException | TagException | ReadOnlyFileException | InvalidAudioFrameException e) {
|
} catch (@NonNull CannotReadException | IOException | TagException | ReadOnlyFileException | InvalidAudioFrameException e) {
|
||||||
Log.e(TAG, "error while reading the song file", e);
|
Log.e(TAG, "error while reading the song file", e);
|
||||||
}
|
}
|
||||||
return dialog;
|
return dialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Spanned makeTextWithTitle(Context context, int titleResId, String text) {
|
private static Spanned makeTextWithTitle(@NonNull Context context, int titleResId, String text) {
|
||||||
return Html.fromHtml("<b>" + context.getResources().getString(titleResId) + ": " + "</b>" + text);
|
return Html.fromHtml("<b>" + context.getResources().getString(titleResId) + ": " + "</b>" + text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import com.kabouzeid.gramophone.util.MusicUtil;
|
||||||
* @author Karim Abou Zeid (kabouzeid)
|
* @author Karim Abou Zeid (kabouzeid)
|
||||||
*/
|
*/
|
||||||
public class SongShareDialog extends DialogFragment {
|
public class SongShareDialog extends DialogFragment {
|
||||||
|
@NonNull
|
||||||
public static SongShareDialog create(final Song song) {
|
public static SongShareDialog create(final Song song) {
|
||||||
final SongShareDialog dialog = new SongShareDialog();
|
final SongShareDialog dialog = new SongShareDialog();
|
||||||
final Bundle args = new Bundle();
|
final Bundle args = new Bundle();
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.kabouzeid.gramophone.helper;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.util.Pair;
|
import android.support.v4.util.Pair;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
@ -31,7 +32,7 @@ import java.util.ArrayList;
|
||||||
*/
|
*/
|
||||||
public class MenuItemClickHelper {
|
public class MenuItemClickHelper {
|
||||||
|
|
||||||
public static boolean handleSongMenuClick(AppCompatActivity activity, Song song, MenuItem item) {
|
public static boolean handleSongMenuClick(@NonNull AppCompatActivity activity, @NonNull Song song, @NonNull MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.action_set_as_ringtone:
|
case R.id.action_set_as_ringtone:
|
||||||
MusicUtil.setRingtone(activity, song.id);
|
MusicUtil.setRingtone(activity, song.id);
|
||||||
|
|
@ -78,7 +79,7 @@ public class MenuItemClickHelper {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean handlePlaylistMenuClick(AppCompatActivity activity, Playlist playlist, MenuItem item) {
|
public static boolean handlePlaylistMenuClick(@NonNull AppCompatActivity activity, @NonNull Playlist playlist, @NonNull MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.action_play:
|
case R.id.action_play:
|
||||||
MusicPlayerRemote.openQueue(new ArrayList<>(getPlaylistSongs(activity, playlist)), 0, true);
|
MusicPlayerRemote.openQueue(new ArrayList<>(getPlaylistSongs(activity, playlist)), 0, true);
|
||||||
|
|
@ -96,7 +97,8 @@ public class MenuItemClickHelper {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ArrayList<? extends Song> getPlaylistSongs(Activity activity, Playlist playlist) {
|
@NonNull
|
||||||
|
private static ArrayList<? extends Song> getPlaylistSongs(@NonNull Activity activity, Playlist playlist) {
|
||||||
return playlist instanceof AbsSmartPlaylist ?
|
return playlist instanceof AbsSmartPlaylist ?
|
||||||
((AbsSmartPlaylist) playlist).getSongs(activity) :
|
((AbsSmartPlaylist) playlist).getSongs(activity) :
|
||||||
PlaylistSongLoader.getPlaylistSongList(activity, playlist.id);
|
PlaylistSongLoader.getPlaylistSongList(activity, playlist.id);
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ import android.content.Intent;
|
||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
import android.media.audiofx.AudioEffect;
|
import android.media.audiofx.AudioEffect;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.kabouzeid.gramophone.R;
|
import com.kabouzeid.gramophone.R;
|
||||||
|
|
@ -26,11 +28,12 @@ public class MusicPlayerRemote {
|
||||||
|
|
||||||
public static final String TAG = MusicPlayerRemote.class.getSimpleName();
|
public static final String TAG = MusicPlayerRemote.class.getSimpleName();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public static MusicService musicService;
|
public static MusicService musicService;
|
||||||
|
|
||||||
private static final WeakHashMap<Context, ServiceBinder> mConnectionMap = new WeakHashMap<>();
|
private static final WeakHashMap<Context, ServiceBinder> mConnectionMap = new WeakHashMap<>();
|
||||||
|
|
||||||
public static ServiceToken bindToService(final Context context,
|
public static ServiceToken bindToService(@NonNull final Context context,
|
||||||
final ServiceConnection callback) {
|
final ServiceConnection callback) {
|
||||||
Activity realActivity = ((Activity) context).getParent();
|
Activity realActivity = ((Activity) context).getParent();
|
||||||
if (realActivity == null) {
|
if (realActivity == null) {
|
||||||
|
|
@ -49,7 +52,7 @@ public class MusicPlayerRemote {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void unbindFromService(final ServiceToken token) {
|
public static void unbindFromService(@Nullable final ServiceToken token) {
|
||||||
if (token == null) {
|
if (token == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -161,6 +164,7 @@ public class MusicPlayerRemote {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public static ArrayList<Song> getPlayingQueue() {
|
public static ArrayList<Song> getPlayingQueue() {
|
||||||
if (musicService != null) {
|
if (musicService != null) {
|
||||||
return musicService.getPlayingQueue();
|
return musicService.getPlayingQueue();
|
||||||
|
|
@ -226,11 +230,11 @@ public class MusicPlayerRemote {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean shuffleAllSongs(final Context context, boolean startPlaying) {
|
public static boolean shuffleAllSongs(@NonNull final Context context, boolean startPlaying) {
|
||||||
return openAndShuffleQueue(context, SongLoader.getAllSongs(context), startPlaying);
|
return openAndShuffleQueue(context, SongLoader.getAllSongs(context), startPlaying);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean openAndShuffleQueue(final Context context, final ArrayList<Song> songs, boolean startPlaying) {
|
public static boolean openAndShuffleQueue(final Context context, @NonNull final ArrayList<Song> songs, boolean startPlaying) {
|
||||||
if (musicService != null) {
|
if (musicService != null) {
|
||||||
if (!songs.isEmpty()) {
|
if (!songs.isEmpty()) {
|
||||||
MusicPlayerRemote.openQueue(songs, new Random().nextInt(songs.size()), startPlaying);
|
MusicPlayerRemote.openQueue(songs, new Random().nextInt(songs.size()), startPlaying);
|
||||||
|
|
@ -259,7 +263,7 @@ public class MusicPlayerRemote {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean enqueue(ArrayList<Song> songs) {
|
public static boolean enqueue(@NonNull ArrayList<Song> songs) {
|
||||||
if (musicService != null) {
|
if (musicService != null) {
|
||||||
musicService.addSongs(songs);
|
musicService.addSongs(songs);
|
||||||
final String toast = songs.size() == 1 ? musicService.getResources().getString(R.string.added_title_to_playing_queue) : musicService.getResources().getString(R.string.added_x_titles_to_playing_queue, songs.size());
|
final String toast = songs.size() == 1 ? musicService.getResources().getString(R.string.added_title_to_playing_queue) : musicService.getResources().getString(R.string.added_x_titles_to_playing_queue, songs.size());
|
||||||
|
|
@ -269,7 +273,7 @@ public class MusicPlayerRemote {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean removeFromQueue(Song song) {
|
public static boolean removeFromQueue(@NonNull Song song) {
|
||||||
if (musicService != null) {
|
if (musicService != null) {
|
||||||
musicService.removeSong(song);
|
musicService.removeSong(song);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
import android.support.v7.graphics.Palette;
|
import android.support.v7.graphics.Palette;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
@ -38,9 +40,12 @@ public class PlayingNotificationHelper {
|
||||||
public static final String ACTION_NOTIFICATION_COLOR_PREFERENCE_CHANGED = "com.kabouzeid.gramophone.NOTIFICATION_COLOR_PREFERENCE_CHANGED";
|
public static final String ACTION_NOTIFICATION_COLOR_PREFERENCE_CHANGED = "com.kabouzeid.gramophone.NOTIFICATION_COLOR_PREFERENCE_CHANGED";
|
||||||
public static final String EXTRA_NOTIFICATION_COLORED = "com.kabouzeid.gramophone.EXTRA_NOTIFICATION_COLORED";
|
public static final String EXTRA_NOTIFICATION_COLORED = "com.kabouzeid.gramophone.EXTRA_NOTIFICATION_COLORED";
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final MusicService service;
|
private final MusicService service;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final NotificationManager notificationManager;
|
private final NotificationManager notificationManager;
|
||||||
|
@Nullable
|
||||||
private Notification notification = null;
|
private Notification notification = null;
|
||||||
|
|
||||||
private RemoteViews notificationLayout;
|
private RemoteViews notificationLayout;
|
||||||
|
|
@ -54,9 +59,10 @@ public class PlayingNotificationHelper {
|
||||||
private boolean isReceiverRegistered;
|
private boolean isReceiverRegistered;
|
||||||
private boolean isNotificationShown;
|
private boolean isNotificationShown;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
final IntentFilter intentFilter;
|
final IntentFilter intentFilter;
|
||||||
|
|
||||||
public PlayingNotificationHelper(final MusicService service) {
|
public PlayingNotificationHelper(@NonNull final MusicService service) {
|
||||||
this.service = service;
|
this.service = service;
|
||||||
notificationManager = (NotificationManager) service
|
notificationManager = (NotificationManager) service
|
||||||
.getSystemService(Context.NOTIFICATION_SERVICE);
|
.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
|
@ -65,9 +71,10 @@ public class PlayingNotificationHelper {
|
||||||
intentFilter.addAction(ACTION_NOTIFICATION_COLOR_PREFERENCE_CHANGED);
|
intentFilter.addAction(ACTION_NOTIFICATION_COLOR_PREFERENCE_CHANGED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private BroadcastReceiver notificationColorPreferenceChangedReceiver = new BroadcastReceiver() {
|
private BroadcastReceiver notificationColorPreferenceChangedReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, @NonNull Intent intent) {
|
||||||
if (intent.getAction().equals(ACTION_NOTIFICATION_COLOR_PREFERENCE_CHANGED)) {
|
if (intent.getAction().equals(ACTION_NOTIFICATION_COLOR_PREFERENCE_CHANGED)) {
|
||||||
boolean isColored = intent.getBooleanExtra(EXTRA_NOTIFICATION_COLORED, false);
|
boolean isColored = intent.getBooleanExtra(EXTRA_NOTIFICATION_COLORED, false);
|
||||||
if (isNotificationShown && PlayingNotificationHelper.this.isColored != isColored) {
|
if (isNotificationShown && PlayingNotificationHelper.this.isColored != isColored) {
|
||||||
|
|
@ -219,7 +226,7 @@ public class PlayingNotificationHelper {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setAlbumArt(Bitmap albumArt) {
|
private void setAlbumArt(@Nullable Bitmap albumArt) {
|
||||||
if (albumArt != null) {
|
if (albumArt != null) {
|
||||||
notificationLayout.setImageViewBitmap(R.id.icon, albumArt);
|
notificationLayout.setImageViewBitmap(R.id.icon, albumArt);
|
||||||
notificationLayoutExpanded.setImageViewBitmap(R.id.icon, albumArt);
|
notificationLayoutExpanded.setImageViewBitmap(R.id.icon, albumArt);
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import android.app.SearchManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import com.kabouzeid.gramophone.loader.SongLoader;
|
import com.kabouzeid.gramophone.loader.SongLoader;
|
||||||
import com.kabouzeid.gramophone.model.Song;
|
import com.kabouzeid.gramophone.model.Song;
|
||||||
|
|
@ -19,7 +20,8 @@ public class SearchQueryHelper {
|
||||||
private static final String ARTIST_SELECTION = "lower(" + MediaStore.Audio.AudioColumns.ARTIST + ") = ?";
|
private static final String ARTIST_SELECTION = "lower(" + MediaStore.Audio.AudioColumns.ARTIST + ") = ?";
|
||||||
private static final String AND = " AND ";
|
private static final String AND = " AND ";
|
||||||
|
|
||||||
public static ArrayList<Song> getSongs(final Context context, final Bundle extras) {
|
@NonNull
|
||||||
|
public static ArrayList<Song> getSongs(@NonNull final Context context, @NonNull final Bundle extras) {
|
||||||
final String query = extras.getString(SearchManager.QUERY, null);
|
final String query = extras.getString(SearchManager.QUERY, null);
|
||||||
final String artistName = extras.getString(MediaStore.EXTRA_MEDIA_ARTIST, null);
|
final String artistName = extras.getString(MediaStore.EXTRA_MEDIA_ARTIST, null);
|
||||||
final String albumName = extras.getString(MediaStore.EXTRA_MEDIA_ALBUM, null);
|
final String albumName = extras.getString(MediaStore.EXTRA_MEDIA_ALBUM, null);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package com.kabouzeid.gramophone.helper;
|
package com.kabouzeid.gramophone.helper;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import com.kabouzeid.gramophone.model.Song;
|
import com.kabouzeid.gramophone.model.Song;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
@ -10,7 +12,7 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public class ShuffleHelper {
|
public class ShuffleHelper {
|
||||||
|
|
||||||
public static void makeShuffleList(List<Song> listToShuffle, final int current) {
|
public static void makeShuffleList(@NonNull List<Song> listToShuffle, final int current) {
|
||||||
if (current >= 0) {
|
if (current >= 0) {
|
||||||
Song song = listToShuffle.remove(current);
|
Song song = listToShuffle.remove(current);
|
||||||
Collections.shuffle(listToShuffle);
|
Collections.shuffle(listToShuffle);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.kabouzeid.gramophone.helper.bitmapblur;
|
package com.kabouzeid.gramophone.helper.bitmapblur;
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
interface BlurProcess {
|
interface BlurProcess {
|
||||||
/**
|
/**
|
||||||
|
|
@ -11,5 +12,6 @@ interface BlurProcess {
|
||||||
* @param radius the radius in pixels to blur the image
|
* @param radius the radius in pixels to blur the image
|
||||||
* @return the blurred version of the image.
|
* @return the blurred version of the image.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
Bitmap blur(Bitmap original, float radius);
|
Bitmap blur(Bitmap original, float radius);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package com.kabouzeid.gramophone.helper.bitmapblur;
|
package com.kabouzeid.gramophone.helper.bitmapblur;
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
|
@ -71,8 +73,9 @@ class JavaBlurProcess implements BlurProcess {
|
||||||
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24
|
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public Bitmap blur(Bitmap original, float radius) {
|
public Bitmap blur(@NonNull Bitmap original, float radius) {
|
||||||
int w = original.getWidth();
|
int w = original.getWidth();
|
||||||
int h = original.getHeight();
|
int h = original.getHeight();
|
||||||
int[] currentPixels = new int[w * h];
|
int[] currentPixels = new int[w * h];
|
||||||
|
|
@ -319,6 +322,7 @@ class JavaBlurProcess implements BlurProcess {
|
||||||
_round = round;
|
_round = round;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public Void call() throws Exception {
|
public Void call() throws Exception {
|
||||||
blurIteration(_src, _w, _h, _radius, _totalCores, _coreIndex, _round);
|
blurIteration(_src, _w, _h, _radius, _totalCores, _coreIndex, _round);
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,8 @@
|
||||||
package com.kabouzeid.gramophone.helper.bitmapblur;
|
package com.kabouzeid.gramophone.helper.bitmapblur;
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import com.kabouzeid.gramophone.util.Util;
|
import com.kabouzeid.gramophone.util.Util;
|
||||||
|
|
||||||
|
|
@ -46,11 +48,13 @@ public class StackBlurManager {
|
||||||
/**
|
/**
|
||||||
* Most recent result of blurring
|
* Most recent result of blurring
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
private Bitmap _result;
|
private Bitmap _result;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method of blurring
|
* Method of blurring
|
||||||
*/
|
*/
|
||||||
|
@NonNull
|
||||||
private final BlurProcess _blurProcess;
|
private final BlurProcess _blurProcess;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -58,7 +62,7 @@ public class StackBlurManager {
|
||||||
*
|
*
|
||||||
* @param image The image that will be analysed
|
* @param image The image that will be analysed
|
||||||
*/
|
*/
|
||||||
public StackBlurManager(Bitmap image) {
|
public StackBlurManager(@NonNull Bitmap image) {
|
||||||
_image = Util.getResizedBitmap(image, 500, 500, false);
|
_image = Util.getResizedBitmap(image, 500, 500, false);
|
||||||
_blurProcess = new JavaBlurProcess();
|
_blurProcess = new JavaBlurProcess();
|
||||||
}
|
}
|
||||||
|
|
@ -68,6 +72,7 @@ public class StackBlurManager {
|
||||||
*
|
*
|
||||||
* @param radius
|
* @param radius
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public Bitmap process(int radius) {
|
public Bitmap process(int radius) {
|
||||||
_result = _blurProcess.blur(_image, radius);
|
_result = _blurProcess.blur(_image, radius);
|
||||||
return _result;
|
return _result;
|
||||||
|
|
@ -78,6 +83,7 @@ public class StackBlurManager {
|
||||||
*
|
*
|
||||||
* @return blurred image
|
* @return blurred image
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public Bitmap returnBlurredImage() {
|
public Bitmap returnBlurredImage() {
|
||||||
return _result;
|
return _result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ package com.kabouzeid.gramophone.imageloader;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import com.kabouzeid.gramophone.loader.AlbumSongLoader;
|
import com.kabouzeid.gramophone.loader.AlbumSongLoader;
|
||||||
import com.kabouzeid.gramophone.model.Song;
|
import com.kabouzeid.gramophone.model.Song;
|
||||||
|
|
@ -24,12 +26,13 @@ public class PhonographImageDownloader extends BaseImageDownloader {
|
||||||
public static final String SCHEME_ALBUM = "album://";
|
public static final String SCHEME_ALBUM = "album://";
|
||||||
public static final String SCHEME_SONG = "song://";
|
public static final String SCHEME_SONG = "song://";
|
||||||
|
|
||||||
public PhonographImageDownloader(Context context) {
|
public PhonographImageDownloader(@NonNull Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
protected InputStream getStreamFromOtherSource(String imageUri, Object extra) throws IOException {
|
protected InputStream getStreamFromOtherSource(@NonNull String imageUri, Object extra) throws IOException {
|
||||||
if (imageUri.startsWith(SCHEME_ALBUM)) {
|
if (imageUri.startsWith(SCHEME_ALBUM)) {
|
||||||
return getStreamFromAlbum(imageUri, extra);
|
return getStreamFromAlbum(imageUri, extra);
|
||||||
} else if (imageUri.startsWith(SCHEME_SONG)) {
|
} else if (imageUri.startsWith(SCHEME_SONG)) {
|
||||||
|
|
@ -39,7 +42,8 @@ public class PhonographImageDownloader extends BaseImageDownloader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected InputStream getStreamFromAlbum(String imageUri, Object extra) throws IOException {
|
@Nullable
|
||||||
|
protected InputStream getStreamFromAlbum(@NonNull String imageUri, Object extra) throws IOException {
|
||||||
int albumId = Integer.valueOf(imageUri.substring(SCHEME_ALBUM.length()));
|
int albumId = Integer.valueOf(imageUri.substring(SCHEME_ALBUM.length()));
|
||||||
|
|
||||||
if (PreferenceUtils.getInstance(context).ignoreMediaStoreArtwork()) {
|
if (PreferenceUtils.getInstance(context).ignoreMediaStoreArtwork()) {
|
||||||
|
|
@ -55,7 +59,8 @@ public class PhonographImageDownloader extends BaseImageDownloader {
|
||||||
return getStream(MusicUtil.getAlbumArtUri(albumId).toString(), extra);
|
return getStream(MusicUtil.getAlbumArtUri(albumId).toString(), extra);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected InputStream getStreamFromSong(String imageUri, Object extra) throws IOException {
|
@Nullable
|
||||||
|
protected InputStream getStreamFromSong(@NonNull String imageUri, Object extra) throws IOException {
|
||||||
String[] data = imageUri.split("#", 2);
|
String[] data = imageUri.split("#", 2);
|
||||||
|
|
||||||
if (PreferenceUtils.getInstance(context).ignoreMediaStoreArtwork()) {
|
if (PreferenceUtils.getInstance(context).ignoreMediaStoreArtwork()) {
|
||||||
|
|
@ -70,7 +75,8 @@ public class PhonographImageDownloader extends BaseImageDownloader {
|
||||||
return getStream(MusicUtil.getAlbumArtUri(id).toString(), extra);
|
return getStream(MusicUtil.getAlbumArtUri(id).toString(), extra);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ByteArrayInputStream getBitmapInputStream(Bitmap bitmap) {
|
@NonNull
|
||||||
|
private static ByteArrayInputStream getBitmapInputStream(@NonNull Bitmap bitmap) {
|
||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
|
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
|
||||||
return new ByteArrayInputStream(bos.toByteArray());
|
return new ByteArrayInputStream(bos.toByteArray());
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.kabouzeid.gramophone.lastfm.rest;
|
package com.kabouzeid.gramophone.lastfm.rest;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import com.kabouzeid.gramophone.lastfm.rest.service.LastFMService;
|
import com.kabouzeid.gramophone.lastfm.rest.service.LastFMService;
|
||||||
import com.squareup.okhttp.Cache;
|
import com.squareup.okhttp.Cache;
|
||||||
|
|
@ -20,7 +21,7 @@ public class LastFMRestClient {
|
||||||
|
|
||||||
private LastFMService apiService;
|
private LastFMService apiService;
|
||||||
|
|
||||||
public LastFMRestClient(Context context) {
|
public LastFMRestClient(@NonNull Context context) {
|
||||||
OkHttpClient okHttpClient = new OkHttpClient();
|
OkHttpClient okHttpClient = new OkHttpClient();
|
||||||
|
|
||||||
File cacheDir = new File(context.getCacheDir().getAbsolutePath(), "/okhttp-lastfm/");
|
File cacheDir = new File(context.getCacheDir().getAbsolutePath(), "/okhttp-lastfm/");
|
||||||
|
|
@ -33,7 +34,7 @@ public class LastFMRestClient {
|
||||||
.setClient(new OkClient(okHttpClient))
|
.setClient(new OkClient(okHttpClient))
|
||||||
.setRequestInterceptor(new RequestInterceptor() {
|
.setRequestInterceptor(new RequestInterceptor() {
|
||||||
@Override
|
@Override
|
||||||
public void intercept(RequestInterceptor.RequestFacade request) {
|
public void intercept(@NonNull RequestInterceptor.RequestFacade request) {
|
||||||
request.addHeader("Cache-Control", String.format("max-age=%d, max-stale=%d", 31536000, 31536000));
|
request.addHeader("Cache-Control", String.format("max-age=%d, max-stale=%d", 31536000, 31536000));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ import android.provider.BaseColumns;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.provider.MediaStore.Audio.AlbumColumns;
|
import android.provider.MediaStore.Audio.AlbumColumns;
|
||||||
import android.provider.MediaStore.Audio.AudioColumns;
|
import android.provider.MediaStore.Audio.AudioColumns;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import com.kabouzeid.gramophone.model.Album;
|
import com.kabouzeid.gramophone.model.Album;
|
||||||
import com.kabouzeid.gramophone.util.PreferenceUtils;
|
import com.kabouzeid.gramophone.util.PreferenceUtils;
|
||||||
|
|
@ -18,22 +20,26 @@ import java.util.ArrayList;
|
||||||
*/
|
*/
|
||||||
public class AlbumLoader {
|
public class AlbumLoader {
|
||||||
|
|
||||||
public static ArrayList<Album> getAllAlbums(final Context context) {
|
@NonNull
|
||||||
|
public static ArrayList<Album> getAllAlbums(@NonNull final Context context) {
|
||||||
Cursor cursor = makeAlbumCursor(context, null, null);
|
Cursor cursor = makeAlbumCursor(context, null, null);
|
||||||
return getAlbums(cursor);
|
return getAlbums(cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Album> getAlbums(final Context context, String query) {
|
@NonNull
|
||||||
|
public static ArrayList<Album> getAlbums(@NonNull final Context context, String query) {
|
||||||
Cursor cursor = makeAlbumCursor(context, AlbumColumns.ALBUM + " LIKE ?", new String[]{"%" + query + "%"});
|
Cursor cursor = makeAlbumCursor(context, AlbumColumns.ALBUM + " LIKE ?", new String[]{"%" + query + "%"});
|
||||||
return getAlbums(cursor);
|
return getAlbums(cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Album getAlbum(final Context context, int albumId) {
|
@NonNull
|
||||||
|
public static Album getAlbum(@NonNull final Context context, int albumId) {
|
||||||
Cursor cursor = makeAlbumCursor(context, BaseColumns._ID + "=?", new String[]{String.valueOf(albumId)});
|
Cursor cursor = makeAlbumCursor(context, BaseColumns._ID + "=?", new String[]{String.valueOf(albumId)});
|
||||||
return getAlbum(cursor);
|
return getAlbum(cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Album> getAlbums(final Cursor cursor) {
|
@NonNull
|
||||||
|
public static ArrayList<Album> getAlbums(@Nullable final Cursor cursor) {
|
||||||
ArrayList<Album> albums = new ArrayList<>();
|
ArrayList<Album> albums = new ArrayList<>();
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
do {
|
do {
|
||||||
|
|
@ -46,7 +52,8 @@ public class AlbumLoader {
|
||||||
return albums;
|
return albums;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Album getAlbum(final Cursor cursor) {
|
@NonNull
|
||||||
|
public static Album getAlbum(@Nullable final Cursor cursor) {
|
||||||
Album album = new Album();
|
Album album = new Album();
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
album = getAlbumFromCursorImpl(cursor);
|
album = getAlbumFromCursorImpl(cursor);
|
||||||
|
|
@ -58,7 +65,8 @@ public class AlbumLoader {
|
||||||
return album;
|
return album;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Album getAlbumFromCursorImpl(final Cursor cursor) {
|
@NonNull
|
||||||
|
private static Album getAlbumFromCursorImpl(@NonNull final Cursor cursor) {
|
||||||
final int id = cursor.getInt(0);
|
final int id = cursor.getInt(0);
|
||||||
final String albumName = cursor.getString(1);
|
final String albumName = cursor.getString(1);
|
||||||
final String artist = cursor.getString(2);
|
final String artist = cursor.getString(2);
|
||||||
|
|
@ -69,15 +77,15 @@ public class AlbumLoader {
|
||||||
return new Album(id, albumName, artist, artistId, songCount, year);
|
return new Album(id, albumName, artist, artistId, songCount, year);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Cursor makeAlbumCursor(final Context context, final String selection, final String[] values) {
|
public static Cursor makeAlbumCursor(@NonNull final Context context, final String selection, final String[] values) {
|
||||||
return makeAlbumCursor(context, selection, values, PreferenceUtils.getInstance(context).getAlbumSortOrder());
|
return makeAlbumCursor(context, selection, values, PreferenceUtils.getInstance(context).getAlbumSortOrder());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Cursor makeAlbumCursor(final Context context, final String selection, final String[] values, final String sortOrder) {
|
public static Cursor makeAlbumCursor(@NonNull final Context context, final String selection, final String[] values, final String sortOrder) {
|
||||||
return makeAlbumCursor(context, MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, selection, values, sortOrder);
|
return makeAlbumCursor(context, MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, selection, values, sortOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Cursor makeAlbumCursor(final Context context, final Uri contentUri, final String selection, final String[] values, final String sortOrder) {
|
public static Cursor makeAlbumCursor(@NonNull final Context context, @NonNull final Uri contentUri, final String selection, final String[] values, final String sortOrder) {
|
||||||
return context.getContentResolver().query(contentUri,
|
return context.getContentResolver().query(contentUri,
|
||||||
new String[]{
|
new String[]{
|
||||||
/* 0 */
|
/* 0 */
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.kabouzeid.gramophone.loader;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import com.kabouzeid.gramophone.model.Song;
|
import com.kabouzeid.gramophone.model.Song;
|
||||||
import com.kabouzeid.gramophone.util.PreferenceUtils;
|
import com.kabouzeid.gramophone.util.PreferenceUtils;
|
||||||
|
|
@ -14,11 +15,12 @@ import java.util.ArrayList;
|
||||||
*/
|
*/
|
||||||
public class AlbumSongLoader {
|
public class AlbumSongLoader {
|
||||||
|
|
||||||
public static ArrayList<Song> getAlbumSongList(final Context context, final int albumId) {
|
@NonNull
|
||||||
|
public static ArrayList<Song> getAlbumSongList(@NonNull final Context context, final int albumId) {
|
||||||
return SongLoader.getSongs(makeAlbumSongCursor(context, albumId));
|
return SongLoader.getSongs(makeAlbumSongCursor(context, albumId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Cursor makeAlbumSongCursor(final Context context, final int albumId) {
|
public static Cursor makeAlbumSongCursor(@NonNull final Context context, final int albumId) {
|
||||||
return SongLoader.makeSongCursor(
|
return SongLoader.makeSongCursor(
|
||||||
context,
|
context,
|
||||||
MediaStore.Audio.AudioColumns.ALBUM_ID + "=?",
|
MediaStore.Audio.AudioColumns.ALBUM_ID + "=?",
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.kabouzeid.gramophone.loader;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import com.kabouzeid.gramophone.model.Album;
|
import com.kabouzeid.gramophone.model.Album;
|
||||||
import com.kabouzeid.gramophone.util.PreferenceUtils;
|
import com.kabouzeid.gramophone.util.PreferenceUtils;
|
||||||
|
|
@ -14,11 +15,12 @@ import java.util.ArrayList;
|
||||||
*/
|
*/
|
||||||
public class ArtistAlbumLoader {
|
public class ArtistAlbumLoader {
|
||||||
|
|
||||||
public static ArrayList<Album> getArtistAlbumList(final Context context, final int artistId) {
|
@NonNull
|
||||||
|
public static ArrayList<Album> getArtistAlbumList(@NonNull final Context context, final int artistId) {
|
||||||
return AlbumLoader.getAlbums(makeArtistAlbumCursor(context, artistId));
|
return AlbumLoader.getAlbums(makeArtistAlbumCursor(context, artistId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Cursor makeArtistAlbumCursor(final Context context, final int artistId) {
|
public static Cursor makeArtistAlbumCursor(@NonNull final Context context, final int artistId) {
|
||||||
return AlbumLoader.makeAlbumCursor(context,
|
return AlbumLoader.makeAlbumCursor(context,
|
||||||
MediaStore.Audio.Artists.Albums.getContentUri("external", artistId),
|
MediaStore.Audio.Artists.Albums.getContentUri("external", artistId),
|
||||||
null,
|
null,
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ import android.database.Cursor;
|
||||||
import android.provider.BaseColumns;
|
import android.provider.BaseColumns;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.provider.MediaStore.Audio.ArtistColumns;
|
import android.provider.MediaStore.Audio.ArtistColumns;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import com.kabouzeid.gramophone.model.Artist;
|
import com.kabouzeid.gramophone.model.Artist;
|
||||||
import com.kabouzeid.gramophone.util.PreferenceUtils;
|
import com.kabouzeid.gramophone.util.PreferenceUtils;
|
||||||
|
|
@ -16,22 +18,26 @@ import java.util.ArrayList;
|
||||||
*/
|
*/
|
||||||
public class ArtistLoader {
|
public class ArtistLoader {
|
||||||
|
|
||||||
public static ArrayList<Artist> getAllArtists(Context context) {
|
@NonNull
|
||||||
|
public static ArrayList<Artist> getAllArtists(@NonNull Context context) {
|
||||||
Cursor cursor = makeArtistCursor(context, null, null);
|
Cursor cursor = makeArtistCursor(context, null, null);
|
||||||
return getArtists(cursor);
|
return getArtists(cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Artist> getArtists(Context context, String query) {
|
@NonNull
|
||||||
|
public static ArrayList<Artist> getArtists(@NonNull Context context, String query) {
|
||||||
Cursor cursor = makeArtistCursor(context, ArtistColumns.ARTIST + " LIKE ?", new String[]{"%" + query + "%"});
|
Cursor cursor = makeArtistCursor(context, ArtistColumns.ARTIST + " LIKE ?", new String[]{"%" + query + "%"});
|
||||||
return getArtists(cursor);
|
return getArtists(cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Artist getArtist(Context context, int artistId) {
|
@NonNull
|
||||||
|
public static Artist getArtist(@NonNull Context context, int artistId) {
|
||||||
Cursor cursor = makeArtistCursor(context, BaseColumns._ID + "=?", new String[]{String.valueOf(artistId)});
|
Cursor cursor = makeArtistCursor(context, BaseColumns._ID + "=?", new String[]{String.valueOf(artistId)});
|
||||||
return getArtist(cursor);
|
return getArtist(cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Artist> getArtists(Cursor cursor) {
|
@NonNull
|
||||||
|
public static ArrayList<Artist> getArtists(@Nullable Cursor cursor) {
|
||||||
ArrayList<Artist> artists = new ArrayList<>();
|
ArrayList<Artist> artists = new ArrayList<>();
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
do {
|
do {
|
||||||
|
|
@ -45,7 +51,8 @@ public class ArtistLoader {
|
||||||
return artists;
|
return artists;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Artist getArtist(Cursor cursor) {
|
@NonNull
|
||||||
|
public static Artist getArtist(@Nullable Cursor cursor) {
|
||||||
Artist artist = new Artist();
|
Artist artist = new Artist();
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
artist = getArtistFromCursorImpl(cursor);
|
artist = getArtistFromCursorImpl(cursor);
|
||||||
|
|
@ -57,7 +64,8 @@ public class ArtistLoader {
|
||||||
return artist;
|
return artist;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Artist getArtistFromCursorImpl(Cursor cursor) {
|
@NonNull
|
||||||
|
private static Artist getArtistFromCursorImpl(@NonNull Cursor cursor) {
|
||||||
final int id = cursor.getInt(0);
|
final int id = cursor.getInt(0);
|
||||||
final String artistName = cursor.getString(1);
|
final String artistName = cursor.getString(1);
|
||||||
final int albumCount = cursor.getInt(2);
|
final int albumCount = cursor.getInt(2);
|
||||||
|
|
@ -66,7 +74,7 @@ public class ArtistLoader {
|
||||||
return new Artist(id, artistName, albumCount, songCount);
|
return new Artist(id, artistName, albumCount, songCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Cursor makeArtistCursor(final Context context, final String selection, final String[] values) {
|
public static Cursor makeArtistCursor(@NonNull final Context context, final String selection, final String[] values) {
|
||||||
return context.getContentResolver().query(MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI,
|
return context.getContentResolver().query(MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI,
|
||||||
new String[]{
|
new String[]{
|
||||||
/* 0 */
|
/* 0 */
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.kabouzeid.gramophone.loader;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import com.kabouzeid.gramophone.model.Song;
|
import com.kabouzeid.gramophone.model.Song;
|
||||||
import com.kabouzeid.gramophone.util.PreferenceUtils;
|
import com.kabouzeid.gramophone.util.PreferenceUtils;
|
||||||
|
|
@ -14,11 +15,12 @@ import java.util.ArrayList;
|
||||||
*/
|
*/
|
||||||
public class ArtistSongLoader {
|
public class ArtistSongLoader {
|
||||||
|
|
||||||
public static ArrayList<Song> getArtistSongList(final Context context, final int artistId) {
|
@NonNull
|
||||||
|
public static ArrayList<Song> getArtistSongList(@NonNull final Context context, final int artistId) {
|
||||||
return SongLoader.getSongs(makeArtistSongCursor(context, artistId));
|
return SongLoader.getSongs(makeArtistSongCursor(context, artistId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Cursor makeArtistSongCursor(final Context context, final int artistId) {
|
public static Cursor makeArtistSongCursor(@NonNull final Context context, final int artistId) {
|
||||||
return SongLoader.makeSongCursor(
|
return SongLoader.makeSongCursor(
|
||||||
context,
|
context,
|
||||||
MediaStore.Audio.AudioColumns.ARTIST_ID + "=?",
|
MediaStore.Audio.AudioColumns.ARTIST_ID + "=?",
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.kabouzeid.gramophone.loader;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import com.kabouzeid.gramophone.model.Song;
|
import com.kabouzeid.gramophone.model.Song;
|
||||||
import com.kabouzeid.gramophone.util.PreferenceUtils;
|
import com.kabouzeid.gramophone.util.PreferenceUtils;
|
||||||
|
|
@ -11,11 +12,12 @@ import java.util.ArrayList;
|
||||||
|
|
||||||
public class LastAddedLoader {
|
public class LastAddedLoader {
|
||||||
|
|
||||||
public static ArrayList<Song> getLastAddedSongs(Context context) {
|
@NonNull
|
||||||
|
public static ArrayList<Song> getLastAddedSongs(@NonNull Context context) {
|
||||||
return SongLoader.getSongs(makeLastAddedCursor(context));
|
return SongLoader.getSongs(makeLastAddedCursor(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Cursor makeLastAddedCursor(final Context context) {
|
public static Cursor makeLastAddedCursor(@NonNull final Context context) {
|
||||||
long fourWeeksAgo = (System.currentTimeMillis() / 1000) - (4 * 3600 * 24 * 7);
|
long fourWeeksAgo = (System.currentTimeMillis() / 1000) - (4 * 3600 * 24 * 7);
|
||||||
// possible saved timestamp caused by user "clearing" the last added playlist
|
// possible saved timestamp caused by user "clearing" the last added playlist
|
||||||
long cutoff = PreferenceUtils.getInstance(context).getLastAddedCutOffTimestamp() / 1000;
|
long cutoff = PreferenceUtils.getInstance(context).getLastAddedCutOffTimestamp() / 1000;
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ import android.database.Cursor;
|
||||||
import android.provider.BaseColumns;
|
import android.provider.BaseColumns;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.provider.MediaStore.Audio.PlaylistsColumns;
|
import android.provider.MediaStore.Audio.PlaylistsColumns;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import com.kabouzeid.gramophone.model.Playlist;
|
import com.kabouzeid.gramophone.model.Playlist;
|
||||||
|
|
||||||
|
|
@ -13,11 +15,13 @@ import java.util.List;
|
||||||
|
|
||||||
public class PlaylistLoader {
|
public class PlaylistLoader {
|
||||||
|
|
||||||
public static List<Playlist> getAllPlaylists(final Context context) {
|
@NonNull
|
||||||
|
public static List<Playlist> getAllPlaylists(@NonNull final Context context) {
|
||||||
return getAllPlaylists(makePlaylistCursor(context, null, null));
|
return getAllPlaylists(makePlaylistCursor(context, null, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Playlist getPlaylist(final Context context, final int playlistId) {
|
@NonNull
|
||||||
|
public static Playlist getPlaylist(@NonNull final Context context, final int playlistId) {
|
||||||
return getPlaylist(makePlaylistCursor(
|
return getPlaylist(makePlaylistCursor(
|
||||||
context,
|
context,
|
||||||
BaseColumns._ID + "=?",
|
BaseColumns._ID + "=?",
|
||||||
|
|
@ -27,7 +31,8 @@ public class PlaylistLoader {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Playlist getPlaylist(final Context context, final String playlistName) {
|
@NonNull
|
||||||
|
public static Playlist getPlaylist(@NonNull final Context context, final String playlistName) {
|
||||||
return getPlaylist(makePlaylistCursor(
|
return getPlaylist(makePlaylistCursor(
|
||||||
context,
|
context,
|
||||||
PlaylistsColumns.NAME + "=?",
|
PlaylistsColumns.NAME + "=?",
|
||||||
|
|
@ -37,7 +42,8 @@ public class PlaylistLoader {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Playlist getPlaylist(final Cursor cursor) {
|
@NonNull
|
||||||
|
public static Playlist getPlaylist(@Nullable final Cursor cursor) {
|
||||||
Playlist playlist = new Playlist();
|
Playlist playlist = new Playlist();
|
||||||
|
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
|
|
@ -48,7 +54,8 @@ public class PlaylistLoader {
|
||||||
return playlist;
|
return playlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Playlist> getAllPlaylists(final Cursor cursor) {
|
@NonNull
|
||||||
|
public static List<Playlist> getAllPlaylists(@Nullable final Cursor cursor) {
|
||||||
List<Playlist> playlists = new ArrayList<>();
|
List<Playlist> playlists = new ArrayList<>();
|
||||||
|
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
|
|
@ -61,13 +68,14 @@ public class PlaylistLoader {
|
||||||
return playlists;
|
return playlists;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Playlist getPlaylistFromCursorImpl(final Cursor cursor) {
|
@NonNull
|
||||||
|
private static Playlist getPlaylistFromCursorImpl(@NonNull final Cursor cursor) {
|
||||||
final int id = cursor.getInt(0);
|
final int id = cursor.getInt(0);
|
||||||
final String name = cursor.getString(1);
|
final String name = cursor.getString(1);
|
||||||
return new Playlist(id, name);
|
return new Playlist(id, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Cursor makePlaylistCursor(final Context context, final String selection, final String[] values) {
|
public static Cursor makePlaylistCursor(@NonNull final Context context, final String selection, final String[] values) {
|
||||||
return context.getContentResolver().query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
|
return context.getContentResolver().query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
|
||||||
new String[]{
|
new String[]{
|
||||||
/* 0 */
|
/* 0 */
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.provider.MediaStore.Audio.AudioColumns;
|
import android.provider.MediaStore.Audio.AudioColumns;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import com.kabouzeid.gramophone.model.PlaylistSong;
|
import com.kabouzeid.gramophone.model.PlaylistSong;
|
||||||
|
|
||||||
|
|
@ -11,7 +12,8 @@ import java.util.ArrayList;
|
||||||
|
|
||||||
public class PlaylistSongLoader {
|
public class PlaylistSongLoader {
|
||||||
|
|
||||||
public static ArrayList<PlaylistSong> getPlaylistSongList(final Context context, final int playlistId) {
|
@NonNull
|
||||||
|
public static ArrayList<PlaylistSong> getPlaylistSongList(@NonNull final Context context, final int playlistId) {
|
||||||
ArrayList<PlaylistSong> songs = new ArrayList<>();
|
ArrayList<PlaylistSong> songs = new ArrayList<>();
|
||||||
Cursor cursor = makePlaylistSongCursor(context, playlistId);
|
Cursor cursor = makePlaylistSongCursor(context, playlistId);
|
||||||
|
|
||||||
|
|
@ -26,7 +28,8 @@ public class PlaylistSongLoader {
|
||||||
return songs;
|
return songs;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PlaylistSong getPlaylistSongFromCursorImpl(Cursor cursor) {
|
@NonNull
|
||||||
|
private static PlaylistSong getPlaylistSongFromCursorImpl(@NonNull Cursor cursor) {
|
||||||
final int id = cursor.getInt(0);
|
final int id = cursor.getInt(0);
|
||||||
final String songName = cursor.getString(1);
|
final String songName = cursor.getString(1);
|
||||||
final String artist = cursor.getString(2);
|
final String artist = cursor.getString(2);
|
||||||
|
|
@ -42,7 +45,7 @@ public class PlaylistSongLoader {
|
||||||
return new PlaylistSong(id, albumId, artistId, songName, artist, album, duration, trackNumber, data, playlistId, idInPlaylist);
|
return new PlaylistSong(id, albumId, artistId, songName, artist, album, duration, trackNumber, data, playlistId, idInPlaylist);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Cursor makePlaylistSongCursor(final Context context, final int playlistId) {
|
public static Cursor makePlaylistSongCursor(@NonNull final Context context, final int playlistId) {
|
||||||
return context.getContentResolver().query(
|
return context.getContentResolver().query(
|
||||||
MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId),
|
MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId),
|
||||||
new String[]{
|
new String[]{
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ import android.database.Cursor;
|
||||||
import android.provider.BaseColumns;
|
import android.provider.BaseColumns;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.provider.MediaStore.Audio.AudioColumns;
|
import android.provider.MediaStore.Audio.AudioColumns;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import com.kabouzeid.gramophone.model.Song;
|
import com.kabouzeid.gramophone.model.Song;
|
||||||
import com.kabouzeid.gramophone.util.PreferenceUtils;
|
import com.kabouzeid.gramophone.util.PreferenceUtils;
|
||||||
|
|
@ -17,22 +19,26 @@ import java.util.ArrayList;
|
||||||
public class SongLoader {
|
public class SongLoader {
|
||||||
protected static final String BASE_SELECTION = AudioColumns.IS_MUSIC + "=1" + " AND " + AudioColumns.TITLE + " != ''";
|
protected static final String BASE_SELECTION = AudioColumns.IS_MUSIC + "=1" + " AND " + AudioColumns.TITLE + " != ''";
|
||||||
|
|
||||||
public static ArrayList<Song> getAllSongs(Context context) {
|
@NonNull
|
||||||
|
public static ArrayList<Song> getAllSongs(@NonNull Context context) {
|
||||||
Cursor cursor = makeSongCursor(context, null, null);
|
Cursor cursor = makeSongCursor(context, null, null);
|
||||||
return getSongs(cursor);
|
return getSongs(cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Song> getSongs(final Context context, final String query) {
|
@NonNull
|
||||||
|
public static ArrayList<Song> getSongs(@NonNull final Context context, final String query) {
|
||||||
Cursor cursor = makeSongCursor(context, AudioColumns.TITLE + " LIKE ?", new String[]{"%" + query + "%"});
|
Cursor cursor = makeSongCursor(context, AudioColumns.TITLE + " LIKE ?", new String[]{"%" + query + "%"});
|
||||||
return getSongs(cursor);
|
return getSongs(cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Song getSong(final Context context, final int queryId) {
|
@NonNull
|
||||||
|
public static Song getSong(@NonNull final Context context, final int queryId) {
|
||||||
Cursor cursor = makeSongCursor(context, AudioColumns._ID + "=?", new String[]{String.valueOf(queryId)});
|
Cursor cursor = makeSongCursor(context, AudioColumns._ID + "=?", new String[]{String.valueOf(queryId)});
|
||||||
return getSong(cursor);
|
return getSong(cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Song> getSongs(final Cursor cursor) {
|
@NonNull
|
||||||
|
public static ArrayList<Song> getSongs(@Nullable final Cursor cursor) {
|
||||||
ArrayList<Song> songs = new ArrayList<>();
|
ArrayList<Song> songs = new ArrayList<>();
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
do {
|
do {
|
||||||
|
|
@ -45,7 +51,8 @@ public class SongLoader {
|
||||||
return songs;
|
return songs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Song getSong(Cursor cursor) {
|
@NonNull
|
||||||
|
public static Song getSong(@Nullable Cursor cursor) {
|
||||||
Song song = new Song();
|
Song song = new Song();
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
song = getSongFromCursorImpl(cursor);
|
song = getSongFromCursorImpl(cursor);
|
||||||
|
|
@ -56,7 +63,8 @@ public class SongLoader {
|
||||||
return song;
|
return song;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Song getSongFromCursorImpl(Cursor cursor) {
|
@NonNull
|
||||||
|
private static Song getSongFromCursorImpl(@NonNull Cursor cursor) {
|
||||||
final int id = cursor.getInt(0);
|
final int id = cursor.getInt(0);
|
||||||
final String songName = cursor.getString(1);
|
final String songName = cursor.getString(1);
|
||||||
final String artist = cursor.getString(2);
|
final String artist = cursor.getString(2);
|
||||||
|
|
@ -69,11 +77,11 @@ public class SongLoader {
|
||||||
return new Song(id, albumId, artistId, songName, artist, album, duration, trackNumber, data);
|
return new Song(id, albumId, artistId, songName, artist, album, duration, trackNumber, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Cursor makeSongCursor(final Context context, final String selection, final String[] values) {
|
public static Cursor makeSongCursor(@NonNull final Context context, final String selection, final String[] values) {
|
||||||
return makeSongCursor(context, selection, values, PreferenceUtils.getInstance(context).getSongSortOrder());
|
return makeSongCursor(context, selection, values, PreferenceUtils.getInstance(context).getSongSortOrder());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Cursor makeSongCursor(final Context context, final String selection, final String[] values, final String sortOrder) {
|
public static Cursor makeSongCursor(@NonNull final Context context, @Nullable final String selection, final String[] values, final String sortOrder) {
|
||||||
String baseSelection = BASE_SELECTION;
|
String baseSelection = BASE_SELECTION;
|
||||||
if (selection != null && !selection.trim().equals("")) {
|
if (selection != null && !selection.trim().equals("")) {
|
||||||
baseSelection += " AND " + selection;
|
baseSelection += " AND " + selection;
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@ package com.kabouzeid.gramophone.loader;
|
||||||
|
|
||||||
import android.database.AbstractCursor;
|
import android.database.AbstractCursor;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
@ -30,6 +32,7 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public class SortedCursor extends AbstractCursor {
|
public class SortedCursor extends AbstractCursor {
|
||||||
// cursor to wrap
|
// cursor to wrap
|
||||||
|
@Nullable
|
||||||
private final Cursor mCursor;
|
private final Cursor mCursor;
|
||||||
// the map of external indices to internal indices
|
// the map of external indices to internal indices
|
||||||
private ArrayList<Integer> mOrderedPositions;
|
private ArrayList<Integer> mOrderedPositions;
|
||||||
|
|
@ -45,8 +48,8 @@ public class SortedCursor extends AbstractCursor {
|
||||||
* @param order the list of unique ids in sorted order to display
|
* @param order the list of unique ids in sorted order to display
|
||||||
* @param columnName the column name of the id to look up in the internal cursor
|
* @param columnName the column name of the id to look up in the internal cursor
|
||||||
*/
|
*/
|
||||||
public SortedCursor(final Cursor cursor, final long[] order, final String columnName,
|
public SortedCursor(@Nullable final Cursor cursor, final long[] order, final String columnName,
|
||||||
final List<? extends Object> extraData) {
|
final List<?> extraData) {
|
||||||
if (cursor == null) {
|
if (cursor == null) {
|
||||||
throw new IllegalArgumentException("Non-null cursor is needed");
|
throw new IllegalArgumentException("Non-null cursor is needed");
|
||||||
}
|
}
|
||||||
|
|
@ -63,14 +66,15 @@ public class SortedCursor extends AbstractCursor {
|
||||||
* @param extraData Extra data we want to add to the cursor
|
* @param extraData Extra data we want to add to the cursor
|
||||||
* @return returns the ids that aren't found in the underlying cursor
|
* @return returns the ids that aren't found in the underlying cursor
|
||||||
*/
|
*/
|
||||||
private ArrayList<Long> buildCursorPositionMapping(final long[] order,
|
@NonNull
|
||||||
final String columnName, final List<? extends Object> extraData) {
|
private ArrayList<Long> buildCursorPositionMapping(@Nullable final long[] order,
|
||||||
ArrayList<Long> missingIds = new ArrayList<Long>();
|
final String columnName, @Nullable final List<?> extraData) {
|
||||||
|
ArrayList<Long> missingIds = new ArrayList<>();
|
||||||
|
|
||||||
mOrderedPositions = new ArrayList<Integer>(mCursor.getCount());
|
mOrderedPositions = new ArrayList<>(mCursor.getCount());
|
||||||
mExtraData = new ArrayList<Object>();
|
mExtraData = new ArrayList<>();
|
||||||
|
|
||||||
mMapCursorPositions = new HashMap<Long, Integer>(mCursor.getCount());
|
mMapCursorPositions = new HashMap<>(mCursor.getCount());
|
||||||
final int idPosition = mCursor.getColumnIndex(columnName);
|
final int idPosition = mCursor.getColumnIndex(columnName);
|
||||||
|
|
||||||
if (mCursor.moveToFirst()) {
|
if (mCursor.moveToFirst()) {
|
||||||
|
|
@ -110,6 +114,7 @@ public class SortedCursor extends AbstractCursor {
|
||||||
/**
|
/**
|
||||||
* @return the list of ids that were in the underlying cursor but not part of the ordered list
|
* @return the list of ids that were in the underlying cursor but not part of the ordered list
|
||||||
*/
|
*/
|
||||||
|
@NonNull
|
||||||
public Collection<Long> getExtraIds() {
|
public Collection<Long> getExtraIds() {
|
||||||
return mMapCursorPositions.keySet();
|
return mMapCursorPositions.keySet();
|
||||||
}
|
}
|
||||||
|
|
@ -117,6 +122,7 @@ public class SortedCursor extends AbstractCursor {
|
||||||
/**
|
/**
|
||||||
* @return the extra object data that was passed in to be attached to the current row
|
* @return the extra object data that was passed in to be attached to the current row
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public Object getExtraData() {
|
public Object getExtraData() {
|
||||||
int position = getPosition();
|
int position = getPosition();
|
||||||
return position < mExtraData.size() ? mExtraData.get(position) : null;
|
return position < mExtraData.size() ? mExtraData.get(position) : null;
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@ package com.kabouzeid.gramophone.loader;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.provider.BaseColumns;
|
import android.provider.BaseColumns;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import com.kabouzeid.gramophone.model.Song;
|
import com.kabouzeid.gramophone.model.Song;
|
||||||
import com.kabouzeid.gramophone.provider.RecentlyPlayedStore;
|
import com.kabouzeid.gramophone.provider.RecentlyPlayedStore;
|
||||||
|
|
@ -29,15 +31,18 @@ import java.util.ArrayList;
|
||||||
public class TopAndRecentlyPlayedTracksLoader {
|
public class TopAndRecentlyPlayedTracksLoader {
|
||||||
public static final int NUMBER_OF_TOP_TRACKS = 99;
|
public static final int NUMBER_OF_TOP_TRACKS = 99;
|
||||||
|
|
||||||
public static ArrayList<Song> getRecentlyPlayedTracks(Context context) {
|
@NonNull
|
||||||
|
public static ArrayList<Song> getRecentlyPlayedTracks(@NonNull Context context) {
|
||||||
return SongLoader.getSongs(makeRecentTracksCursorAndClearUpDatabase(context));
|
return SongLoader.getSongs(makeRecentTracksCursorAndClearUpDatabase(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Song> getTopTracks(Context context) {
|
@NonNull
|
||||||
|
public static ArrayList<Song> getTopTracks(@NonNull Context context) {
|
||||||
return SongLoader.getSongs(makeTopTracksCursorAndClearUpDatabase(context));
|
return SongLoader.getSongs(makeTopTracksCursorAndClearUpDatabase(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Cursor makeRecentTracksCursorAndClearUpDatabase(final Context context) {
|
@Nullable
|
||||||
|
public static Cursor makeRecentTracksCursorAndClearUpDatabase(@NonNull final Context context) {
|
||||||
SortedCursor retCursor = makeRecentTracksCursorImpl(context);
|
SortedCursor retCursor = makeRecentTracksCursorImpl(context);
|
||||||
|
|
||||||
// clean up the databases with any ids not found
|
// clean up the databases with any ids not found
|
||||||
|
|
@ -52,7 +57,8 @@ public class TopAndRecentlyPlayedTracksLoader {
|
||||||
return retCursor;
|
return retCursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Cursor makeTopTracksCursorAndClearUpDatabase(final Context context) {
|
@Nullable
|
||||||
|
public static Cursor makeTopTracksCursorAndClearUpDatabase(@NonNull final Context context) {
|
||||||
SortedCursor retCursor = makeTopTracksCursorImpl(context);
|
SortedCursor retCursor = makeTopTracksCursorImpl(context);
|
||||||
|
|
||||||
// clean up the databases with any ids not found
|
// clean up the databases with any ids not found
|
||||||
|
|
@ -67,7 +73,8 @@ public class TopAndRecentlyPlayedTracksLoader {
|
||||||
return retCursor;
|
return retCursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SortedCursor makeRecentTracksCursorImpl(final Context context) {
|
@Nullable
|
||||||
|
private static SortedCursor makeRecentTracksCursorImpl(@NonNull final Context context) {
|
||||||
// first get the top results ids from the internal database
|
// first get the top results ids from the internal database
|
||||||
Cursor songs = RecentlyPlayedStore.getInstance(context).queryRecentIds();
|
Cursor songs = RecentlyPlayedStore.getInstance(context).queryRecentIds();
|
||||||
|
|
||||||
|
|
@ -81,7 +88,8 @@ public class TopAndRecentlyPlayedTracksLoader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SortedCursor makeTopTracksCursorImpl(final Context context) {
|
@Nullable
|
||||||
|
private static SortedCursor makeTopTracksCursorImpl(@NonNull final Context context) {
|
||||||
// first get the top results ids from the internal database
|
// first get the top results ids from the internal database
|
||||||
Cursor songs = SongPlayCountStore.getInstance(context).getTopPlayedResults(NUMBER_OF_TOP_TRACKS);
|
Cursor songs = SongPlayCountStore.getInstance(context).getTopPlayedResults(NUMBER_OF_TOP_TRACKS);
|
||||||
|
|
||||||
|
|
@ -95,7 +103,8 @@ public class TopAndRecentlyPlayedTracksLoader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SortedCursor makeSortedCursor(final Context context, final Cursor cursor,
|
@Nullable
|
||||||
|
private static SortedCursor makeSortedCursor(@NonNull final Context context, @Nullable final Cursor cursor,
|
||||||
final int idColumn) {
|
final int idColumn) {
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
// create the list of ids to select against
|
// create the list of ids to select against
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import android.graphics.Canvas;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.drawable.BitmapDrawable;
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
@ -52,6 +53,7 @@ public class DragSortRecycler extends RecyclerView.ItemDecoration implements Rec
|
||||||
private float autoScrollWindow = 0.1f;
|
private float autoScrollWindow = 0.1f;
|
||||||
private float autoScrollSpeed = 0.5f;
|
private float autoScrollSpeed = 0.5f;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private BitmapDrawable floatingItem;
|
private BitmapDrawable floatingItem;
|
||||||
private Rect floatingItemStatingBounds;
|
private Rect floatingItemStatingBounds;
|
||||||
private Rect floatingItemBounds;
|
private Rect floatingItemBounds;
|
||||||
|
|
@ -85,6 +87,7 @@ public class DragSortRecycler extends RecyclerView.ItemDecoration implements Rec
|
||||||
Log.d(TAG, log);
|
Log.d(TAG, log);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public RecyclerView.OnScrollListener getScrollListener() {
|
public RecyclerView.OnScrollListener getScrollListener() {
|
||||||
return scrollListener;
|
return scrollListener;
|
||||||
}
|
}
|
||||||
|
|
@ -128,7 +131,7 @@ public class DragSortRecycler extends RecyclerView.ItemDecoration implements Rec
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getItemOffsets(Rect outRect, View view, RecyclerView rv, RecyclerView.State state) {
|
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView rv, RecyclerView.State state) {
|
||||||
super.getItemOffsets(outRect, view, rv, state);
|
super.getItemOffsets(outRect, view, rv, state);
|
||||||
|
|
||||||
debugLog("getItemOffsets");
|
debugLog("getItemOffsets");
|
||||||
|
|
@ -195,7 +198,7 @@ public class DragSortRecycler extends RecyclerView.ItemDecoration implements Rec
|
||||||
* This *seems* to work, another method would be to use
|
* This *seems* to work, another method would be to use
|
||||||
* getItemOffsets, but I think that could miss items?..
|
* getItemOffsets, but I think that could miss items?..
|
||||||
*/
|
*/
|
||||||
private int getNewPostion(RecyclerView rv) {
|
private int getNewPostion(@NonNull RecyclerView rv) {
|
||||||
int itemsOnScreen = rv.getLayoutManager().getChildCount();
|
int itemsOnScreen = rv.getLayoutManager().getChildCount();
|
||||||
|
|
||||||
float floatMiddleY = floatingItemBounds.top + floatingItemBounds.height() / 2;
|
float floatMiddleY = floatingItemBounds.top + floatingItemBounds.height() / 2;
|
||||||
|
|
@ -242,7 +245,7 @@ public class DragSortRecycler extends RecyclerView.ItemDecoration implements Rec
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
|
public boolean onInterceptTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) {
|
||||||
debugLog("onInterceptTouchEvent");
|
debugLog("onInterceptTouchEvent");
|
||||||
|
|
||||||
//if (e.getAction() == MotionEvent.ACTION_DOWN)
|
//if (e.getAction() == MotionEvent.ACTION_DOWN)
|
||||||
|
|
@ -315,7 +318,7 @@ public class DragSortRecycler extends RecyclerView.ItemDecoration implements Rec
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTouchEvent(RecyclerView rv, MotionEvent e) {
|
public void onTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) {
|
||||||
debugLog("onTouchEvent");
|
debugLog("onTouchEvent");
|
||||||
|
|
||||||
if ((e.getAction() == MotionEvent.ACTION_UP) ||
|
if ((e.getAction() == MotionEvent.ACTION_UP) ||
|
||||||
|
|
@ -388,7 +391,7 @@ public class DragSortRecycler extends RecyclerView.ItemDecoration implements Rec
|
||||||
final Paint bgColor = new Paint();
|
final Paint bgColor = new Paint();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
|
public void onDrawOver(@NonNull Canvas c, RecyclerView parent, RecyclerView.State state) {
|
||||||
if (floatingItem != null) {
|
if (floatingItem != null) {
|
||||||
floatingItem.setAlpha((int) (255 * floatingItemAlpha));
|
floatingItem.setAlpha((int) (255 * floatingItemAlpha));
|
||||||
bgColor.setColor(floatingItemBgColor);
|
bgColor.setColor(floatingItemBgColor);
|
||||||
|
|
@ -410,7 +413,8 @@ public class DragSortRecycler extends RecyclerView.ItemDecoration implements Rec
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private BitmapDrawable createFloatingBitmap(View v) {
|
@NonNull
|
||||||
|
private BitmapDrawable createFloatingBitmap(@NonNull View v) {
|
||||||
floatingItemStatingBounds = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
|
floatingItemStatingBounds = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
|
||||||
floatingItemBounds = new Rect(floatingItemStatingBounds);
|
floatingItemBounds = new Rect(floatingItemStatingBounds);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.kabouzeid.gramophone.model;
|
package com.kabouzeid.gramophone.model;
|
||||||
|
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -46,7 +47,7 @@ public class Album {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(final Object obj) {
|
public boolean equals(@Nullable final Object obj) {
|
||||||
if (this == obj) {
|
if (this == obj) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.kabouzeid.gramophone.model;
|
package com.kabouzeid.gramophone.model;
|
||||||
|
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -37,7 +38,7 @@ public class Artist {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(final Object obj) {
|
public boolean equals(@Nullable final Object obj) {
|
||||||
if (this == obj) {
|
if (this == obj) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.kabouzeid.gramophone.model;
|
package com.kabouzeid.gramophone.model;
|
||||||
|
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
@ -34,7 +35,7 @@ public class Playlist implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(final Object obj) {
|
public boolean equals(@Nullable final Object obj) {
|
||||||
if (this == obj) {
|
if (this == obj) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.kabouzeid.gramophone.model;
|
package com.kabouzeid.gramophone.model;
|
||||||
|
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
@ -59,7 +60,7 @@ public class Song implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(final Object obj) {
|
public boolean equals(@Nullable final Object obj) {
|
||||||
if (this == obj) {
|
if (this == obj) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.kabouzeid.gramophone.model.smartplaylist;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.support.annotation.DrawableRes;
|
import android.support.annotation.DrawableRes;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
|
||||||
|
|
@ -32,6 +33,7 @@ public abstract class AbsSmartPlaylist extends Playlist {
|
||||||
this.iconRes = R.drawable.ic_queue_music_white_24dp;
|
this.iconRes = R.drawable.ic_queue_music_white_24dp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public SmartPlaylistSongAdapter createAdapter(AppCompatActivity activity, @Nullable CabHolder cabHolder) {
|
public SmartPlaylistSongAdapter createAdapter(AppCompatActivity activity, @Nullable CabHolder cabHolder) {
|
||||||
return new SmartPlaylistSongAdapter(activity, this, cabHolder);
|
return new SmartPlaylistSongAdapter(activity, this, cabHolder);
|
||||||
}
|
}
|
||||||
|
|
@ -49,7 +51,7 @@ public abstract class AbsSmartPlaylist extends Playlist {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(final Object obj) {
|
public boolean equals(@NonNull final Object obj) {
|
||||||
if (super.equals(obj)) {
|
if (super.equals(obj)) {
|
||||||
if (getClass() != obj.getClass()) {
|
if (getClass() != obj.getClass()) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.kabouzeid.gramophone.model.smartplaylist;
|
package com.kabouzeid.gramophone.model.smartplaylist;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import com.kabouzeid.gramophone.App;
|
import com.kabouzeid.gramophone.App;
|
||||||
import com.kabouzeid.gramophone.R;
|
import com.kabouzeid.gramophone.R;
|
||||||
|
|
@ -16,17 +17,18 @@ import java.util.ArrayList;
|
||||||
*/
|
*/
|
||||||
public class LastAddedPlaylist extends AbsSmartPlaylist {
|
public class LastAddedPlaylist extends AbsSmartPlaylist {
|
||||||
|
|
||||||
public LastAddedPlaylist(Context context) {
|
public LastAddedPlaylist(@NonNull Context context) {
|
||||||
super(context.getString(R.string.last_added), R.drawable.ic_queue_white_24dp);
|
super(context.getString(R.string.last_added), R.drawable.ic_queue_white_24dp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<Song> getSongs(Context context) {
|
public ArrayList<Song> getSongs(@NonNull Context context) {
|
||||||
return LastAddedLoader.getLastAddedSongs(context);
|
return LastAddedLoader.getLastAddedSongs(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clear(Context context) {
|
public void clear(@NonNull Context context) {
|
||||||
PreferenceUtils.getInstance(context).setLastAddedCutoffTimestamp(System.currentTimeMillis());
|
PreferenceUtils.getInstance(context).setLastAddedCutoffTimestamp(System.currentTimeMillis());
|
||||||
App.bus.post(new DataBaseChangedEvent(DataBaseChangedEvent.PLAYLISTS_CHANGED));
|
App.bus.post(new DataBaseChangedEvent(DataBaseChangedEvent.PLAYLISTS_CHANGED));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.kabouzeid.gramophone.model.smartplaylist;
|
package com.kabouzeid.gramophone.model.smartplaylist;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import com.kabouzeid.gramophone.App;
|
import com.kabouzeid.gramophone.App;
|
||||||
import com.kabouzeid.gramophone.R;
|
import com.kabouzeid.gramophone.R;
|
||||||
|
|
@ -16,17 +17,18 @@ import java.util.ArrayList;
|
||||||
*/
|
*/
|
||||||
public class MyTopTracksPlaylist extends AbsSmartPlaylist {
|
public class MyTopTracksPlaylist extends AbsSmartPlaylist {
|
||||||
|
|
||||||
public MyTopTracksPlaylist(Context context) {
|
public MyTopTracksPlaylist(@NonNull Context context) {
|
||||||
super(context.getString(R.string.my_top_tracks), R.drawable.ic_trending_up_white_24dp);
|
super(context.getString(R.string.my_top_tracks), R.drawable.ic_trending_up_white_24dp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<Song> getSongs(Context context) {
|
public ArrayList<Song> getSongs(@NonNull Context context) {
|
||||||
return TopAndRecentlyPlayedTracksLoader.getTopTracks(context);
|
return TopAndRecentlyPlayedTracksLoader.getTopTracks(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clear(Context context) {
|
public void clear(@NonNull Context context) {
|
||||||
SongPlayCountStore.getInstance(context).clear();
|
SongPlayCountStore.getInstance(context).clear();
|
||||||
App.bus.post(new DataBaseChangedEvent(DataBaseChangedEvent.PLAYLISTS_CHANGED));
|
App.bus.post(new DataBaseChangedEvent(DataBaseChangedEvent.PLAYLISTS_CHANGED));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.kabouzeid.gramophone.model.smartplaylist;
|
package com.kabouzeid.gramophone.model.smartplaylist;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import com.kabouzeid.gramophone.App;
|
import com.kabouzeid.gramophone.App;
|
||||||
import com.kabouzeid.gramophone.R;
|
import com.kabouzeid.gramophone.R;
|
||||||
|
|
@ -16,17 +17,18 @@ import java.util.ArrayList;
|
||||||
*/
|
*/
|
||||||
public class RecentlyPlayedPlaylist extends AbsSmartPlaylist {
|
public class RecentlyPlayedPlaylist extends AbsSmartPlaylist {
|
||||||
|
|
||||||
public RecentlyPlayedPlaylist(Context context) {
|
public RecentlyPlayedPlaylist(@NonNull Context context) {
|
||||||
super(context.getString(R.string.recently_played), R.drawable.ic_access_time_white_24dp);
|
super(context.getString(R.string.recently_played), R.drawable.ic_access_time_white_24dp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<Song> getSongs(Context context) {
|
public ArrayList<Song> getSongs(@NonNull Context context) {
|
||||||
return TopAndRecentlyPlayedTracksLoader.getRecentlyPlayedTracks(context);
|
return TopAndRecentlyPlayedTracksLoader.getRecentlyPlayedTracks(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clear(Context context) {
|
public void clear(@NonNull Context context) {
|
||||||
RecentlyPlayedStore.getInstance(context).clear();
|
RecentlyPlayedStore.getInstance(context).clear();
|
||||||
App.bus.post(new DataBaseChangedEvent(DataBaseChangedEvent.PLAYLISTS_CHANGED));
|
App.bus.post(new DataBaseChangedEvent(DataBaseChangedEvent.PLAYLISTS_CHANGED));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,15 +15,15 @@ public class ColorChooserPreference extends Preference {
|
||||||
private int color;
|
private int color;
|
||||||
private int border;
|
private int border;
|
||||||
|
|
||||||
public ColorChooserPreference(Context context, AttributeSet attrs) {
|
public ColorChooserPreference(@NonNull Context context, @NonNull AttributeSet attrs) {
|
||||||
this(context, attrs, 0);
|
this(context, attrs, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ColorChooserPreference(Context context) {
|
public ColorChooserPreference(@NonNull Context context) {
|
||||||
this(context, null, 0);
|
this(context, null, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ColorChooserPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
public ColorChooserPreference(@NonNull Context context, @NonNull AttributeSet attrs, int defStyleAttr) {
|
||||||
super(context, attrs, defStyleAttr);
|
super(context, attrs, defStyleAttr);
|
||||||
setLayoutResource(R.layout.preference_custom);
|
setLayoutResource(R.layout.preference_custom);
|
||||||
setWidgetLayoutResource(R.layout.preference_color_widget);
|
setWidgetLayoutResource(R.layout.preference_color_widget);
|
||||||
|
|
|
||||||
|
|
@ -17,15 +17,15 @@ import com.kabouzeid.gramophone.R;
|
||||||
*/
|
*/
|
||||||
public class DynamicPreferenceCategory extends PreferenceCategory {
|
public class DynamicPreferenceCategory extends PreferenceCategory {
|
||||||
|
|
||||||
public DynamicPreferenceCategory(Context context, AttributeSet attrs) {
|
public DynamicPreferenceCategory(@NonNull Context context, @NonNull AttributeSet attrs) {
|
||||||
this(context, attrs, 0);
|
this(context, attrs, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DynamicPreferenceCategory(Context context) {
|
public DynamicPreferenceCategory(@NonNull Context context) {
|
||||||
this(context, null, 0);
|
this(context, null, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DynamicPreferenceCategory(Context context, AttributeSet attrs, int defStyleAttr) {
|
public DynamicPreferenceCategory(@NonNull Context context, @NonNull AttributeSet attrs, int defStyleAttr) {
|
||||||
super(context, attrs, defStyleAttr);
|
super(context, attrs, defStyleAttr);
|
||||||
setLayoutResource(R.layout.preference_category_custom);
|
setLayoutResource(R.layout.preference_category_custom);
|
||||||
setSelectable(false);
|
setSelectable(false);
|
||||||
|
|
|
||||||
|
|
@ -5,25 +5,29 @@ import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.database.sqlite.SQLiteOpenHelper;
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
public class AlbumJSONStore extends SQLiteOpenHelper {
|
public class AlbumJSONStore extends SQLiteOpenHelper {
|
||||||
|
|
||||||
public static final String DATABASE_NAME = "albums_last_fm.db";
|
public static final String DATABASE_NAME = "albums_last_fm.db";
|
||||||
private static final int VERSION = 1;
|
private static final int VERSION = 1;
|
||||||
|
@Nullable
|
||||||
private static AlbumJSONStore sInstance = null;
|
private static AlbumJSONStore sInstance = null;
|
||||||
|
|
||||||
public AlbumJSONStore(final Context context) {
|
public AlbumJSONStore(final Context context) {
|
||||||
super(context, DATABASE_NAME, null, VERSION);
|
super(context, DATABASE_NAME, null, VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized AlbumJSONStore getInstance(final Context context) {
|
@Nullable
|
||||||
|
public static synchronized AlbumJSONStore getInstance(@NonNull final Context context) {
|
||||||
if (sInstance == null) {
|
if (sInstance == null) {
|
||||||
sInstance = new AlbumJSONStore(context.getApplicationContext());
|
sInstance = new AlbumJSONStore(context.getApplicationContext());
|
||||||
}
|
}
|
||||||
return sInstance;
|
return sInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAlbumJSON(final String albumAndArtistName, final String json) {
|
public void addAlbumJSON(@Nullable final String albumAndArtistName, @Nullable final String json) {
|
||||||
if (albumAndArtistName == null || json == null) {
|
if (albumAndArtistName == null || json == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -41,7 +45,8 @@ public class AlbumJSONStore extends SQLiteOpenHelper {
|
||||||
database.endTransaction();
|
database.endTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getJSONData(final String albumAndArtistName) {
|
@Nullable
|
||||||
|
public String getJSONData(@Nullable final String albumAndArtistName) {
|
||||||
if (albumAndArtistName == null) {
|
if (albumAndArtistName == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -68,7 +73,7 @@ public class AlbumJSONStore extends SQLiteOpenHelper {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeAlbumJSON(final String albumAndArtistName) {
|
public void removeAlbumJSON(@NonNull final String albumAndArtistName) {
|
||||||
final SQLiteDatabase database = getReadableDatabase();
|
final SQLiteDatabase database = getReadableDatabase();
|
||||||
database.delete(AlbumJSONColumns.NAME, AlbumJSONColumns.ALBUM_PLUS_ARTIST_NAME + " = ?", new String[]{
|
database.delete(AlbumJSONColumns.NAME, AlbumJSONColumns.ALBUM_PLUS_ARTIST_NAME + " = ?", new String[]{
|
||||||
albumAndArtistName.trim().toLowerCase()
|
albumAndArtistName.trim().toLowerCase()
|
||||||
|
|
@ -83,7 +88,7 @@ public class AlbumJSONStore extends SQLiteOpenHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(final SQLiteDatabase db) {
|
public void onCreate(@NonNull final SQLiteDatabase db) {
|
||||||
db.execSQL("CREATE TABLE IF NOT EXISTS " + AlbumJSONColumns.NAME +
|
db.execSQL("CREATE TABLE IF NOT EXISTS " + AlbumJSONColumns.NAME +
|
||||||
" (" + AlbumJSONColumns.ALBUM_PLUS_ARTIST_NAME + " TEXT NOT NULL," +
|
" (" + AlbumJSONColumns.ALBUM_PLUS_ARTIST_NAME + " TEXT NOT NULL," +
|
||||||
AlbumJSONColumns.JSON_DATA + " TEXT NOT NULL);"
|
AlbumJSONColumns.JSON_DATA + " TEXT NOT NULL);"
|
||||||
|
|
@ -92,7 +97,7 @@ public class AlbumJSONStore extends SQLiteOpenHelper {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpgrade(final SQLiteDatabase db, final int oldVersion, final int newVersion) {
|
public void onUpgrade(@NonNull final SQLiteDatabase db, final int oldVersion, final int newVersion) {
|
||||||
db.execSQL("DROP TABLE IF EXISTS " + AlbumJSONColumns.NAME);
|
db.execSQL("DROP TABLE IF EXISTS " + AlbumJSONColumns.NAME);
|
||||||
onCreate(db);
|
onCreate(db);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,25 +5,29 @@ import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.database.sqlite.SQLiteOpenHelper;
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
public class ArtistJSONStore extends SQLiteOpenHelper {
|
public class ArtistJSONStore extends SQLiteOpenHelper {
|
||||||
|
|
||||||
public static final String DATABASE_NAME = "artists_last_fm.db";
|
public static final String DATABASE_NAME = "artists_last_fm.db";
|
||||||
private static final int VERSION = 1;
|
private static final int VERSION = 1;
|
||||||
|
@Nullable
|
||||||
private static ArtistJSONStore sInstance = null;
|
private static ArtistJSONStore sInstance = null;
|
||||||
|
|
||||||
public ArtistJSONStore(final Context context) {
|
public ArtistJSONStore(final Context context) {
|
||||||
super(context, DATABASE_NAME, null, VERSION);
|
super(context, DATABASE_NAME, null, VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized ArtistJSONStore getInstance(final Context context) {
|
@Nullable
|
||||||
|
public static synchronized ArtistJSONStore getInstance(@NonNull final Context context) {
|
||||||
if (sInstance == null) {
|
if (sInstance == null) {
|
||||||
sInstance = new ArtistJSONStore(context.getApplicationContext());
|
sInstance = new ArtistJSONStore(context.getApplicationContext());
|
||||||
}
|
}
|
||||||
return sInstance;
|
return sInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addArtistJSON(final String artistName, final String json) {
|
public void addArtistJSON(@Nullable final String artistName, @Nullable final String json) {
|
||||||
if (artistName == null || json == null) {
|
if (artistName == null || json == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -41,7 +45,8 @@ public class ArtistJSONStore extends SQLiteOpenHelper {
|
||||||
database.endTransaction();
|
database.endTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getArtistJSON(final String artistName) {
|
@Nullable
|
||||||
|
public String getArtistJSON(@Nullable final String artistName) {
|
||||||
if (artistName == null) {
|
if (artistName == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -68,7 +73,7 @@ public class ArtistJSONStore extends SQLiteOpenHelper {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeArtistJSON(final String artistName) {
|
public void removeArtistJSON(@NonNull final String artistName) {
|
||||||
final SQLiteDatabase database = getReadableDatabase();
|
final SQLiteDatabase database = getReadableDatabase();
|
||||||
database.delete(ArtistJSONColumns.NAME, ArtistJSONColumns.ARTIST_NAME + "=?", new String[]{
|
database.delete(ArtistJSONColumns.NAME, ArtistJSONColumns.ARTIST_NAME + "=?", new String[]{
|
||||||
artistName.trim().toLowerCase()
|
artistName.trim().toLowerCase()
|
||||||
|
|
@ -83,7 +88,7 @@ public class ArtistJSONStore extends SQLiteOpenHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(final SQLiteDatabase db) {
|
public void onCreate(@NonNull final SQLiteDatabase db) {
|
||||||
db.execSQL("CREATE TABLE IF NOT EXISTS " + ArtistJSONColumns.NAME +
|
db.execSQL("CREATE TABLE IF NOT EXISTS " + ArtistJSONColumns.NAME +
|
||||||
" (" + ArtistJSONColumns.ARTIST_NAME + " TEXT NOT NULL," +
|
" (" + ArtistJSONColumns.ARTIST_NAME + " TEXT NOT NULL," +
|
||||||
ArtistJSONColumns.JSON_DATA + " TEXT NOT NULL);"
|
ArtistJSONColumns.JSON_DATA + " TEXT NOT NULL);"
|
||||||
|
|
@ -92,7 +97,7 @@ public class ArtistJSONStore extends SQLiteOpenHelper {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpgrade(final SQLiteDatabase db, final int oldVersion, final int newVersion) {
|
public void onUpgrade(@NonNull final SQLiteDatabase db, final int oldVersion, final int newVersion) {
|
||||||
db.execSQL("DROP TABLE IF EXISTS " + ArtistJSONColumns.NAME);
|
db.execSQL("DROP TABLE IF EXISTS " + ArtistJSONColumns.NAME);
|
||||||
onCreate(db);
|
onCreate(db);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,8 @@ import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.database.sqlite.SQLiteOpenHelper;
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
import android.provider.BaseColumns;
|
import android.provider.BaseColumns;
|
||||||
import android.provider.MediaStore.Audio.AudioColumns;
|
import android.provider.MediaStore.Audio.AudioColumns;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import com.kabouzeid.gramophone.loader.SongLoader;
|
import com.kabouzeid.gramophone.loader.SongLoader;
|
||||||
import com.kabouzeid.gramophone.model.Song;
|
import com.kabouzeid.gramophone.model.Song;
|
||||||
|
|
@ -34,6 +36,7 @@ import java.util.ArrayList;
|
||||||
* This keeps track of the music playback and history state of the playback service
|
* This keeps track of the music playback and history state of the playback service
|
||||||
*/
|
*/
|
||||||
public class MusicPlaybackQueueStore extends SQLiteOpenHelper {
|
public class MusicPlaybackQueueStore extends SQLiteOpenHelper {
|
||||||
|
@Nullable
|
||||||
private static MusicPlaybackQueueStore sInstance = null;
|
private static MusicPlaybackQueueStore sInstance = null;
|
||||||
public static final String DATABASE_NAME = "music_playback_state.db";
|
public static final String DATABASE_NAME = "music_playback_state.db";
|
||||||
public static final String PLAYING_QUEUE_TABLE_NAME = "playing_queue";
|
public static final String PLAYING_QUEUE_TABLE_NAME = "playing_queue";
|
||||||
|
|
@ -50,12 +53,12 @@ public class MusicPlaybackQueueStore extends SQLiteOpenHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(final SQLiteDatabase db) {
|
public void onCreate(@NonNull final SQLiteDatabase db) {
|
||||||
createTable(db, PLAYING_QUEUE_TABLE_NAME);
|
createTable(db, PLAYING_QUEUE_TABLE_NAME);
|
||||||
createTable(db, ORIGINAL_PLAYING_QUEUE_TABLE_NAME);
|
createTable(db, ORIGINAL_PLAYING_QUEUE_TABLE_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createTable(final SQLiteDatabase db, final String tableName) {
|
private void createTable(@NonNull final SQLiteDatabase db, final String tableName) {
|
||||||
//noinspection StringBufferReplaceableByString
|
//noinspection StringBufferReplaceableByString
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append("CREATE TABLE IF NOT EXISTS ");
|
builder.append("CREATE TABLE IF NOT EXISTS ");
|
||||||
|
|
@ -93,7 +96,7 @@ public class MusicPlaybackQueueStore extends SQLiteOpenHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpgrade(final SQLiteDatabase db, final int oldVersion, final int newVersion) {
|
public void onUpgrade(@NonNull final SQLiteDatabase db, final int oldVersion, final int newVersion) {
|
||||||
// not necessary yet
|
// not necessary yet
|
||||||
db.execSQL("DROP TABLE IF EXISTS " + PLAYING_QUEUE_TABLE_NAME);
|
db.execSQL("DROP TABLE IF EXISTS " + PLAYING_QUEUE_TABLE_NAME);
|
||||||
db.execSQL("DROP TABLE IF EXISTS " + ORIGINAL_PLAYING_QUEUE_TABLE_NAME);
|
db.execSQL("DROP TABLE IF EXISTS " + ORIGINAL_PLAYING_QUEUE_TABLE_NAME);
|
||||||
|
|
@ -101,7 +104,7 @@ public class MusicPlaybackQueueStore extends SQLiteOpenHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
public void onDowngrade(@NonNull SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||||
// If we ever have downgrade, drop the table to be safe
|
// If we ever have downgrade, drop the table to be safe
|
||||||
db.execSQL("DROP TABLE IF EXISTS " + PLAYING_QUEUE_TABLE_NAME);
|
db.execSQL("DROP TABLE IF EXISTS " + PLAYING_QUEUE_TABLE_NAME);
|
||||||
db.execSQL("DROP TABLE IF EXISTS " + ORIGINAL_PLAYING_QUEUE_TABLE_NAME);
|
db.execSQL("DROP TABLE IF EXISTS " + ORIGINAL_PLAYING_QUEUE_TABLE_NAME);
|
||||||
|
|
@ -112,14 +115,15 @@ public class MusicPlaybackQueueStore extends SQLiteOpenHelper {
|
||||||
* @param context The {@link Context} to use
|
* @param context The {@link Context} to use
|
||||||
* @return A new instance of this class.
|
* @return A new instance of this class.
|
||||||
*/
|
*/
|
||||||
public static synchronized MusicPlaybackQueueStore getInstance(final Context context) {
|
@Nullable
|
||||||
|
public static synchronized MusicPlaybackQueueStore getInstance(@NonNull final Context context) {
|
||||||
if (sInstance == null) {
|
if (sInstance == null) {
|
||||||
sInstance = new MusicPlaybackQueueStore(context.getApplicationContext());
|
sInstance = new MusicPlaybackQueueStore(context.getApplicationContext());
|
||||||
}
|
}
|
||||||
return sInstance;
|
return sInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void saveQueues(final ArrayList<Song> playingQueue, final ArrayList<Song> originalPlayingQueue) {
|
public synchronized void saveQueues(@NonNull final ArrayList<Song> playingQueue, @NonNull final ArrayList<Song> originalPlayingQueue) {
|
||||||
saveQueue(PLAYING_QUEUE_TABLE_NAME, playingQueue);
|
saveQueue(PLAYING_QUEUE_TABLE_NAME, playingQueue);
|
||||||
saveQueue(ORIGINAL_PLAYING_QUEUE_TABLE_NAME, originalPlayingQueue);
|
saveQueue(ORIGINAL_PLAYING_QUEUE_TABLE_NAME, originalPlayingQueue);
|
||||||
}
|
}
|
||||||
|
|
@ -130,7 +134,7 @@ public class MusicPlaybackQueueStore extends SQLiteOpenHelper {
|
||||||
*
|
*
|
||||||
* @param queue the queue to save
|
* @param queue the queue to save
|
||||||
*/
|
*/
|
||||||
private synchronized void saveQueue(final String tableName, final ArrayList<Song> queue) {
|
private synchronized void saveQueue(final String tableName, @NonNull final ArrayList<Song> queue) {
|
||||||
final SQLiteDatabase database = getWritableDatabase();
|
final SQLiteDatabase database = getWritableDatabase();
|
||||||
database.beginTransaction();
|
database.beginTransaction();
|
||||||
|
|
||||||
|
|
@ -170,15 +174,18 @@ public class MusicPlaybackQueueStore extends SQLiteOpenHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public ArrayList<Song> getSavedPlayingQueue() {
|
public ArrayList<Song> getSavedPlayingQueue() {
|
||||||
return getQueue(PLAYING_QUEUE_TABLE_NAME);
|
return getQueue(PLAYING_QUEUE_TABLE_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public ArrayList<Song> getSavedOriginalPlayingQueue() {
|
public ArrayList<Song> getSavedOriginalPlayingQueue() {
|
||||||
return getQueue(ORIGINAL_PLAYING_QUEUE_TABLE_NAME);
|
return getQueue(ORIGINAL_PLAYING_QUEUE_TABLE_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArrayList<Song> getQueue(final String tableName) {
|
@NonNull
|
||||||
|
private ArrayList<Song> getQueue(@NonNull final String tableName) {
|
||||||
Cursor cursor = getReadableDatabase().query(tableName, null,
|
Cursor cursor = getReadableDatabase().query(tableName, null,
|
||||||
null, null, null, null, null);
|
null, null, null, null, null);
|
||||||
return SongLoader.getSongs(cursor);
|
return SongLoader.getSongs(cursor);
|
||||||
|
|
|
||||||
|
|
@ -21,12 +21,15 @@ import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.database.sqlite.SQLiteOpenHelper;
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
public class RecentlyPlayedStore extends SQLiteOpenHelper {
|
public class RecentlyPlayedStore extends SQLiteOpenHelper {
|
||||||
private static final int MAX_ITEMS_IN_DB = 100;
|
private static final int MAX_ITEMS_IN_DB = 100;
|
||||||
|
|
||||||
public static final String DATABASE_NAME = "recently_played.db";
|
public static final String DATABASE_NAME = "recently_played.db";
|
||||||
private static final int VERSION = 1;
|
private static final int VERSION = 1;
|
||||||
|
@Nullable
|
||||||
private static RecentlyPlayedStore sInstance = null;
|
private static RecentlyPlayedStore sInstance = null;
|
||||||
|
|
||||||
public RecentlyPlayedStore(final Context context) {
|
public RecentlyPlayedStore(final Context context) {
|
||||||
|
|
@ -34,25 +37,26 @@ public class RecentlyPlayedStore extends SQLiteOpenHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(final SQLiteDatabase db) {
|
public void onCreate(@NonNull final SQLiteDatabase db) {
|
||||||
db.execSQL("CREATE TABLE IF NOT EXISTS " + RecentStoreColumns.NAME + " ("
|
db.execSQL("CREATE TABLE IF NOT EXISTS " + RecentStoreColumns.NAME + " ("
|
||||||
+ RecentStoreColumns.ID + " LONG NOT NULL," + RecentStoreColumns.TIME_PLAYED
|
+ RecentStoreColumns.ID + " LONG NOT NULL," + RecentStoreColumns.TIME_PLAYED
|
||||||
+ " LONG NOT NULL);");
|
+ " LONG NOT NULL);");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
public void onUpgrade(@NonNull SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||||
db.execSQL("DROP TABLE IF EXISTS " + RecentStoreColumns.NAME);
|
db.execSQL("DROP TABLE IF EXISTS " + RecentStoreColumns.NAME);
|
||||||
onCreate(db);
|
onCreate(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
public void onDowngrade(@NonNull SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||||
db.execSQL("DROP TABLE IF EXISTS " + RecentStoreColumns.NAME);
|
db.execSQL("DROP TABLE IF EXISTS " + RecentStoreColumns.NAME);
|
||||||
onCreate(db);
|
onCreate(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized RecentlyPlayedStore getInstance(final Context context) {
|
@Nullable
|
||||||
|
public static synchronized RecentlyPlayedStore getInstance(@NonNull final Context context) {
|
||||||
if (sInstance == null) {
|
if (sInstance == null) {
|
||||||
sInstance = new RecentlyPlayedStore(context.getApplicationContext());
|
sInstance = new RecentlyPlayedStore(context.getApplicationContext());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@ import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.database.sqlite.SQLiteOpenHelper;
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.view.animation.AccelerateInterpolator;
|
import android.view.animation.AccelerateInterpolator;
|
||||||
import android.view.animation.Interpolator;
|
import android.view.animation.Interpolator;
|
||||||
|
|
||||||
|
|
@ -29,12 +31,14 @@ import android.view.animation.Interpolator;
|
||||||
* the top played tracks as well as the playlist images
|
* the top played tracks as well as the playlist images
|
||||||
*/
|
*/
|
||||||
public class SongPlayCountStore extends SQLiteOpenHelper {
|
public class SongPlayCountStore extends SQLiteOpenHelper {
|
||||||
|
@Nullable
|
||||||
private static SongPlayCountStore sInstance = null;
|
private static SongPlayCountStore sInstance = null;
|
||||||
|
|
||||||
public static final String DATABASE_NAME = "song_play_count.db";
|
public static final String DATABASE_NAME = "song_play_count.db";
|
||||||
private static final int VERSION = 1;
|
private static final int VERSION = 1;
|
||||||
|
|
||||||
// interpolator curve applied for measuring the curve
|
// interpolator curve applied for measuring the curve
|
||||||
|
@NonNull
|
||||||
private static Interpolator sInterpolator = new AccelerateInterpolator(1.5f);
|
private static Interpolator sInterpolator = new AccelerateInterpolator(1.5f);
|
||||||
|
|
||||||
// how many weeks worth of playback to track
|
// how many weeks worth of playback to track
|
||||||
|
|
@ -51,6 +55,7 @@ public class SongPlayCountStore extends SQLiteOpenHelper {
|
||||||
@SuppressWarnings("FieldCanBeLocal")
|
@SuppressWarnings("FieldCanBeLocal")
|
||||||
private static int ONE_WEEK_IN_MS = 1000 * 60 * 60 * 24 * 7;
|
private static int ONE_WEEK_IN_MS = 1000 * 60 * 60 * 24 * 7;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private static String WHERE_ID_EQUALS = SongPlayCountColumns.ID + "=?";
|
private static String WHERE_ID_EQUALS = SongPlayCountColumns.ID + "=?";
|
||||||
|
|
||||||
// number of weeks since epoch time
|
// number of weeks since epoch time
|
||||||
|
|
@ -69,7 +74,7 @@ public class SongPlayCountStore extends SQLiteOpenHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(final SQLiteDatabase db) {
|
public void onCreate(@NonNull final SQLiteDatabase db) {
|
||||||
// create the play count table
|
// create the play count table
|
||||||
// WARNING: If you change the order of these columns
|
// WARNING: If you change the order of these columns
|
||||||
// please update getColumnIndexForWeek
|
// please update getColumnIndexForWeek
|
||||||
|
|
@ -95,13 +100,13 @@ public class SongPlayCountStore extends SQLiteOpenHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpgrade(final SQLiteDatabase db, final int oldVersion, final int newVersion) {
|
public void onUpgrade(@NonNull final SQLiteDatabase db, final int oldVersion, final int newVersion) {
|
||||||
db.execSQL("DROP TABLE IF EXISTS " + SongPlayCountColumns.NAME);
|
db.execSQL("DROP TABLE IF EXISTS " + SongPlayCountColumns.NAME);
|
||||||
onCreate(db);
|
onCreate(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
public void onDowngrade(@NonNull SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||||
// If we ever have downgrade, drop the table to be safe
|
// If we ever have downgrade, drop the table to be safe
|
||||||
db.execSQL("DROP TABLE IF EXISTS " + SongPlayCountColumns.NAME);
|
db.execSQL("DROP TABLE IF EXISTS " + SongPlayCountColumns.NAME);
|
||||||
onCreate(db);
|
onCreate(db);
|
||||||
|
|
@ -111,7 +116,8 @@ public class SongPlayCountStore extends SQLiteOpenHelper {
|
||||||
* @param context The {@link Context} to use
|
* @param context The {@link Context} to use
|
||||||
* @return A new instance of this class.
|
* @return A new instance of this class.
|
||||||
*/
|
*/
|
||||||
public static synchronized SongPlayCountStore getInstance(final Context context) {
|
@Nullable
|
||||||
|
public static synchronized SongPlayCountStore getInstance(@NonNull final Context context) {
|
||||||
if (sInstance == null) {
|
if (sInstance == null) {
|
||||||
sInstance = new SongPlayCountStore(context.getApplicationContext());
|
sInstance = new SongPlayCountStore(context.getApplicationContext());
|
||||||
}
|
}
|
||||||
|
|
@ -138,7 +144,7 @@ public class SongPlayCountStore extends SQLiteOpenHelper {
|
||||||
* @param database a write able database
|
* @param database a write able database
|
||||||
* @param songId the id of the track
|
* @param songId the id of the track
|
||||||
*/
|
*/
|
||||||
private void createNewPlayedEntry(final SQLiteDatabase database, final long songId) {
|
private void createNewPlayedEntry(@NonNull final SQLiteDatabase database, final long songId) {
|
||||||
// no row exists, create a new one
|
// no row exists, create a new one
|
||||||
float newScore = getScoreMultiplierForWeek(0);
|
float newScore = getScoreMultiplierForWeek(0);
|
||||||
int newPlayCount = 1;
|
int newPlayCount = 1;
|
||||||
|
|
@ -160,7 +166,7 @@ public class SongPlayCountStore extends SQLiteOpenHelper {
|
||||||
* @param id the id of the track to bump
|
* @param id the id of the track to bump
|
||||||
* @param bumpCount whether to bump the current's week play count by 1 and adjust the score
|
* @param bumpCount whether to bump the current's week play count by 1 and adjust the score
|
||||||
*/
|
*/
|
||||||
private void updateExistingRow(final SQLiteDatabase database, final long id, boolean bumpCount) {
|
private void updateExistingRow(@NonNull final SQLiteDatabase database, final long id, boolean bumpCount) {
|
||||||
String stringId = String.valueOf(id);
|
String stringId = String.valueOf(id);
|
||||||
|
|
||||||
// begin the transaction
|
// begin the transaction
|
||||||
|
|
@ -329,7 +335,7 @@ public class SongPlayCountStore extends SQLiteOpenHelper {
|
||||||
* @param database database to use
|
* @param database database to use
|
||||||
* @param stringId id to delete
|
* @param stringId id to delete
|
||||||
*/
|
*/
|
||||||
private void deleteEntry(final SQLiteDatabase database, final String stringId) {
|
private void deleteEntry(@NonNull final SQLiteDatabase database, final String stringId) {
|
||||||
database.delete(SongPlayCountColumns.NAME, WHERE_ID_EQUALS, new String[]{stringId});
|
database.delete(SongPlayCountColumns.NAME, WHERE_ID_EQUALS, new String[]{stringId});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -340,7 +346,7 @@ public class SongPlayCountStore extends SQLiteOpenHelper {
|
||||||
* where playCounts[N] is the # of times it was played N weeks ago
|
* where playCounts[N] is the # of times it was played N weeks ago
|
||||||
* @return the score
|
* @return the score
|
||||||
*/
|
*/
|
||||||
private static float calculateScore(final int[] playCounts) {
|
private static float calculateScore(@Nullable final int[] playCounts) {
|
||||||
if (playCounts == null) {
|
if (playCounts == null) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -359,6 +365,7 @@ public class SongPlayCountStore extends SQLiteOpenHelper {
|
||||||
* @param week number
|
* @param week number
|
||||||
* @return the column name
|
* @return the column name
|
||||||
*/
|
*/
|
||||||
|
@NonNull
|
||||||
private static String getColumnNameForWeek(final int week) {
|
private static String getColumnNameForWeek(final int week) {
|
||||||
return SongPlayCountColumns.WEEK_PLAY_COUNT + String.valueOf(week);
|
return SongPlayCountColumns.WEEK_PLAY_COUNT + String.valueOf(week);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.kabouzeid.gramophone.service;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
|
||||||
public class MediaButtonIntentReceiver extends BroadcastReceiver {
|
public class MediaButtonIntentReceiver extends BroadcastReceiver {
|
||||||
|
|
@ -12,7 +13,7 @@ public class MediaButtonIntentReceiver extends BroadcastReceiver {
|
||||||
private static long mLastClickTime = 0;
|
private static long mLastClickTime = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(@NonNull Context context, @NonNull Intent intent) {
|
||||||
if (intent.getAction().equals(Intent.ACTION_MEDIA_BUTTON)) {
|
if (intent.getAction().equals(Intent.ACTION_MEDIA_BUTTON)) {
|
||||||
final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
|
final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
|
||||||
if (event == null)
|
if (event == null)
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ import android.media.audiofx.AudioEffect;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
|
@ -22,9 +24,12 @@ public class MultiPlayer implements MediaPlayer.OnErrorListener,
|
||||||
MediaPlayer.OnCompletionListener {
|
MediaPlayer.OnCompletionListener {
|
||||||
public static final String TAG = MultiPlayer.class.getSimpleName();
|
public static final String TAG = MultiPlayer.class.getSimpleName();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final WeakReference<MusicService> mService;
|
private final WeakReference<MusicService> mService;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private MediaPlayer mCurrentMediaPlayer = new MediaPlayer();
|
private MediaPlayer mCurrentMediaPlayer = new MediaPlayer();
|
||||||
|
@Nullable
|
||||||
private MediaPlayer mNextMediaPlayer;
|
private MediaPlayer mNextMediaPlayer;
|
||||||
|
|
||||||
private Handler mHandler;
|
private Handler mHandler;
|
||||||
|
|
@ -45,7 +50,7 @@ public class MultiPlayer implements MediaPlayer.OnErrorListener,
|
||||||
* @return True if the <code>player</code> has been prepared and is
|
* @return True if the <code>player</code> has been prepared and is
|
||||||
* ready to play, false otherwise
|
* ready to play, false otherwise
|
||||||
*/
|
*/
|
||||||
public boolean setDataSource(final String path) {
|
public boolean setDataSource(@NonNull final String path) {
|
||||||
mIsInitialized = false;
|
mIsInitialized = false;
|
||||||
mIsInitialized = setDataSourceImpl(mCurrentMediaPlayer, path);
|
mIsInitialized = setDataSourceImpl(mCurrentMediaPlayer, path);
|
||||||
if (mIsInitialized) {
|
if (mIsInitialized) {
|
||||||
|
|
@ -61,7 +66,7 @@ public class MultiPlayer implements MediaPlayer.OnErrorListener,
|
||||||
* @return True if the <code>player</code> has been prepared and is
|
* @return True if the <code>player</code> has been prepared and is
|
||||||
* ready to play, false otherwise
|
* ready to play, false otherwise
|
||||||
*/
|
*/
|
||||||
private boolean setDataSourceImpl(final MediaPlayer player, final String path) {
|
private boolean setDataSourceImpl(@NonNull final MediaPlayer player, @NonNull final String path) {
|
||||||
MusicService service = mService.get();
|
MusicService service = mService.get();
|
||||||
if (service == null) {
|
if (service == null) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -95,7 +100,7 @@ public class MultiPlayer implements MediaPlayer.OnErrorListener,
|
||||||
* @param path The path of the file, or the http/rtsp URL of the stream
|
* @param path The path of the file, or the http/rtsp URL of the stream
|
||||||
* you want to play
|
* you want to play
|
||||||
*/
|
*/
|
||||||
public void setNextDataSource(final String path) {
|
public void setNextDataSource(@Nullable final String path) {
|
||||||
MusicService service = mService.get();
|
MusicService service = mService.get();
|
||||||
if (service == null) {
|
if (service == null) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -122,7 +127,7 @@ public class MultiPlayer implements MediaPlayer.OnErrorListener,
|
||||||
if (setDataSourceImpl(mNextMediaPlayer, path)) {
|
if (setDataSourceImpl(mNextMediaPlayer, path)) {
|
||||||
try {
|
try {
|
||||||
mCurrentMediaPlayer.setNextMediaPlayer(mNextMediaPlayer);
|
mCurrentMediaPlayer.setNextMediaPlayer(mNextMediaPlayer);
|
||||||
} catch (IllegalArgumentException | IllegalStateException e) {
|
} catch (@NonNull IllegalArgumentException | IllegalStateException e) {
|
||||||
Log.e(TAG, "setNextDataSource: setNextMediaPlayer()", e);
|
Log.e(TAG, "setNextDataSource: setNextMediaPlayer()", e);
|
||||||
if (mNextMediaPlayer != null) {
|
if (mNextMediaPlayer != null) {
|
||||||
mNextMediaPlayer.release();
|
mNextMediaPlayer.release();
|
||||||
|
|
@ -269,7 +274,7 @@ public class MultiPlayer implements MediaPlayer.OnErrorListener,
|
||||||
try {
|
try {
|
||||||
mCurrentMediaPlayer.setAudioSessionId(sessionId);
|
mCurrentMediaPlayer.setAudioSessionId(sessionId);
|
||||||
return true;
|
return true;
|
||||||
} catch (IllegalArgumentException | IllegalStateException e) {
|
} catch (@NonNull IllegalArgumentException | IllegalStateException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,8 @@ import android.os.Message;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
|
@ -95,8 +97,11 @@ public class MusicService extends Service {
|
||||||
|
|
||||||
private final IBinder musicBind = new MusicBinder();
|
private final IBinder musicBind = new MusicBinder();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private MultiPlayer player;
|
private MultiPlayer player;
|
||||||
|
@Nullable
|
||||||
private ArrayList<Song> playingQueue;
|
private ArrayList<Song> playingQueue;
|
||||||
|
@Nullable
|
||||||
private ArrayList<Song> originalPlayingQueue;
|
private ArrayList<Song> originalPlayingQueue;
|
||||||
private int position = -1;
|
private int position = -1;
|
||||||
private int nextPosition = -1;
|
private int nextPosition = -1;
|
||||||
|
|
@ -113,14 +118,16 @@ public class MusicService extends Service {
|
||||||
private QueueSaveHandler queueSaveHandler;
|
private QueueSaveHandler queueSaveHandler;
|
||||||
private HandlerThread musicPlayerHandlerThread;
|
private HandlerThread musicPlayerHandlerThread;
|
||||||
private HandlerThread queueSaveHandlerThread;
|
private HandlerThread queueSaveHandlerThread;
|
||||||
|
@Nullable
|
||||||
private RecentlyPlayedStore recentlyPlayedStore;
|
private RecentlyPlayedStore recentlyPlayedStore;
|
||||||
|
@Nullable
|
||||||
private SongPlayCountStore songPlayCountStore;
|
private SongPlayCountStore songPlayCountStore;
|
||||||
private boolean notNotifiedMetaChangedForCurrentTrack;
|
private boolean notNotifiedMetaChangedForCurrentTrack;
|
||||||
private boolean isServiceInUse;
|
private boolean isServiceInUse;
|
||||||
|
|
||||||
private final BroadcastReceiver becomingNoisyReceiver = new BroadcastReceiver() {
|
private final BroadcastReceiver becomingNoisyReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, @NonNull Intent intent) {
|
||||||
if (intent.getAction().equals(AudioManager.ACTION_AUDIO_BECOMING_NOISY)) {
|
if (intent.getAction().equals(AudioManager.ACTION_AUDIO_BECOMING_NOISY)) {
|
||||||
pause();
|
pause();
|
||||||
}
|
}
|
||||||
|
|
@ -129,7 +136,7 @@ public class MusicService extends Service {
|
||||||
|
|
||||||
private final BroadcastReceiver preferencesChangedReceiver = new BroadcastReceiver() {
|
private final BroadcastReceiver preferencesChangedReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, @NonNull Intent intent) {
|
||||||
switch (intent.getAction()) {
|
switch (intent.getAction()) {
|
||||||
case SETTING_GAPLESS_PLAYBACK_CHANGED:
|
case SETTING_GAPLESS_PLAYBACK_CHANGED:
|
||||||
setGaplessPlaybackEnabled(intent.getBooleanExtra(SETTING_BOOLEAN_EXTRA, false));
|
setGaplessPlaybackEnabled(intent.getBooleanExtra(SETTING_BOOLEAN_EXTRA, false));
|
||||||
|
|
@ -225,7 +232,7 @@ public class MusicService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(@Nullable Intent intent, int flags, int startId) {
|
||||||
if (intent != null) {
|
if (intent != null) {
|
||||||
if (intent.getAction() != null) {
|
if (intent.getAction() != null) {
|
||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
|
|
@ -438,7 +445,7 @@ public class MusicService extends Service {
|
||||||
final String currentAlbumArtUri = MusicUtil.getSongImageLoaderString(song);
|
final String currentAlbumArtUri = MusicUtil.getSongImageLoaderString(song);
|
||||||
ImageLoader.getInstance().displayImage(currentAlbumArtUri, new NonViewAware(new ImageSize(-1, -1), ViewScaleType.CROP), new SimpleImageLoadingListener() {
|
ImageLoader.getInstance().displayImage(currentAlbumArtUri, new NonViewAware(new ImageSize(-1, -1), ViewScaleType.CROP), new SimpleImageLoadingListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
|
public void onLoadingComplete(String imageUri, View view, @Nullable Bitmap loadedImage) {
|
||||||
if (currentAlbumArtUri.equals(imageUri)) {
|
if (currentAlbumArtUri.equals(imageUri)) {
|
||||||
if (loadedImage != null) {
|
if (loadedImage != null) {
|
||||||
// RemoteControlClient wants to recycle the bitmaps thrown at it, so we need
|
// RemoteControlClient wants to recycle the bitmaps thrown at it, so we need
|
||||||
|
|
@ -495,7 +502,7 @@ public class MusicService extends Service {
|
||||||
WidgetMedium.updateWidgets(this, getCurrentSong(), isPlaying());
|
WidgetMedium.updateWidgets(this, getCurrentSong(), isPlaying());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getTrackUri(Song song) {
|
private static String getTrackUri(@NonNull Song song) {
|
||||||
return ContentUris.withAppendedId(android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, song.id).toString();
|
return ContentUris.withAppendedId(android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, song.id).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -530,6 +537,7 @@ public class MusicService extends Service {
|
||||||
return getPosition() == getPlayingQueue().size() - 1;
|
return getPosition() == getPlayingQueue().size() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public ArrayList<Song> getPlayingQueue() {
|
public ArrayList<Song> getPlayingQueue() {
|
||||||
return playingQueue;
|
return playingQueue;
|
||||||
}
|
}
|
||||||
|
|
@ -553,7 +561,7 @@ public class MusicService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void openAndPlayQueue(final ArrayList<Song> playingQueue, final int startPosition, final boolean startPlaying) {
|
public void openAndPlayQueue(@Nullable final ArrayList<Song> playingQueue, final int startPosition, final boolean startPlaying) {
|
||||||
if (playingQueue != null && !playingQueue.isEmpty() && startPosition >= 0 && startPosition < playingQueue.size()) {
|
if (playingQueue != null && !playingQueue.isEmpty() && startPosition >= 0 && startPosition < playingQueue.size()) {
|
||||||
originalPlayingQueue = playingQueue;
|
originalPlayingQueue = playingQueue;
|
||||||
this.playingQueue = new ArrayList<>(originalPlayingQueue);
|
this.playingQueue = new ArrayList<>(originalPlayingQueue);
|
||||||
|
|
@ -618,7 +626,7 @@ public class MusicService extends Service {
|
||||||
saveState();
|
saveState();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeSong(Song song) {
|
public void removeSong(@NonNull Song song) {
|
||||||
for (int i = 0; i < playingQueue.size(); i++) {
|
for (int i = 0; i < playingQueue.size(); i++) {
|
||||||
if (playingQueue.get(i).id == song.id) playingQueue.remove(i);
|
if (playingQueue.get(i).id == song.id) playingQueue.remove(i);
|
||||||
}
|
}
|
||||||
|
|
@ -796,7 +804,7 @@ public class MusicService extends Service {
|
||||||
notifyChange(SHUFFLE_MODE_CHANGED);
|
notifyChange(SHUFFLE_MODE_CHANGED);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notifyChange(final String what) {
|
private void notifyChange(@NonNull final String what) {
|
||||||
final Intent internalIntent = new Intent(what);
|
final Intent internalIntent = new Intent(what);
|
||||||
|
|
||||||
final Song currentSong = getCurrentSong();
|
final Song currentSong = getCurrentSong();
|
||||||
|
|
@ -857,21 +865,23 @@ public class MusicService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MusicBinder extends Binder {
|
public class MusicBinder extends Binder {
|
||||||
|
@NonNull
|
||||||
public MusicService getService() {
|
public MusicService getService() {
|
||||||
return MusicService.this;
|
return MusicService.this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class QueueSaveHandler extends Handler {
|
private static final class QueueSaveHandler extends Handler {
|
||||||
|
@NonNull
|
||||||
private final WeakReference<MusicService> mService;
|
private final WeakReference<MusicService> mService;
|
||||||
|
|
||||||
public QueueSaveHandler(final MusicService service, final Looper looper) {
|
public QueueSaveHandler(final MusicService service, @NonNull final Looper looper) {
|
||||||
super(looper);
|
super(looper);
|
||||||
mService = new WeakReference<>(service);
|
mService = new WeakReference<>(service);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message msg) {
|
public void handleMessage(@NonNull Message msg) {
|
||||||
final MusicService service = mService.get();
|
final MusicService service = mService.get();
|
||||||
switch (msg.what) {
|
switch (msg.what) {
|
||||||
case SAVE_QUEUES:
|
case SAVE_QUEUES:
|
||||||
|
|
@ -882,16 +892,17 @@ public class MusicService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class MusicPlayerHandler extends Handler {
|
private static final class MusicPlayerHandler extends Handler {
|
||||||
|
@NonNull
|
||||||
private final WeakReference<MusicService> mService;
|
private final WeakReference<MusicService> mService;
|
||||||
private float currentDuckVolume = 1.0f;
|
private float currentDuckVolume = 1.0f;
|
||||||
|
|
||||||
public MusicPlayerHandler(final MusicService service, final Looper looper) {
|
public MusicPlayerHandler(final MusicService service, @NonNull final Looper looper) {
|
||||||
super(looper);
|
super(looper);
|
||||||
mService = new WeakReference<>(service);
|
mService = new WeakReference<>(service);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(final Message msg) {
|
public void handleMessage(@NonNull final Message msg) {
|
||||||
final MusicService service = mService.get();
|
final MusicService service = mService.get();
|
||||||
if (service == null) {
|
if (service == null) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ import android.graphics.BitmapFactory;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.util.Pair;
|
import android.support.v4.util.Pair;
|
||||||
import android.support.v7.graphics.Palette;
|
import android.support.v7.graphics.Palette;
|
||||||
import android.support.v7.widget.GridLayoutManager;
|
import android.support.v7.widget.GridLayoutManager;
|
||||||
|
|
@ -181,6 +183,7 @@ public class AlbumDetailActivity extends AbsFabActivity implements PaletteColorH
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public String getTag() {
|
public String getTag() {
|
||||||
return TAG;
|
return TAG;
|
||||||
|
|
@ -226,7 +229,7 @@ public class AlbumDetailActivity extends AbsFabActivity implements PaletteColorH
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
|
public void onLoadingComplete(String imageUri, View view, @NonNull Bitmap loadedImage) {
|
||||||
applyPalette(loadedImage);
|
applyPalette(loadedImage);
|
||||||
albumArtBackground.setImageBitmap(new StackBlurManager(loadedImage).process(10));
|
albumArtBackground.setImageBitmap(new StackBlurManager(loadedImage).process(10));
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
|
||||||
|
|
@ -236,13 +239,13 @@ public class AlbumDetailActivity extends AbsFabActivity implements PaletteColorH
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyPalette(Bitmap bitmap) {
|
private void applyPalette(@Nullable Bitmap bitmap) {
|
||||||
if (bitmap != null) {
|
if (bitmap != null) {
|
||||||
Palette.from(bitmap)
|
Palette.from(bitmap)
|
||||||
.resizeBitmapSize(100)
|
.resizeBitmapSize(100)
|
||||||
.generate(new Palette.PaletteAsyncListener() {
|
.generate(new Palette.PaletteAsyncListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onGenerated(Palette palette) {
|
public void onGenerated(@NonNull Palette palette) {
|
||||||
final Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();
|
final Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();
|
||||||
if (vibrantSwatch != null) {
|
if (vibrantSwatch != null) {
|
||||||
toolbarColor = vibrantSwatch.getRgb();
|
toolbarColor = vibrantSwatch.getRgb();
|
||||||
|
|
@ -345,7 +348,7 @@ public class AlbumDetailActivity extends AbsFabActivity implements PaletteColorH
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||||
int id = item.getItemId();
|
int id = item.getItemId();
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case R.id.action_sleep_timer:
|
case R.id.action_sleep_timer:
|
||||||
|
|
@ -389,7 +392,7 @@ public class AlbumDetailActivity extends AbsFabActivity implements PaletteColorH
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onDataBaseEvent(DataBaseChangedEvent event) {
|
public void onDataBaseEvent(@NonNull DataBaseChangedEvent event) {
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
case DataBaseChangedEvent.SONGS_CHANGED:
|
case DataBaseChangedEvent.SONGS_CHANGED:
|
||||||
case DataBaseChangedEvent.ALBUMS_CHANGED:
|
case DataBaseChangedEvent.ALBUMS_CHANGED:
|
||||||
|
|
@ -402,7 +405,7 @@ public class AlbumDetailActivity extends AbsFabActivity implements PaletteColorH
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onUIPreferenceChanged(UIPreferenceChangedEvent event) {
|
public void onUIPreferenceChanged(@NonNull UIPreferenceChangedEvent event) {
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
case UIPreferenceChangedEvent.COLORED_NAVIGATION_BAR_ALBUM_CHANGED:
|
case UIPreferenceChangedEvent.COLORED_NAVIGATION_BAR_ALBUM_CHANGED:
|
||||||
setNavigationBarColored((boolean) event.getValue());
|
setNavigationBarColored((boolean) event.getValue());
|
||||||
|
|
@ -417,7 +420,7 @@ public class AlbumDetailActivity extends AbsFabActivity implements PaletteColorH
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MaterialCab openCab(int menuRes, final MaterialCab.Callback callback) {
|
public MaterialCab openCab(int menuRes, @NonNull final MaterialCab.Callback callback) {
|
||||||
if (cab != null && cab.isActive()) cab.finish();
|
if (cab != null && cab.isActive()) cab.finish();
|
||||||
cab = new MaterialCab(this, R.id.cab_stub)
|
cab = new MaterialCab(this, R.id.cab_stub)
|
||||||
.setMenu(menuRes)
|
.setMenu(menuRes)
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ import android.graphics.BitmapFactory;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.graphics.Palette;
|
import android.support.v7.graphics.Palette;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
|
@ -109,6 +111,7 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
|
||||||
private int bottomOffset;
|
private int bottomOffset;
|
||||||
|
|
||||||
private Artist artist;
|
private Artist artist;
|
||||||
|
@Nullable
|
||||||
private Spanned biography;
|
private Spanned biography;
|
||||||
private ArtistAlbumAdapter albumAdapter;
|
private ArtistAlbumAdapter albumAdapter;
|
||||||
private ArtistSongAdapter songAdapter;
|
private ArtistSongAdapter songAdapter;
|
||||||
|
|
@ -219,6 +222,7 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
|
||||||
albumRecyclerView = ButterKnife.findById(songListHeader, R.id.recycler_view);
|
albumRecyclerView = ButterKnife.findById(songListHeader, R.id.recycler_view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public String getTag() {
|
public String getTag() {
|
||||||
return TAG;
|
return TAG;
|
||||||
|
|
@ -276,7 +280,7 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
|
||||||
private void loadBiography() {
|
private void loadBiography() {
|
||||||
lastFMRestClient.getApiService().getArtistInfo(artist.name, null, new Callback<ArtistInfo>() {
|
lastFMRestClient.getApiService().getArtistInfo(artist.name, null, new Callback<ArtistInfo>() {
|
||||||
@Override
|
@Override
|
||||||
public void success(ArtistInfo artistInfo, Response response) {
|
public void success(@NonNull ArtistInfo artistInfo, Response response) {
|
||||||
if (artistInfo.getArtist() != null) {
|
if (artistInfo.getArtist() != null) {
|
||||||
String bio = artistInfo.getArtist().getBio().getContent();
|
String bio = artistInfo.getArtist().getBio().getContent();
|
||||||
if (bio != null && !bio.trim().equals("")) {
|
if (bio != null && !bio.trim().equals("")) {
|
||||||
|
|
@ -315,7 +319,7 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
|
||||||
}
|
}
|
||||||
lastFMRestClient.getApiService().getArtistInfo(artist.name, forceDownload ? "no-cache" : null, new Callback<ArtistInfo>() {
|
lastFMRestClient.getApiService().getArtistInfo(artist.name, forceDownload ? "no-cache" : null, new Callback<ArtistInfo>() {
|
||||||
@Override
|
@Override
|
||||||
public void success(ArtistInfo artistInfo, Response response) {
|
public void success(@NonNull ArtistInfo artistInfo, Response response) {
|
||||||
if (artistInfo.getArtist() != null) {
|
if (artistInfo.getArtist() != null) {
|
||||||
List<Image> images = artistInfo.getArtist().getImage();
|
List<Image> images = artistInfo.getArtist().getImage();
|
||||||
int lastElementIndex = images.size() - 1;
|
int lastElementIndex = images.size() - 1;
|
||||||
|
|
@ -336,7 +340,7 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
|
public void onLoadingComplete(String imageUri, View view, @Nullable Bitmap loadedImage) {
|
||||||
if (loadedImage != null) {
|
if (loadedImage != null) {
|
||||||
applyPalette(loadedImage);
|
applyPalette(loadedImage);
|
||||||
artistImageBackground.setImageBitmap(new StackBlurManager(loadedImage).process(10));
|
artistImageBackground.setImageBitmap(new StackBlurManager(loadedImage).process(10));
|
||||||
|
|
@ -373,14 +377,14 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
|
||||||
artistImageBackground.setImageBitmap(defaultArtistImageBlurManager.process(10));
|
artistImageBackground.setImageBitmap(defaultArtistImageBlurManager.process(10));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyPalette(Bitmap bitmap) {
|
private void applyPalette(@Nullable Bitmap bitmap) {
|
||||||
if (bitmap != null) {
|
if (bitmap != null) {
|
||||||
Palette.from(bitmap)
|
Palette.from(bitmap)
|
||||||
.resizeBitmapSize(100)
|
.resizeBitmapSize(100)
|
||||||
.generate(new Palette.PaletteAsyncListener() {
|
.generate(new Palette.PaletteAsyncListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onGenerated(Palette palette) {
|
public void onGenerated(@NonNull Palette palette) {
|
||||||
final Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();
|
final Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();
|
||||||
if (vibrantSwatch != null) {
|
if (vibrantSwatch != null) {
|
||||||
toolbarColor = vibrantSwatch.getRgb();
|
toolbarColor = vibrantSwatch.getRgb();
|
||||||
|
|
@ -447,7 +451,7 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||||
int id = item.getItemId();
|
int id = item.getItemId();
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case R.id.action_sleep_timer:
|
case R.id.action_sleep_timer:
|
||||||
|
|
@ -531,7 +535,7 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onDataBaseEvent(DataBaseChangedEvent event) {
|
public void onDataBaseEvent(@NonNull DataBaseChangedEvent event) {
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
case DataBaseChangedEvent.SONGS_CHANGED:
|
case DataBaseChangedEvent.SONGS_CHANGED:
|
||||||
case DataBaseChangedEvent.ALBUMS_CHANGED:
|
case DataBaseChangedEvent.ALBUMS_CHANGED:
|
||||||
|
|
@ -547,7 +551,7 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onUIPreferenceChanged(UIPreferenceChangedEvent event) {
|
public void onUIPreferenceChanged(@NonNull UIPreferenceChangedEvent event) {
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
case UIPreferenceChangedEvent.COLORED_NAVIGATION_BAR_ARTIST_CHANGED:
|
case UIPreferenceChangedEvent.COLORED_NAVIGATION_BAR_ARTIST_CHANGED:
|
||||||
setNavigationBarColored((boolean) event.getValue());
|
setNavigationBarColored((boolean) event.getValue());
|
||||||
|
|
@ -562,7 +566,7 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MaterialCab openCab(int menuRes, final MaterialCab.Callback callback) {
|
public MaterialCab openCab(int menuRes, @NonNull final MaterialCab.Callback callback) {
|
||||||
if (cab != null && cab.isActive()) cab.finish();
|
if (cab != null && cab.isActive()) cab.finish();
|
||||||
cab = new MaterialCab(this, R.id.cab_stub)
|
cab = new MaterialCab(this, R.id.cab_stub)
|
||||||
.setMenu(menuRes)
|
.setMenu(menuRes)
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.design.widget.AppBarLayout;
|
import android.support.design.widget.AppBarLayout;
|
||||||
import android.support.design.widget.AppBarLayout.OnOffsetChangedListener;
|
import android.support.design.widget.AppBarLayout.OnOffsetChangedListener;
|
||||||
import android.support.design.widget.NavigationView;
|
import android.support.design.widget.NavigationView;
|
||||||
|
|
@ -87,6 +88,7 @@ public class MainActivity extends AbsFabActivity
|
||||||
private PagerAdapter pagerAdapter;
|
private PagerAdapter pagerAdapter;
|
||||||
private int currentPage = -1;
|
private int currentPage = -1;
|
||||||
private MaterialCab cab;
|
private MaterialCab cab;
|
||||||
|
@Nullable
|
||||||
private View navigationDrawerHeader;
|
private View navigationDrawerHeader;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -180,7 +182,7 @@ public class MainActivity extends AbsFabActivity
|
||||||
));
|
));
|
||||||
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
|
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onNavigationItemSelected(MenuItem menuItem) {
|
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
|
||||||
drawerLayout.closeDrawers();
|
drawerLayout.closeDrawers();
|
||||||
switch (menuItem.getItemId()) {
|
switch (menuItem.getItemId()) {
|
||||||
case R.id.nav_songs:
|
case R.id.nav_songs:
|
||||||
|
|
@ -242,6 +244,7 @@ public class MainActivity extends AbsFabActivity
|
||||||
setUpNavigationView();
|
setUpNavigationView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public String getTag() {
|
public String getTag() {
|
||||||
return TAG;
|
return TAG;
|
||||||
|
|
@ -307,7 +310,7 @@ public class MainActivity extends AbsFabActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(@NonNull Menu menu) {
|
||||||
if (isAlbumPage()) {
|
if (isAlbumPage()) {
|
||||||
getMenuInflater().inflate(R.menu.menu_albums, menu);
|
getMenuInflater().inflate(R.menu.menu_albums, menu);
|
||||||
setUpGridMenu(menu);
|
setUpGridMenu(menu);
|
||||||
|
|
@ -329,7 +332,7 @@ public class MainActivity extends AbsFabActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||||
if (drawerToggle.onOptionsItemSelected(item)) {
|
if (drawerToggle.onOptionsItemSelected(item)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -370,7 +373,7 @@ public class MainActivity extends AbsFabActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUIPreferenceChangedEvent(UIPreferenceChangedEvent event) {
|
public void onUIPreferenceChangedEvent(@NonNull UIPreferenceChangedEvent event) {
|
||||||
super.onUIPreferenceChangedEvent(event);
|
super.onUIPreferenceChangedEvent(event);
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
case UIPreferenceChangedEvent.COLORED_NAVIGATION_BAR_OTHER_SCREENS_CHANGED:
|
case UIPreferenceChangedEvent.COLORED_NAVIGATION_BAR_OTHER_SCREENS_CHANGED:
|
||||||
|
|
@ -402,7 +405,7 @@ public class MainActivity extends AbsFabActivity
|
||||||
PreferenceUtils.getInstance(MainActivity.this).setLastStartPage(currentPage);
|
PreferenceUtils.getInstance(MainActivity.this).setLastStartPage(currentPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handlePlaybackIntent(Intent intent) {
|
private void handlePlaybackIntent(@Nullable Intent intent) {
|
||||||
if (intent == null) {
|
if (intent == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -447,7 +450,7 @@ public class MainActivity extends AbsFabActivity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private long parseIdFromIntent(Intent intent, String longKey,
|
private long parseIdFromIntent(@NonNull Intent intent, String longKey,
|
||||||
String stringKey) {
|
String stringKey) {
|
||||||
long id = intent.getLongExtra(longKey, -1);
|
long id = intent.getLongExtra(longKey, -1);
|
||||||
if (id < 0) {
|
if (id < 0) {
|
||||||
|
|
@ -475,6 +478,7 @@ public class MainActivity extends AbsFabActivity
|
||||||
return pager.getCurrentItem() == PagerAdapter.MusicFragments.ALBUM.ordinal();
|
return pager.getCurrentItem() == PagerAdapter.MusicFragments.ALBUM.ordinal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public AlbumViewFragment getAlbumFragment() {
|
public AlbumViewFragment getAlbumFragment() {
|
||||||
return (AlbumViewFragment) pagerAdapter.getFragment(PagerAdapter.MusicFragments.ALBUM.ordinal());
|
return (AlbumViewFragment) pagerAdapter.getFragment(PagerAdapter.MusicFragments.ALBUM.ordinal());
|
||||||
}
|
}
|
||||||
|
|
@ -495,7 +499,7 @@ public class MainActivity extends AbsFabActivity
|
||||||
// return (PlaylistViewFragment) pagerAdapter.getFragment(PagerAdapter.MusicFragments.PLAYLIST.ordinal());
|
// return (PlaylistViewFragment) pagerAdapter.getFragment(PagerAdapter.MusicFragments.PLAYLIST.ordinal());
|
||||||
// }
|
// }
|
||||||
|
|
||||||
private void setUpGridMenu(Menu menu) {
|
private void setUpGridMenu(@NonNull Menu menu) {
|
||||||
boolean isPortrait = Util.isInPortraitMode(this);
|
boolean isPortrait = Util.isInPortraitMode(this);
|
||||||
int columns = isPortrait ? PreferenceUtils.getInstance(this).getAlbumGridColumns() : PreferenceUtils.getInstance(this).getAlbumGridColumnsLand();
|
int columns = isPortrait ? PreferenceUtils.getInstance(this).getAlbumGridColumns() : PreferenceUtils.getInstance(this).getAlbumGridColumnsLand();
|
||||||
String title = isPortrait ? getResources().getString(R.string.action_grid_columns) : getResources().getString(R.string.action_grid_columns_land);
|
String title = isPortrait ? getResources().getString(R.string.action_grid_columns) : getResources().getString(R.string.action_grid_columns_land);
|
||||||
|
|
@ -507,7 +511,7 @@ public class MainActivity extends AbsFabActivity
|
||||||
gridSizeMenu.getItem(columns - 1).setChecked(true);
|
gridSizeMenu.getItem(columns - 1).setChecked(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean handleGridSize(MenuItem item) {
|
private boolean handleGridSize(@NonNull MenuItem item) {
|
||||||
int size = -1;
|
int size = -1;
|
||||||
|
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ import android.os.Handler;
|
||||||
import android.os.HandlerThread;
|
import android.os.HandlerThread;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.graphics.Palette;
|
import android.support.v7.graphics.Palette;
|
||||||
import android.support.v7.widget.CardView;
|
import android.support.v7.widget.CardView;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
|
|
@ -279,7 +281,7 @@ public class MusicControllerActivity extends AbsFabActivity {
|
||||||
setUpProgressSlider();
|
setUpProgressSlider();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setTint(SeekBar seekBar, int color) {
|
private void setTint(@NonNull SeekBar seekBar, int color) {
|
||||||
ColorStateList s1 = ColorStateList.valueOf(color);
|
ColorStateList s1 = ColorStateList.valueOf(color);
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
seekBar.setThumbTintList(s1);
|
seekBar.setThumbTintList(s1);
|
||||||
|
|
@ -380,6 +382,7 @@ public class MusicControllerActivity extends AbsFabActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public String getTag() {
|
public String getTag() {
|
||||||
return TAG;
|
return TAG;
|
||||||
|
|
@ -443,7 +446,7 @@ public class MusicControllerActivity extends AbsFabActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
|
public void onLoadingComplete(String imageUri, View view, @NonNull Bitmap loadedImage) {
|
||||||
applyPalette(loadedImage);
|
applyPalette(loadedImage);
|
||||||
albumArtBackground.setImageBitmap(new StackBlurManager(loadedImage).process(10));
|
albumArtBackground.setImageBitmap(new StackBlurManager(loadedImage).process(10));
|
||||||
}
|
}
|
||||||
|
|
@ -451,13 +454,13 @@ public class MusicControllerActivity extends AbsFabActivity {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyPalette(Bitmap bitmap) {
|
private void applyPalette(@Nullable Bitmap bitmap) {
|
||||||
if (bitmap != null) {
|
if (bitmap != null) {
|
||||||
Palette.from(bitmap)
|
Palette.from(bitmap)
|
||||||
.resizeBitmapSize(100)
|
.resizeBitmapSize(100)
|
||||||
.generate(new Palette.PaletteAsyncListener() {
|
.generate(new Palette.PaletteAsyncListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onGenerated(Palette palette) {
|
public void onGenerated(@NonNull Palette palette) {
|
||||||
final Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();
|
final Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();
|
||||||
if (vibrantSwatch != null) {
|
if (vibrantSwatch != null) {
|
||||||
final int swatchRgb = vibrantSwatch.getRgb();
|
final int swatchRgb = vibrantSwatch.getRgb();
|
||||||
|
|
@ -616,7 +619,7 @@ public class MusicControllerActivity extends AbsFabActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(@NonNull Menu menu) {
|
||||||
getMenuInflater().inflate(R.menu.menu_music_playing, menu);
|
getMenuInflater().inflate(R.menu.menu_music_playing, menu);
|
||||||
boolean isFavorite = MusicUtil.isFavorite(this, song);
|
boolean isFavorite = MusicUtil.isFavorite(this, song);
|
||||||
menu.findItem(R.id.action_toggle_favorite)
|
menu.findItem(R.id.action_toggle_favorite)
|
||||||
|
|
@ -626,7 +629,7 @@ public class MusicControllerActivity extends AbsFabActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||||
int id = item.getItemId();
|
int id = item.getItemId();
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case R.id.action_sleep_timer:
|
case R.id.action_sleep_timer:
|
||||||
|
|
@ -701,13 +704,13 @@ public class MusicControllerActivity extends AbsFabActivity {
|
||||||
private static class MusicProgressViewsUpdateHandler extends Handler {
|
private static class MusicProgressViewsUpdateHandler extends Handler {
|
||||||
private WeakReference<MusicControllerActivity> activityReference;
|
private WeakReference<MusicControllerActivity> activityReference;
|
||||||
|
|
||||||
public MusicProgressViewsUpdateHandler(final MusicControllerActivity activity, final Looper looper) {
|
public MusicProgressViewsUpdateHandler(final MusicControllerActivity activity, @NonNull final Looper looper) {
|
||||||
super(looper);
|
super(looper);
|
||||||
activityReference = new WeakReference<>(activity);
|
activityReference = new WeakReference<>(activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message msg) {
|
public void handleMessage(@NonNull Message msg) {
|
||||||
super.handleMessage(msg);
|
super.handleMessage(msg);
|
||||||
if (msg.what == CMD_UPDATE_PROGRESS_VIEWS) {
|
if (msg.what == CMD_UPDATE_PROGRESS_VIEWS) {
|
||||||
activityReference.get().updateProgressViews();
|
activityReference.get().updateProgressViews();
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package com.kabouzeid.gramophone.ui.activities;
|
package com.kabouzeid.gramophone.ui.activities;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.widget.GridLayoutManager;
|
import android.support.v7.widget.GridLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
|
|
@ -33,6 +35,7 @@ public class PlaylistDetailActivity extends AbsFabActivity implements CabHolder
|
||||||
|
|
||||||
public static final String TAG = PlaylistDetailActivity.class.getSimpleName();
|
public static final String TAG = PlaylistDetailActivity.class.getSimpleName();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public static String EXTRA_PLAYLIST = "extra_playlist";
|
public static String EXTRA_PLAYLIST = "extra_playlist";
|
||||||
|
|
||||||
@InjectView(R.id.recycler_view)
|
@InjectView(R.id.recycler_view)
|
||||||
|
|
@ -42,8 +45,10 @@ public class PlaylistDetailActivity extends AbsFabActivity implements CabHolder
|
||||||
@InjectView(android.R.id.empty)
|
@InjectView(android.R.id.empty)
|
||||||
TextView empty;
|
TextView empty;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private Playlist playlist;
|
private Playlist playlist;
|
||||||
private MaterialCab cab;
|
private MaterialCab cab;
|
||||||
|
@Nullable
|
||||||
private AbsPlaylistSongAdapter adapter;
|
private AbsPlaylistSongAdapter adapter;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -110,6 +115,7 @@ public class PlaylistDetailActivity extends AbsFabActivity implements CabHolder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public String getTag() {
|
public String getTag() {
|
||||||
return TAG;
|
return TAG;
|
||||||
|
|
@ -122,7 +128,7 @@ public class PlaylistDetailActivity extends AbsFabActivity implements CabHolder
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||||
int id = item.getItemId();
|
int id = item.getItemId();
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case R.id.action_sleep_timer:
|
case R.id.action_sleep_timer:
|
||||||
|
|
@ -165,7 +171,7 @@ public class PlaylistDetailActivity extends AbsFabActivity implements CabHolder
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onDataBaseEvent(DataBaseChangedEvent event) {
|
public void onDataBaseEvent(@NonNull DataBaseChangedEvent event) {
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
case DataBaseChangedEvent.PLAYLISTS_CHANGED:
|
case DataBaseChangedEvent.PLAYLISTS_CHANGED:
|
||||||
case DataBaseChangedEvent.DATABASE_CHANGED:
|
case DataBaseChangedEvent.DATABASE_CHANGED:
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import android.graphics.Color;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.support.v4.view.MenuItemCompat;
|
import android.support.v4.view.MenuItemCompat;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
|
|
@ -74,6 +75,7 @@ public class SearchActivity extends AbsBaseActivity {
|
||||||
setStatusBarThemeColor();
|
setStatusBarThemeColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public String getTag() {
|
public String getTag() {
|
||||||
return TAG;
|
return TAG;
|
||||||
|
|
@ -92,7 +94,7 @@ public class SearchActivity extends AbsBaseActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(@NonNull Menu menu) {
|
||||||
getMenuInflater().inflate(R.menu.menu_search, menu);
|
getMenuInflater().inflate(R.menu.menu_search, menu);
|
||||||
|
|
||||||
final MenuItem search = menu.findItem(R.id.action_search);
|
final MenuItem search = menu.findItem(R.id.action_search);
|
||||||
|
|
@ -111,7 +113,7 @@ public class SearchActivity extends AbsBaseActivity {
|
||||||
|
|
||||||
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onQueryTextSubmit(String query) {
|
public boolean onQueryTextSubmit(@NonNull String query) {
|
||||||
onQueryTextChange(query);
|
onQueryTextChange(query);
|
||||||
Util.hideSoftKeyboard(SearchActivity.this);
|
Util.hideSoftKeyboard(SearchActivity.this);
|
||||||
searchView.clearFocus();
|
searchView.clearFocus();
|
||||||
|
|
@ -119,7 +121,7 @@ public class SearchActivity extends AbsBaseActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onQueryTextChange(String newText) {
|
public boolean onQueryTextChange(@NonNull String newText) {
|
||||||
search(newText);
|
search(newText);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -142,7 +144,7 @@ public class SearchActivity extends AbsBaseActivity {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void search(String query) {
|
private void search(@NonNull String query) {
|
||||||
if (searchAdapter != null) {
|
if (searchAdapter != null) {
|
||||||
searchAdapter.search(query);
|
searchAdapter.search(query);
|
||||||
empty.setVisibility(searchAdapter.getItemCount() < 1 ? View.VISIBLE : View.GONE);
|
empty.setVisibility(searchAdapter.getItemCount() < 1 ? View.VISIBLE : View.GONE);
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@ import android.preference.ListPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.PreferenceFragment;
|
import android.preference.PreferenceFragment;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
|
|
@ -31,7 +33,7 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
|
||||||
public static final String TAG = SettingsActivity.class.getSimpleName();
|
public static final String TAG = SettingsActivity.class.getSimpleName();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_preferences);
|
setContentView(R.layout.activity_preferences);
|
||||||
|
|
||||||
|
|
@ -77,7 +79,7 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
|
||||||
setSummary(defaultStartPage);
|
setSummary(defaultStartPage);
|
||||||
defaultStartPage.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
defaultStartPage.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object o) {
|
public boolean onPreferenceChange(Preference preference, @NonNull Object o) {
|
||||||
setSummary(defaultStartPage, o);
|
setSummary(defaultStartPage, o);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -87,7 +89,7 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
|
||||||
setSummary(generalTheme);
|
setSummary(generalTheme);
|
||||||
generalTheme.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
generalTheme.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object o) {
|
public boolean onPreferenceChange(Preference preference, @NonNull Object o) {
|
||||||
setSummary(generalTheme, o);
|
setSummary(generalTheme, o);
|
||||||
App.bus.post(new UIPreferenceChangedEvent(UIPreferenceChangedEvent.THEME_CHANGED, o));
|
App.bus.post(new UIPreferenceChangedEvent(UIPreferenceChangedEvent.THEME_CHANGED, o));
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -99,7 +101,7 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
|
||||||
DialogUtils.resolveColor(getActivity(), android.R.attr.textColorPrimary));
|
DialogUtils.resolveColor(getActivity(), android.R.attr.textColorPrimary));
|
||||||
primaryColor.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
primaryColor.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
public boolean onPreferenceClick(@NonNull Preference preference) {
|
||||||
new ColorChooserDialog().show(getActivity(), preference.getTitleRes(),
|
new ColorChooserDialog().show(getActivity(), preference.getTitleRes(),
|
||||||
PreferenceUtils.getInstance(getActivity()).getThemeColorPrimary());
|
PreferenceUtils.getInstance(getActivity()).getThemeColorPrimary());
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -111,7 +113,7 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
|
||||||
DialogUtils.resolveColor(getActivity(), android.R.attr.textColorPrimary));
|
DialogUtils.resolveColor(getActivity(), android.R.attr.textColorPrimary));
|
||||||
accentColor.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
accentColor.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
public boolean onPreferenceClick(@NonNull Preference preference) {
|
||||||
new ColorChooserDialog().show(getActivity(), preference.getTitleRes(),
|
new ColorChooserDialog().show(getActivity(), preference.getTitleRes(),
|
||||||
PreferenceUtils.getInstance(getActivity()).getThemeColorAccent());
|
PreferenceUtils.getInstance(getActivity()).getThemeColorAccent());
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -178,13 +180,13 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setSummary(Preference preference) {
|
private static void setSummary(@NonNull Preference preference) {
|
||||||
setSummary(preference, PreferenceManager
|
setSummary(preference, PreferenceManager
|
||||||
.getDefaultSharedPreferences(preference.getContext())
|
.getDefaultSharedPreferences(preference.getContext())
|
||||||
.getString(preference.getKey(), ""));
|
.getString(preference.getKey(), ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setSummary(Preference preference, Object value) {
|
private static void setSummary(Preference preference, @NonNull Object value) {
|
||||||
String stringValue = value.toString();
|
String stringValue = value.toString();
|
||||||
|
|
||||||
if (preference instanceof ListPreference) {
|
if (preference instanceof ListPreference) {
|
||||||
|
|
@ -211,7 +213,7 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onUIPreferenceChangedEvent(UIPreferenceChangedEvent event) {
|
protected void onUIPreferenceChangedEvent(@NonNull UIPreferenceChangedEvent event) {
|
||||||
super.onUIPreferenceChangedEvent(event);
|
super.onUIPreferenceChangedEvent(event);
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
case UIPreferenceChangedEvent.COLORED_NAVIGATION_BAR_OTHER_SCREENS_CHANGED:
|
case UIPreferenceChangedEvent.COLORED_NAVIGATION_BAR_OTHER_SCREENS_CHANGED:
|
||||||
|
|
@ -231,7 +233,7 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||||
if (item.getItemId() == android.R.id.home) {
|
if (item.getItemId() == android.R.id.home) {
|
||||||
onBackPressed();
|
onBackPressed();
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -239,6 +241,7 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public String getTag() {
|
public String getTag() {
|
||||||
return TAG;
|
return TAG;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.kabouzeid.gramophone.ui.activities.base;
|
||||||
|
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import com.crashlytics.android.Crashlytics;
|
import com.crashlytics.android.Crashlytics;
|
||||||
import com.kabouzeid.gramophone.App;
|
import com.kabouzeid.gramophone.App;
|
||||||
|
|
@ -18,7 +19,7 @@ public abstract class AbsBaseActivity extends AbsThemeActivity implements KabVie
|
||||||
private boolean areViewsEnabled;
|
private boolean areViewsEnabled;
|
||||||
private final Object uiPreferenceChangeListener = new Object() {
|
private final Object uiPreferenceChangeListener = new Object() {
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onUIPreferenceChangedEvent(UIPreferenceChangedEvent event) {
|
public void onUIPreferenceChangedEvent(@NonNull UIPreferenceChangedEvent event) {
|
||||||
AbsBaseActivity.this.onUIPreferenceChangedEvent(event);
|
AbsBaseActivity.this.onUIPreferenceChangedEvent(event);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -34,6 +35,7 @@ public abstract class AbsBaseActivity extends AbsThemeActivity implements KabVie
|
||||||
setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
protected abstract String getTag();
|
protected abstract String getTag();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -57,7 +59,7 @@ public abstract class AbsBaseActivity extends AbsThemeActivity implements KabVie
|
||||||
return areViewsEnabled;
|
return areViewsEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onUIPreferenceChangedEvent(UIPreferenceChangedEvent event) {
|
protected void onUIPreferenceChangedEvent(@NonNull UIPreferenceChangedEvent event) {
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
case UIPreferenceChangedEvent.THEME_CHANGED:
|
case UIPreferenceChangedEvent.THEME_CHANGED:
|
||||||
recreate();
|
recreate();
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@ package com.kabouzeid.gramophone.ui.activities.base;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.design.widget.FloatingActionButton;
|
import android.support.design.widget.FloatingActionButton;
|
||||||
import android.support.v4.util.Pair;
|
import android.support.v4.util.Pair;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
@ -30,6 +32,7 @@ import butterknife.Optional;
|
||||||
public abstract class AbsFabActivity extends AbsPlaybackControlActivity {
|
public abstract class AbsFabActivity extends AbsPlaybackControlActivity {
|
||||||
public static final String TAG = AbsFabActivity.class.getSimpleName();
|
public static final String TAG = AbsFabActivity.class.getSimpleName();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@Optional
|
@Optional
|
||||||
@InjectView(R.id.fab)
|
@InjectView(R.id.fab)
|
||||||
FloatingActionButton fab;
|
FloatingActionButton fab;
|
||||||
|
|
@ -83,7 +86,7 @@ public abstract class AbsFabActivity extends AbsPlaybackControlActivity {
|
||||||
|
|
||||||
getFab().setOnTouchListener(new View.OnTouchListener() {
|
getFab().setOnTouchListener(new View.OnTouchListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouch(View view, MotionEvent event) {
|
public boolean onTouch(View view, @NonNull MotionEvent event) {
|
||||||
gestureDetector.onTouchEvent(event);
|
gestureDetector.onTouchEvent(event);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -119,6 +122,7 @@ public abstract class AbsFabActivity extends AbsPlaybackControlActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
protected FloatingActionButton getFab() {
|
protected FloatingActionButton getFab() {
|
||||||
if (fab == null) {
|
if (fab == null) {
|
||||||
fab = (FloatingActionButton) findViewById(R.id.fab);
|
fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||||
|
|
@ -136,7 +140,7 @@ public abstract class AbsFabActivity extends AbsPlaybackControlActivity {
|
||||||
updateFabState();
|
updateFabState();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Pair[] getSharedViewsWithFab(Pair[] sharedViews) {
|
public Pair[] getSharedViewsWithFab(@Nullable Pair[] sharedViews) {
|
||||||
Pair[] sharedViewsWithFab;
|
Pair[] sharedViewsWithFab;
|
||||||
if (sharedViews != null) {
|
if (sharedViews != null) {
|
||||||
sharedViewsWithFab = new Pair[sharedViews.length + 1];
|
sharedViewsWithFab = new Pair[sharedViews.length + 1];
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ import android.content.IntentFilter;
|
||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||||
import com.kabouzeid.gramophone.service.MusicService;
|
import com.kabouzeid.gramophone.service.MusicService;
|
||||||
|
|
@ -18,6 +20,7 @@ import java.lang.ref.WeakReference;
|
||||||
* @author Karim Abou Zeid (kabouzeid)
|
* @author Karim Abou Zeid (kabouzeid)
|
||||||
*/
|
*/
|
||||||
public abstract class AbsPlaybackControlActivity extends AbsBaseActivity {
|
public abstract class AbsPlaybackControlActivity extends AbsBaseActivity {
|
||||||
|
@Nullable
|
||||||
private MusicPlayerRemote.ServiceToken serviceToken;
|
private MusicPlayerRemote.ServiceToken serviceToken;
|
||||||
private PlaybackStatusReceiver playbackStatusReceiver;
|
private PlaybackStatusReceiver playbackStatusReceiver;
|
||||||
|
|
||||||
|
|
@ -88,6 +91,7 @@ public abstract class AbsPlaybackControlActivity extends AbsBaseActivity {
|
||||||
|
|
||||||
private static final class PlaybackStatusReceiver extends BroadcastReceiver {
|
private static final class PlaybackStatusReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final WeakReference<AbsPlaybackControlActivity> reference;
|
private final WeakReference<AbsPlaybackControlActivity> reference;
|
||||||
|
|
||||||
public PlaybackStatusReceiver(final AbsPlaybackControlActivity activity) {
|
public PlaybackStatusReceiver(final AbsPlaybackControlActivity activity) {
|
||||||
|
|
@ -95,7 +99,7 @@ public abstract class AbsPlaybackControlActivity extends AbsBaseActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(final Context context, final Intent intent) {
|
public void onReceive(final Context context, @NonNull final Intent intent) {
|
||||||
final String action = intent.getAction();
|
final String action = intent.getAction();
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case MusicService.META_CHANGED:
|
case MusicService.META_CHANGED:
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.kabouzeid.gramophone.ui.activities.base;
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
|
|
@ -21,6 +22,7 @@ public abstract class AbsThemeActivity extends AppCompatActivity implements KabV
|
||||||
private int colorPrimaryDarker;
|
private int colorPrimaryDarker;
|
||||||
private int colorAccent;
|
private int colorAccent;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private ActivityManager.TaskDescription taskDescription;
|
private ActivityManager.TaskDescription taskDescription;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@ import android.media.MediaScannerConnection;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.design.widget.FloatingActionButton;
|
import android.support.design.widget.FloatingActionButton;
|
||||||
import android.support.v7.graphics.Palette;
|
import android.support.v7.graphics.Palette;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
|
|
@ -52,7 +54,6 @@ import java.util.Map;
|
||||||
|
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import butterknife.InjectView;
|
import butterknife.InjectView;
|
||||||
import butterknife.Optional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Karim Abou Zeid (kabouzeid)
|
* @author Karim Abou Zeid (kabouzeid)
|
||||||
|
|
@ -77,7 +78,6 @@ public abstract class AbsTagEditorActivity extends AbsBaseActivity {
|
||||||
ObservableScrollView observableScrollView;
|
ObservableScrollView observableScrollView;
|
||||||
@InjectView(R.id.toolbar)
|
@InjectView(R.id.toolbar)
|
||||||
Toolbar toolbar;
|
Toolbar toolbar;
|
||||||
@Optional
|
|
||||||
@InjectView(R.id.image)
|
@InjectView(R.id.image)
|
||||||
ImageView image;
|
ImageView image;
|
||||||
@InjectView(R.id.header)
|
@InjectView(R.id.header)
|
||||||
|
|
@ -220,9 +220,10 @@ public abstract class AbsTagEditorActivity extends AbsBaseActivity {
|
||||||
|
|
||||||
protected abstract int getContentViewLayout();
|
protected abstract int getContentViewLayout();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
protected abstract List<String> getSongPaths();
|
protected abstract List<String> getSongPaths();
|
||||||
|
|
||||||
protected void searchWebFor(List<String> strings) {
|
protected void searchWebFor(@NonNull List<String> strings) {
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
for (String string : strings) {
|
for (String string : strings) {
|
||||||
stringBuilder.append(string);
|
stringBuilder.append(string);
|
||||||
|
|
@ -234,7 +235,7 @@ public abstract class AbsTagEditorActivity extends AbsBaseActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||||
int id = item.getItemId();
|
int id = item.getItemId();
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case android.R.id.home:
|
case android.R.id.home:
|
||||||
|
|
@ -281,7 +282,7 @@ public abstract class AbsTagEditorActivity extends AbsBaseActivity {
|
||||||
setImageBitmap(bitmap);
|
setImageBitmap(bitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setImageBitmap(final Bitmap bitmap) {
|
protected void setImageBitmap(@Nullable final Bitmap bitmap) {
|
||||||
if (bitmap != null) {
|
if (bitmap != null) {
|
||||||
image.setImageBitmap(bitmap);
|
image.setImageBitmap(bitmap);
|
||||||
applyPalette(bitmap);
|
applyPalette(bitmap);
|
||||||
|
|
@ -290,12 +291,12 @@ public abstract class AbsTagEditorActivity extends AbsBaseActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyPalette(final Bitmap bitmap) {
|
private void applyPalette(@NonNull final Bitmap bitmap) {
|
||||||
Palette.from(bitmap)
|
Palette.from(bitmap)
|
||||||
.resizeBitmapSize(100)
|
.resizeBitmapSize(100)
|
||||||
.generate(new Palette.PaletteAsyncListener() {
|
.generate(new Palette.PaletteAsyncListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onGenerated(Palette palette) {
|
public void onGenerated(@NonNull Palette palette) {
|
||||||
final Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();
|
final Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();
|
||||||
if (vibrantSwatch != null) {
|
if (vibrantSwatch != null) {
|
||||||
paletteColorPrimary = palette.getVibrantColor(DialogUtils.resolveColor(AbsTagEditorActivity.this, R.attr.default_bar_color));
|
paletteColorPrimary = palette.getVibrantColor(DialogUtils.resolveColor(AbsTagEditorActivity.this, R.attr.default_bar_color));
|
||||||
|
|
@ -317,11 +318,11 @@ public abstract class AbsTagEditorActivity extends AbsBaseActivity {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void writeValuesToFiles(final Map<FieldKey, String> fieldKeyValueMap) {
|
protected void writeValuesToFiles(@NonNull final Map<FieldKey, String> fieldKeyValueMap) {
|
||||||
writeValuesToFiles(fieldKeyValueMap, null, false);
|
writeValuesToFiles(fieldKeyValueMap, null, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void writeValuesToFiles(final Map<FieldKey, String> fieldKeyValueMap, final Artwork artwork, final boolean deleteArtwork) {
|
protected void writeValuesToFiles(@NonNull final Map<FieldKey, String> fieldKeyValueMap, @Nullable final Artwork artwork, final boolean deleteArtwork) {
|
||||||
Util.hideSoftKeyboard(this);
|
Util.hideSoftKeyboard(this);
|
||||||
final String writingFileStr = getResources().getString(R.string.writing_file_number);
|
final String writingFileStr = getResources().getString(R.string.writing_file_number);
|
||||||
final MaterialDialog progressDialog = new MaterialDialog.Builder(AbsTagEditorActivity.this)
|
final MaterialDialog progressDialog = new MaterialDialog.Builder(AbsTagEditorActivity.this)
|
||||||
|
|
@ -361,7 +362,7 @@ public abstract class AbsTagEditorActivity extends AbsBaseActivity {
|
||||||
tag.setField(artwork);
|
tag.setField(artwork);
|
||||||
}
|
}
|
||||||
audioFile.commit();
|
audioFile.commit();
|
||||||
} catch (CannotReadException | IOException | TagException | ReadOnlyFileException | InvalidAudioFrameException e) {
|
} catch (@NonNull CannotReadException | IOException | TagException | ReadOnlyFileException | InvalidAudioFrameException e) {
|
||||||
Log.e(TAG, "Error while reading audio file.", e);
|
Log.e(TAG, "Error while reading audio file.", e);
|
||||||
} catch (CannotWriteException e) {
|
} catch (CannotWriteException e) {
|
||||||
Log.e(TAG, "Error while writing audio file.", e);
|
Log.e(TAG, "Error while writing audio file.", e);
|
||||||
|
|
@ -390,7 +391,7 @@ public abstract class AbsTagEditorActivity extends AbsBaseActivity {
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void rescanMediaAndQuitOnFinish(final OnScannedAllListener listener) {
|
private void rescanMediaAndQuitOnFinish(@NonNull final OnScannedAllListener listener) {
|
||||||
String[] toBeScanned = new String[songPaths.size()];
|
String[] toBeScanned = new String[songPaths.size()];
|
||||||
toBeScanned = songPaths.toArray(toBeScanned);
|
toBeScanned = songPaths.toArray(toBeScanned);
|
||||||
final int toBeScannedLength = toBeScanned.length;
|
final int toBeScannedLength = toBeScanned.length;
|
||||||
|
|
@ -418,7 +419,7 @@ public abstract class AbsTagEditorActivity extends AbsBaseActivity {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void writeValuesToFiles(final Map<FieldKey, String> fieldKeyValueMap, final Artwork artwork) {
|
protected void writeValuesToFiles(@NonNull final Map<FieldKey, String> fieldKeyValueMap, @Nullable final Artwork artwork) {
|
||||||
if (artwork == null) {
|
if (artwork == null) {
|
||||||
writeValuesToFiles(fieldKeyValueMap, null, true);
|
writeValuesToFiles(fieldKeyValueMap, null, true);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -426,12 +427,12 @@ public abstract class AbsTagEditorActivity extends AbsBaseActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void writeValuesToFiles(final Map<FieldKey, String> fieldKeyValueMap, boolean deleteArtwork) {
|
protected void writeValuesToFiles(@NonNull final Map<FieldKey, String> fieldKeyValueMap, boolean deleteArtwork) {
|
||||||
writeValuesToFiles(fieldKeyValueMap, null, deleteArtwork);
|
writeValuesToFiles(fieldKeyValueMap, null, deleteArtwork);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
|
protected void onActivityResult(int requestCode, int resultCode, @NonNull Intent imageReturnedIntent) {
|
||||||
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
|
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
|
||||||
switch (requestCode) {
|
switch (requestCode) {
|
||||||
case REQUEST_CODE_SELECT_IMAGE:
|
case REQUEST_CODE_SELECT_IMAGE:
|
||||||
|
|
@ -444,6 +445,7 @@ public abstract class AbsTagEditorActivity extends AbsBaseActivity {
|
||||||
|
|
||||||
protected abstract void loadImageFromFile(Uri selectedFile);
|
protected abstract void loadImageFromFile(Uri selectedFile);
|
||||||
|
|
||||||
|
@Nullable
|
||||||
protected String getSongTitle() {
|
protected String getSongTitle() {
|
||||||
try {
|
try {
|
||||||
return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.TITLE);
|
return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.TITLE);
|
||||||
|
|
@ -452,15 +454,16 @@ public abstract class AbsTagEditorActivity extends AbsBaseActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private AudioFile getAudioFile(String path) {
|
private AudioFile getAudioFile(@NonNull String path) {
|
||||||
try {
|
try {
|
||||||
return AudioFileIO.read(new File(path));
|
return AudioFileIO.read(new File(path));
|
||||||
} catch (CannotReadException | ReadOnlyFileException | InvalidAudioFrameException | TagException | IOException e) {
|
} catch (@NonNull CannotReadException | ReadOnlyFileException | InvalidAudioFrameException | TagException | IOException e) {
|
||||||
Log.e(TAG, "Error while trying to create the AudioFile from java.io.File", e);
|
Log.e(TAG, "Error while trying to create the AudioFile from java.io.File", e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
protected String getAlbumTitle() {
|
protected String getAlbumTitle() {
|
||||||
try {
|
try {
|
||||||
return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.ALBUM);
|
return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.ALBUM);
|
||||||
|
|
@ -469,6 +472,7 @@ public abstract class AbsTagEditorActivity extends AbsBaseActivity {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
protected String getArtistName() {
|
protected String getArtistName() {
|
||||||
try {
|
try {
|
||||||
return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.ARTIST);
|
return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.ARTIST);
|
||||||
|
|
@ -477,6 +481,7 @@ public abstract class AbsTagEditorActivity extends AbsBaseActivity {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
protected String getAlbumArtistName() {
|
protected String getAlbumArtistName() {
|
||||||
try {
|
try {
|
||||||
return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.ALBUM_ARTIST);
|
return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.ALBUM_ARTIST);
|
||||||
|
|
@ -485,6 +490,7 @@ public abstract class AbsTagEditorActivity extends AbsBaseActivity {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
protected String getGenreName() {
|
protected String getGenreName() {
|
||||||
try {
|
try {
|
||||||
return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.GENRE);
|
return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.GENRE);
|
||||||
|
|
@ -493,6 +499,7 @@ public abstract class AbsTagEditorActivity extends AbsBaseActivity {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
protected String getSongYear() {
|
protected String getSongYear() {
|
||||||
try {
|
try {
|
||||||
return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.YEAR);
|
return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.YEAR);
|
||||||
|
|
@ -501,6 +508,7 @@ public abstract class AbsTagEditorActivity extends AbsBaseActivity {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
protected String getTrackNumber() {
|
protected String getTrackNumber() {
|
||||||
try {
|
try {
|
||||||
return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.TRACK);
|
return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.TRACK);
|
||||||
|
|
@ -509,6 +517,7 @@ public abstract class AbsTagEditorActivity extends AbsBaseActivity {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
protected Bitmap getAlbumArt() {
|
protected Bitmap getAlbumArt() {
|
||||||
try {
|
try {
|
||||||
Artwork artworkTag = getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirstArtwork();
|
Artwork artworkTag = getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirstArtwork();
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.kabouzeid.gramophone.ui.activities.tageditor;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
@ -67,6 +68,7 @@ public class AlbumTagEditorActivity extends AbsTagEditorActivity implements Text
|
||||||
setUpViews();
|
setUpViews();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public String getTag() {
|
public String getTag() {
|
||||||
return TAG;
|
return TAG;
|
||||||
|
|
@ -104,7 +106,7 @@ public class AlbumTagEditorActivity extends AbsTagEditorActivity implements Text
|
||||||
}
|
}
|
||||||
lastFMRestClient.getApiService().getAlbumInfo(albumTitleStr, albumArtistNameStr, new Callback<AlbumInfo>() {
|
lastFMRestClient.getApiService().getAlbumInfo(albumTitleStr, albumArtistNameStr, new Callback<AlbumInfo>() {
|
||||||
@Override
|
@Override
|
||||||
public void success(AlbumInfo albumInfo, Response response) {
|
public void success(@NonNull AlbumInfo albumInfo, Response response) {
|
||||||
if (albumInfo.getAlbum() != null) {
|
if (albumInfo.getAlbum() != null) {
|
||||||
List<Image> images = albumInfo.getAlbum().getImage();
|
List<Image> images = albumInfo.getAlbum().getImage();
|
||||||
int lastIndexOfImages = images.size() - 1;
|
int lastIndexOfImages = images.size() - 1;
|
||||||
|
|
@ -187,6 +189,7 @@ public class AlbumTagEditorActivity extends AbsTagEditorActivity implements Text
|
||||||
return R.layout.activity_album_tag_editor;
|
return R.layout.activity_album_tag_editor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
protected List<String> getSongPaths() {
|
protected List<String> getSongPaths() {
|
||||||
ArrayList<Song> songs = AlbumSongLoader.getAlbumSongList(this, getId());
|
ArrayList<Song> songs = AlbumSongLoader.getAlbumSongList(this, getId());
|
||||||
|
|
@ -198,7 +201,7 @@ public class AlbumTagEditorActivity extends AbsTagEditorActivity implements Text
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void loadImageFromFile(final Uri selectedFileUri) {
|
protected void loadImageFromFile(@NonNull final Uri selectedFileUri) {
|
||||||
ImageLoader.getInstance().loadImage(selectedFileUri.toString(),
|
ImageLoader.getInstance().loadImage(selectedFileUri.toString(),
|
||||||
new ImageSize(500, 500),
|
new ImageSize(500, 500),
|
||||||
new SimpleImageLoadingListener() {
|
new SimpleImageLoadingListener() {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.kabouzeid.gramophone.ui.activities.tageditor;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
|
@ -45,6 +46,7 @@ public class SongTagEditorActivity extends AbsTagEditorActivity implements TextW
|
||||||
setUpViews();
|
setUpViews();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public String getTag() {
|
public String getTag() {
|
||||||
return TAG;
|
return TAG;
|
||||||
|
|
@ -106,6 +108,7 @@ public class SongTagEditorActivity extends AbsTagEditorActivity implements TextW
|
||||||
return R.layout.activity_song_tag_editor;
|
return R.layout.activity_song_tag_editor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
protected List<String> getSongPaths() {
|
protected List<String> getSongPaths() {
|
||||||
ArrayList<String> paths = new ArrayList<>(1);
|
ArrayList<String> paths = new ArrayList<>(1);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.kabouzeid.gramophone.ui.fragments.mainactivityfragments;
|
package com.kabouzeid.gramophone.ui.fragments.mainactivityfragments;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
|
|
||||||
import com.kabouzeid.gramophone.interfaces.KabViewsDisableAble;
|
import com.kabouzeid.gramophone.interfaces.KabViewsDisableAble;
|
||||||
|
|
@ -12,6 +13,7 @@ import com.kabouzeid.gramophone.ui.activities.MainActivity;
|
||||||
public abstract class AbsMainActivityFragment extends Fragment implements KabViewsDisableAble {
|
public abstract class AbsMainActivityFragment extends Fragment implements KabViewsDisableAble {
|
||||||
private boolean areViewsEnabled;
|
private boolean areViewsEnabled;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
protected MainActivity getMainActivity() {
|
protected MainActivity getMainActivity() {
|
||||||
return (MainActivity) getActivity();
|
return (MainActivity) getActivity();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.kabouzeid.gramophone.ui.fragments.mainactivityfragments;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.LayoutRes;
|
import android.support.annotation.LayoutRes;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.annotation.StringRes;
|
import android.support.annotation.StringRes;
|
||||||
import android.support.design.widget.AppBarLayout;
|
import android.support.design.widget.AppBarLayout;
|
||||||
|
|
@ -40,7 +41,7 @@ public abstract class AbsMainActivityRecyclerViewFragment extends AbsMainActivit
|
||||||
private RecyclerView.Adapter mAdapter;
|
private RecyclerView.Adapter mAdapter;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(getLayoutRes(), container, false);
|
View view = inflater.inflate(getLayoutRes(), container, false);
|
||||||
ButterKnife.inject(this, view);
|
ButterKnife.inject(this, view);
|
||||||
return view;
|
return view;
|
||||||
|
|
@ -130,6 +131,7 @@ public abstract class AbsMainActivityRecyclerViewFragment extends AbsMainActivit
|
||||||
|
|
||||||
protected abstract RecyclerView.LayoutManager createLayoutManager();
|
protected abstract RecyclerView.LayoutManager createLayoutManager();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
protected abstract RecyclerView.Adapter createAdapter();
|
protected abstract RecyclerView.Adapter createAdapter();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.kabouzeid.gramophone.ui.fragments.mainactivityfragments;
|
package com.kabouzeid.gramophone.ui.fragments.mainactivityfragments;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v7.widget.GridLayoutManager;
|
import android.support.v7.widget.GridLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
|
||||||
|
|
@ -23,6 +24,7 @@ public class AlbumViewFragment extends AbsMainActivityRecyclerViewFragment {
|
||||||
return layoutManager;
|
return layoutManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
protected RecyclerView.Adapter createAdapter() {
|
protected RecyclerView.Adapter createAdapter() {
|
||||||
return new AlbumAdapter(getMainActivity(), getMainActivity());
|
return new AlbumAdapter(getMainActivity(), getMainActivity());
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.kabouzeid.gramophone.ui.fragments.mainactivityfragments;
|
package com.kabouzeid.gramophone.ui.fragments.mainactivityfragments;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v7.widget.GridLayoutManager;
|
import android.support.v7.widget.GridLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
|
||||||
|
|
@ -13,11 +14,13 @@ public class ArtistViewFragment extends AbsMainActivityRecyclerViewFragment {
|
||||||
|
|
||||||
public static final String TAG = ArtistViewFragment.class.getSimpleName();
|
public static final String TAG = ArtistViewFragment.class.getSimpleName();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
protected RecyclerView.LayoutManager createLayoutManager() {
|
protected RecyclerView.LayoutManager createLayoutManager() {
|
||||||
return new GridLayoutManager(getActivity(), 1);
|
return new GridLayoutManager(getActivity(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
protected RecyclerView.Adapter createAdapter() {
|
protected RecyclerView.Adapter createAdapter() {
|
||||||
return new ArtistAdapter(getMainActivity(), getMainActivity());
|
return new ArtistAdapter(getMainActivity(), getMainActivity());
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.kabouzeid.gramophone.ui.fragments.mainactivityfragments;
|
package com.kabouzeid.gramophone.ui.fragments.mainactivityfragments;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v7.widget.GridLayoutManager;
|
import android.support.v7.widget.GridLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
|
||||||
|
|
@ -13,11 +14,13 @@ public class PlaylistViewFragment extends AbsMainActivityRecyclerViewFragment {
|
||||||
|
|
||||||
public static final String TAG = PlaylistViewFragment.class.getSimpleName();
|
public static final String TAG = PlaylistViewFragment.class.getSimpleName();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
protected RecyclerView.LayoutManager createLayoutManager() {
|
protected RecyclerView.LayoutManager createLayoutManager() {
|
||||||
return new GridLayoutManager(getActivity(), 1);
|
return new GridLayoutManager(getActivity(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
protected RecyclerView.Adapter createAdapter() {
|
protected RecyclerView.Adapter createAdapter() {
|
||||||
return new PlaylistAdapter(getMainActivity(), getMainActivity());
|
return new PlaylistAdapter(getMainActivity(), getMainActivity());
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.kabouzeid.gramophone.ui.fragments.mainactivityfragments;
|
package com.kabouzeid.gramophone.ui.fragments.mainactivityfragments;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v7.widget.GridLayoutManager;
|
import android.support.v7.widget.GridLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
|
||||||
|
|
@ -13,11 +14,13 @@ public class SongViewFragment extends AbsMainActivityRecyclerViewFragment {
|
||||||
|
|
||||||
public static final String TAG = SongViewFragment.class.getSimpleName();
|
public static final String TAG = SongViewFragment.class.getSimpleName();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
protected RecyclerView.LayoutManager createLayoutManager() {
|
protected RecyclerView.LayoutManager createLayoutManager() {
|
||||||
return new GridLayoutManager(getActivity(), 1);
|
return new GridLayoutManager(getActivity(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
protected RecyclerView.Adapter createAdapter() {
|
protected RecyclerView.Adapter createAdapter() {
|
||||||
return new SongAdapter(getMainActivity(), getMainActivity());
|
return new SongAdapter(getMainActivity(), getMainActivity());
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.graphics.Point;
|
import android.graphics.Point;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.view.Display;
|
import android.view.Display;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
|
@ -24,7 +25,7 @@ import java.io.IOException;
|
||||||
public class ImageUtil {
|
public class ImageUtil {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static Bitmap getEmbeddedSongArt(File songFile, Context context) {
|
public static Bitmap getEmbeddedSongArt(File songFile, @NonNull Context context) {
|
||||||
try {
|
try {
|
||||||
AudioFile audioFile = AudioFileIO.read(songFile);
|
AudioFile audioFile = AudioFileIO.read(songFile);
|
||||||
byte[] data = audioFile.getTag().getFirstArtwork().getBinaryData();
|
byte[] data = audioFile.getTag().getFirstArtwork().getBinaryData();
|
||||||
|
|
@ -39,13 +40,13 @@ public class ImageUtil {
|
||||||
options.inJustDecodeBounds = false;
|
options.inJustDecodeBounds = false;
|
||||||
return BitmapFactory.decodeByteArray(data, 0, data.length, options);
|
return BitmapFactory.decodeByteArray(data, 0, data.length, options);
|
||||||
}
|
}
|
||||||
} catch (CannotReadException | TagException | IOException | ReadOnlyFileException | InvalidAudioFrameException e) {
|
} catch (@NonNull CannotReadException | TagException | IOException | ReadOnlyFileException | InvalidAudioFrameException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int calculateInSampleSize(BitmapFactory.Options options, Context context) {
|
public static int calculateInSampleSize(@NonNull BitmapFactory.Options options, @NonNull Context context) {
|
||||||
|
|
||||||
// Raw height and width of image
|
// Raw height and width of image
|
||||||
final int height = options.outHeight;
|
final int height = options.outHeight;
|
||||||
|
|
@ -76,7 +77,7 @@ public class ImageUtil {
|
||||||
return inSampleSize;
|
return inSampleSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getSmallerScreenSize(Context c) {
|
private static int getSmallerScreenSize(@NonNull Context c) {
|
||||||
Display display = ((WindowManager) c.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
|
Display display = ((WindowManager) c.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
|
||||||
Point size = new Point();
|
Point size = new Point();
|
||||||
display.getSize(size);
|
display.getSize(size);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.kabouzeid.gramophone.util;
|
package com.kabouzeid.gramophone.util;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
|
@ -22,7 +23,7 @@ public final class InternalStorageUtil {
|
||||||
* @param key the filename
|
* @param key the filename
|
||||||
* @param object any {@link java.io.Serializable} object which will be written to the internal storage
|
* @param object any {@link java.io.Serializable} object which will be written to the internal storage
|
||||||
*/
|
*/
|
||||||
public static synchronized void writeObject(final Context context, final String key, final Object object) throws IOException {
|
public static synchronized void writeObject(@NonNull final Context context, @NonNull final String key, final Object object) throws IOException {
|
||||||
// First write the object to a file with ".tmp" postfix,
|
// First write the object to a file with ".tmp" postfix,
|
||||||
// so when an error occurs, we do not overwrite the original
|
// so when an error occurs, we do not overwrite the original
|
||||||
// file (if exists) with a corrupted file.
|
// file (if exists) with a corrupted file.
|
||||||
|
|
@ -43,7 +44,7 @@ public final class InternalStorageUtil {
|
||||||
* @param originalFileName the original filename
|
* @param originalFileName the original filename
|
||||||
* @param newFileName the new filename
|
* @param newFileName the new filename
|
||||||
*/
|
*/
|
||||||
public static synchronized void renameAppFile(final Context context, String originalFileName, String newFileName) {
|
public static synchronized void renameAppFile(@NonNull final Context context, String originalFileName, @NonNull String newFileName) {
|
||||||
File originalFile = context.getFileStreamPath(originalFileName);
|
File originalFile = context.getFileStreamPath(originalFileName);
|
||||||
File newFile = new File(originalFile.getParent(), newFileName);
|
File newFile = new File(originalFile.getParent(), newFileName);
|
||||||
if (newFile.exists()) {
|
if (newFile.exists()) {
|
||||||
|
|
@ -57,7 +58,7 @@ public final class InternalStorageUtil {
|
||||||
* @param context a valid {@link Context}
|
* @param context a valid {@link Context}
|
||||||
* @param key the filename
|
* @param key the filename
|
||||||
*/
|
*/
|
||||||
public static synchronized Object readObject(final Context context, String key) throws IOException,
|
public static synchronized Object readObject(@NonNull final Context context, String key) throws IOException,
|
||||||
ClassNotFoundException {
|
ClassNotFoundException {
|
||||||
FileInputStream fis = context.openFileInput(key);
|
FileInputStream fis = context.openFileInput(key);
|
||||||
ObjectInputStream ois = new ObjectInputStream(fis);
|
ObjectInputStream ois = new ObjectInputStream(fis);
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import android.provider.BaseColumns;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
|
@ -37,11 +38,13 @@ import java.util.List;
|
||||||
public class MusicUtil {
|
public class MusicUtil {
|
||||||
public static final String TAG = MusicUtil.class.getSimpleName();
|
public static final String TAG = MusicUtil.class.getSimpleName();
|
||||||
|
|
||||||
public static String getAlbumImageLoaderString(Album album) {
|
@NonNull
|
||||||
|
public static String getAlbumImageLoaderString(@NonNull Album album) {
|
||||||
return PhonographImageDownloader.SCHEME_ALBUM + album.id;
|
return PhonographImageDownloader.SCHEME_ALBUM + album.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getSongImageLoaderString(Song song) {
|
@NonNull
|
||||||
|
public static String getSongImageLoaderString(@NonNull Song song) {
|
||||||
return PhonographImageDownloader.SCHEME_SONG + song.albumId + "#" + song.data;
|
return PhonographImageDownloader.SCHEME_SONG + song.albumId + "#" + song.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -57,14 +60,14 @@ public class MusicUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static Intent createShareSongFileIntent(final Song song) {
|
public static Intent createShareSongFileIntent(@NonNull final Song song) {
|
||||||
return new Intent()
|
return new Intent()
|
||||||
.setAction(Intent.ACTION_SEND)
|
.setAction(Intent.ACTION_SEND)
|
||||||
.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + song.data))
|
.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + song.data))
|
||||||
.setType("audio/*");
|
.setType("audio/*");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setRingtone(final Context context, final int id) {
|
public static void setRingtone(@NonNull final Context context, final int id) {
|
||||||
final ContentResolver resolver = context.getContentResolver();
|
final ContentResolver resolver = context.getContentResolver();
|
||||||
final Uri uri = getSongUri(id);
|
final Uri uri = getSongUri(id);
|
||||||
try {
|
try {
|
||||||
|
|
@ -72,7 +75,7 @@ public class MusicUtil {
|
||||||
values.put(MediaStore.Audio.AudioColumns.IS_RINGTONE, "1");
|
values.put(MediaStore.Audio.AudioColumns.IS_RINGTONE, "1");
|
||||||
values.put(MediaStore.Audio.AudioColumns.IS_ALARM, "1");
|
values.put(MediaStore.Audio.AudioColumns.IS_ALARM, "1");
|
||||||
resolver.update(uri, values, null, null);
|
resolver.update(uri, values, null, null);
|
||||||
} catch (final UnsupportedOperationException ignored) {
|
} catch (@NonNull final UnsupportedOperationException ignored) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -95,7 +98,8 @@ public class MusicUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getArtistInfoString(Context context, Artist artist) {
|
@NonNull
|
||||||
|
public static String getArtistInfoString(@NonNull Context context, @NonNull Artist artist) {
|
||||||
return artist.songCount + " " + context.getResources().getString(R.string.songs) + " | " + artist.albumCount + " " + context.getResources().getString(R.string.albums);
|
return artist.songCount + " " + context.getResources().getString(R.string.songs) + " | " + artist.albumCount + " " + context.getResources().getString(R.string.albums);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -111,7 +115,7 @@ public class MusicUtil {
|
||||||
return trackNumberToFix % 1000;
|
return trackNumberToFix % 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void insertAlbumArt(Context context, int albumId, String path) {
|
public static void insertAlbumArt(@NonNull Context context, int albumId, String path) {
|
||||||
ContentResolver contentResolver = context.getContentResolver();
|
ContentResolver contentResolver = context.getContentResolver();
|
||||||
|
|
||||||
Uri artworkUri = Uri.parse("content://media/external/audio/albumart");
|
Uri artworkUri = Uri.parse("content://media/external/audio/albumart");
|
||||||
|
|
@ -124,16 +128,18 @@ public class MusicUtil {
|
||||||
contentResolver.insert(artworkUri, values);
|
contentResolver.insert(artworkUri, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void deleteAlbumArt(Context context, int albumId) {
|
public static void deleteAlbumArt(@NonNull Context context, int albumId) {
|
||||||
ContentResolver contentResolver = context.getContentResolver();
|
ContentResolver contentResolver = context.getContentResolver();
|
||||||
Uri localUri = Uri.parse("content://media/external/audio/albumart");
|
Uri localUri = Uri.parse("content://media/external/audio/albumart");
|
||||||
contentResolver.delete(ContentUris.withAppendedId(localUri, albumId), null, null);
|
contentResolver.delete(ContentUris.withAppendedId(localUri, albumId), null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public static File createAlbumArtFile(String name) {
|
public static File createAlbumArtFile(String name) {
|
||||||
return new File(createAlbumArtDir(), name + System.currentTimeMillis());
|
return new File(createAlbumArtDir(), name + System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
public static File createAlbumArtDir() {
|
public static File createAlbumArtDir() {
|
||||||
File albumArtDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "/.albumart/");
|
File albumArtDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "/.albumart/");
|
||||||
|
|
@ -148,7 +154,7 @@ public class MusicUtil {
|
||||||
return albumArtDir;
|
return albumArtDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void deleteTracks(final Context context, final List<Song> songs) {
|
public static void deleteTracks(@NonNull final Context context, @NonNull final List<Song> songs) {
|
||||||
final String[] projection = new String[]{
|
final String[] projection = new String[]{
|
||||||
BaseColumns._ID, MediaStore.MediaColumns.DATA
|
BaseColumns._ID, MediaStore.MediaColumns.DATA
|
||||||
};
|
};
|
||||||
|
|
@ -191,7 +197,7 @@ public class MusicUtil {
|
||||||
Log.e("MusicUtils", "Failed to delete file " + name);
|
Log.e("MusicUtils", "Failed to delete file " + name);
|
||||||
}
|
}
|
||||||
cursor.moveToNext();
|
cursor.moveToNext();
|
||||||
} catch (final SecurityException ex) {
|
} catch (@NonNull final SecurityException ex) {
|
||||||
cursor.moveToNext();
|
cursor.moveToNext();
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
Log.e("MusicUtils", "Failed to find file " + name);
|
Log.e("MusicUtils", "Failed to find file " + name);
|
||||||
|
|
@ -204,19 +210,19 @@ public class MusicUtil {
|
||||||
App.bus.post(new DataBaseChangedEvent(DataBaseChangedEvent.DATABASE_CHANGED));
|
App.bus.post(new DataBaseChangedEvent(DataBaseChangedEvent.DATABASE_CHANGED));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Playlist getFavoritesPlaylist(final Context context) {
|
private static Playlist getFavoritesPlaylist(@NonNull final Context context) {
|
||||||
return PlaylistLoader.getPlaylist(context, context.getString(R.string.favorites));
|
return PlaylistLoader.getPlaylist(context, context.getString(R.string.favorites));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Playlist getOrCreateFavoritesPlaylist(final Context context) {
|
private static Playlist getOrCreateFavoritesPlaylist(@NonNull final Context context) {
|
||||||
return PlaylistLoader.getPlaylist(context, PlaylistsUtil.createPlaylist(context, context.getString(R.string.favorites)));
|
return PlaylistLoader.getPlaylist(context, PlaylistsUtil.createPlaylist(context, context.getString(R.string.favorites)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isFavorite(final Context context, final Song song) {
|
public static boolean isFavorite(@NonNull final Context context, @NonNull final Song song) {
|
||||||
return PlaylistsUtil.doPlaylistContains(context, getFavoritesPlaylist(context).id, song.id);
|
return PlaylistsUtil.doPlaylistContains(context, getFavoritesPlaylist(context).id, song.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void toggleFavorite(final Context context, final Song song) {
|
public static void toggleFavorite(@NonNull final Context context, @NonNull final Song song) {
|
||||||
if (isFavorite(context, song)) {
|
if (isFavorite(context, song)) {
|
||||||
PlaylistsUtil.removeFromPlaylist(context, song, getFavoritesPlaylist(context).id);
|
PlaylistsUtil.removeFromPlaylist(context, song, getFavoritesPlaylist(context).id);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -224,7 +230,7 @@ public class MusicUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isArtistNameUnknown(final String artistName) {
|
public static boolean isArtistNameUnknown(@Nullable final String artistName) {
|
||||||
return artistName != null && (artistName.trim().toLowerCase().equals("unknown") || artistName.trim().toLowerCase().equals("<unknown>"));
|
return artistName != null && (artistName.trim().toLowerCase().equals("unknown") || artistName.trim().toLowerCase().equals("<unknown>"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ import android.app.Activity;
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.media.audiofx.AudioEffect;
|
import android.media.audiofx.AudioEffect;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.app.ActivityCompat;
|
import android.support.v4.app.ActivityCompat;
|
||||||
import android.support.v4.app.ActivityOptionsCompat;
|
import android.support.v4.app.ActivityOptionsCompat;
|
||||||
import android.support.v4.util.Pair;
|
import android.support.v4.util.Pair;
|
||||||
|
|
@ -25,7 +27,7 @@ import com.kabouzeid.gramophone.ui.activities.PlaylistDetailActivity;
|
||||||
*/
|
*/
|
||||||
public class NavigationUtil {
|
public class NavigationUtil {
|
||||||
|
|
||||||
public static void goToArtist(final Activity activity, final int artistId, final Pair[] sharedViews) {
|
public static void goToArtist(final Activity activity, final int artistId, @Nullable final Pair[] sharedViews) {
|
||||||
if (activity instanceof ArtistDetailActivity)
|
if (activity instanceof ArtistDetailActivity)
|
||||||
return;
|
return;
|
||||||
if ((activity instanceof KabViewsDisableAble && ((KabViewsDisableAble) activity).areViewsEnabled()) || !(activity instanceof KabViewsDisableAble)) {
|
if ((activity instanceof KabViewsDisableAble && ((KabViewsDisableAble) activity).areViewsEnabled()) || !(activity instanceof KabViewsDisableAble)) {
|
||||||
|
|
@ -44,7 +46,7 @@ public class NavigationUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void goToAlbum(final Activity activity, final int albumId, final Pair[] sharedViews) {
|
public static void goToAlbum(final Activity activity, final int albumId, @Nullable final Pair[] sharedViews) {
|
||||||
if (activity instanceof AlbumDetailActivity)
|
if (activity instanceof AlbumDetailActivity)
|
||||||
return;
|
return;
|
||||||
if ((activity instanceof KabViewsDisableAble && ((KabViewsDisableAble) activity).areViewsEnabled()) || !(activity instanceof KabViewsDisableAble)) {
|
if ((activity instanceof KabViewsDisableAble && ((KabViewsDisableAble) activity).areViewsEnabled()) || !(activity instanceof KabViewsDisableAble)) {
|
||||||
|
|
@ -63,7 +65,7 @@ public class NavigationUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void goToPlaylist(final Activity activity, final Playlist playlist, final Pair[] sharedViews) {
|
public static void goToPlaylist(final Activity activity, final Playlist playlist, @Nullable final Pair[] sharedViews) {
|
||||||
if ((activity instanceof KabViewsDisableAble && ((KabViewsDisableAble) activity).areViewsEnabled()) || !(activity instanceof KabViewsDisableAble)) {
|
if ((activity instanceof KabViewsDisableAble && ((KabViewsDisableAble) activity).areViewsEnabled()) || !(activity instanceof KabViewsDisableAble)) {
|
||||||
if (activity instanceof KabViewsDisableAble)
|
if (activity instanceof KabViewsDisableAble)
|
||||||
((KabViewsDisableAble) activity).disableViews();
|
((KabViewsDisableAble) activity).disableViews();
|
||||||
|
|
@ -83,7 +85,7 @@ public class NavigationUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void openCurrentPlayingIfPossible(final Activity activity, final Pair[] sharedViews) {
|
public static void openCurrentPlayingIfPossible(final Activity activity, @Nullable final Pair[] sharedViews) {
|
||||||
if (activity instanceof MusicControllerActivity) {
|
if (activity instanceof MusicControllerActivity) {
|
||||||
activity.onBackPressed();
|
activity.onBackPressed();
|
||||||
return;
|
return;
|
||||||
|
|
@ -107,7 +109,7 @@ public class NavigationUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void openPlayingQueueDialog(final AppCompatActivity activity) {
|
public static void openPlayingQueueDialog(@NonNull final AppCompatActivity activity) {
|
||||||
PlayingQueueDialog dialog = PlayingQueueDialog.create();
|
PlayingQueueDialog dialog = PlayingQueueDialog.create();
|
||||||
if (dialog != null) {
|
if (dialog != null) {
|
||||||
dialog.show(activity.getSupportFragmentManager(), "PLAY_QUEUE");
|
dialog.show(activity.getSupportFragmentManager(), "PLAY_QUEUE");
|
||||||
|
|
@ -116,7 +118,7 @@ public class NavigationUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void openEqualizer(final Activity activity) {
|
public static void openEqualizer(@NonNull final Activity activity) {
|
||||||
final int sessionId = MusicPlayerRemote.getAudioSessionId();
|
final int sessionId = MusicPlayerRemote.getAudioSessionId();
|
||||||
if (sessionId == AudioEffect.ERROR_BAD_VALUE) {
|
if (sessionId == AudioEffect.ERROR_BAD_VALUE) {
|
||||||
Toast.makeText(activity, activity.getResources().getString(R.string.no_audio_ID), Toast.LENGTH_LONG).show();
|
Toast.makeText(activity, activity.getResources().getString(R.string.no_audio_ID), Toast.LENGTH_LONG).show();
|
||||||
|
|
@ -126,7 +128,7 @@ public class NavigationUtil {
|
||||||
effects.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, sessionId);
|
effects.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, sessionId);
|
||||||
effects.putExtra(AudioEffect.EXTRA_CONTENT_TYPE, AudioEffect.CONTENT_TYPE_MUSIC);
|
effects.putExtra(AudioEffect.EXTRA_CONTENT_TYPE, AudioEffect.CONTENT_TYPE_MUSIC);
|
||||||
activity.startActivityForResult(effects, 0);
|
activity.startActivityForResult(effects, 0);
|
||||||
} catch (final ActivityNotFoundException notFound) {
|
} catch (@NonNull final ActivityNotFoundException notFound) {
|
||||||
Toast.makeText(activity, activity.getResources().getString(R.string.no_equalizer), Toast.LENGTH_SHORT).show();
|
Toast.makeText(activity, activity.getResources().getString(R.string.no_equalizer), Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ import android.database.Cursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.provider.BaseColumns;
|
import android.provider.BaseColumns;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.kabouzeid.gramophone.App;
|
import com.kabouzeid.gramophone.App;
|
||||||
|
|
@ -24,7 +26,7 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public class PlaylistsUtil {
|
public class PlaylistsUtil {
|
||||||
|
|
||||||
public static int createPlaylist(final Context context, final String name) {
|
public static int createPlaylist(@NonNull final Context context, @Nullable final String name) {
|
||||||
int id = -1;
|
int id = -1;
|
||||||
if (name != null && name.length() > 0) {
|
if (name != null && name.length() > 0) {
|
||||||
Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
|
Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
|
||||||
|
|
@ -70,7 +72,7 @@ public class PlaylistsUtil {
|
||||||
// App.bus.post(new DataBaseChangedEvent(DataBaseChangedEvent.PLAYLISTS_CHANGED));
|
// App.bus.post(new DataBaseChangedEvent(DataBaseChangedEvent.PLAYLISTS_CHANGED));
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public static void deletePlaylists(final Context context, final ArrayList<Playlist> playlists) {
|
public static void deletePlaylists(@NonNull final Context context, @NonNull final ArrayList<Playlist> playlists) {
|
||||||
final Uri uri = MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI;
|
final Uri uri = MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI;
|
||||||
final StringBuilder selection = new StringBuilder();
|
final StringBuilder selection = new StringBuilder();
|
||||||
selection.append(MediaStore.Audio.Playlists._ID + " IN (");
|
selection.append(MediaStore.Audio.Playlists._ID + " IN (");
|
||||||
|
|
@ -85,13 +87,13 @@ public class PlaylistsUtil {
|
||||||
App.bus.post(new DataBaseChangedEvent(DataBaseChangedEvent.PLAYLISTS_CHANGED));
|
App.bus.post(new DataBaseChangedEvent(DataBaseChangedEvent.PLAYLISTS_CHANGED));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addToPlaylist(final Context context, final Song song, final int playlistId, final boolean showToastOnFinish) {
|
public static void addToPlaylist(@NonNull final Context context, final Song song, final int playlistId, final boolean showToastOnFinish) {
|
||||||
List<Song> helperList = new ArrayList<>();
|
List<Song> helperList = new ArrayList<>();
|
||||||
helperList.add(song);
|
helperList.add(song);
|
||||||
addToPlaylist(context, helperList, playlistId, showToastOnFinish);
|
addToPlaylist(context, helperList, playlistId, showToastOnFinish);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addToPlaylist(final Context context, final List<Song> songs, final int playlistId, final boolean showToastOnFinish) {
|
public static void addToPlaylist(@NonNull final Context context, @NonNull final List<Song> songs, final int playlistId, final boolean showToastOnFinish) {
|
||||||
final int size = songs.size();
|
final int size = songs.size();
|
||||||
final ContentResolver resolver = context.getContentResolver();
|
final ContentResolver resolver = context.getContentResolver();
|
||||||
final String[] projection = new String[]{
|
final String[] projection = new String[]{
|
||||||
|
|
@ -124,7 +126,8 @@ public class PlaylistsUtil {
|
||||||
App.bus.post(new DataBaseChangedEvent(DataBaseChangedEvent.PLAYLISTS_CHANGED));
|
App.bus.post(new DataBaseChangedEvent(DataBaseChangedEvent.PLAYLISTS_CHANGED));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ContentValues[] makeInsertItems(final List<Song> songs, final int offset, int len, final int base) {
|
@NonNull
|
||||||
|
public static ContentValues[] makeInsertItems(@NonNull final List<Song> songs, final int offset, int len, final int base) {
|
||||||
if (offset + len > songs.size()) {
|
if (offset + len > songs.size()) {
|
||||||
len = songs.size() - offset;
|
len = songs.size() - offset;
|
||||||
}
|
}
|
||||||
|
|
@ -139,7 +142,7 @@ public class PlaylistsUtil {
|
||||||
return contentValues;
|
return contentValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeFromPlaylist(final Context context, final Song song, int playlistId) {
|
public static void removeFromPlaylist(@NonNull final Context context, @NonNull final Song song, int playlistId) {
|
||||||
Uri uri = MediaStore.Audio.Playlists.Members.getContentUri(
|
Uri uri = MediaStore.Audio.Playlists.Members.getContentUri(
|
||||||
"external", playlistId);
|
"external", playlistId);
|
||||||
String selection = MediaStore.Audio.Playlists.Members.AUDIO_ID + " =?";
|
String selection = MediaStore.Audio.Playlists.Members.AUDIO_ID + " =?";
|
||||||
|
|
@ -149,7 +152,7 @@ public class PlaylistsUtil {
|
||||||
App.bus.post(new DataBaseChangedEvent(DataBaseChangedEvent.PLAYLISTS_CHANGED));
|
App.bus.post(new DataBaseChangedEvent(DataBaseChangedEvent.PLAYLISTS_CHANGED));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeFromPlaylist(final Context context, final List<PlaylistSong> songs) {
|
public static void removeFromPlaylist(@NonNull final Context context, @NonNull final List<PlaylistSong> songs) {
|
||||||
final int playlistId = songs.get(0).playlistId;
|
final int playlistId = songs.get(0).playlistId;
|
||||||
Uri uri = MediaStore.Audio.Playlists.Members.getContentUri(
|
Uri uri = MediaStore.Audio.Playlists.Members.getContentUri(
|
||||||
"external", playlistId);
|
"external", playlistId);
|
||||||
|
|
@ -165,7 +168,7 @@ public class PlaylistsUtil {
|
||||||
App.bus.post(new DataBaseChangedEvent(DataBaseChangedEvent.PLAYLISTS_CHANGED));
|
App.bus.post(new DataBaseChangedEvent(DataBaseChangedEvent.PLAYLISTS_CHANGED));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean doPlaylistContains(final Context context, final long playlistId, final int songId) {
|
public static boolean doPlaylistContains(@NonNull final Context context, final long playlistId, final int songId) {
|
||||||
if (playlistId != -1) {
|
if (playlistId != -1) {
|
||||||
Cursor c = context.getContentResolver().query(
|
Cursor c = context.getContentResolver().query(
|
||||||
MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId),
|
MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId),
|
||||||
|
|
@ -195,12 +198,12 @@ public class PlaylistsUtil {
|
||||||
// return 0;
|
// return 0;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public static boolean moveItem(final Context context, int playlistId, int from, int to) {
|
public static boolean moveItem(@NonNull final Context context, int playlistId, int from, int to) {
|
||||||
return MediaStore.Audio.Playlists.Members.moveItem(context.getContentResolver(),
|
return MediaStore.Audio.Playlists.Members.moveItem(context.getContentResolver(),
|
||||||
playlistId, from, to);
|
playlistId, from, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void renamePlaylist(final Context context, final long id, final String newName) {
|
public static void renamePlaylist(@NonNull final Context context, final long id, final String newName) {
|
||||||
ContentValues contentValues = new ContentValues();
|
ContentValues contentValues = new ContentValues();
|
||||||
contentValues.put(MediaStore.Audio.PlaylistsColumns.NAME, newName);
|
contentValues.put(MediaStore.Audio.PlaylistsColumns.NAME, newName);
|
||||||
context.getContentResolver().update(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
|
context.getContentResolver().update(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
|
||||||
|
|
@ -210,7 +213,7 @@ public class PlaylistsUtil {
|
||||||
App.bus.post(new DataBaseChangedEvent(DataBaseChangedEvent.PLAYLISTS_CHANGED));
|
App.bus.post(new DataBaseChangedEvent(DataBaseChangedEvent.PLAYLISTS_CHANGED));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getNameForPlaylist(final Context context, final long id) {
|
public static String getNameForPlaylist(@NonNull final Context context, final long id) {
|
||||||
Cursor cursor = context.getContentResolver().query(
|
Cursor cursor = context.getContentResolver().query(
|
||||||
MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
|
MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
|
||||||
new String[]{MediaStore.Audio.PlaylistsColumns.NAME},
|
new String[]{MediaStore.Audio.PlaylistsColumns.NAME},
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import com.kabouzeid.gramophone.R;
|
import com.kabouzeid.gramophone.R;
|
||||||
|
|
||||||
|
|
@ -49,15 +51,16 @@ public final class PreferenceUtils {
|
||||||
|
|
||||||
private static PreferenceUtils sInstance;
|
private static PreferenceUtils sInstance;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final SharedPreferences mPreferences;
|
private final SharedPreferences mPreferences;
|
||||||
|
|
||||||
public PreferenceUtils(final Context context) {
|
public PreferenceUtils(@NonNull final Context context) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mPreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
mPreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PreferenceUtils getInstance(final Context context) {
|
public static PreferenceUtils getInstance(@NonNull final Context context) {
|
||||||
if (sInstance == null) {
|
if (sInstance == null) {
|
||||||
sInstance = new PreferenceUtils(context.getApplicationContext());
|
sInstance = new PreferenceUtils(context.getApplicationContext());
|
||||||
}
|
}
|
||||||
|
|
@ -204,29 +207,35 @@ public final class PreferenceUtils {
|
||||||
return mPreferences.getBoolean(IGNORE_MEDIA_STORE_ARTWORK, false);
|
return mPreferences.getBoolean(IGNORE_MEDIA_STORE_ARTWORK, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public final String getArtistSortOrder() {
|
public final String getArtistSortOrder() {
|
||||||
return mPreferences.getString(ARTIST_SORT_ORDER, SortOrder.ArtistSortOrder.ARTIST_A_Z);
|
return mPreferences.getString(ARTIST_SORT_ORDER, SortOrder.ArtistSortOrder.ARTIST_A_Z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public final String getArtistSongSortOrder() {
|
public final String getArtistSongSortOrder() {
|
||||||
return mPreferences.getString(ARTIST_SONG_SORT_ORDER,
|
return mPreferences.getString(ARTIST_SONG_SORT_ORDER,
|
||||||
SortOrder.ArtistSongSortOrder.SONG_A_Z);
|
SortOrder.ArtistSongSortOrder.SONG_A_Z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public final String getArtistAlbumSortOrder() {
|
public final String getArtistAlbumSortOrder() {
|
||||||
return mPreferences.getString(ARTIST_ALBUM_SORT_ORDER,
|
return mPreferences.getString(ARTIST_ALBUM_SORT_ORDER,
|
||||||
SortOrder.ArtistAlbumSortOrder.ALBUM_YEAR_ASC);
|
SortOrder.ArtistAlbumSortOrder.ALBUM_YEAR_ASC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public final String getAlbumSortOrder() {
|
public final String getAlbumSortOrder() {
|
||||||
return mPreferences.getString(ALBUM_SORT_ORDER, SortOrder.AlbumSortOrder.ALBUM_A_Z);
|
return mPreferences.getString(ALBUM_SORT_ORDER, SortOrder.AlbumSortOrder.ALBUM_A_Z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public final String getAlbumSongSortOrder() {
|
public final String getAlbumSongSortOrder() {
|
||||||
return mPreferences.getString(ALBUM_SONG_SORT_ORDER,
|
return mPreferences.getString(ALBUM_SONG_SORT_ORDER,
|
||||||
SortOrder.AlbumSongSortOrder.SONG_TRACK_LIST);
|
SortOrder.AlbumSongSortOrder.SONG_TRACK_LIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public final String getSongSortOrder() {
|
public final String getSongSortOrder() {
|
||||||
return mPreferences.getString(SONG_SORT_ORDER, SortOrder.SongSortOrder.SONG_A_Z);
|
return mPreferences.getString(SONG_SORT_ORDER, SortOrder.SongSortOrder.SONG_A_Z);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ import android.os.Build;
|
||||||
import android.support.annotation.AttrRes;
|
import android.support.annotation.AttrRes;
|
||||||
import android.support.annotation.ColorInt;
|
import android.support.annotation.ColorInt;
|
||||||
import android.support.annotation.DrawableRes;
|
import android.support.annotation.DrawableRes;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
@ -36,7 +38,7 @@ public class Util {
|
||||||
// return resId;
|
// return resId;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public static int resolveColor(Context context, @AttrRes int colorAttr) {
|
public static int resolveColor(@NonNull Context context, @AttrRes int colorAttr) {
|
||||||
TypedArray a = context.obtainStyledAttributes(new int[]{colorAttr});
|
TypedArray a = context.obtainStyledAttributes(new int[]{colorAttr});
|
||||||
int resId = a.getColor(0, 0);
|
int resId = a.getColor(0, 0);
|
||||||
a.recycle();
|
a.recycle();
|
||||||
|
|
@ -50,7 +52,7 @@ public class Util {
|
||||||
// return result;
|
// return result;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public static int getActionBarSize(Context context) {
|
public static int getActionBarSize(@NonNull Context context) {
|
||||||
TypedValue typedValue = new TypedValue();
|
TypedValue typedValue = new TypedValue();
|
||||||
int[] textSizeAttr = new int[]{R.attr.actionBarSize};
|
int[] textSizeAttr = new int[]{R.attr.actionBarSize};
|
||||||
int indexOfAttrTextSize = 0;
|
int indexOfAttrTextSize = 0;
|
||||||
|
|
@ -60,7 +62,7 @@ public class Util {
|
||||||
return actionBarSize;
|
return actionBarSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getStatusBarHeight(Context context) {
|
public static int getStatusBarHeight(@NonNull Context context) {
|
||||||
int result = 0;
|
int result = 0;
|
||||||
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
|
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
|
||||||
if (resourceId > 0) {
|
if (resourceId > 0) {
|
||||||
|
|
@ -69,7 +71,7 @@ public class Util {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getNavigationBarHeight(Context context) {
|
public static int getNavigationBarHeight(@NonNull Context context) {
|
||||||
int result = 0;
|
int result = 0;
|
||||||
int resourceId = context.getResources().getIdentifier("navigation_bar_height", "dimen", "android");
|
int resourceId = context.getResources().getIdentifier("navigation_bar_height", "dimen", "android");
|
||||||
if (resourceId > 0) {
|
if (resourceId > 0) {
|
||||||
|
|
@ -96,7 +98,7 @@ public class Util {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
@TargetApi(19)
|
@TargetApi(19)
|
||||||
public static void setStatusBarTranslucent(Window window, boolean translucent) {
|
public static void setStatusBarTranslucent(@NonNull Window window, boolean translucent) {
|
||||||
if (translucent) {
|
if (translucent) {
|
||||||
window.setFlags(
|
window.setFlags(
|
||||||
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
|
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
|
||||||
|
|
@ -112,12 +114,13 @@ public class Util {
|
||||||
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
|
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setAllowDrawUnderStatusBar(Window window) {
|
public static void setAllowDrawUnderStatusBar(@NonNull Window window) {
|
||||||
window.getDecorView().setSystemUiVisibility(
|
window.getDecorView().setSystemUiVisibility(
|
||||||
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||||
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
|
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public static String getFileSizeString(long sizeInBytes) {
|
public static String getFileSizeString(long sizeInBytes) {
|
||||||
long fileSizeInKB = sizeInBytes / 1024;
|
long fileSizeInKB = sizeInBytes / 1024;
|
||||||
long fileSizeInMB = fileSizeInKB / 1024;
|
long fileSizeInMB = fileSizeInKB / 1024;
|
||||||
|
|
@ -142,7 +145,7 @@ public class Util {
|
||||||
// return Bitmap.createScaledBitmap(bitmap, albumArtSize, albumArtSize, false);
|
// return Bitmap.createScaledBitmap(bitmap, albumArtSize, albumArtSize, false);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public static void hideSoftKeyboard(Activity activity) {
|
public static void hideSoftKeyboard(@Nullable Activity activity) {
|
||||||
if (activity != null) {
|
if (activity != null) {
|
||||||
View currentFocus = activity.getCurrentFocus();
|
View currentFocus = activity.getCurrentFocus();
|
||||||
if (currentFocus != null) {
|
if (currentFocus != null) {
|
||||||
|
|
@ -160,15 +163,15 @@ public class Util {
|
||||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
|
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isTablet(final Context context) {
|
public static boolean isTablet(@NonNull final Context context) {
|
||||||
return context.getResources().getConfiguration().smallestScreenWidthDp >= 600;
|
return context.getResources().getConfiguration().smallestScreenWidthDp >= 600;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isInPortraitMode(final Context context) {
|
public static boolean isInPortraitMode(@NonNull final Context context) {
|
||||||
return context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
|
return context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Drawable getTintedDrawable(Context context, @DrawableRes int drawableResId, int color) {
|
public static Drawable getTintedDrawable(@NonNull Context context, @DrawableRes int drawableResId, int color) {
|
||||||
Drawable drawable = ContextCompat.getDrawable(context, drawableResId);
|
Drawable drawable = ContextCompat.getDrawable(context, drawableResId);
|
||||||
if (drawable != null) {
|
if (drawable != null) {
|
||||||
drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
|
drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
|
||||||
|
|
@ -195,6 +198,7 @@ public class Util {
|
||||||
return (alpha << 24) + (0x00ffffff & Color.HSVToColor(hsv));
|
return (alpha << 24) + (0x00ffffff & Color.HSVToColor(hsv));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public static ColorStateList getEmptyColorStateList(int color) {
|
public static ColorStateList getEmptyColorStateList(int color) {
|
||||||
return new ColorStateList(
|
return new ColorStateList(
|
||||||
new int[][]{
|
new int[][]{
|
||||||
|
|
@ -205,14 +209,14 @@ public class Util {
|
||||||
}
|
}
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
|
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
|
||||||
public static boolean isRTL(Context context) {
|
public static boolean isRTL(@NonNull Context context) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||||
Configuration config = context.getResources().getConfiguration();
|
Configuration config = context.getResources().getConfiguration();
|
||||||
return config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
|
return config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
|
||||||
} else return false;
|
} else return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth, boolean recycleOld) {
|
public static Bitmap getResizedBitmap(@NonNull Bitmap bm, int newHeight, int newWidth, boolean recycleOld) {
|
||||||
int width = bm.getWidth();
|
int width = bm.getWidth();
|
||||||
int height = bm.getHeight();
|
int height = bm.getHeight();
|
||||||
float scaleWidth = ((float) newWidth) / width;
|
float scaleWidth = ((float) newWidth) / width;
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@ package com.kabouzeid.gramophone.util;
|
||||||
import android.animation.ArgbEvaluator;
|
import android.animation.ArgbEvaluator;
|
||||||
import android.animation.ObjectAnimator;
|
import android.animation.ObjectAnimator;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.internal.view.menu.ListMenuItemView;
|
import android.support.v7.internal.view.menu.ListMenuItemView;
|
||||||
import android.support.v7.internal.view.menu.MenuPopupHelper;
|
import android.support.v7.internal.view.menu.MenuPopupHelper;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
@ -26,7 +28,7 @@ import java.lang.reflect.Field;
|
||||||
public class ViewUtil {
|
public class ViewUtil {
|
||||||
public final static int DEFAULT_COLOR_ANIMATION_DURATION = 500;
|
public final static int DEFAULT_COLOR_ANIMATION_DURATION = 500;
|
||||||
|
|
||||||
public static void disableViews(ViewGroup layout) {
|
public static void disableViews(@NonNull ViewGroup layout) {
|
||||||
for (int i = 0; i < layout.getChildCount(); i++) {
|
for (int i = 0; i < layout.getChildCount(); i++) {
|
||||||
View child = layout.getChildAt(i);
|
View child = layout.getChildAt(i);
|
||||||
if (child instanceof ViewGroup) {
|
if (child instanceof ViewGroup) {
|
||||||
|
|
@ -37,7 +39,7 @@ public class ViewUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void enableViews(ViewGroup layout) {
|
public static void enableViews(@NonNull ViewGroup layout) {
|
||||||
for (int i = 0; i < layout.getChildCount(); i++) {
|
for (int i = 0; i < layout.getChildCount(); i++) {
|
||||||
View child = layout.getChildAt(i);
|
View child = layout.getChildAt(i);
|
||||||
if (child instanceof ViewGroup) {
|
if (child instanceof ViewGroup) {
|
||||||
|
|
@ -48,7 +50,7 @@ public class ViewUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setListViewHeightBasedOnChildren(ListView listView) {
|
public static void setListViewHeightBasedOnChildren(@NonNull ListView listView) {
|
||||||
ListAdapter listAdapter = listView.getAdapter();
|
ListAdapter listAdapter = listView.getAdapter();
|
||||||
if (listAdapter == null)
|
if (listAdapter == null)
|
||||||
return;
|
return;
|
||||||
|
|
@ -100,13 +102,13 @@ public class ViewUtil {
|
||||||
animator.start();
|
animator.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setBackgroundAlpha(View view, float alpha, int baseColor) {
|
public static void setBackgroundAlpha(@NonNull View view, float alpha, int baseColor) {
|
||||||
int a = Math.min(255, Math.max(0, (int) (alpha * 255))) << 24;
|
int a = Math.min(255, Math.max(0, (int) (alpha * 255))) << 24;
|
||||||
int rgb = 0x00ffffff & baseColor;
|
int rgb = 0x00ffffff & baseColor;
|
||||||
view.setBackgroundColor(a + rgb);
|
view.setBackgroundColor(a + rgb);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addOnGlobalLayoutListener(final View view, final Runnable runnable) {
|
public static void addOnGlobalLayoutListener(@NonNull final View view, @NonNull final Runnable runnable) {
|
||||||
ViewTreeObserver vto = view.getViewTreeObserver();
|
ViewTreeObserver vto = view.getViewTreeObserver();
|
||||||
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -134,7 +136,7 @@ public class ViewUtil {
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public static void setCheckBoxTintForMenu(MenuPopupHelper menuPopupHelper) {
|
public static void setCheckBoxTintForMenu(@Nullable MenuPopupHelper menuPopupHelper) {
|
||||||
if (menuPopupHelper != null) {
|
if (menuPopupHelper != null) {
|
||||||
final ListView listView = menuPopupHelper.getPopup().getListView();
|
final ListView listView = menuPopupHelper.getPopup().getListView();
|
||||||
listView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
listView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@ import android.graphics.Matrix;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.graphics.PorterDuffColorFilter;
|
import android.graphics.PorterDuffColorFilter;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
|
|
||||||
|
|
@ -18,20 +20,23 @@ import com.kabouzeid.gramophone.util.Util;
|
||||||
public class ColorView extends FrameLayout {
|
public class ColorView extends FrameLayout {
|
||||||
|
|
||||||
private final Bitmap mCheck;
|
private final Bitmap mCheck;
|
||||||
|
@NonNull
|
||||||
private final Paint paint;
|
private final Paint paint;
|
||||||
|
@NonNull
|
||||||
private final Paint paintBorder;
|
private final Paint paintBorder;
|
||||||
|
@Nullable
|
||||||
private Paint paintCheck;
|
private Paint paintCheck;
|
||||||
private final int borderWidth;
|
private final int borderWidth;
|
||||||
|
|
||||||
public ColorView(Context context) {
|
public ColorView(@NonNull Context context) {
|
||||||
this(context, null, 0);
|
this(context, null, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ColorView(Context context, AttributeSet attrs) {
|
public ColorView(@NonNull Context context, AttributeSet attrs) {
|
||||||
this(context, attrs, 0);
|
this(context, attrs, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ColorView(Context context, AttributeSet attrs, int defStyleAttr) {
|
public ColorView(@NonNull Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
super(context, attrs, defStyleAttr);
|
super(context, attrs, defStyleAttr);
|
||||||
final int checkSize = (int) context.getResources().getDimension(R.dimen.circle_view_check);
|
final int checkSize = (int) context.getResources().getDimension(R.dimen.circle_view_check);
|
||||||
mCheck = getResizedBitmap(BitmapFactory.decodeResource(context.getResources(),
|
mCheck = getResizedBitmap(BitmapFactory.decodeResource(context.getResources(),
|
||||||
|
|
@ -47,7 +52,7 @@ public class ColorView extends FrameLayout {
|
||||||
setWillNotDraw(false);
|
setWillNotDraw(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {
|
private static Bitmap getResizedBitmap(@NonNull Bitmap bm, int newHeight, int newWidth) {
|
||||||
int width = bm.getWidth();
|
int width = bm.getWidth();
|
||||||
int height = bm.getHeight();
|
int height = bm.getHeight();
|
||||||
float scaleWidth = ((float) newWidth) / width;
|
float scaleWidth = ((float) newWidth) / width;
|
||||||
|
|
@ -88,7 +93,7 @@ public class ColorView extends FrameLayout {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDraw(Canvas canvas) {
|
protected void onDraw(@NonNull Canvas canvas) {
|
||||||
super.onDraw(canvas);
|
super.onDraw(canvas);
|
||||||
|
|
||||||
int canvasSize = canvas.getWidth();
|
int canvasSize = canvas.getWidth();
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import android.content.res.ColorStateList;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.support.v4.graphics.ColorUtils;
|
import android.support.v4.graphics.ColorUtils;
|
||||||
import android.support.v4.graphics.drawable.DrawableCompat;
|
import android.support.v4.graphics.drawable.DrawableCompat;
|
||||||
|
|
@ -25,17 +26,17 @@ public class DynamicSwitch extends SwitchCompat {
|
||||||
static final int[] CHECKED_STATE_SET = new int[]{android.R.attr.state_checked};
|
static final int[] CHECKED_STATE_SET = new int[]{android.R.attr.state_checked};
|
||||||
static final int[] EMPTY_STATE_SET = new int[0];
|
static final int[] EMPTY_STATE_SET = new int[0];
|
||||||
|
|
||||||
public DynamicSwitch(Context context) {
|
public DynamicSwitch(@NonNull Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
public DynamicSwitch(Context context, AttributeSet attrs) {
|
public DynamicSwitch(@NonNull Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
public DynamicSwitch(Context context, AttributeSet attrs, int defStyleAttr) {
|
public DynamicSwitch(@NonNull Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
super(context, attrs, defStyleAttr);
|
super(context, attrs, defStyleAttr);
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
@ -45,7 +46,7 @@ public class DynamicSwitch extends SwitchCompat {
|
||||||
setTint(this, color);
|
setTint(this, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setTint(SwitchCompat switchCompat, int color) {
|
public static void setTint(@NonNull SwitchCompat switchCompat, int color) {
|
||||||
ColorStateList trackColorSl = createSwitchTrackColorStateList(switchCompat.getContext(), color);
|
ColorStateList trackColorSl = createSwitchTrackColorStateList(switchCompat.getContext(), color);
|
||||||
ColorStateList thumbColorSl = createSwitchThumbColorStateList(switchCompat.getContext(), color);
|
ColorStateList thumbColorSl = createSwitchThumbColorStateList(switchCompat.getContext(), color);
|
||||||
|
|
||||||
|
|
@ -59,7 +60,8 @@ public class DynamicSwitch extends SwitchCompat {
|
||||||
switchCompat.setTrackDrawable(trackDrawable);
|
switchCompat.setTrackDrawable(trackDrawable);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ColorStateList createSwitchTrackColorStateList(Context context, int colorActivated) {
|
@NonNull
|
||||||
|
private static ColorStateList createSwitchTrackColorStateList(@NonNull Context context, int colorActivated) {
|
||||||
final int[][] states = new int[3][];
|
final int[][] states = new int[3][];
|
||||||
final int[] colors = new int[3];
|
final int[] colors = new int[3];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
@ -80,7 +82,8 @@ public class DynamicSwitch extends SwitchCompat {
|
||||||
return new ColorStateList(states, colors);
|
return new ColorStateList(states, colors);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ColorStateList createSwitchThumbColorStateList(Context context, int colorActivated) {
|
@NonNull
|
||||||
|
private static ColorStateList createSwitchThumbColorStateList(@NonNull Context context, int colorActivated) {
|
||||||
final int[][] states = new int[3][];
|
final int[][] states = new int[3][];
|
||||||
final int[] colors = new int[3];
|
final int[] colors = new int[3];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import android.graphics.drawable.Drawable;
|
||||||
import android.graphics.drawable.InsetDrawable;
|
import android.graphics.drawable.InsetDrawable;
|
||||||
import android.graphics.drawable.StateListDrawable;
|
import android.graphics.drawable.StateListDrawable;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
|
@ -36,19 +37,20 @@ public class FastScroller extends FrameLayout {
|
||||||
private boolean isHidden;
|
private boolean isHidden;
|
||||||
private int hideTranslationX;
|
private int hideTranslationX;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private ViewPropertyAnimator currentAnimator = null;
|
private ViewPropertyAnimator currentAnimator = null;
|
||||||
|
|
||||||
public FastScroller(Context context, AttributeSet attrs) {
|
public FastScroller(@NonNull Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
initialise(context);
|
initialise(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FastScroller(Context context, AttributeSet attrs, int defStyleAttr) {
|
public FastScroller(@NonNull Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
super(context, attrs, defStyleAttr);
|
super(context, attrs, defStyleAttr);
|
||||||
initialise(context);
|
initialise(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initialise(Context context) {
|
private void initialise(@NonNull Context context) {
|
||||||
hideTranslationX = getContext().getResources().getDimensionPixelSize(R.dimen.scrollbar_width) * (Util.isRTL(context) ? -1 : 1);
|
hideTranslationX = getContext().getResources().getDimensionPixelSize(R.dimen.scrollbar_width) * (Util.isRTL(context) ? -1 : 1);
|
||||||
setClipChildren(false);
|
setClipChildren(false);
|
||||||
inflate(context, R.layout.vertical_recycler_fast_scroller_layout, this);
|
inflate(context, R.layout.vertical_recycler_fast_scroller_layout, this);
|
||||||
|
|
@ -76,7 +78,7 @@ public class FastScroller extends FrameLayout {
|
||||||
return super.onTouchEvent(event);
|
return super.onTouchEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRecyclerView(RecyclerView recyclerView) {
|
public void setRecyclerView(@NonNull RecyclerView recyclerView) {
|
||||||
this.recyclerView = recyclerView;
|
this.recyclerView = recyclerView;
|
||||||
recyclerView.addOnScrollListener(scrollListener);
|
recyclerView.addOnScrollListener(scrollListener);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.kabouzeid.gramophone.views;
|
package com.kabouzeid.gramophone.views;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
|
||||||
|
|
@ -13,11 +14,11 @@ public class HeightFitSquareImageView extends ImageView {
|
||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HeightFitSquareImageView(Context context, AttributeSet attrs) {
|
public HeightFitSquareImageView(@NonNull Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HeightFitSquareImageView(Context context, AttributeSet attrs, int defStyle) {
|
public HeightFitSquareImageView(@NonNull Context context, AttributeSet attrs, int defStyle) {
|
||||||
super(context, attrs, defStyle);
|
super(context, attrs, defStyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.kabouzeid.gramophone.views;
|
package com.kabouzeid.gramophone.views;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
|
||||||
|
|
@ -13,11 +14,11 @@ public class HeightWidthFitSquareImageView extends ImageView {
|
||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HeightWidthFitSquareImageView(Context context, AttributeSet attrs) {
|
public HeightWidthFitSquareImageView(@NonNull Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HeightWidthFitSquareImageView(Context context, AttributeSet attrs, int defStyle) {
|
public HeightWidthFitSquareImageView(@NonNull Context context, AttributeSet attrs, int defStyle) {
|
||||||
super(context, attrs, defStyle);
|
super(context, attrs, defStyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import android.graphics.Path;
|
||||||
import android.graphics.PixelFormat;
|
import android.graphics.PixelFormat;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.util.Property;
|
import android.util.Property;
|
||||||
import android.view.animation.DecelerateInterpolator;
|
import android.view.animation.DecelerateInterpolator;
|
||||||
|
|
||||||
|
|
@ -25,12 +26,12 @@ public class PlayPauseDrawable extends Drawable {
|
||||||
private static final Property<PlayPauseDrawable, Float> PROGRESS =
|
private static final Property<PlayPauseDrawable, Float> PROGRESS =
|
||||||
new Property<PlayPauseDrawable, Float>(Float.class, "progress") {
|
new Property<PlayPauseDrawable, Float>(Float.class, "progress") {
|
||||||
@Override
|
@Override
|
||||||
public Float get(PlayPauseDrawable d) {
|
public Float get(@NonNull PlayPauseDrawable d) {
|
||||||
return d.getProgress();
|
return d.getProgress();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void set(PlayPauseDrawable d, Float value) {
|
public void set(@NonNull PlayPauseDrawable d, Float value) {
|
||||||
d.setProgress(value);
|
d.setProgress(value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -51,7 +52,7 @@ public class PlayPauseDrawable extends Drawable {
|
||||||
|
|
||||||
private AnimatorSet animatorSet;
|
private AnimatorSet animatorSet;
|
||||||
|
|
||||||
public PlayPauseDrawable(Context context) {
|
public PlayPauseDrawable(@NonNull Context context) {
|
||||||
final Resources res = context.getResources();
|
final Resources res = context.getResources();
|
||||||
paint.setAntiAlias(true);
|
paint.setAntiAlias(true);
|
||||||
paint.setStyle(Paint.Style.FILL);
|
paint.setStyle(Paint.Style.FILL);
|
||||||
|
|
@ -62,7 +63,7 @@ public class PlayPauseDrawable extends Drawable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onBoundsChange(final Rect bounds) {
|
protected void onBoundsChange(@NonNull final Rect bounds) {
|
||||||
super.onBoundsChange(bounds);
|
super.onBoundsChange(bounds);
|
||||||
if (bounds.width() > 0 && bounds.height() > 0) {
|
if (bounds.width() > 0 && bounds.height() > 0) {
|
||||||
width = bounds.width();
|
width = bounds.width();
|
||||||
|
|
@ -71,7 +72,7 @@ public class PlayPauseDrawable extends Drawable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Canvas canvas) {
|
public void draw(@NonNull Canvas canvas) {
|
||||||
leftPauseBar.rewind();
|
leftPauseBar.rewind();
|
||||||
rightPauseBar.rewind();
|
rightPauseBar.rewind();
|
||||||
|
|
||||||
|
|
@ -126,6 +127,7 @@ public class PlayPauseDrawable extends Drawable {
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private Animator getPausePlayAnimator() {
|
private Animator getPausePlayAnimator() {
|
||||||
isPlaySet = !isPlaySet;
|
isPlaySet = !isPlaySet;
|
||||||
final Animator anim = ObjectAnimator.ofFloat(this, PROGRESS, isPlay ? 1 : 0, isPlay ? 0 : 1);
|
final Animator anim = ObjectAnimator.ofFloat(this, PROGRESS, isPlay ? 1 : 0, isPlay ? 0 : 1);
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue