diff --git a/app/src/main/java/com/cappielloantonio/play/adapter/AlbumAdapter.java b/app/src/main/java/com/cappielloantonio/play/adapter/AlbumAdapter.java index 6f4cdae5..c7aecd7d 100644 --- a/app/src/main/java/com/cappielloantonio/play/adapter/AlbumAdapter.java +++ b/app/src/main/java/com/cappielloantonio/play/adapter/AlbumAdapter.java @@ -56,6 +56,15 @@ public class AlbumAdapter extends RecyclerView.Adapter return albums.size(); } + public Album getItem(int position) { + return albums.get(position); + } + + public void setItems(List 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 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 return true; } } - - public Album getItem(int position) { - return albums.get(position); - } - - public void setItems(List albums) { - this.albums = albums; - notifyDataSetChanged(); - } } diff --git a/app/src/main/java/com/cappielloantonio/play/adapter/AlbumArtistPageAdapter.java b/app/src/main/java/com/cappielloantonio/play/adapter/AlbumArtistPageAdapter.java index 36dce6ad..e8f9aa0c 100644 --- a/app/src/main/java/com/cappielloantonio/play/adapter/AlbumArtistPageAdapter.java +++ b/app/src/main/java/com/cappielloantonio/play/adapter/AlbumArtistPageAdapter.java @@ -54,6 +54,15 @@ public class AlbumArtistPageAdapter extends RecyclerView.Adapter 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 albums) { - this.albums = albums; - notifyDataSetChanged(); - } } diff --git a/app/src/main/java/com/cappielloantonio/play/adapter/AlbumCatalogueAdapter.java b/app/src/main/java/com/cappielloantonio/play/adapter/AlbumCatalogueAdapter.java index b83a152f..34187384 100644 --- a/app/src/main/java/com/cappielloantonio/play/adapter/AlbumCatalogueAdapter.java +++ b/app/src/main/java/com/cappielloantonio/play/adapter/AlbumCatalogueAdapter.java @@ -31,6 +31,36 @@ public class AlbumCatalogueAdapter extends RecyclerView.Adapter 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 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 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 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(); - } - }; } diff --git a/app/src/main/java/com/cappielloantonio/play/adapter/ArtistAdapter.java b/app/src/main/java/com/cappielloantonio/play/adapter/ArtistAdapter.java index c9fc0618..19d3ce29 100644 --- a/app/src/main/java/com/cappielloantonio/play/adapter/ArtistAdapter.java +++ b/app/src/main/java/com/cappielloantonio/play/adapter/ArtistAdapter.java @@ -55,6 +55,15 @@ public class ArtistAdapter extends RecyclerView.Adapter 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 artists) { - this.artists = artists; - notifyDataSetChanged(); - } } diff --git a/app/src/main/java/com/cappielloantonio/play/adapter/ArtistCatalogueAdapter.java b/app/src/main/java/com/cappielloantonio/play/adapter/ArtistCatalogueAdapter.java index 236121d8..90ab3cbe 100644 --- a/app/src/main/java/com/cappielloantonio/play/adapter/ArtistCatalogueAdapter.java +++ b/app/src/main/java/com/cappielloantonio/play/adapter/ArtistCatalogueAdapter.java @@ -31,6 +31,36 @@ public class ArtistCatalogueAdapter extends RecyclerView.Adapter 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 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 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 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(); - } - }; } diff --git a/app/src/main/java/com/cappielloantonio/play/adapter/DiscoverSongAdapter.java b/app/src/main/java/com/cappielloantonio/play/adapter/DiscoverSongAdapter.java index fe5b5945..e8244dd2 100644 --- a/app/src/main/java/com/cappielloantonio/play/adapter/DiscoverSongAdapter.java +++ b/app/src/main/java/com/cappielloantonio/play/adapter/DiscoverSongAdapter.java @@ -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 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 songs) { - this.songs = songs; - notifyDataSetChanged(); - } } \ No newline at end of file diff --git a/app/src/main/java/com/cappielloantonio/play/adapter/GenreAdapter.java b/app/src/main/java/com/cappielloantonio/play/adapter/GenreAdapter.java index ea986c50..47f20ada 100644 --- a/app/src/main/java/com/cappielloantonio/play/adapter/GenreAdapter.java +++ b/app/src/main/java/com/cappielloantonio/play/adapter/GenreAdapter.java @@ -46,6 +46,23 @@ public class GenreAdapter extends RecyclerView.Adapter return genres.size(); } + public Genre getItem(int position) { + return genres.get(position); + } + + public void setItems(List 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 itemClickListener.onItemClick(view, getBindingAdapterPosition()); } } - - public Genre getItem(int position) { - return genres.get(position); - } - - public void setItems(List genres) { - this.genres = genres; - notifyDataSetChanged(); - } - - public void setClickListener(ItemClickListener itemClickListener) { - this.itemClickListener = itemClickListener; - } - - public interface ItemClickListener { - void onItemClick(View view, int position); - } } diff --git a/app/src/main/java/com/cappielloantonio/play/adapter/GenreCatalogueAdapter.java b/app/src/main/java/com/cappielloantonio/play/adapter/GenreCatalogueAdapter.java index 5206e91c..8aeff5ed 100644 --- a/app/src/main/java/com/cappielloantonio/play/adapter/GenreCatalogueAdapter.java +++ b/app/src/main/java/com/cappielloantonio/play/adapter/GenreCatalogueAdapter.java @@ -27,78 +27,6 @@ public class GenreCatalogueAdapter extends RecyclerView.Adapter(); - } - - @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 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(); + } + + @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 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); + } + } + } } diff --git a/app/src/main/java/com/cappielloantonio/play/adapter/PlayerNowPlayingSongAdapter.java b/app/src/main/java/com/cappielloantonio/play/adapter/PlayerNowPlayingSongAdapter.java index bda86258..a1d055f0 100644 --- a/app/src/main/java/com/cappielloantonio/play/adapter/PlayerNowPlayingSongAdapter.java +++ b/app/src/main/java/com/cappielloantonio/play/adapter/PlayerNowPlayingSongAdapter.java @@ -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 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 songs) { - this.songs = songs; - notifyDataSetChanged(); - } } \ No newline at end of file diff --git a/app/src/main/java/com/cappielloantonio/play/adapter/PlayerSongQueueAdapter.java b/app/src/main/java/com/cappielloantonio/play/adapter/PlayerSongQueueAdapter.java index 5379a0d9..451177a1 100644 --- a/app/src/main/java/com/cappielloantonio/play/adapter/PlayerSongQueueAdapter.java +++ b/app/src/main/java/com/cappielloantonio/play/adapter/PlayerSongQueueAdapter.java @@ -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 getItems() { + return this.songs; + } + + public void setItems(List 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 songs) { - this.songs = songs; - notifyDataSetChanged(); - } - - public List getItems() { - return this.songs; - } - - public Song getItem(int id) { - return songs.get(id); - } } diff --git a/app/src/main/java/com/cappielloantonio/play/adapter/PlaylistAdapter.java b/app/src/main/java/com/cappielloantonio/play/adapter/PlaylistAdapter.java index 24dbfbd3..80c19c59 100644 --- a/app/src/main/java/com/cappielloantonio/play/adapter/PlaylistAdapter.java +++ b/app/src/main/java/com/cappielloantonio/play/adapter/PlaylistAdapter.java @@ -56,6 +56,15 @@ public class PlaylistAdapter extends RecyclerView.Adapter 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 playlists) { - this.playlists = playlists; - notifyDataSetChanged(); - } } diff --git a/app/src/main/java/com/cappielloantonio/play/adapter/PlaylistCatalogueAdapter.java b/app/src/main/java/com/cappielloantonio/play/adapter/PlaylistCatalogueAdapter.java index fb490986..7705f7fe 100644 --- a/app/src/main/java/com/cappielloantonio/play/adapter/PlaylistCatalogueAdapter.java +++ b/app/src/main/java/com/cappielloantonio/play/adapter/PlaylistCatalogueAdapter.java @@ -29,6 +29,36 @@ public class PlaylistCatalogueAdapter extends RecyclerView.Adapter 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 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 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 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(); - } - }; } diff --git a/app/src/main/java/com/cappielloantonio/play/adapter/RecentMusicAdapter.java b/app/src/main/java/com/cappielloantonio/play/adapter/RecentMusicAdapter.java index d7aa33ac..51c79286 100644 --- a/app/src/main/java/com/cappielloantonio/play/adapter/RecentMusicAdapter.java +++ b/app/src/main/java/com/cappielloantonio/play/adapter/RecentMusicAdapter.java @@ -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 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 songs) { - this.songs = songs; - notifyDataSetChanged(); - } } diff --git a/app/src/main/java/com/cappielloantonio/play/adapter/SongResultSearchAdapter.java b/app/src/main/java/com/cappielloantonio/play/adapter/SongResultSearchAdapter.java index 21ba53e6..b4724f3e 100644 --- a/app/src/main/java/com/cappielloantonio/play/adapter/SongResultSearchAdapter.java +++ b/app/src/main/java/com/cappielloantonio/play/adapter/SongResultSearchAdapter.java @@ -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 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 songs) { - this.songs = songs; - notifyDataSetChanged(); - } - - public Song getItem(int id) { - return songs.get(id); - } } diff --git a/app/src/main/java/com/cappielloantonio/play/adapter/YearAdapter.java b/app/src/main/java/com/cappielloantonio/play/adapter/YearAdapter.java index daff0b63..8b1ae125 100644 --- a/app/src/main/java/com/cappielloantonio/play/adapter/YearAdapter.java +++ b/app/src/main/java/com/cappielloantonio/play/adapter/YearAdapter.java @@ -43,23 +43,6 @@ public class YearAdapter extends RecyclerView.Adapter { 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 { 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()); + } + } } diff --git a/app/src/main/java/com/cappielloantonio/play/broadcast/receiver/MediaButtonIntentReceiver.java b/app/src/main/java/com/cappielloantonio/play/broadcast/receiver/MediaButtonIntentReceiver.java index 1c7d3b3d..b6e1352b 100644 --- a/app/src/main/java/com/cappielloantonio/play/broadcast/receiver/MediaButtonIntentReceiver.java +++ b/app/src/main/java/com/cappielloantonio/play/broadcast/receiver/MediaButtonIntentReceiver.java @@ -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(); + } + } } diff --git a/app/src/main/java/com/cappielloantonio/play/database/AppDatabase.java b/app/src/main/java/com/cappielloantonio/play/database/AppDatabase.java index 78de47ad..1ab3f2cb 100644 --- a/app/src/main/java/com/cappielloantonio/play/database/AppDatabase.java +++ b/app/src/main/java/com/cappielloantonio/play/database/AppDatabase.java @@ -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) { diff --git a/app/src/main/java/com/cappielloantonio/play/database/dao/AlbumArtistCrossDao.java b/app/src/main/java/com/cappielloantonio/play/database/dao/AlbumArtistCrossDao.java index 12debfe2..0da5ffa1 100644 --- a/app/src/main/java/com/cappielloantonio/play/database/dao/AlbumArtistCrossDao.java +++ b/app/src/main/java/com/cappielloantonio/play/database/dao/AlbumArtistCrossDao.java @@ -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; diff --git a/app/src/main/java/com/cappielloantonio/play/database/dao/AlbumDao.java b/app/src/main/java/com/cappielloantonio/play/database/dao/AlbumDao.java index 44bbf9cd..fe0da3ea 100644 --- a/app/src/main/java/com/cappielloantonio/play/database/dao/AlbumDao.java +++ b/app/src/main/java/com/cappielloantonio/play/database/dao/AlbumDao.java @@ -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; diff --git a/app/src/main/java/com/cappielloantonio/play/database/dao/ArtistDao.java b/app/src/main/java/com/cappielloantonio/play/database/dao/ArtistDao.java index 75b72271..1155301f 100644 --- a/app/src/main/java/com/cappielloantonio/play/database/dao/ArtistDao.java +++ b/app/src/main/java/com/cappielloantonio/play/database/dao/ArtistDao.java @@ -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; diff --git a/app/src/main/java/com/cappielloantonio/play/database/dao/GenreDao.java b/app/src/main/java/com/cappielloantonio/play/database/dao/GenreDao.java index 1b6b2e6a..a3599b13 100644 --- a/app/src/main/java/com/cappielloantonio/play/database/dao/GenreDao.java +++ b/app/src/main/java/com/cappielloantonio/play/database/dao/GenreDao.java @@ -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; diff --git a/app/src/main/java/com/cappielloantonio/play/database/dao/PlaylistDao.java b/app/src/main/java/com/cappielloantonio/play/database/dao/PlaylistDao.java index 06f64cef..a68f269d 100644 --- a/app/src/main/java/com/cappielloantonio/play/database/dao/PlaylistDao.java +++ b/app/src/main/java/com/cappielloantonio/play/database/dao/PlaylistDao.java @@ -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; diff --git a/app/src/main/java/com/cappielloantonio/play/database/dao/PlaylistSongCrossDao.java b/app/src/main/java/com/cappielloantonio/play/database/dao/PlaylistSongCrossDao.java index 248a79d3..279462bf 100644 --- a/app/src/main/java/com/cappielloantonio/play/database/dao/PlaylistSongCrossDao.java +++ b/app/src/main/java/com/cappielloantonio/play/database/dao/PlaylistSongCrossDao.java @@ -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; diff --git a/app/src/main/java/com/cappielloantonio/play/database/dao/QueueDao.java b/app/src/main/java/com/cappielloantonio/play/database/dao/QueueDao.java index bedb2ca2..70016c16 100644 --- a/app/src/main/java/com/cappielloantonio/play/database/dao/QueueDao.java +++ b/app/src/main/java/com/cappielloantonio/play/database/dao/QueueDao.java @@ -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; diff --git a/app/src/main/java/com/cappielloantonio/play/database/dao/RecentSearchDao.java b/app/src/main/java/com/cappielloantonio/play/database/dao/RecentSearchDao.java index 1fa8ddd6..34bf58c0 100644 --- a/app/src/main/java/com/cappielloantonio/play/database/dao/RecentSearchDao.java +++ b/app/src/main/java/com/cappielloantonio/play/database/dao/RecentSearchDao.java @@ -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; diff --git a/app/src/main/java/com/cappielloantonio/play/database/dao/SongArtistCrossDao.java b/app/src/main/java/com/cappielloantonio/play/database/dao/SongArtistCrossDao.java index 85de4e08..4c6af345 100644 --- a/app/src/main/java/com/cappielloantonio/play/database/dao/SongArtistCrossDao.java +++ b/app/src/main/java/com/cappielloantonio/play/database/dao/SongArtistCrossDao.java @@ -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; diff --git a/app/src/main/java/com/cappielloantonio/play/database/dao/SongDao.java b/app/src/main/java/com/cappielloantonio/play/database/dao/SongDao.java index 9559236e..231c7279 100644 --- a/app/src/main/java/com/cappielloantonio/play/database/dao/SongDao.java +++ b/app/src/main/java/com/cappielloantonio/play/database/dao/SongDao.java @@ -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; diff --git a/app/src/main/java/com/cappielloantonio/play/glide/CustomGlideRequest.java b/app/src/main/java/com/cappielloantonio/play/glide/CustomGlideRequest.java index 2ea16301..5098b47f 100644 --- a/app/src/main/java/com/cappielloantonio/play/glide/CustomGlideRequest.java +++ b/app/src/main/java/com/cappielloantonio/play/glide/CustomGlideRequest.java @@ -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 build() { - return requestManager.load(item); - } - } - - public static class BitmapBuilder { - private final Builder builder; - - public BitmapBuilder(Builder builder) { - this.builder = builder; - } - - public RequestBuilder 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 build() { + return requestManager.load(item); + } + } + + public static class BitmapBuilder { + private final Builder builder; + + public BitmapBuilder(Builder builder) { + this.builder = builder; + } + + public RequestBuilder build() { + return builder.requestManager.asBitmap().load(builder.item); + } + } } diff --git a/app/src/main/java/com/cappielloantonio/play/helper/MusicProgressViewUpdateHelper.java b/app/src/main/java/com/cappielloantonio/play/helper/MusicProgressViewUpdateHelper.java index 31b06ca1..b738c7d3 100644 --- a/app/src/main/java/com/cappielloantonio/play/helper/MusicProgressViewUpdateHelper.java +++ b/app/src/main/java/com/cappielloantonio/play/helper/MusicProgressViewUpdateHelper.java @@ -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); diff --git a/app/src/main/java/com/cappielloantonio/play/helper/ThemeHelper.java b/app/src/main/java/com/cappielloantonio/play/helper/ThemeHelper.java index 273f3e0c..b9c4c985 100644 --- a/app/src/main/java/com/cappielloantonio/play/helper/ThemeHelper.java +++ b/app/src/main/java/com/cappielloantonio/play/helper/ThemeHelper.java @@ -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) { diff --git a/app/src/main/java/com/cappielloantonio/play/interfaces/Playback.java b/app/src/main/java/com/cappielloantonio/play/interfaces/Playback.java index fe0c23fc..fc2a65d8 100644 --- a/app/src/main/java/com/cappielloantonio/play/interfaces/Playback.java +++ b/app/src/main/java/com/cappielloantonio/play/interfaces/Playback.java @@ -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); diff --git a/app/src/main/java/com/cappielloantonio/play/repository/AlbumArtistRepository.java b/app/src/main/java/com/cappielloantonio/play/repository/AlbumArtistRepository.java index 540e643f..bc4b9270 100644 --- a/app/src/main/java/com/cappielloantonio/play/repository/AlbumArtistRepository.java +++ b/app/src/main/java/com/cappielloantonio/play/repository/AlbumArtistRepository.java @@ -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 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; diff --git a/app/src/main/java/com/cappielloantonio/play/repository/AlbumRepository.java b/app/src/main/java/com/cappielloantonio/play/repository/AlbumRepository.java index 23d35541..a396bde5 100644 --- a/app/src/main/java/com/cappielloantonio/play/repository/AlbumRepository.java +++ b/app/src/main/java/com/cappielloantonio/play/repository/AlbumRepository.java @@ -63,6 +63,35 @@ public class AlbumRepository { return suggestions; } + public void insertAll(ArrayList 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 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; diff --git a/app/src/main/java/com/cappielloantonio/play/repository/ArtistRepository.java b/app/src/main/java/com/cappielloantonio/play/repository/ArtistRepository.java index 56d0a6e6..63b59e5a 100644 --- a/app/src/main/java/com/cappielloantonio/play/repository/ArtistRepository.java +++ b/app/src/main/java/com/cappielloantonio/play/repository/ArtistRepository.java @@ -55,6 +55,35 @@ public class ArtistRepository { return suggestions; } + public void insertAll(ArrayList 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 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 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; diff --git a/app/src/main/java/com/cappielloantonio/play/repository/GenreRepository.java b/app/src/main/java/com/cappielloantonio/play/repository/GenreRepository.java index 0655c7f5..8f399650 100644 --- a/app/src/main/java/com/cappielloantonio/play/repository/GenreRepository.java +++ b/app/src/main/java/com/cappielloantonio/play/repository/GenreRepository.java @@ -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 list = null; - - public GetGenreListThreadSafe(GenreDao genreDao) { - this.genreDao = genreDao; - } - - @Override - public void run() { - list = genreDao.getGenreList(); - } - - public List getList() { - return list; - } - } - public void insertAll(ArrayList 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 genres; - - public InsertAllThreadSafe(GenreDao genreDao, ArrayList 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> 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 list = null; + + public GetGenreListThreadSafe(GenreDao genreDao) { + this.genreDao = genreDao; + } + + @Override + public void run() { + list = genreDao.getGenreList(); + } + + public List getList() { + return list; + } + } + + private static class InsertAllThreadSafe implements Runnable { + private GenreDao genreDao; + private ArrayList genres; + + public InsertAllThreadSafe(GenreDao genreDao, ArrayList 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; diff --git a/app/src/main/java/com/cappielloantonio/play/repository/PlaylistRepository.java b/app/src/main/java/com/cappielloantonio/play/repository/PlaylistRepository.java index 2c649fdc..ce83d47d 100644 --- a/app/src/main/java/com/cappielloantonio/play/repository/PlaylistRepository.java +++ b/app/src/main/java/com/cappielloantonio/play/repository/PlaylistRepository.java @@ -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 playlists; - - public InsertAllThreadSafe(PlaylistDao playlistDao, ArrayList 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 getRandomSample(int number) { List sample = new ArrayList<>(); @@ -85,6 +54,35 @@ public class PlaylistRepository { return sample; } + private static class InsertAllThreadSafe implements Runnable { + private PlaylistDao playlistDao; + private ArrayList playlists; + + public InsertAllThreadSafe(PlaylistDao playlistDao, ArrayList 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; diff --git a/app/src/main/java/com/cappielloantonio/play/repository/PlaylistSongRepository.java b/app/src/main/java/com/cappielloantonio/play/repository/PlaylistSongRepository.java index 27fdf262..a9c32f37 100644 --- a/app/src/main/java/com/cappielloantonio/play/repository/PlaylistSongRepository.java +++ b/app/src/main/java/com/cappielloantonio/play/repository/PlaylistSongRepository.java @@ -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 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; diff --git a/app/src/main/java/com/cappielloantonio/play/repository/QueueRepository.java b/app/src/main/java/com/cappielloantonio/play/repository/QueueRepository.java index 1eb474bc..8e32993d 100644 --- a/app/src/main/java/com/cappielloantonio/play/repository/QueueRepository.java +++ b/app/src/main/java/com/cappielloantonio/play/repository/QueueRepository.java @@ -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 songs; - - public GetSongsThreadSafe(QueueDao queueDao) { - this.queueDao = queueDao; - } - - @Override - public void run() { - songs = queueDao.getAllSimple(); - } - - public List getSongs() { - return songs; - } - } - public void insertAll(List 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 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 songs; + + public GetSongsThreadSafe(QueueDao queueDao) { + this.queueDao = queueDao; + } + + @Override + public void run() { + songs = queueDao.getAllSimple(); + } + + public List getSongs() { + return songs; + } + } + private static class GetSongsByIDThreadSafe implements Runnable { private SongDao songDao; private List IDs; @@ -114,20 +155,6 @@ public class QueueRepository { } } - public void insertAllAndStartNew(List 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 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; diff --git a/app/src/main/java/com/cappielloantonio/play/repository/RecentSearchRepository.java b/app/src/main/java/com/cappielloantonio/play/repository/RecentSearchRepository.java index e34b5746..162d59ff 100644 --- a/app/src/main/java/com/cappielloantonio/play/repository/RecentSearchRepository.java +++ b/app/src/main/java/com/cappielloantonio/play/repository/RecentSearchRepository.java @@ -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 getRecentSearchSuggestion(int limit) { + List 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 getRecentSearchSuggestion(int limit) { - List 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; diff --git a/app/src/main/java/com/cappielloantonio/play/repository/SongArtistRepository.java b/app/src/main/java/com/cappielloantonio/play/repository/SongArtistRepository.java index 464bd63c..231ceda9 100644 --- a/app/src/main/java/com/cappielloantonio/play/repository/SongArtistRepository.java +++ b/app/src/main/java/com/cappielloantonio/play/repository/SongArtistRepository.java @@ -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 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; diff --git a/app/src/main/java/com/cappielloantonio/play/repository/SongRepository.java b/app/src/main/java/com/cappielloantonio/play/repository/SongRepository.java index 6cbf5878..51a7ced1 100644 --- a/app/src/main/java/com/cappielloantonio/play/repository/SongRepository.java +++ b/app/src/main/java/com/cappielloantonio/play/repository/SongRepository.java @@ -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 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 getSongs() { - return songs; - } - } - public LiveData> 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 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 getSongs() { - return songs; - } - } - public LiveData> getFilteredListLiveSong(ArrayList 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 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 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 catalogue = new ArrayList<>(); - - public GetCatalogueThreadSafe(SongDao songDao) { - this.songDao = songDao; - } - - @Override - public void run() { - catalogue = songDao.getAllList(); - } - - public List getCatalogue() { - return catalogue; - } - } - public List getYearList() { List years = new ArrayList<>(); @@ -271,35 +189,6 @@ public class SongRepository { return years; } - private static class GetYearListThreadSafe implements Runnable { - private SongDao songDao; - private List years = new ArrayList<>(); - private List 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 getYearList() { - return years; - } - - public List getDecadeList() { - return decades; - } - } - public LiveData> 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 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 getRandomSample(int number) { + List 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 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 getSongs() { + return songs; + } + } + + private static class GetSongsByAlbumIDThreadSafe implements Runnable { + private SongDao songDao; + private String albumID; + private List 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 getSongs() { + return songs; + } + } + + private static class SearchSuggestionsThreadSafe implements Runnable { + private SongDao songDao; + private String query; + private int number; + private List 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 getSuggestions() { + return suggestions; + } + } + + private static class GetCatalogueThreadSafe implements Runnable { + private SongDao songDao; + private List catalogue = new ArrayList<>(); + + public GetCatalogueThreadSafe(SongDao songDao) { + this.songDao = songDao; + } + + @Override + public void run() { + catalogue = songDao.getAllList(); + } + + public List getCatalogue() { + return catalogue; + } + } + + private static class GetYearListThreadSafe implements Runnable { + private SongDao songDao; + private List years = new ArrayList<>(); + private List 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 getYearList() { + return years; + } + + public List 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 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 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 getRandomSample(int number) { - List 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; diff --git a/app/src/main/java/com/cappielloantonio/play/service/DownloadTracker.java b/app/src/main/java/com/cappielloantonio/play/service/DownloadTracker.java index be4a7693..d04deee7 100644 --- a/app/src/main/java/com/cappielloantonio/play/service/DownloadTracker.java +++ b/app/src/main/java/com/cappielloantonio/play/service/DownloadTracker.java @@ -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 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); diff --git a/app/src/main/java/com/cappielloantonio/play/service/DownloaderService.java b/app/src/main/java/com/cappielloantonio/play/service/DownloaderService.java index be077674..4cc02676 100644 --- a/app/src/main/java/com/cappielloantonio/play/service/DownloaderService.java +++ b/app/src/main/java/com/cappielloantonio/play/service/DownloaderService.java @@ -44,7 +44,7 @@ public class DownloaderService extends DownloadService { @Override @NonNull protected Notification getForegroundNotification(@NonNull List 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 { diff --git a/app/src/main/java/com/cappielloantonio/play/service/MultiPlayer.java b/app/src/main/java/com/cappielloantonio/play/service/MultiPlayer.java index 4f6bccbb..ee9b9ec9 100644 --- a/app/src/main/java/com/cappielloantonio/play/service/MultiPlayer.java +++ b/app/src/main/java/com/cappielloantonio/play/service/MultiPlayer.java @@ -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); + } } diff --git a/app/src/main/java/com/cappielloantonio/play/service/MusicPlayerRemote.java b/app/src/main/java/com/cappielloantonio/play/service/MusicPlayerRemote.java index c34b9860..a8463112 100644 --- a/app/src/main/java/com/cappielloantonio/play/service/MusicPlayerRemote.java +++ b/app/src/main/java/com/cappielloantonio/play/service/MusicPlayerRemote.java @@ -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 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 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; + } + } } diff --git a/app/src/main/java/com/cappielloantonio/play/service/MusicService.java b/app/src/main/java/com/cappielloantonio/play/service/MusicService.java index ffa697e5..0e68d242 100644 --- a/app/src/main/java/com/cappielloantonio/play/service/MusicService.java +++ b/app/src/main/java/com/cappielloantonio/play/service/MusicService.java @@ -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 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 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 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 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 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); + } + } } diff --git a/app/src/main/java/com/cappielloantonio/play/util/MusicUtil.java b/app/src/main/java/com/cappielloantonio/play/util/MusicUtil.java index d5745637..c832db43 100644 --- a/app/src/main/java/com/cappielloantonio/play/util/MusicUtil.java +++ b/app/src/main/java/com/cappielloantonio/play/util/MusicUtil.java @@ -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 getMediaItemsFromSongs(List songs) { List 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 getRandomSongNumber(Context context, int numberOfNumbers, int refreshAfterXHours) { List 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)); } diff --git a/app/src/main/java/com/cappielloantonio/play/util/PreferenceUtil.java b/app/src/main/java/com/cappielloantonio/play/util/PreferenceUtil.java index bd428eb1..84bf4bee 100644 --- a/app/src/main/java/com/cappielloantonio/play/util/PreferenceUtil.java +++ b/app/src/main/java/com/cappielloantonio/play/util/PreferenceUtil.java @@ -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"); diff --git a/app/src/main/java/com/cappielloantonio/play/util/QueueUtil.java b/app/src/main/java/com/cappielloantonio/play/util/QueueUtil.java index 1b94a074..a0f10b0a 100644 --- a/app/src/main/java/com/cappielloantonio/play/util/QueueUtil.java +++ b/app/src/main/java/com/cappielloantonio/play/util/QueueUtil.java @@ -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 = 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 getIDsFromSongs(List songs) { List 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 orderSongByIdList(List IDs, List songs) { List 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; } diff --git a/app/src/main/java/com/cappielloantonio/play/util/SyncUtil.java b/app/src/main/java/com/cappielloantonio/play/util/SyncUtil.java index 66a9a329..2e301041 100644 --- a/app/src/main/java/com/cappielloantonio/play/util/SyncUtil.java +++ b/app/src/main/java/com/cappielloantonio/play/util/SyncUtil.java @@ -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 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()); diff --git a/app/src/main/java/com/cappielloantonio/play/viewmodel/AlbumCatalogueViewModel.java b/app/src/main/java/com/cappielloantonio/play/viewmodel/AlbumCatalogueViewModel.java index 2ed61dac..44671256 100644 --- a/app/src/main/java/com/cappielloantonio/play/viewmodel/AlbumCatalogueViewModel.java +++ b/app/src/main/java/com/cappielloantonio/play/viewmodel/AlbumCatalogueViewModel.java @@ -12,9 +12,8 @@ import com.cappielloantonio.play.repository.AlbumRepository; import java.util.List; public class AlbumCatalogueViewModel extends AndroidViewModel { - private AlbumRepository albumRepository; public LiveData> albumList; - + private AlbumRepository albumRepository; private String query = ""; public AlbumCatalogueViewModel(@NonNull Application application) { diff --git a/app/src/main/java/com/cappielloantonio/play/viewmodel/ArtistBottomSheetViewModel.java b/app/src/main/java/com/cappielloantonio/play/viewmodel/ArtistBottomSheetViewModel.java index b2a2a36d..7ce9a7a4 100644 --- a/app/src/main/java/com/cappielloantonio/play/viewmodel/ArtistBottomSheetViewModel.java +++ b/app/src/main/java/com/cappielloantonio/play/viewmodel/ArtistBottomSheetViewModel.java @@ -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; + } } diff --git a/app/src/main/java/com/cappielloantonio/play/viewmodel/GenreCatalogueViewModel.java b/app/src/main/java/com/cappielloantonio/play/viewmodel/GenreCatalogueViewModel.java index a8c1e9c8..852825d4 100644 --- a/app/src/main/java/com/cappielloantonio/play/viewmodel/GenreCatalogueViewModel.java +++ b/app/src/main/java/com/cappielloantonio/play/viewmodel/GenreCatalogueViewModel.java @@ -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; diff --git a/app/src/main/java/com/cappielloantonio/play/viewmodel/HomeViewModel.java b/app/src/main/java/com/cappielloantonio/play/viewmodel/HomeViewModel.java index 0d5ce6d8..c3b8e9be 100644 --- a/app/src/main/java/com/cappielloantonio/play/viewmodel/HomeViewModel.java +++ b/app/src/main/java/com/cappielloantonio/play/viewmodel/HomeViewModel.java @@ -39,7 +39,7 @@ public class HomeViewModel extends AndroidViewModel { public List getDiscoverSongList() { - if(dicoverSongSample.isEmpty()) { + if (dicoverSongSample.isEmpty()) { dicoverSongSample = songRepository.getRandomSample(10); } diff --git a/app/src/main/java/com/cappielloantonio/play/viewmodel/LibraryViewModel.java b/app/src/main/java/com/cappielloantonio/play/viewmodel/LibraryViewModel.java index f4d880e4..accd1ad3 100644 --- a/app/src/main/java/com/cappielloantonio/play/viewmodel/LibraryViewModel.java +++ b/app/src/main/java/com/cappielloantonio/play/viewmodel/LibraryViewModel.java @@ -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 getPlaylistSample() { - if(playlistSample.isEmpty()) { + if (playlistSample.isEmpty()) { playlistSample = playlistRepository.getRandomSample(5); } diff --git a/app/src/main/java/com/cappielloantonio/play/viewmodel/MainViewModel.java b/app/src/main/java/com/cappielloantonio/play/viewmodel/MainViewModel.java index 25ed2d31..75f4a3c1 100644 --- a/app/src/main/java/com/cappielloantonio/play/viewmodel/MainViewModel.java +++ b/app/src/main/java/com/cappielloantonio/play/viewmodel/MainViewModel.java @@ -19,7 +19,7 @@ public class MainViewModel extends AndroidViewModel { } public boolean isQueueLoaded() { - if(queueRepository.count() == 0) + if (queueRepository.count() == 0) return false; return true; diff --git a/app/src/main/java/com/cappielloantonio/play/viewmodel/PlayerBottomSheetViewModel.java b/app/src/main/java/com/cappielloantonio/play/viewmodel/PlayerBottomSheetViewModel.java index 91a6de4e..68845c76 100644 --- a/app/src/main/java/com/cappielloantonio/play/viewmodel/PlayerBottomSheetViewModel.java +++ b/app/src/main/java/com/cappielloantonio/play/viewmodel/PlayerBottomSheetViewModel.java @@ -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; diff --git a/app/src/main/java/com/cappielloantonio/play/viewmodel/PlaylistCatalogueViewModel.java b/app/src/main/java/com/cappielloantonio/play/viewmodel/PlaylistCatalogueViewModel.java index a88b3d1b..5582e418 100644 --- a/app/src/main/java/com/cappielloantonio/play/viewmodel/PlaylistCatalogueViewModel.java +++ b/app/src/main/java/com/cappielloantonio/play/viewmodel/PlaylistCatalogueViewModel.java @@ -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; diff --git a/app/src/main/java/com/cappielloantonio/play/viewmodel/PlaylistPageViewModel.java b/app/src/main/java/com/cappielloantonio/play/viewmodel/PlaylistPageViewModel.java index 5d77a4a0..37a8ebbb 100644 --- a/app/src/main/java/com/cappielloantonio/play/viewmodel/PlaylistPageViewModel.java +++ b/app/src/main/java/com/cappielloantonio/play/viewmodel/PlaylistPageViewModel.java @@ -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; diff --git a/app/src/main/java/com/cappielloantonio/play/viewmodel/SearchViewModel.java b/app/src/main/java/com/cappielloantonio/play/viewmodel/SearchViewModel.java index ff117ecf..99f7fb52 100644 --- a/app/src/main/java/com/cappielloantonio/play/viewmodel/SearchViewModel.java +++ b/app/src/main/java/com/cappielloantonio/play/viewmodel/SearchViewModel.java @@ -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); } } diff --git a/app/src/main/java/com/cappielloantonio/play/viewmodel/SongBottomSheetViewModel.java b/app/src/main/java/com/cappielloantonio/play/viewmodel/SongBottomSheetViewModel.java index 66d676bb..2570d035 100644 --- a/app/src/main/java/com/cappielloantonio/play/viewmodel/SongBottomSheetViewModel.java +++ b/app/src/main/java/com/cappielloantonio/play/viewmodel/SongBottomSheetViewModel.java @@ -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); diff --git a/app/src/main/java/com/cappielloantonio/play/viewmodel/SongListPageViewModel.java b/app/src/main/java/com/cappielloantonio/play/viewmodel/SongListPageViewModel.java index 1342a9a8..d7b441a8 100644 --- a/app/src/main/java/com/cappielloantonio/play/viewmodel/SongListPageViewModel.java +++ b/app/src/main/java/com/cappielloantonio/play/viewmodel/SongListPageViewModel.java @@ -16,16 +16,14 @@ import java.util.ArrayList; import java.util.List; public class SongListPageViewModel extends AndroidViewModel { - private SongRepository songRepository; - - private LiveData> songList; - public String title; public Genre genre; public Artist artist; public ArrayList filters = new ArrayList<>(); public ArrayList filterNames = new ArrayList<>(); public int year = 0; + private SongRepository songRepository; + private LiveData> songList; public SongListPageViewModel(@NonNull Application application) { super(application); diff --git a/app/src/main/java/com/cappielloantonio/play/viewmodel/SyncViewModel.java b/app/src/main/java/com/cappielloantonio/play/viewmodel/SyncViewModel.java index 64c5c9ee..1cfb20b3 100644 --- a/app/src/main/java/com/cappielloantonio/play/viewmodel/SyncViewModel.java +++ b/app/src/main/java/com/cappielloantonio/play/viewmodel/SyncViewModel.java @@ -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 getCatalogue() { Map map = new HashMap<>(); - for(Song song: songRepository.getCatalogue()){ + for (Song song : songRepository.getCatalogue()) { map.put(song.hashCode(), song); }