Imports optimization and entries rearranged

This commit is contained in:
CappielloAntonio 2021-04-27 11:01:02 +02:00
parent 3c2837e096
commit 65e47f61ef
63 changed files with 987 additions and 1087 deletions

View file

@ -56,6 +56,15 @@ public class AlbumAdapter extends RecyclerView.Adapter<AlbumAdapter.ViewHolder>
return albums.size();
}
public Album getItem(int position) {
return albums.get(position);
}
public void setItems(List<Album> albums) {
this.albums = albums;
notifyDataSetChanged();
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
TextView textAlbumName;
TextView textArtistName;
@ -79,11 +88,9 @@ public class AlbumAdapter extends RecyclerView.Adapter<AlbumAdapter.ViewHolder>
if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.searchFragment) {
Navigation.findNavController(view).navigate(R.id.action_searchFragment_to_albumPageFragment, bundle);
}
else if(Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.libraryFragment) {
} else if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.libraryFragment) {
Navigation.findNavController(view).navigate(R.id.action_libraryFragment_to_albumPageFragment, bundle);
}
else if(Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.albumCatalogueFragment) {
} else if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.albumCatalogueFragment) {
Navigation.findNavController(view).navigate(R.id.action_albumCatalogueFragment_to_albumPageFragment, bundle);
}
}
@ -96,13 +103,4 @@ public class AlbumAdapter extends RecyclerView.Adapter<AlbumAdapter.ViewHolder>
return true;
}
}
public Album getItem(int position) {
return albums.get(position);
}
public void setItems(List<Album> albums) {
this.albums = albums;
notifyDataSetChanged();
}
}

View file

@ -54,6 +54,15 @@ public class AlbumArtistPageAdapter extends RecyclerView.Adapter<AlbumArtistPage
return albums.size();
}
public Album getItem(int position) {
return albums.get(position);
}
public void setItems(List<Album> albums) {
this.albums = albums;
notifyDataSetChanged();
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
TextView textAlbumName;
ImageView cover;
@ -83,13 +92,4 @@ public class AlbumArtistPageAdapter extends RecyclerView.Adapter<AlbumArtistPage
return true;
}
}
public Album getItem(int position) {
return albums.get(position);
}
public void setItems(List<Album> albums) {
this.albums = albums;
notifyDataSetChanged();
}
}

View file

@ -31,6 +31,36 @@ public class AlbumCatalogueAdapter extends RecyclerView.Adapter<AlbumCatalogueAd
private LayoutInflater inflater;
private MainActivity activity;
private Context context;
private Filter filtering = new Filter() {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
List<Album> filteredList = new ArrayList<>();
if (constraint == null || constraint.length() == 0) {
filteredList.addAll(albumsFull);
} else {
String filterPattern = constraint.toString().toLowerCase().trim();
for (Album item : albumsFull) {
if (item.getTitle().toLowerCase().contains(filterPattern)) {
filteredList.add(item);
}
}
}
FilterResults results = new FilterResults();
results.values = filteredList;
return results;
}
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
albums.clear();
albums.addAll((List) results.values);
notifyDataSetChanged();
}
};
public AlbumCatalogueAdapter(MainActivity activity, Context context) {
this.activity = activity;
@ -64,6 +94,21 @@ public class AlbumCatalogueAdapter extends RecyclerView.Adapter<AlbumCatalogueAd
return albums.size();
}
public Album getItem(int position) {
return albums.get(position);
}
public void setItems(List<Album> albums) {
this.albums = albums;
this.albumsFull = new ArrayList<>(albums);
notifyDataSetChanged();
}
@Override
public Filter getFilter() {
return filtering;
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
TextView textAlbumName;
TextView textArtistName;
@ -87,15 +132,13 @@ public class AlbumCatalogueAdapter extends RecyclerView.Adapter<AlbumCatalogueAd
if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.searchFragment) {
Navigation.findNavController(view).navigate(R.id.action_searchFragment_to_albumPageFragment, bundle);
}
else if(Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.libraryFragment) {
} else if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.libraryFragment) {
Navigation.findNavController(view).navigate(R.id.action_libraryFragment_to_albumPageFragment, bundle);
}
else if(Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.albumCatalogueFragment) {
} else if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.albumCatalogueFragment) {
Navigation.findNavController(view).navigate(R.id.action_albumCatalogueFragment_to_albumPageFragment, bundle);
}
InputMethodManager imm = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
@ -107,50 +150,4 @@ public class AlbumCatalogueAdapter extends RecyclerView.Adapter<AlbumCatalogueAd
return true;
}
}
public Album getItem(int position) {
return albums.get(position);
}
public void setItems(List<Album> albums) {
this.albums = albums;
this.albumsFull = new ArrayList<>(albums);
notifyDataSetChanged();
}
@Override
public Filter getFilter() {
return filtering;
}
private Filter filtering = new Filter() {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
List<Album> filteredList = new ArrayList<>();
if (constraint == null || constraint.length() == 0) {
filteredList.addAll(albumsFull);
} else {
String filterPattern = constraint.toString().toLowerCase().trim();
for (Album item : albumsFull) {
if (item.getTitle().toLowerCase().contains(filterPattern)) {
filteredList.add(item);
}
}
}
FilterResults results = new FilterResults();
results.values = filteredList;
return results;
}
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
albums.clear();
albums.addAll((List) results.values);
notifyDataSetChanged();
}
};
}

View file

@ -55,6 +55,15 @@ public class ArtistAdapter extends RecyclerView.Adapter<ArtistAdapter.ViewHolder
return artists.size();
}
public Artist getItem(int position) {
return artists.get(position);
}
public void setItems(List<Artist> artists) {
this.artists = artists;
notifyDataSetChanged();
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
TextView textArtistName;
ImageView cover;
@ -76,11 +85,9 @@ public class ArtistAdapter extends RecyclerView.Adapter<ArtistAdapter.ViewHolder
if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.searchFragment) {
Navigation.findNavController(view).navigate(R.id.action_searchFragment_to_artistPageFragment, bundle);
}
else if(Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.libraryFragment) {
} else if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.libraryFragment) {
Navigation.findNavController(view).navigate(R.id.action_libraryFragment_to_artistPageFragment, bundle);
}
else if(Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.artistCatalogueFragment) {
} else if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.artistCatalogueFragment) {
Navigation.findNavController(view).navigate(R.id.action_artistCatalogueFragment_to_artistPageFragment, bundle);
}
}
@ -93,13 +100,4 @@ public class ArtistAdapter extends RecyclerView.Adapter<ArtistAdapter.ViewHolder
return true;
}
}
public Artist getItem(int position) {
return artists.get(position);
}
public void setItems(List<Artist> artists) {
this.artists = artists;
notifyDataSetChanged();
}
}

View file

@ -31,6 +31,36 @@ public class ArtistCatalogueAdapter extends RecyclerView.Adapter<ArtistCatalogue
private LayoutInflater inflater;
private MainActivity activity;
private Context context;
private Filter filtering = new Filter() {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
List<Artist> filteredList = new ArrayList<>();
if (constraint == null || constraint.length() == 0) {
filteredList.addAll(artistFull);
} else {
String filterPattern = constraint.toString().toLowerCase().trim();
for (Artist item : artistFull) {
if (item.getName().toLowerCase().contains(filterPattern)) {
filteredList.add(item);
}
}
}
FilterResults results = new FilterResults();
results.values = filteredList;
return results;
}
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
artists.clear();
artists.addAll((List) results.values);
notifyDataSetChanged();
}
};
public ArtistCatalogueAdapter(MainActivity activity, Context context) {
this.activity = activity;
@ -62,6 +92,21 @@ public class ArtistCatalogueAdapter extends RecyclerView.Adapter<ArtistCatalogue
return artists.size();
}
public Artist getItem(int position) {
return artists.get(position);
}
public void setItems(List<Artist> artists) {
this.artists = artists;
this.artistFull = new ArrayList<>(artists);
notifyDataSetChanged();
}
@Override
public Filter getFilter() {
return filtering;
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
TextView textArtistName;
ImageView cover;
@ -83,15 +128,13 @@ public class ArtistCatalogueAdapter extends RecyclerView.Adapter<ArtistCatalogue
if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.searchFragment) {
Navigation.findNavController(view).navigate(R.id.action_searchFragment_to_artistPageFragment, bundle);
}
else if(Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.libraryFragment) {
} else if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.libraryFragment) {
Navigation.findNavController(view).navigate(R.id.action_libraryFragment_to_artistPageFragment, bundle);
}
else if(Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.artistCatalogueFragment) {
} else if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.artistCatalogueFragment) {
Navigation.findNavController(view).navigate(R.id.action_artistCatalogueFragment_to_artistPageFragment, bundle);
}
InputMethodManager imm = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
@ -103,50 +146,4 @@ public class ArtistCatalogueAdapter extends RecyclerView.Adapter<ArtistCatalogue
return true;
}
}
public Artist getItem(int position) {
return artists.get(position);
}
public void setItems(List<Artist> artists) {
this.artists = artists;
this.artistFull = new ArrayList<>(artists);
notifyDataSetChanged();
}
@Override
public Filter getFilter() {
return filtering;
}
private Filter filtering = new Filter() {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
List<Artist> filteredList = new ArrayList<>();
if (constraint == null || constraint.length() == 0) {
filteredList.addAll(artistFull);
} else {
String filterPattern = constraint.toString().toLowerCase().trim();
for (Artist item : artistFull) {
if (item.getName().toLowerCase().contains(filterPattern)) {
filteredList.add(item);
}
}
}
FilterResults results = new FilterResults();
results.values = filteredList;
return results;
}
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
artists.clear();
artists.addAll((List) results.values);
notifyDataSetChanged();
}
};
}

View file

@ -13,10 +13,10 @@ import androidx.recyclerview.widget.RecyclerView;
import com.cappielloantonio.play.App;
import com.cappielloantonio.play.R;
import com.cappielloantonio.play.glide.CustomGlideRequest;
import com.cappielloantonio.play.service.MusicPlayerRemote;
import com.cappielloantonio.play.interfaces.MediaCallback;
import com.cappielloantonio.play.model.Song;
import com.cappielloantonio.play.repository.QueueRepository;
import com.cappielloantonio.play.service.MusicPlayerRemote;
import com.cappielloantonio.play.ui.activity.MainActivity;
import com.cappielloantonio.play.util.PreferenceUtil;
import com.cappielloantonio.play.util.SyncUtil;
@ -63,6 +63,11 @@ public class DiscoverSongAdapter extends RecyclerView.Adapter<DiscoverSongAdapte
return songs.size();
}
public void setItems(List<Song> songs) {
this.songs = songs;
notifyDataSetChanged();
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView textTitle;
TextView textAlbum;
@ -100,9 +105,4 @@ public class DiscoverSongAdapter extends RecyclerView.Adapter<DiscoverSongAdapte
}, SyncUtil.SONG, songs.get(getBindingAdapterPosition()).getId(), PreferenceUtil.getInstance(context).getInstantMixSongNumber());
}
}
public void setItems(List<Song> songs) {
this.songs = songs;
notifyDataSetChanged();
}
}

View file

@ -46,6 +46,23 @@ public class GenreAdapter extends RecyclerView.Adapter<GenreAdapter.ViewHolder>
return genres.size();
}
public Genre getItem(int position) {
return genres.get(position);
}
public void setItems(List<Genre> genres) {
this.genres = genres;
notifyDataSetChanged();
}
public void setClickListener(ItemClickListener itemClickListener) {
this.itemClickListener = itemClickListener;
}
public interface ItemClickListener {
void onItemClick(View view, int position);
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView textGenre;
@ -63,21 +80,4 @@ public class GenreAdapter extends RecyclerView.Adapter<GenreAdapter.ViewHolder>
itemClickListener.onItemClick(view, getBindingAdapterPosition());
}
}
public Genre getItem(int position) {
return genres.get(position);
}
public void setItems(List<Genre> genres) {
this.genres = genres;
notifyDataSetChanged();
}
public void setClickListener(ItemClickListener itemClickListener) {
this.itemClickListener = itemClickListener;
}
public interface ItemClickListener {
void onItemClick(View view, int position);
}
}

View file

@ -27,78 +27,6 @@ public class GenreCatalogueAdapter extends RecyclerView.Adapter<GenreCatalogueAd
private MainActivity activity;
private Context context;
private ItemClickListener itemClickListener;
public GenreCatalogueAdapter(MainActivity activity, Context context) {
this.activity = activity;
this.context = context;
this.mInflater = LayoutInflater.from(context);
this.genres = new ArrayList<>();
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = mInflater.inflate(R.layout.item_library_catalogue_genre, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
Genre genre = genres.get(position);
holder.textGenre.setText(genre.getName());
}
@Override
public int getItemCount() {
return genres.size();
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView textGenre;
ViewHolder(View itemView) {
super(itemView);
textGenre = itemView.findViewById(R.id.genre_label);
itemView.setOnClickListener(this);
}
@Override
public void onClick(View view) {
if (itemClickListener != null) {
itemClickListener.onItemClick(view, getBindingAdapterPosition());
InputMethodManager imm = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
}
public Genre getItem(int position) {
return genres.get(position);
}
public void setItems(List<Genre> genres) {
this.genres = genres;
this.genresFull = new ArrayList<>(genres);
notifyDataSetChanged();
}
public void setClickListener(ItemClickListener itemClickListener) {
this.itemClickListener = itemClickListener;
}
public interface ItemClickListener {
void onItemClick(View view, int position);
}
@Override
public Filter getFilter() {
return filtering;
}
private Filter filtering = new Filter() {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
@ -129,4 +57,74 @@ public class GenreCatalogueAdapter extends RecyclerView.Adapter<GenreCatalogueAd
notifyDataSetChanged();
}
};
public GenreCatalogueAdapter(MainActivity activity, Context context) {
this.activity = activity;
this.context = context;
this.mInflater = LayoutInflater.from(context);
this.genres = new ArrayList<>();
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = mInflater.inflate(R.layout.item_library_catalogue_genre, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
Genre genre = genres.get(position);
holder.textGenre.setText(genre.getName());
}
@Override
public int getItemCount() {
return genres.size();
}
public Genre getItem(int position) {
return genres.get(position);
}
public void setItems(List<Genre> genres) {
this.genres = genres;
this.genresFull = new ArrayList<>(genres);
notifyDataSetChanged();
}
public void setClickListener(ItemClickListener itemClickListener) {
this.itemClickListener = itemClickListener;
}
@Override
public Filter getFilter() {
return filtering;
}
public interface ItemClickListener {
void onItemClick(View view, int position);
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView textGenre;
ViewHolder(View itemView) {
super(itemView);
textGenre = itemView.findViewById(R.id.genre_label);
itemView.setOnClickListener(this);
}
@Override
public void onClick(View view) {
if (itemClickListener != null) {
itemClickListener.onItemClick(view, getBindingAdapterPosition());
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
}
}

View file

@ -10,8 +10,8 @@ import androidx.recyclerview.widget.RecyclerView;
import com.cappielloantonio.play.R;
import com.cappielloantonio.play.glide.CustomGlideRequest;
import com.cappielloantonio.play.service.MusicPlayerRemote;
import com.cappielloantonio.play.model.Song;
import com.cappielloantonio.play.service.MusicPlayerRemote;
import java.util.ArrayList;
import java.util.List;
@ -50,6 +50,19 @@ public class PlayerNowPlayingSongAdapter extends RecyclerView.Adapter<PlayerNowP
return songs.size();
}
public Song getItem(int position) {
try {
return songs.get(position);
} catch (IndexOutOfBoundsException e) {
return null;
}
}
public void setItems(List<Song> songs) {
this.songs = songs;
notifyDataSetChanged();
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
ImageView cover;
@ -70,17 +83,4 @@ public class PlayerNowPlayingSongAdapter extends RecyclerView.Adapter<PlayerNowP
}
}
}
public Song getItem(int position) {
try {
return songs.get(position);
} catch ( IndexOutOfBoundsException e ) {
return null;
}
}
public void setItems(List<Song> songs) {
this.songs = songs;
notifyDataSetChanged();
}
}

View file

@ -11,8 +11,8 @@ import androidx.recyclerview.widget.RecyclerView;
import com.cappielloantonio.play.R;
import com.cappielloantonio.play.glide.CustomGlideRequest;
import com.cappielloantonio.play.service.MusicPlayerRemote;
import com.cappielloantonio.play.model.Song;
import com.cappielloantonio.play.service.MusicPlayerRemote;
import com.cappielloantonio.play.ui.fragment.PlayerBottomSheetFragment;
import com.cappielloantonio.play.util.MusicUtil;
@ -56,7 +56,7 @@ public class PlayerSongQueueAdapter extends RecyclerView.Adapter<PlayerSongQueue
.build()
.into(holder.cover);
if(position < MusicPlayerRemote.getPosition()) {
if (position < MusicPlayerRemote.getPosition()) {
holder.songTitle.setTextColor(context.getResources().getColor(R.color.songToPlayTextColor, null));
holder.songArtist.setTextColor(context.getResources().getColor(R.color.songToPlayTextColor, null));
holder.songDuration.setTextColor(context.getResources().getColor(R.color.songToPlayTextColor, null));
@ -68,6 +68,19 @@ public class PlayerSongQueueAdapter extends RecyclerView.Adapter<PlayerSongQueue
return songs.size();
}
public List<Song> getItems() {
return this.songs;
}
public void setItems(List<Song> songs) {
this.songs = songs;
notifyDataSetChanged();
}
public Song getItem(int id) {
return songs.get(id);
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView songTitle;
TextView songArtist;
@ -93,17 +106,4 @@ public class PlayerSongQueueAdapter extends RecyclerView.Adapter<PlayerSongQueue
MusicPlayerRemote.openQueue(songs, getBindingAdapterPosition(), true);
}
}
public void setItems(List<Song> songs) {
this.songs = songs;
notifyDataSetChanged();
}
public List<Song> getItems() {
return this.songs;
}
public Song getItem(int id) {
return songs.get(id);
}
}

View file

@ -56,6 +56,15 @@ public class PlaylistAdapter extends RecyclerView.Adapter<PlaylistAdapter.ViewHo
return playlists.size();
}
public Playlist getItem(int position) {
return playlists.get(position);
}
public void setItems(List<Playlist> playlists) {
this.playlists = playlists;
notifyDataSetChanged();
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView textPlaylistName;
ImageView cover;
@ -77,13 +86,4 @@ public class PlaylistAdapter extends RecyclerView.Adapter<PlaylistAdapter.ViewHo
}
}
public Playlist getItem(int position) {
return playlists.get(position);
}
public void setItems(List<Playlist> playlists) {
this.playlists = playlists;
notifyDataSetChanged();
}
}

View file

@ -29,6 +29,36 @@ public class PlaylistCatalogueAdapter extends RecyclerView.Adapter<PlaylistCatal
private LayoutInflater mInflater;
private MainActivity activity;
private Context context;
private Filter filtering = new Filter() {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
List<Playlist> filteredList = new ArrayList<>();
if (constraint == null || constraint.length() == 0) {
filteredList.addAll(playlistsFull);
} else {
String filterPattern = constraint.toString().toLowerCase().trim();
for (Playlist item : playlistsFull) {
if (item.getName().toLowerCase().contains(filterPattern)) {
filteredList.add(item);
}
}
}
FilterResults results = new FilterResults();
results.values = filteredList;
return results;
}
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
playlists.clear();
playlists.addAll((List) results.values);
notifyDataSetChanged();
}
};
public PlaylistCatalogueAdapter(MainActivity activity, Context context) {
this.activity = activity;
@ -60,6 +90,21 @@ public class PlaylistCatalogueAdapter extends RecyclerView.Adapter<PlaylistCatal
return playlists.size();
}
public Playlist getItem(int position) {
return playlists.get(position);
}
public void setItems(List<Playlist> playlists) {
this.playlists = playlists;
this.playlistsFull = new ArrayList<>(playlists);
notifyDataSetChanged();
}
@Override
public Filter getFilter() {
return filtering;
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView textPlaylistName;
ImageView cover;
@ -79,54 +124,8 @@ public class PlaylistCatalogueAdapter extends RecyclerView.Adapter<PlaylistCatal
bundle.putParcelable("playlist_object", playlists.get(getBindingAdapterPosition()));
Navigation.findNavController(view).navigate(R.id.action_playlistCatalogueFragment_to_playlistPageFragment, bundle);
InputMethodManager imm = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
public Playlist getItem(int position) {
return playlists.get(position);
}
public void setItems(List<Playlist> playlists) {
this.playlists = playlists;
this.playlistsFull = new ArrayList<>(playlists);
notifyDataSetChanged();
}
@Override
public Filter getFilter() {
return filtering;
}
private Filter filtering = new Filter() {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
List<Playlist> filteredList = new ArrayList<>();
if (constraint == null || constraint.length() == 0) {
filteredList.addAll(playlistsFull);
} else {
String filterPattern = constraint.toString().toLowerCase().trim();
for (Playlist item : playlistsFull) {
if (item.getName().toLowerCase().contains(filterPattern)) {
filteredList.add(item);
}
}
}
FilterResults results = new FilterResults();
results.values = filteredList;
return results;
}
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
playlists.clear();
playlists.addAll((List) results.values);
notifyDataSetChanged();
}
};
}

View file

@ -15,9 +15,9 @@ import androidx.recyclerview.widget.RecyclerView;
import com.cappielloantonio.play.App;
import com.cappielloantonio.play.R;
import com.cappielloantonio.play.glide.CustomGlideRequest;
import com.cappielloantonio.play.service.MusicPlayerRemote;
import com.cappielloantonio.play.model.Song;
import com.cappielloantonio.play.repository.QueueRepository;
import com.cappielloantonio.play.service.MusicPlayerRemote;
import com.cappielloantonio.play.ui.activity.MainActivity;
import java.util.ArrayList;
@ -67,6 +67,11 @@ public class RecentMusicAdapter extends RecyclerView.Adapter<RecentMusicAdapter.
return songs.size();
}
public void setItems(List<Song> songs) {
this.songs = songs;
notifyDataSetChanged();
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
TextView textTitle;
TextView textAlbum;
@ -102,9 +107,4 @@ public class RecentMusicAdapter extends RecyclerView.Adapter<RecentMusicAdapter.
return true;
}
}
public void setItems(List<Song> songs) {
this.songs = songs;
notifyDataSetChanged();
}
}

View file

@ -15,9 +15,9 @@ import androidx.recyclerview.widget.RecyclerView;
import com.cappielloantonio.play.App;
import com.cappielloantonio.play.R;
import com.cappielloantonio.play.glide.CustomGlideRequest;
import com.cappielloantonio.play.service.MusicPlayerRemote;
import com.cappielloantonio.play.model.Song;
import com.cappielloantonio.play.repository.QueueRepository;
import com.cappielloantonio.play.service.MusicPlayerRemote;
import com.cappielloantonio.play.ui.activity.MainActivity;
import com.cappielloantonio.play.util.MusicUtil;
@ -75,6 +75,15 @@ public class SongResultSearchAdapter extends RecyclerView.Adapter<SongResultSear
return songs.size();
}
public void setItems(List<Song> songs) {
this.songs = songs;
notifyDataSetChanged();
}
public Song getItem(int id) {
return songs.get(id);
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
TextView songTitle;
TextView songArtist;
@ -127,13 +136,4 @@ public class SongResultSearchAdapter extends RecyclerView.Adapter<SongResultSear
}
}
public void setItems(List<Song> songs) {
this.songs = songs;
notifyDataSetChanged();
}
public Song getItem(int id) {
return songs.get(id);
}
}

View file

@ -43,23 +43,6 @@ public class YearAdapter extends RecyclerView.Adapter<YearAdapter.ViewHolder> {
return years.size();
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView textYear;
ViewHolder(View itemView) {
super(itemView);
textYear = itemView.findViewById(R.id.year_label);
itemView.setOnClickListener(this);
}
@Override
public void onClick(View view) {
if (itemClickListener != null) itemClickListener.onItemClick(view, getBindingAdapterPosition());
}
}
public Integer getItem(int position) {
return years.get(position);
}
@ -76,4 +59,22 @@ public class YearAdapter extends RecyclerView.Adapter<YearAdapter.ViewHolder> {
public interface ItemClickListener {
void onItemClick(View view, int position);
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView textYear;
ViewHolder(View itemView) {
super(itemView);
textYear = itemView.findViewById(R.id.year_label);
itemView.setOnClickListener(this);
}
@Override
public void onClick(View view) {
if (itemClickListener != null)
itemClickListener.onItemClick(view, getBindingAdapterPosition());
}
}
}

View file

@ -36,9 +36,8 @@ import com.cappielloantonio.play.service.MusicService;
* Triple press: previous track
*/
public class MediaButtonIntentReceiver extends BroadcastReceiver {
private static final boolean DEBUG = BuildConfig.DEBUG;
public static final String TAG = MediaButtonIntentReceiver.class.getSimpleName();
private static final boolean DEBUG = BuildConfig.DEBUG;
private static final int MSG_HEADSET_DOUBLE_CLICK_TIMEOUT = 2;
private static final int DOUBLE_CLICK = 400;
@ -85,14 +84,6 @@ public class MediaButtonIntentReceiver extends BroadcastReceiver {
}
};
@Override
public void onReceive(final Context context, final Intent intent) {
if (DEBUG) Log.v(TAG, "Received intent: " + intent);
if (handleIntent(context, intent) && isOrderedBroadcast()) {
abortBroadcast();
}
}
public static boolean handleIntent(final Context context, final Intent intent) {
final String intentAction = intent.getAction();
if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
@ -217,4 +208,12 @@ public class MediaButtonIntentReceiver extends BroadcastReceiver {
mWakeLock = null;
}
}
@Override
public void onReceive(final Context context, final Intent intent) {
if (DEBUG) Log.v(TAG, "Received intent: " + intent);
if (handleIntent(context, intent) && isOrderedBroadcast()) {
abortBroadcast();
}
}
}

View file

@ -32,9 +32,8 @@ import com.cappielloantonio.play.model.SongGenreCross;
@Database(entities = {Album.class, Artist.class, Genre.class, Playlist.class, Song.class, RecentSearch.class, SongGenreCross.class, Queue.class, AlbumArtistCross.class, SongArtistCross.class, PlaylistSongCross.class}, version = 12, exportSchema = false)
public abstract class AppDatabase extends RoomDatabase {
private static final String TAG = "AppDatabase";
private static AppDatabase instance;
private final static String DB_NAME = "play_db";
private static AppDatabase instance;
public static synchronized AppDatabase getInstance(Context context) {

View file

@ -9,7 +9,6 @@ import androidx.room.Query;
import androidx.room.Update;
import com.cappielloantonio.play.model.AlbumArtistCross;
import com.cappielloantonio.play.model.SongGenreCross;
import java.util.List;

View file

@ -2,7 +2,6 @@ package com.cappielloantonio.play.database.dao;
import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;

View file

@ -2,7 +2,6 @@ package com.cappielloantonio.play.database.dao;
import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;

View file

@ -2,12 +2,10 @@ package com.cappielloantonio.play.database.dao;
import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import com.cappielloantonio.play.model.Artist;
import com.cappielloantonio.play.model.Genre;
import java.util.List;

View file

@ -2,13 +2,11 @@ package com.cappielloantonio.play.database.dao;
import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import com.cappielloantonio.play.model.Playlist;
import com.cappielloantonio.play.model.Song;
import java.util.List;

View file

@ -9,7 +9,6 @@ import androidx.room.Query;
import androidx.room.Update;
import com.cappielloantonio.play.model.PlaylistSongCross;
import com.cappielloantonio.play.model.SongArtistCross;
import java.util.List;

View file

@ -2,7 +2,6 @@ package com.cappielloantonio.play.database.dao;
import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;

View file

@ -1,6 +1,5 @@
package com.cappielloantonio.play.database.dao;
import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;

View file

@ -8,7 +8,6 @@ import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.Update;
import com.cappielloantonio.play.model.AlbumArtistCross;
import com.cappielloantonio.play.model.SongArtistCross;
import java.util.List;

View file

@ -2,7 +2,6 @@ package com.cappielloantonio.play.database.dao;
import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;

View file

@ -37,51 +37,6 @@ public class CustomGlideRequest {
public static final DiskCacheStrategy DEFAULT_DISK_CACHE_STRATEGY = DiskCacheStrategy.ALL;
public static final int DEFAULT_IMAGE = R.drawable.default_album_art;
public static class Builder {
private final RequestManager requestManager;
private final Object item;
private final Context context;
private Builder(Context context, String item, String placeholder, String itemType, String quality, String category) {
this.requestManager = Glide.with(context);
this.item = item != null ? createUrl(item, itemType, quality) : MusicUtil.getDefaultPicPerCategory(category);
this.context = context;
if (placeholder != null) {
Bitmap bitmap = BlurHashDecoder.INSTANCE.decode(placeholder, 40, 40, 1, true);
BitmapDrawable drawable = new BitmapDrawable(context.getResources(), bitmap);
requestManager.applyDefaultRequestOptions(createRequestOptions(item, drawable));
} else {
Drawable drawable = ResourcesCompat.getDrawable(context.getResources(), MusicUtil.getDefaultPicPerCategory(category), null);
requestManager.applyDefaultRequestOptions(createRequestOptions(item, drawable));
}
}
public static Builder from(Context context, String item, String placeholder, String itemType, String quality, String category) {
return new Builder(context, item, placeholder, itemType, quality, category);
}
public BitmapBuilder bitmap() {
return new BitmapBuilder(this);
}
public RequestBuilder<Drawable> build() {
return requestManager.load(item);
}
}
public static class BitmapBuilder {
private final Builder builder;
public BitmapBuilder(Builder builder) {
this.builder = builder;
}
public RequestBuilder<Bitmap> build() {
return builder.requestManager.asBitmap().load(builder.item);
}
}
public static RequestOptions createRequestOptions(String item, Drawable placeholder) {
RequestOptions options = new RequestOptions()
.placeholder(placeholder)
@ -130,4 +85,49 @@ public class CustomGlideRequest {
return App.getApiClientInstance(App.getInstance()).GetImageUrl(item, options);
}
public static class Builder {
private final RequestManager requestManager;
private final Object item;
private final Context context;
private Builder(Context context, String item, String placeholder, String itemType, String quality, String category) {
this.requestManager = Glide.with(context);
this.item = item != null ? createUrl(item, itemType, quality) : MusicUtil.getDefaultPicPerCategory(category);
this.context = context;
if (placeholder != null) {
Bitmap bitmap = BlurHashDecoder.INSTANCE.decode(placeholder, 40, 40, 1, true);
BitmapDrawable drawable = new BitmapDrawable(context.getResources(), bitmap);
requestManager.applyDefaultRequestOptions(createRequestOptions(item, drawable));
} else {
Drawable drawable = ResourcesCompat.getDrawable(context.getResources(), MusicUtil.getDefaultPicPerCategory(category), null);
requestManager.applyDefaultRequestOptions(createRequestOptions(item, drawable));
}
}
public static Builder from(Context context, String item, String placeholder, String itemType, String quality, String category) {
return new Builder(context, item, placeholder, itemType, quality, category);
}
public BitmapBuilder bitmap() {
return new BitmapBuilder(this);
}
public RequestBuilder<Drawable> build() {
return requestManager.load(item);
}
}
public static class BitmapBuilder {
private final Builder builder;
public BitmapBuilder(Builder builder) {
this.builder = builder;
}
public RequestBuilder<Bitmap> build() {
return builder.requestManager.asBitmap().load(builder.item);
}
}
}

View file

@ -18,6 +18,12 @@ public class MusicProgressViewUpdateHelper extends Handler {
private int intervalPlaying;
private int intervalPaused;
public MusicProgressViewUpdateHelper(Callback callback) {
this.callback = callback;
this.intervalPlaying = UPDATE_INTERVAL_PLAYING;
this.intervalPaused = UPDATE_INTERVAL_PAUSED;
}
public void start() {
queueNextRefresh(1);
}
@ -26,12 +32,6 @@ public class MusicProgressViewUpdateHelper extends Handler {
removeMessages(CMD_REFRESH_PROGRESS_VIEWS);
}
public MusicProgressViewUpdateHelper(Callback callback) {
this.callback = callback;
this.intervalPlaying = UPDATE_INTERVAL_PLAYING;
this.intervalPaused = UPDATE_INTERVAL_PAUSED;
}
@Override
public void handleMessage(@NonNull Message msg) {
super.handleMessage(msg);

View file

@ -1,17 +1,15 @@
package com.cappielloantonio.play.helper;
import android.os.Build;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatDelegate;
public class ThemeHelper {
private static final String TAG = "ThemeHelper";
public static final String LIGHT_MODE = "light";
public static final String DARK_MODE = "dark";
public static final String DEFAULT_MODE = "default";
private static final String TAG = "ThemeHelper";
public static void applyTheme(@NonNull String themePref) {
switch (themePref) {

View file

@ -23,14 +23,14 @@ public interface Playback {
int getProgress();
int getDuration();
void setProgress(int progress);
void setVolume(int volume);
int getDuration();
int getVolume();
void setVolume(int volume);
interface PlaybackCallbacks {
void onStateChanged(int state);

View file

@ -2,19 +2,10 @@ package com.cappielloantonio.play.repository;
import android.app.Application;
import androidx.lifecycle.LiveData;
import com.cappielloantonio.play.database.AppDatabase;
import com.cappielloantonio.play.database.dao.AlbumArtistCrossDao;
import com.cappielloantonio.play.database.dao.QueueDao;
import com.cappielloantonio.play.database.dao.SongArtistCrossDao;
import com.cappielloantonio.play.model.AlbumArtistCross;
import com.cappielloantonio.play.model.Queue;
import com.cappielloantonio.play.model.Song;
import com.cappielloantonio.play.model.SongArtistCross;
import com.cappielloantonio.play.util.QueueUtil;
import java.util.ArrayList;
import java.util.List;
public class AlbumArtistRepository {
@ -41,6 +32,12 @@ public class AlbumArtistRepository {
}
}
public void deleteAll() {
DeleteAllAlbumArtistCrossThreadSafe delete = new DeleteAllAlbumArtistCrossThreadSafe(albumArtistCrossDao);
Thread thread = new Thread(delete);
thread.start();
}
private static class InsertAllThreadSafe implements Runnable {
private AlbumArtistCrossDao albumArtistCrossDao;
private List<AlbumArtistCross> crosses;
@ -56,12 +53,6 @@ public class AlbumArtistRepository {
}
}
public void deleteAll() {
DeleteAllAlbumArtistCrossThreadSafe delete = new DeleteAllAlbumArtistCrossThreadSafe(albumArtistCrossDao);
Thread thread = new Thread(delete);
thread.start();
}
private static class DeleteAllAlbumArtistCrossThreadSafe implements Runnable {
private AlbumArtistCrossDao albumArtistCrossDao;

View file

@ -63,6 +63,35 @@ public class AlbumRepository {
return suggestions;
}
public void insertAll(ArrayList<Album> albums) {
InsertAllThreadSafe insertAll = new InsertAllThreadSafe(albumDao, albums);
Thread thread = new Thread(insertAll);
thread.start();
}
public void deleteAll() {
DeleteAllThreadSafe delete = new DeleteAllThreadSafe(albumDao);
Thread thread = new Thread(delete);
thread.start();
}
public Album getAlbumByID(String id) {
Album album = null;
GetAlbumByIDThreadSafe getAlbum = new GetAlbumByIDThreadSafe(albumDao, id);
Thread thread = new Thread(getAlbum);
thread.start();
try {
thread.join();
album = getAlbum.getAlbum();
} catch (InterruptedException e) {
e.printStackTrace();
}
return album;
}
private static class SearchSuggestionsThreadSafe implements Runnable {
private AlbumDao albumDao;
private String query;
@ -85,18 +114,6 @@ public class AlbumRepository {
}
}
public void insertAll(ArrayList<Album> albums) {
InsertAllThreadSafe insertAll = new InsertAllThreadSafe(albumDao, albums);
Thread thread = new Thread(insertAll);
thread.start();
}
public void deleteAll() {
DeleteAllThreadSafe delete = new DeleteAllThreadSafe(albumDao);
Thread thread = new Thread(delete);
thread.start();
}
private static class DeleteAllThreadSafe implements Runnable {
private AlbumDao albumDao;
@ -110,23 +127,6 @@ public class AlbumRepository {
}
}
public Album getAlbumByID(String id) {
Album album = null;
GetAlbumByIDThreadSafe getAlbum = new GetAlbumByIDThreadSafe(albumDao, id);
Thread thread = new Thread(getAlbum);
thread.start();
try {
thread.join();
album = getAlbum.getAlbum();
} catch (InterruptedException e) {
e.printStackTrace();
}
return album;
}
private static class GetAlbumByIDThreadSafe implements Runnable {
private Album album;
private AlbumDao albumDao;

View file

@ -55,6 +55,35 @@ public class ArtistRepository {
return suggestions;
}
public void insertAll(ArrayList<Artist> artists) {
InsertAllThreadSafe insertAll = new InsertAllThreadSafe(artistDao, artists);
Thread thread = new Thread(insertAll);
thread.start();
}
public void deleteAll() {
DeleteAllThreadSafe delete = new DeleteAllThreadSafe(artistDao);
Thread thread = new Thread(delete);
thread.start();
}
public Artist getArtistByID(String id) {
Artist artist = null;
GetArtistByIDThreadSafe getArtist = new GetArtistByIDThreadSafe(artistDao, id);
Thread thread = new Thread(getArtist);
thread.start();
try {
thread.join();
artist = getArtist.getArtist();
} catch (InterruptedException e) {
e.printStackTrace();
}
return artist;
}
private static class SearchSuggestionsThreadSafe implements Runnable {
private ArtistDao artistDao;
private String query;
@ -77,12 +106,6 @@ public class ArtistRepository {
}
}
public void insertAll(ArrayList<Artist> artists) {
InsertAllThreadSafe insertAll = new InsertAllThreadSafe(artistDao, artists);
Thread thread = new Thread(insertAll);
thread.start();
}
private static class InsertAllThreadSafe implements Runnable {
private ArtistDao artistDao;
private ArrayList<Artist> artists;
@ -99,12 +122,6 @@ public class ArtistRepository {
}
}
public void deleteAll() {
DeleteAllThreadSafe delete = new DeleteAllThreadSafe(artistDao);
Thread thread = new Thread(delete);
thread.start();
}
private static class DeleteAllThreadSafe implements Runnable {
private ArtistDao artistDao;
@ -118,23 +135,6 @@ public class ArtistRepository {
}
}
public Artist getArtistByID(String id) {
Artist artist = null;
GetArtistByIDThreadSafe getArtist = new GetArtistByIDThreadSafe(artistDao, id);
Thread thread = new Thread(getArtist);
thread.start();
try {
thread.join();
artist = getArtist.getArtist();
} catch (InterruptedException e) {
e.printStackTrace();
}
return artist;
}
private static class GetArtistByIDThreadSafe implements Runnable {
private Artist artist;
private ArtistDao artistDao;

View file

@ -5,10 +5,8 @@ import android.app.Application;
import androidx.lifecycle.LiveData;
import com.cappielloantonio.play.database.AppDatabase;
import com.cappielloantonio.play.database.dao.ArtistDao;
import com.cappielloantonio.play.database.dao.GenreDao;
import com.cappielloantonio.play.database.dao.SongGenreCrossDao;
import com.cappielloantonio.play.model.Artist;
import com.cappielloantonio.play.model.Genre;
import java.util.ArrayList;
@ -47,73 +45,25 @@ public class GenreRepository {
try {
thread.join();
list = getGenreListThread.getList();
}
catch (InterruptedException e) {
} catch (InterruptedException e) {
e.printStackTrace();
}
return list;
}
private static class GetGenreListThreadSafe implements Runnable {
private GenreDao genreDao;
private List<Genre> list = null;
public GetGenreListThreadSafe(GenreDao genreDao) {
this.genreDao = genreDao;
}
@Override
public void run() {
list = genreDao.getGenreList();
}
public List<Genre> getList() {
return list;
}
}
public void insertAll(ArrayList<Genre> genres) {
InsertAllThreadSafe insertAll = new InsertAllThreadSafe(genreDao, genres);
Thread thread = new Thread(insertAll);
thread.start();
}
private static class InsertAllThreadSafe implements Runnable {
private GenreDao genreDao;
private ArrayList<Genre> genres;
public InsertAllThreadSafe(GenreDao genreDao, ArrayList<Genre> genres) {
this.genreDao = genreDao;
this.genres = genres;
}
@Override
public void run() {
genreDao.deleteAll();
genreDao.insertAll(genres);
}
}
public void deleteAll() {
DeleteAllGenreThreadSafe delete = new DeleteAllGenreThreadSafe(genreDao);
Thread thread = new Thread(delete);
thread.start();
}
private static class DeleteAllGenreThreadSafe implements Runnable {
private GenreDao genreDao;
public DeleteAllGenreThreadSafe(GenreDao genreDao) {
this.genreDao = genreDao;
}
@Override
public void run() {
genreDao.deleteAll();
}
}
public LiveData<List<Genre>> searchListLiveGenre(String name, int limit) {
searchListLiveGenre = genreDao.searchGenre(name, limit);
return searchListLiveGenre;
@ -136,6 +86,53 @@ public class GenreRepository {
return suggestions;
}
private static class GetGenreListThreadSafe implements Runnable {
private GenreDao genreDao;
private List<Genre> list = null;
public GetGenreListThreadSafe(GenreDao genreDao) {
this.genreDao = genreDao;
}
@Override
public void run() {
list = genreDao.getGenreList();
}
public List<Genre> getList() {
return list;
}
}
private static class InsertAllThreadSafe implements Runnable {
private GenreDao genreDao;
private ArrayList<Genre> genres;
public InsertAllThreadSafe(GenreDao genreDao, ArrayList<Genre> genres) {
this.genreDao = genreDao;
this.genres = genres;
}
@Override
public void run() {
genreDao.deleteAll();
genreDao.insertAll(genres);
}
}
private static class DeleteAllGenreThreadSafe implements Runnable {
private GenreDao genreDao;
public DeleteAllGenreThreadSafe(GenreDao genreDao) {
this.genreDao = genreDao;
}
@Override
public void run() {
genreDao.deleteAll();
}
}
private static class SearchSuggestionsThreadSafe implements Runnable {
private GenreDao genreDao;
private String query;

View file

@ -6,9 +6,7 @@ import androidx.lifecycle.LiveData;
import com.cappielloantonio.play.database.AppDatabase;
import com.cappielloantonio.play.database.dao.PlaylistDao;
import com.cappielloantonio.play.database.dao.SongDao;
import com.cappielloantonio.play.model.Playlist;
import com.cappielloantonio.play.model.Song;
import java.util.ArrayList;
import java.util.List;
@ -33,41 +31,12 @@ public class PlaylistRepository {
thread.start();
}
private static class InsertAllThreadSafe implements Runnable {
private PlaylistDao playlistDao;
private ArrayList<Playlist> playlists;
public InsertAllThreadSafe(PlaylistDao playlistDao, ArrayList<Playlist> playlists) {
this.playlistDao = playlistDao;
this.playlists = playlists;
}
@Override
public void run() {
playlistDao.deleteAll();
playlistDao.insertAll(playlists);
}
}
public void deleteAll() {
DeleteAllThreadSafe delete = new DeleteAllThreadSafe(playlistDao);
Thread thread = new Thread(delete);
thread.start();
}
private static class DeleteAllThreadSafe implements Runnable {
private PlaylistDao playlistDao;
public DeleteAllThreadSafe(PlaylistDao playlistDao) {
this.playlistDao = playlistDao;
}
@Override
public void run() {
playlistDao.deleteAll();
}
}
public List<Playlist> getRandomSample(int number) {
List<Playlist> sample = new ArrayList<>();
@ -85,6 +54,35 @@ public class PlaylistRepository {
return sample;
}
private static class InsertAllThreadSafe implements Runnable {
private PlaylistDao playlistDao;
private ArrayList<Playlist> playlists;
public InsertAllThreadSafe(PlaylistDao playlistDao, ArrayList<Playlist> playlists) {
this.playlistDao = playlistDao;
this.playlists = playlists;
}
@Override
public void run() {
playlistDao.deleteAll();
playlistDao.insertAll(playlists);
}
}
private static class DeleteAllThreadSafe implements Runnable {
private PlaylistDao playlistDao;
public DeleteAllThreadSafe(PlaylistDao playlistDao) {
this.playlistDao = playlistDao;
}
@Override
public void run() {
playlistDao.deleteAll();
}
}
private static class PickRandomThreadSafe implements Runnable {
private PlaylistDao playlistDao;
private int elementNumber;

View file

@ -4,9 +4,7 @@ import android.app.Application;
import com.cappielloantonio.play.database.AppDatabase;
import com.cappielloantonio.play.database.dao.PlaylistSongCrossDao;
import com.cappielloantonio.play.database.dao.SongArtistCrossDao;
import com.cappielloantonio.play.model.PlaylistSongCross;
import com.cappielloantonio.play.model.SongArtistCross;
import java.util.List;
@ -26,6 +24,12 @@ public class PlaylistSongRepository {
thread.start();
}
public void deleteAll() {
DeleteAllPlaylistSongCrossThreadSafe delete = new DeleteAllPlaylistSongCrossThreadSafe(playlistSongCrossDao);
Thread thread = new Thread(delete);
thread.start();
}
private static class InsertAllThreadSafe implements Runnable {
private PlaylistSongCrossDao playlistSongCrossDao;
private List<PlaylistSongCross> crosses;
@ -41,12 +45,6 @@ public class PlaylistSongRepository {
}
}
public void deleteAll() {
DeleteAllPlaylistSongCrossThreadSafe delete = new DeleteAllPlaylistSongCrossThreadSafe(playlistSongCrossDao);
Thread thread = new Thread(delete);
thread.start();
}
private static class DeleteAllPlaylistSongCrossThreadSafe implements Runnable {
private PlaylistSongCrossDao playlistSongCrossDao;

View file

@ -7,11 +7,9 @@ import androidx.lifecycle.LiveData;
import com.cappielloantonio.play.database.AppDatabase;
import com.cappielloantonio.play.database.dao.QueueDao;
import com.cappielloantonio.play.database.dao.SongDao;
import com.cappielloantonio.play.model.Queue;
import com.cappielloantonio.play.model.Song;
import com.cappielloantonio.play.util.QueueUtil;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
@ -50,24 +48,6 @@ public class QueueRepository {
return songs;
}
private static class GetSongsThreadSafe implements Runnable {
private QueueDao queueDao;
private List<Song> songs;
public GetSongsThreadSafe(QueueDao queueDao) {
this.queueDao = queueDao;
}
@Override
public void run() {
songs = queueDao.getAllSimple();
}
public List<Song> getSongs() {
return songs;
}
}
public void insertAll(List<Song> songs) {
InsertAllThreadSafe insertAll = new InsertAllThreadSafe(queueDao, songs);
Thread thread = new Thread(insertAll);
@ -94,6 +74,67 @@ public class QueueRepository {
return mix;
}
public void insertAllAndStartNew(List<Song> songs) {
try {
final Thread delete = new Thread(new DeleteAllThreadSafe(queueDao));
final Thread insertAll = new Thread(new InsertAllThreadSafe(queueDao, songs));
delete.start();
delete.join();
insertAll.start();
insertAll.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void deleteByPosition(int position) {
DeleteByPositionThreadSafe delete = new DeleteByPositionThreadSafe(queueDao, position);
Thread thread = new Thread(delete);
thread.start();
}
public void deleteAll() {
DeleteAllThreadSafe delete = new DeleteAllThreadSafe(queueDao);
Thread thread = new Thread(delete);
thread.start();
}
public int count() {
int count = 0;
CountThreadSafe countThread = new CountThreadSafe(queueDao);
Thread thread = new Thread(countThread);
thread.start();
try {
thread.join();
count = countThread.getCount();
} catch (InterruptedException e) {
e.printStackTrace();
}
return count;
}
private static class GetSongsThreadSafe implements Runnable {
private QueueDao queueDao;
private List<Song> songs;
public GetSongsThreadSafe(QueueDao queueDao) {
this.queueDao = queueDao;
}
@Override
public void run() {
songs = queueDao.getAllSimple();
}
public List<Song> getSongs() {
return songs;
}
}
private static class GetSongsByIDThreadSafe implements Runnable {
private SongDao songDao;
private List<String> IDs;
@ -114,20 +155,6 @@ public class QueueRepository {
}
}
public void insertAllAndStartNew(List<Song> songs) {
try {
final Thread delete = new Thread(new DeleteAllThreadSafe(queueDao));
final Thread insertAll = new Thread(new InsertAllThreadSafe(queueDao, songs));
delete.start();
delete.join();
insertAll.start();
insertAll.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private static class InsertAllThreadSafe implements Runnable {
private QueueDao queueDao;
private List<Song> songs;
@ -143,17 +170,11 @@ public class QueueRepository {
}
}
public void deleteByPosition(int position) {
DeleteByPositionThreadSafe delete = new DeleteByPositionThreadSafe(queueDao, position);
Thread thread = new Thread(delete);
thread.start();
}
private static class DeleteByPositionThreadSafe implements Runnable {
private QueueDao queueDao;
private int position;
public DeleteByPositionThreadSafe(QueueDao queueDao,int position) {
public DeleteByPositionThreadSafe(QueueDao queueDao, int position) {
this.queueDao = queueDao;
this.position = position;
}
@ -164,12 +185,6 @@ public class QueueRepository {
}
}
public void deleteAll() {
DeleteAllThreadSafe delete = new DeleteAllThreadSafe(queueDao);
Thread thread = new Thread(delete);
thread.start();
}
private static class DeleteAllThreadSafe implements Runnable {
private QueueDao queueDao;
@ -183,23 +198,6 @@ public class QueueRepository {
}
}
public int count() {
int count = 0;
CountThreadSafe countThread = new CountThreadSafe(queueDao);
Thread thread = new Thread(countThread);
thread.start();
try {
thread.join();
count = countThread.getCount();
} catch (InterruptedException e) {
e.printStackTrace();
}
return count;
}
private static class CountThreadSafe implements Runnable {
private QueueDao queueDao;
private int count = 0;

View file

@ -2,8 +2,6 @@ package com.cappielloantonio.play.repository;
import android.app.Application;
import androidx.lifecycle.LiveData;
import com.cappielloantonio.play.database.AppDatabase;
import com.cappielloantonio.play.database.dao.RecentSearchDao;
import com.cappielloantonio.play.model.RecentSearch;
@ -31,6 +29,29 @@ public class RecentSearchRepository {
thread.start();
}
public void deleteAll() {
DeleteAllThreadSafe delete = new DeleteAllThreadSafe(recentSearchDao);
Thread thread = new Thread(delete);
thread.start();
}
public List<String> getRecentSearchSuggestion(int limit) {
List<String> recent = new ArrayList<>();
RecentThreadSafe suggestionsThread = new RecentThreadSafe(recentSearchDao, limit);
Thread thread = new Thread(suggestionsThread);
thread.start();
try {
thread.join();
recent = suggestionsThread.getRecent();
} catch (InterruptedException e) {
e.printStackTrace();
}
return recent;
}
private static class DeleteThreadSafe implements Runnable {
private RecentSearchDao recentSearchDao;
private RecentSearch recentSearch;
@ -61,12 +82,6 @@ public class RecentSearchRepository {
}
}
public void deleteAll() {
DeleteAllThreadSafe delete = new DeleteAllThreadSafe(recentSearchDao);
Thread thread = new Thread(delete);
thread.start();
}
private static class DeleteAllThreadSafe implements Runnable {
private RecentSearchDao recentSearchDao;
@ -80,23 +95,6 @@ public class RecentSearchRepository {
}
}
public List<String> getRecentSearchSuggestion(int limit) {
List<String> recent = new ArrayList<>();
RecentThreadSafe suggestionsThread = new RecentThreadSafe(recentSearchDao,limit);
Thread thread = new Thread(suggestionsThread);
thread.start();
try {
thread.join();
recent = suggestionsThread.getRecent();
} catch (InterruptedException e) {
e.printStackTrace();
}
return recent;
}
private static class RecentThreadSafe implements Runnable {
private RecentSearchDao recentSearchDao;
private int limit;

View file

@ -3,11 +3,7 @@ package com.cappielloantonio.play.repository;
import android.app.Application;
import com.cappielloantonio.play.database.AppDatabase;
import com.cappielloantonio.play.database.dao.AlbumArtistCrossDao;
import com.cappielloantonio.play.database.dao.SongArtistCrossDao;
import com.cappielloantonio.play.database.dao.SongGenreCrossDao;
import com.cappielloantonio.play.model.AlbumArtistCross;
import com.cappielloantonio.play.model.Song;
import com.cappielloantonio.play.model.SongArtistCross;
import java.util.List;
@ -36,6 +32,12 @@ public class SongArtistRepository {
}
}
public void deleteAll() {
DeleteAllSongArtistCrossThreadSafe delete = new DeleteAllSongArtistCrossThreadSafe(songArtistCrossDao);
Thread thread = new Thread(delete);
thread.start();
}
private static class InsertAllThreadSafe implements Runnable {
private SongArtistCrossDao songArtistCrossDao;
private List<SongArtistCross> crosses;
@ -51,12 +53,6 @@ public class SongArtistRepository {
}
}
public void deleteAll() {
DeleteAllSongArtistCrossThreadSafe delete = new DeleteAllSongArtistCrossThreadSafe(songArtistCrossDao);
Thread thread = new Thread(delete);
thread.start();
}
private static class DeleteAllSongArtistCrossThreadSafe implements Runnable {
private SongArtistCrossDao songArtistCrossDao;

View file

@ -98,28 +98,6 @@ public class SongRepository {
return songs;
}
private static class GetRandomSongsByArtistIDThreadSafe implements Runnable {
private SongDao songDao;
private String artistID;
private int limit;
private List<Song> songs = new ArrayList<>();
public GetRandomSongsByArtistIDThreadSafe(SongDao songDao, String artistID, int limit) {
this.songDao = songDao;
this.artistID = artistID;
this.limit = limit;
}
@Override
public void run() {
songs = songDao.getArtistRandomSongs(artistID, limit);
}
public List<Song> getSongs() {
return songs;
}
}
public LiveData<List<Song>> getAlbumListLiveSong(String albumID) {
listLiveAlbumSongs = songDao.getLiveAlbumSong(albumID);
return listLiveAlbumSongs;
@ -144,33 +122,13 @@ public class SongRepository {
e.printStackTrace();
}
if(randomOrder) {
if (randomOrder) {
Collections.shuffle(songs);
}
return songs;
}
private static class GetSongsByAlbumIDThreadSafe implements Runnable {
private SongDao songDao;
private String albumID;
private List<Song> songs = new ArrayList<>();
public GetSongsByAlbumIDThreadSafe(SongDao songDao, String albumID) {
this.songDao = songDao;
this.albumID = albumID;
}
@Override
public void run() {
songs = songDao.getAlbumSong(albumID);
}
public List<Song> getSongs() {
return songs;
}
}
public LiveData<List<Song>> getFilteredListLiveSong(ArrayList<String> filters) {
listLiveFilteredSongs = songDao.getFilteredSong(filters);
return listLiveFilteredSongs;
@ -193,28 +151,6 @@ public class SongRepository {
return suggestions;
}
private static class SearchSuggestionsThreadSafe implements Runnable {
private SongDao songDao;
private String query;
private int number;
private List<String> suggestions = new ArrayList<>();
public SearchSuggestionsThreadSafe(SongDao songDao, String query, int number) {
this.songDao = songDao;
this.query = query;
this.number = number;
}
@Override
public void run() {
suggestions = songDao.searchSuggestions(query, number);
}
public List<String> getSuggestions() {
return suggestions;
}
}
/*
* Funzione che ritorna l'intero set di canzoni.
* Utilizzato per l'aggiornamento del catalogo.
@ -236,24 +172,6 @@ public class SongRepository {
return catalogue;
}
private static class GetCatalogueThreadSafe implements Runnable {
private SongDao songDao;
private List<Song> catalogue = new ArrayList<>();
public GetCatalogueThreadSafe(SongDao songDao) {
this.songDao = songDao;
}
@Override
public void run() {
catalogue = songDao.getAllList();
}
public List<Song> getCatalogue() {
return catalogue;
}
}
public List<Integer> getYearList() {
List<Integer> years = new ArrayList<>();
@ -271,35 +189,6 @@ public class SongRepository {
return years;
}
private static class GetYearListThreadSafe implements Runnable {
private SongDao songDao;
private List<Integer> years = new ArrayList<>();
private List<Integer> decades = new ArrayList<>();
public GetYearListThreadSafe(SongDao songDao) {
this.songDao = songDao;
}
@Override
public void run() {
years = songDao.getYearList();
for(int year : years) {
if(!decades.contains(year - year % 10)) {
decades.add(year);
}
}
}
public List<Integer> getYearList() {
return years;
}
public List<Integer> getDecadeList() {
return decades;
}
}
public LiveData<List<Song>> getSongByYearListLive(int year) {
listLiveSongByYear = songDao.getSongsByYear(year);
return listLiveSongByYear;
@ -331,6 +220,178 @@ public class SongRepository {
thread.start();
}
public void increasePlayCount(Song song) {
if (song.nowPlaying()) {
UpdateThreadSafe update = new UpdateThreadSafe(songDao, song);
Thread thread = new Thread(update);
thread.start();
}
}
public void setFavoriteStatus(Song song) {
UpdateThreadSafe update = new UpdateThreadSafe(songDao, song);
Thread thread = new Thread(update);
thread.start();
}
public void setOfflineStatus(Song song) {
UpdateThreadSafe update = new UpdateThreadSafe(songDao, song);
Thread thread = new Thread(update);
thread.start();
}
public void setAllOffline() {
SetAllOfflineThreadSafe update = new SetAllOfflineThreadSafe(songDao);
Thread thread = new Thread(update);
thread.start();
}
public void insertSongPerGenre(ArrayList<SongGenreCross> songGenreCrosses) {
InsertPerGenreThreadSafe insertPerGenre = new InsertPerGenreThreadSafe(songGenreCrossDao, songGenreCrosses);
Thread thread = new Thread(insertPerGenre);
thread.start();
}
public void deleteAllSong() {
DeleteAllSongThreadSafe delete = new DeleteAllSongThreadSafe(songDao);
Thread thread = new Thread(delete);
thread.start();
}
public void deleteAllSongGenreCross() {
DeleteAllSongGenreCrossThreadSafe delete = new DeleteAllSongGenreCrossThreadSafe(songGenreCrossDao);
Thread thread = new Thread(delete);
thread.start();
}
public List<Song> getRandomSample(int number) {
List<Song> sample = new ArrayList<>();
PickRandomThreadSafe randomThread = new PickRandomThreadSafe(songDao, number);
Thread thread = new Thread(randomThread);
thread.start();
try {
thread.join();
sample = randomThread.getSample();
} catch (InterruptedException e) {
e.printStackTrace();
}
return sample;
}
private static class GetRandomSongsByArtistIDThreadSafe implements Runnable {
private SongDao songDao;
private String artistID;
private int limit;
private List<Song> songs = new ArrayList<>();
public GetRandomSongsByArtistIDThreadSafe(SongDao songDao, String artistID, int limit) {
this.songDao = songDao;
this.artistID = artistID;
this.limit = limit;
}
@Override
public void run() {
songs = songDao.getArtistRandomSongs(artistID, limit);
}
public List<Song> getSongs() {
return songs;
}
}
private static class GetSongsByAlbumIDThreadSafe implements Runnable {
private SongDao songDao;
private String albumID;
private List<Song> songs = new ArrayList<>();
public GetSongsByAlbumIDThreadSafe(SongDao songDao, String albumID) {
this.songDao = songDao;
this.albumID = albumID;
}
@Override
public void run() {
songs = songDao.getAlbumSong(albumID);
}
public List<Song> getSongs() {
return songs;
}
}
private static class SearchSuggestionsThreadSafe implements Runnable {
private SongDao songDao;
private String query;
private int number;
private List<String> suggestions = new ArrayList<>();
public SearchSuggestionsThreadSafe(SongDao songDao, String query, int number) {
this.songDao = songDao;
this.query = query;
this.number = number;
}
@Override
public void run() {
suggestions = songDao.searchSuggestions(query, number);
}
public List<String> getSuggestions() {
return suggestions;
}
}
private static class GetCatalogueThreadSafe implements Runnable {
private SongDao songDao;
private List<Song> catalogue = new ArrayList<>();
public GetCatalogueThreadSafe(SongDao songDao) {
this.songDao = songDao;
}
@Override
public void run() {
catalogue = songDao.getAllList();
}
public List<Song> getCatalogue() {
return catalogue;
}
}
private static class GetYearListThreadSafe implements Runnable {
private SongDao songDao;
private List<Integer> years = new ArrayList<>();
private List<Integer> decades = new ArrayList<>();
public GetYearListThreadSafe(SongDao songDao) {
this.songDao = songDao;
}
@Override
public void run() {
years = songDao.getYearList();
for (int year : years) {
if (!decades.contains(year - year % 10)) {
decades.add(year);
}
}
}
public List<Integer> getYearList() {
return years;
}
public List<Integer> getDecadeList() {
return decades;
}
}
private static class InsertAllThreadSafe implements Runnable {
private SongDao songDao;
private SongGenreCrossDao songGenreCrossDao;
@ -350,26 +411,6 @@ public class SongRepository {
}
}
public void increasePlayCount(Song song) {
if(song.nowPlaying()) {
UpdateThreadSafe update = new UpdateThreadSafe(songDao, song);
Thread thread = new Thread(update);
thread.start();
}
}
public void setFavoriteStatus(Song song) {
UpdateThreadSafe update = new UpdateThreadSafe(songDao, song);
Thread thread = new Thread(update);
thread.start();
}
public void setOfflineStatus(Song song) {
UpdateThreadSafe update = new UpdateThreadSafe(songDao, song);
Thread thread = new Thread(update);
thread.start();
}
private static class UpdateThreadSafe implements Runnable {
private SongDao songDao;
private Song song;
@ -385,12 +426,6 @@ public class SongRepository {
}
}
public void setAllOffline() {
SetAllOfflineThreadSafe update = new SetAllOfflineThreadSafe(songDao);
Thread thread = new Thread(update);
thread.start();
}
private static class SetAllOfflineThreadSafe implements Runnable {
private SongDao songDao;
@ -404,12 +439,6 @@ public class SongRepository {
}
}
public void insertSongPerGenre(ArrayList<SongGenreCross> songGenreCrosses) {
InsertPerGenreThreadSafe insertPerGenre = new InsertPerGenreThreadSafe(songGenreCrossDao, songGenreCrosses);
Thread thread = new Thread(insertPerGenre);
thread.start();
}
private static class InsertPerGenreThreadSafe implements Runnable {
private SongGenreCrossDao songGenreCrossDao;
private ArrayList<SongGenreCross> cross;
@ -425,12 +454,6 @@ public class SongRepository {
}
}
public void deleteAllSong() {
DeleteAllSongThreadSafe delete = new DeleteAllSongThreadSafe(songDao);
Thread thread = new Thread(delete);
thread.start();
}
private static class DeleteAllSongThreadSafe implements Runnable {
private SongDao songDao;
@ -444,12 +467,6 @@ public class SongRepository {
}
}
public void deleteAllSongGenreCross() {
DeleteAllSongGenreCrossThreadSafe delete = new DeleteAllSongGenreCrossThreadSafe(songGenreCrossDao);
Thread thread = new Thread(delete);
thread.start();
}
private static class DeleteAllSongGenreCrossThreadSafe implements Runnable {
private SongGenreCrossDao songGenreCrossDao;
@ -463,23 +480,6 @@ public class SongRepository {
}
}
public List<Song> getRandomSample(int number) {
List<Song> sample = new ArrayList<>();
PickRandomThreadSafe randomThread = new PickRandomThreadSafe(songDao, number);
Thread thread = new Thread(randomThread);
thread.start();
try {
thread.join();
sample = randomThread.getSample();
} catch (InterruptedException e) {
e.printStackTrace();
}
return sample;
}
private static class PickRandomThreadSafe implements Runnable {
private SongDao songDao;
private int elementNumber;

View file

@ -28,7 +28,6 @@ import java.util.List;
import java.util.concurrent.CopyOnWriteArraySet;
import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
import static com.google.android.exoplayer2.util.Assertions.checkStateNotNull;
public class DownloadTracker {
@ -40,7 +39,7 @@ public class DownloadTracker {
private final DownloadIndex downloadIndex;
private final DefaultTrackSelector.Parameters trackSelectorParameters;
public DownloadTracker(Context context,HttpDataSource.Factory httpDataSourceFactory,DownloadManager downloadManager) {
public DownloadTracker(Context context, HttpDataSource.Factory httpDataSourceFactory, DownloadManager downloadManager) {
this.context = context.getApplicationContext();
this.httpDataSourceFactory = httpDataSourceFactory;
listeners = new CopyOnWriteArraySet<>();
@ -74,7 +73,7 @@ public class DownloadTracker {
public void toggleDownload(List<Song> songs) {
SongRepository songRepository = new SongRepository(App.getInstance());
for(Song song: songs) {
for (Song song : songs) {
MediaItem mediaItem = MusicUtil.getMediaItemFromSong(song);
@Nullable Download download = downloads.get(checkNotNull(mediaItem.playbackProperties).uri);
@ -84,7 +83,7 @@ public class DownloadTracker {
DownloadService.sendRemoveDownload(context, DownloaderService.class, download.request.id, false);
} else {
song.setOffline(true);
DownloadService.sendAddDownload(context, DownloaderService.class, getDownloadRequest(mediaItem.playbackProperties.uri),false);
DownloadService.sendAddDownload(context, DownloaderService.class, getDownloadRequest(mediaItem.playbackProperties.uri), false);
}
songRepository.setOfflineStatus(song);

View file

@ -44,7 +44,7 @@ public class DownloaderService extends DownloadService {
@Override
@NonNull
protected Notification getForegroundNotification(@NonNull List<Download> downloads) {
return DownloadUtil.getDownloadNotificationHelper(this).buildProgressNotification(this, R.drawable.ic_downloading,null, null, downloads);
return DownloadUtil.getDownloadNotificationHelper(this).buildProgressNotification(this, R.drawable.ic_downloading, null, null, downloads);
}
private static final class TerminalStateNotificationHelper implements DownloadManager.Listener {
@ -65,7 +65,7 @@ public class DownloaderService extends DownloadService {
Notification notification;
if (download.state == Download.STATE_COMPLETED) {
notification = notificationHelper.buildDownloadCompletedNotification(context, R.drawable.ic_done,null, Util.fromUtf8Bytes(download.request.data));
notification = notificationHelper.buildDownloadCompletedNotification(context, R.drawable.ic_done, null, Util.fromUtf8Bytes(download.request.data));
} else if (download.state == Download.STATE_FAILED) {
notification = notificationHelper.buildDownloadFailedNotification(context, R.drawable.ic_error, null, Util.fromUtf8Bytes(download.request.data));
} else {

View file

@ -6,15 +6,15 @@ import android.util.Log;
import android.widget.Toast;
import com.cappielloantonio.play.R;
import com.cappielloantonio.play.model.Song;
import com.cappielloantonio.play.interfaces.Playback;
import com.cappielloantonio.play.model.Song;
import com.cappielloantonio.play.util.DownloadUtil;
import com.cappielloantonio.play.util.MusicUtil;
import com.cappielloantonio.play.util.PreferenceUtil;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.database.ExoDatabaseProvider;
import com.google.android.exoplayer2.source.DefaultMediaSourceFactory;
@ -185,23 +185,23 @@ public class MultiPlayer implements Playback {
return (int) exoPlayer.getCurrentPosition();
}
@Override
public int getDuration() {
return (int) exoPlayer.getDuration();
}
@Override
public void setProgress(int progress) {
exoPlayer.seekTo(progress);
}
@Override
public void setVolume(int volume) {
exoPlayer.setVolume(volume / 100f);
public int getDuration() {
return (int) exoPlayer.getDuration();
}
@Override
public int getVolume() {
return (int) (exoPlayer.getVolume() * 100);
}
@Override
public void setVolume(int volume) {
exoPlayer.setVolume(volume / 100f);
}
}

View file

@ -15,7 +15,6 @@ import androidx.annotation.Nullable;
import com.cappielloantonio.play.App;
import com.cappielloantonio.play.model.Song;
import com.cappielloantonio.play.repository.QueueRepository;
import com.cappielloantonio.play.service.MusicService;
import java.util.ArrayList;
import java.util.List;
@ -23,10 +22,8 @@ import java.util.WeakHashMap;
public class MusicPlayerRemote {
private static final String TAG = "MusicPlayerRemote";
public static MusicService musicService;
private static final WeakHashMap<Context, ServiceBinder> mConnectionMap = new WeakHashMap<>();
public static MusicService musicService;
public static ServiceToken bindToService(@NonNull final Context context, final ServiceConnection callback) {
Activity realActivity = ((Activity) context).getParent();
@ -64,52 +61,12 @@ public class MusicPlayerRemote {
}
}
public static final class ServiceBinder implements ServiceConnection {
private final ServiceConnection mCallback;
public ServiceBinder(final ServiceConnection callback) {
mCallback = callback;
}
@Override
public void onServiceConnected(final ComponentName className, final IBinder service) {
MusicService.MusicBinder binder = (MusicService.MusicBinder) service;
musicService = binder.getService();
if (mCallback != null) {
mCallback.onServiceConnected(className, service);
}
}
@Override
public void onServiceDisconnected(final ComponentName className) {
if (mCallback != null) {
mCallback.onServiceDisconnected(className);
}
musicService = null;
}
}
public static final class ServiceToken {
public ContextWrapper mWrappedContext;
public ServiceToken(final ContextWrapper context) {
mWrappedContext = context;
}
}
public static void playSongAt(final int position) {
if (musicService != null) {
musicService.playSongAt(position);
}
}
public static void setPosition(final int position) {
if (musicService != null) {
musicService.setPosition(position);
}
}
public static void pauseSong() {
if (musicService != null) {
musicService.pause();
@ -192,6 +149,12 @@ public class MusicPlayerRemote {
return -1;
}
public static void setPosition(final int position) {
if (musicService != null) {
musicService.setPosition(position);
}
}
public static List<Song> getPlayingQueue() {
if (musicService != null) {
return musicService.getPlayingQueue();
@ -328,4 +291,38 @@ public class MusicPlayerRemote {
return false;
}
public static final class ServiceBinder implements ServiceConnection {
private final ServiceConnection mCallback;
public ServiceBinder(final ServiceConnection callback) {
mCallback = callback;
}
@Override
public void onServiceConnected(final ComponentName className, final IBinder service) {
MusicService.MusicBinder binder = (MusicService.MusicBinder) service;
musicService = binder.getService();
if (mCallback != null) {
mCallback.onServiceConnected(className, service);
}
}
@Override
public void onServiceDisconnected(final ComponentName className) {
if (mCallback != null) {
mCallback.onServiceDisconnected(className);
}
musicService = null;
}
}
public static final class ServiceToken {
public ContextWrapper mWrappedContext;
public ServiceToken(final ContextWrapper context) {
mWrappedContext = context;
}
}
}

View file

@ -28,12 +28,12 @@ import androidx.annotation.Nullable;
import com.cappielloantonio.play.App;
import com.cappielloantonio.play.R;
import com.cappielloantonio.play.broadcast.receiver.MediaButtonIntentReceiver;
import com.cappielloantonio.play.interfaces.Playback;
import com.cappielloantonio.play.model.Playlist;
import com.cappielloantonio.play.model.Song;
import com.cappielloantonio.play.repository.QueueRepository;
import com.cappielloantonio.play.repository.SongRepository;
import com.cappielloantonio.play.ui.notification.PlayingNotification;
import com.cappielloantonio.play.interfaces.Playback;
import com.cappielloantonio.play.util.PreferenceUtil;
import org.jellyfin.apiclient.interaction.EmptyResponse;
@ -57,8 +57,6 @@ import static com.google.android.exoplayer2.Player.PLAY_WHEN_READY_CHANGE_REASON
public class MusicService extends Service implements Playback.PlaybackCallbacks {
public static final String PACKAGE_NAME = "com.antoniocappiello.play";
private static final String TAG = "MusicService";
public static final String ACTION_TOGGLE = PACKAGE_NAME + ".toggle";
public static final String ACTION_PLAY = PACKAGE_NAME + ".play";
public static final String ACTION_PLAY_PLAYLIST = PACKAGE_NAME + ".play.playlist";
@ -68,17 +66,13 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
public static final String ACTION_REWIND = PACKAGE_NAME + ".rewind";
public static final String ACTION_QUIT = PACKAGE_NAME + ".quit";
public static final String ACTION_PENDING_QUIT = PACKAGE_NAME + ".quit.pending";
public static final String INTENT_EXTRA_PLAYLIST = PACKAGE_NAME + ".extra.playlist";
public static final String STATE_CHANGED = PACKAGE_NAME + ".state.changed";
public static final String META_CHANGED = PACKAGE_NAME + ".meta.changed";
public static final String QUEUE_CHANGED = PACKAGE_NAME + ".queue.changed";
public static final int TRACK_STARTED = 9;
public static final int TRACK_CHANGED = 1;
public static final int TRACK_ENDED = 2;
public static final int RELEASE_WAKELOCK = 0;
public static final int PLAY_SONG = 3;
public static final int PREPARE_NEXT = 4;
@ -86,39 +80,25 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
public static final int FOCUS_CHANGE = 6;
public static final int DUCK = 7;
public static final int UNDUCK = 8;
public static final int LOAD_QUEUE = 9;
private static final String TAG = "MusicService";
private static final long MEDIA_SESSION_ACTIONS = PlaybackStateCompat.ACTION_PLAY
| PlaybackStateCompat.ACTION_PAUSE
| PlaybackStateCompat.ACTION_PLAY_PAUSE
| PlaybackStateCompat.ACTION_SKIP_TO_NEXT
| PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS
| PlaybackStateCompat.ACTION_STOP
| PlaybackStateCompat.ACTION_SEEK_TO;
private final IBinder musicBinder = new MusicBinder();
public boolean pendingQuit = false;
private Playback playback;
private List<Song> playingQueue = new ArrayList<>();
private int position = -1;
private int nextPosition = -1;
private boolean notHandledMetaChangedForCurrentTrack;
private boolean queuesRestored;
private boolean pausedByTransientLossOfFocus;
private PlayingNotification playingNotification;
private AudioManager audioManager;
private MediaSessionCompat mediaSession;
private PowerManager.WakeLock wakeLock;
private PlaybackHandler playerHandler;
private Handler uiThreadHandler;
private ThrottledSeekHandler throttledSeekHandler;
private QueueHandler queueHandler;
private ProgressHandler progressHandler;
private HandlerThread playerHandlerThread;
private HandlerThread progressHandlerThread;
private HandlerThread queueHandlerThread;
private final BroadcastReceiver becomingNoisyReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, @NonNull Intent intent) {
@ -127,21 +107,23 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
}
}
};
private AudioManager audioManager;
private MediaSessionCompat mediaSession;
private PowerManager.WakeLock wakeLock;
private PlaybackHandler playerHandler;
private final AudioManager.OnAudioFocusChangeListener audioFocusListener = new AudioManager.OnAudioFocusChangeListener() {
@Override
public void onAudioFocusChange(final int focusChange) {
playerHandler.obtainMessage(FOCUS_CHANGE, focusChange, 0).sendToTarget();
}
};
private static final long MEDIA_SESSION_ACTIONS = PlaybackStateCompat.ACTION_PLAY
| PlaybackStateCompat.ACTION_PAUSE
| PlaybackStateCompat.ACTION_PLAY_PAUSE
| PlaybackStateCompat.ACTION_SKIP_TO_NEXT
| PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS
| PlaybackStateCompat.ACTION_STOP
| PlaybackStateCompat.ACTION_SEEK_TO;
private Handler uiThreadHandler;
private ThrottledSeekHandler throttledSeekHandler;
private QueueHandler queueHandler;
private ProgressHandler progressHandler;
private HandlerThread playerHandlerThread;
private HandlerThread progressHandlerThread;
private HandlerThread queueHandlerThread;
@Override
public void onCreate() {
@ -304,26 +286,6 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
return musicBinder;
}
private static final class QueueHandler extends Handler {
@NonNull
private final WeakReference<MusicService> mService;
public QueueHandler(final MusicService service, @NonNull final Looper looper) {
super(looper);
mService = new WeakReference<>(service);
}
@Override
public void handleMessage(@NonNull Message msg) {
final MusicService service = mService.get();
switch (msg.what) {
case LOAD_QUEUE:
service.restoreQueuesAndPositionIfNecessary();
break;
}
}
}
public void saveState() {
savePosition();
saveProgress();
@ -405,6 +367,12 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
return position;
}
public void setPosition(final int position) {
// handle this on the handlers thread to avoid blocking the ui thread
playerHandler.removeMessages(SET_POSITION);
playerHandler.obtainMessage(SET_POSITION, position, 0).sendToTarget();
}
public void playNextSong() {
playSongAt(getNextPosition());
}
@ -609,12 +577,6 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
playerHandler.obtainMessage(PLAY_SONG, position, 0).sendToTarget();
}
public void setPosition(final int position) {
// handle this on the handlers thread to avoid blocking the ui thread
playerHandler.removeMessages(SET_POSITION);
playerHandler.obtainMessage(SET_POSITION, position, 0).sendToTarget();
}
private void playSongAtImpl(int position) {
openTrackAndPrepareNextAt(position);
}
@ -774,6 +736,26 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
}
}
private static final class QueueHandler extends Handler {
@NonNull
private final WeakReference<MusicService> mService;
public QueueHandler(final MusicService service, @NonNull final Looper looper) {
super(looper);
mService = new WeakReference<>(service);
}
@Override
public void handleMessage(@NonNull Message msg) {
final MusicService service = mService.get();
switch (msg.what) {
case LOAD_QUEUE:
service.restoreQueuesAndPositionIfNecessary();
break;
}
}
}
private static final class PlaybackHandler extends Handler {
private final WeakReference<MusicService> mService;
private int currentDuckVolume = 100;
@ -907,33 +889,6 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
}
}
public class MusicBinder extends Binder {
@NonNull
public MusicService getService() {
return MusicService.this;
}
}
private class ThrottledSeekHandler implements Runnable {
// milliseconds to throttle before calling run to aggregate events
private static final long THROTTLE = 500;
private final Handler mHandler;
public ThrottledSeekHandler(Handler handler) {
mHandler = handler;
}
public void notifySeek() {
mHandler.removeCallbacks(this);
mHandler.postDelayed(this, THROTTLE);
}
@Override
public void run() {
notifyChange(STATE_CHANGED);
}
}
private static final class ProgressHandler extends Handler {
private final WeakReference<MusicService> mService;
@ -1012,4 +967,31 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
if (executorService != null) executorService.shutdownNow();
}
}
public class MusicBinder extends Binder {
@NonNull
public MusicService getService() {
return MusicService.this;
}
}
private class ThrottledSeekHandler implements Runnable {
// milliseconds to throttle before calling run to aggregate events
private static final long THROTTLE = 500;
private final Handler mHandler;
public ThrottledSeekHandler(Handler handler) {
mHandler = handler;
}
public void notifySeek() {
mHandler.removeCallbacks(this);
mHandler.postDelayed(this, THROTTLE);
}
@Override
public void run() {
notifyChange(STATE_CHANGED);
}
}
}

View file

@ -75,19 +75,15 @@ public class MusicUtil {
}
public static int getDefaultPicPerCategory(String category) {
if(category.equals(CustomGlideRequest.SONG_PIC)) {
if (category.equals(CustomGlideRequest.SONG_PIC)) {
return R.drawable.default_album_art;
}
else if(category.equals(CustomGlideRequest.ALBUM_PIC)) {
} else if (category.equals(CustomGlideRequest.ALBUM_PIC)) {
return R.drawable.default_album_art;
}
else if(category.equals(CustomGlideRequest.ARTIST_PIC)) {
} else if (category.equals(CustomGlideRequest.ARTIST_PIC)) {
return R.drawable.default_album_art;
}
else if(category.equals(CustomGlideRequest.PLAYLIST_PIC)) {
} else if (category.equals(CustomGlideRequest.PLAYLIST_PIC)) {
return R.drawable.default_album_art;
}
else {
} else {
return R.drawable.default_album_art;
}
}
@ -95,7 +91,7 @@ public class MusicUtil {
public static List<MediaItem> getMediaItemsFromSongs(List<Song> songs) {
List<MediaItem> mediaItems = new ArrayList<>();
for(Song song: songs) {
for (Song song : songs) {
mediaItems.add(getMediaItemFromSong(song));
}
@ -111,8 +107,7 @@ public class MusicUtil {
public static List<Integer> getRandomSongNumber(Context context, int numberOfNumbers, int refreshAfterXHours) {
List<Integer> list = new ArrayList<>();
for (int i = 0; i < numberOfNumbers; i++)
{
for (int i = 0; i < numberOfNumbers; i++) {
list.add(getRandomNumber(0, PreferenceUtil.getInstance(context).getSongNumber(), getMidnightTimestamp(System.currentTimeMillis() / 1000, refreshAfterXHours) + i));
}

View file

@ -14,31 +14,24 @@ import java.util.List;
import java.util.Set;
public class PreferenceUtil {
private static final String TAG = "PreferenceUtil";
public static final String SERVER = "server";
public static final String USER = "user";
public static final String TOKEN = "token";
public static final String MUSIC_LIBRARY_ID = "music_library_id";
public static final String POSITION = "position";
public static final String PROGRESS = "progress";
public static final String SYNC = "sync";
public static final String SONG_GENRE_SYNC = "song_genre_sync";
public static final String SEARCH_ELEMENT_PER_CATEGORY = "search_element_per_category";
public static final String IMAGE_CACHE_SIZE = "image_cache_size";
public static final String MEDIA_CACHE_SIZE = "media_cache_size";
public static final String INSTANT_MIX_SONG_NUMBER = "instant_mix_song_number";
public static final String TRANSCODE_CODEC = "transcode_codec";
public static final String DIRECT_PLAY_CODECS = "direct_play_codecs";
public static final String MAXIMUM_BITRATE = "maximum_bitrate";
public static final String AUDIO_DUCKING = "audio_ducking";
public static final String SONG_NUMBER = "SONG_NUMBER";
private static final String TAG = "PreferenceUtil";
private static PreferenceUtil sInstance;
private final SharedPreferences mPreferences;
@ -54,7 +47,9 @@ public class PreferenceUtil {
return sInstance;
}
public String getTheme() { return mPreferences.getString("themePref", ThemeHelper.DEFAULT_MODE ); }
public String getTheme() {
return mPreferences.getString("themePref", ThemeHelper.DEFAULT_MODE);
}
public String getServer() {
return mPreferences.getString(SERVER, "https://jellyfin.org");

View file

@ -1,7 +1,5 @@
package com.cappielloantonio.play.util;
import android.util.Log;
import com.cappielloantonio.play.model.Queue;
import com.cappielloantonio.play.model.Song;
@ -19,7 +17,7 @@ public class QueueUtil {
int counter = 0;
List<Queue> queue = new ArrayList<>();
for(Song song: songs) {
for (Song song : songs) {
queue.add(new Queue(counter, song.getId()));
counter++;
}
@ -30,7 +28,7 @@ public class QueueUtil {
public static List<String> getIDsFromSongs(List<Song> songs) {
List<String> IDs = new ArrayList<>();
for(Song song: songs) {
for (Song song : songs) {
IDs.add(song.getId());
}
@ -40,9 +38,9 @@ public class QueueUtil {
public static List<Song> orderSongByIdList(List<String> IDs, List<Song> songs) {
List<Song> orderedSong = new ArrayList<>();
for(String ID: IDs) {
for(Song song: songs) {
if(ID.equals(song.getId())) {
for (String ID : IDs) {
for (Song song : songs) {
if (ID.equals(song.getId())) {
orderedSong.add(song);
break;
}

View file

@ -16,12 +16,12 @@ import com.cappielloantonio.play.model.SongGenreCross;
import org.jellyfin.apiclient.interaction.Response;
import org.jellyfin.apiclient.model.dto.BaseItemDto;
import org.jellyfin.apiclient.model.dto.BaseItemType;
import org.jellyfin.apiclient.model.playlists.PlaylistItemQuery;
import org.jellyfin.apiclient.model.querying.ArtistsQuery;
import org.jellyfin.apiclient.model.querying.ItemFields;
import org.jellyfin.apiclient.model.querying.ItemQuery;
import org.jellyfin.apiclient.model.querying.ItemsByNameQuery;
import org.jellyfin.apiclient.model.querying.ItemsResult;
import org.jellyfin.apiclient.model.playlists.PlaylistItemQuery;
import org.jellyfin.apiclient.model.querying.SimilarItemsQuery;
import java.util.ArrayList;
@ -30,11 +30,10 @@ import java.util.List;
import java.util.Map;
public class SyncUtil {
private static final String TAG = "SyncUtil";
public static final String SONG = "song";
public static final String ALBUM = "album";
public static final String ARTIST = "artist";
private static final String TAG = "SyncUtil";
public static void getLibraries(Context context, MediaCallback callback) {
String id = App.getApiClientInstance(context).getCurrentUserId();
@ -258,11 +257,9 @@ public class SyncUtil {
for (BaseItemDto itemDto : result.getItems()) {
if (resultType.equals(ARTIST) && itemDto.getBaseItemType() == BaseItemType.MusicArtist) {
items.add(new Artist(itemDto));
}
else if (resultType.equals(ALBUM) && itemDto.getBaseItemType() == BaseItemType.MusicAlbum) {
} else if (resultType.equals(ALBUM) && itemDto.getBaseItemType() == BaseItemType.MusicAlbum) {
items.add(new Album(itemDto));
}
else if (resultType.equals(SONG) && itemDto.getBaseItemType() == BaseItemType.Audio) {
} else if (resultType.equals(SONG) && itemDto.getBaseItemType() == BaseItemType.Audio) {
items.add(new Song(itemDto));
}
}
@ -290,7 +287,7 @@ public class SyncUtil {
}
private static Song updateSongData(Map<Integer, Song> library, Song newSong) {
if(library.containsKey(newSong.hashCode())) {
if (library.containsKey(newSong.hashCode())) {
Song oldSong = library.get(newSong.hashCode());
newSong.setFavorite(oldSong.isFavorite());
newSong.setAdded(oldSong.getAdded());

View file

@ -12,9 +12,8 @@ import com.cappielloantonio.play.repository.AlbumRepository;
import java.util.List;
public class AlbumCatalogueViewModel extends AndroidViewModel {
private AlbumRepository albumRepository;
public LiveData<List<Album>> albumList;
private AlbumRepository albumRepository;
private String query = "";
public AlbumCatalogueViewModel(@NonNull Application application) {

View file

@ -14,11 +14,11 @@ public class ArtistBottomSheetViewModel extends AndroidViewModel {
super(application);
}
public void setArtist(Artist artist) {
this.artist = artist;
}
public Artist getArtist() {
return artist;
}
public void setArtist(Artist artist) {
this.artist = artist;
}
}

View file

@ -6,9 +6,7 @@ import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import com.cappielloantonio.play.model.Artist;
import com.cappielloantonio.play.model.Genre;
import com.cappielloantonio.play.repository.ArtistRepository;
import com.cappielloantonio.play.repository.GenreRepository;
import java.util.List;

View file

@ -39,7 +39,7 @@ public class HomeViewModel extends AndroidViewModel {
public List<Song> getDiscoverSongList() {
if(dicoverSongSample.isEmpty()) {
if (dicoverSongSample.isEmpty()) {
dicoverSongSample = songRepository.getRandomSample(10);
}

View file

@ -10,13 +10,11 @@ import com.cappielloantonio.play.model.Album;
import com.cappielloantonio.play.model.Artist;
import com.cappielloantonio.play.model.Genre;
import com.cappielloantonio.play.model.Playlist;
import com.cappielloantonio.play.model.Song;
import com.cappielloantonio.play.repository.AlbumRepository;
import com.cappielloantonio.play.repository.ArtistRepository;
import com.cappielloantonio.play.repository.GenreRepository;
import com.cappielloantonio.play.repository.PlaylistRepository;
import java.util.ArrayList;
import java.util.List;
public class LibraryViewModel extends AndroidViewModel {
@ -47,7 +45,7 @@ public class LibraryViewModel extends AndroidViewModel {
}
public List<Playlist> getPlaylistSample() {
if(playlistSample.isEmpty()) {
if (playlistSample.isEmpty()) {
playlistSample = playlistRepository.getRandomSample(5);
}

View file

@ -19,7 +19,7 @@ public class MainViewModel extends AndroidViewModel {
}
public boolean isQueueLoaded() {
if(queueRepository.count() == 0)
if (queueRepository.count() == 0)
return false;
return true;

View file

@ -6,10 +6,10 @@ import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import com.cappielloantonio.play.service.MusicPlayerRemote;
import com.cappielloantonio.play.model.Song;
import com.cappielloantonio.play.repository.QueueRepository;
import com.cappielloantonio.play.repository.SongRepository;
import com.cappielloantonio.play.service.MusicPlayerRemote;
import java.util.List;

View file

@ -6,9 +6,7 @@ import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import com.cappielloantonio.play.model.Genre;
import com.cappielloantonio.play.model.Playlist;
import com.cappielloantonio.play.repository.GenreRepository;
import com.cappielloantonio.play.repository.PlaylistRepository;
import java.util.List;

View file

@ -1,13 +1,11 @@
package com.cappielloantonio.play.viewmodel;
import android.app.Application;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import com.cappielloantonio.play.model.Album;
import com.cappielloantonio.play.model.Playlist;
import com.cappielloantonio.play.model.Song;
import com.cappielloantonio.play.repository.SongRepository;

View file

@ -56,7 +56,7 @@ public class SearchViewModel extends AndroidViewModel {
public void setQuery(String query) {
this.query = query;
if(!query.isEmpty()) {
if (!query.isEmpty()) {
insertNewSearch(query);
}
}

View file

@ -27,14 +27,14 @@ public class SongBottomSheetViewModel extends AndroidViewModel {
artistRepository = new ArtistRepository(application);
}
public void setSong(Song song) {
this.song = song;
}
public Song getSong() {
return song;
}
public void setSong(Song song) {
this.song = song;
}
public void setFavorite() {
song.setFavorite(!song.isFavorite());
songRepository.setFavoriteStatus(song);

View file

@ -16,16 +16,14 @@ import java.util.ArrayList;
import java.util.List;
public class SongListPageViewModel extends AndroidViewModel {
private SongRepository songRepository;
private LiveData<List<Song>> songList;
public String title;
public Genre genre;
public Artist artist;
public ArrayList<String> filters = new ArrayList<>();
public ArrayList<String> filterNames = new ArrayList<>();
public int year = 0;
private SongRepository songRepository;
private LiveData<List<Song>> songList;
public SongListPageViewModel(@NonNull Application application) {
super(application);

View file

@ -49,12 +49,12 @@ public class SyncViewModel extends AndroidViewModel {
}
private void countStep() {
if(syncAlbum) step++;
if(syncArtist) step++;
if(syncGenres) step++;
if(syncPlaylist) step++;
if(syncSong) step++;
if(crossSyncSongGenre) step++;
if (syncAlbum) step++;
if (syncArtist) step++;
if (syncGenres) step++;
if (syncPlaylist) step++;
if (syncSong) step++;
if (crossSyncSongGenre) step++;
}
public boolean isSyncAlbum() {
@ -90,7 +90,7 @@ public class SyncViewModel extends AndroidViewModel {
}
public void setProgress(Boolean step) {
if(step) progress++;
if (step) progress++;
}
public int getProgressBarInfo() {
@ -100,7 +100,7 @@ public class SyncViewModel extends AndroidViewModel {
public Map<Integer, Song> getCatalogue() {
Map<Integer, Song> map = new HashMap<>();
for(Song song: songRepository.getCatalogue()){
for (Song song : songRepository.getCatalogue()) {
map.put(song.hashCode(), song);
}