Added discover/recentryAddedAlbum/recentlyPlayedAlbum/mostPlayedAlbum data retrieval

This commit is contained in:
CappielloAntonio 2021-07-27 12:10:28 +02:00
parent 304a5f078a
commit 532fcd1ee6
45 changed files with 351 additions and 1205 deletions

View file

@ -180,7 +180,7 @@ public class AlbumPageFragment extends Fragment {
private void initBackCover() {
CustomGlideRequest.Builder
.from(requireContext(), albumPageViewModel.getAlbum().getPrimary(), albumPageViewModel.getAlbum().getBlurHash(), CustomGlideRequest.PRIMARY, PreferenceUtil.getInstance(requireContext()).getImageQuality(), CustomGlideRequest.ALBUM_PIC)
.from(requireContext(), albumPageViewModel.getAlbum().getPrimary(), albumPageViewModel.getAlbum().getBlurHash(), CustomGlideRequest.ALBUM_PIC)
.build()
.into(bind.albumCoverImageView);
}

View file

@ -114,7 +114,7 @@ public class ArtistPageFragment extends Fragment {
private void initBackdrop() {
CustomGlideRequest.Builder
.from(requireContext(), artistPageViewModel.getArtist().getBackdrop(), artistPageViewModel.getArtist().getBackdropBlurHash(), CustomGlideRequest.BACKDROP, PreferenceUtil.getInstance(requireContext()).getImageQuality(), CustomGlideRequest.ARTIST_PIC)
.from(requireContext(), artistPageViewModel.getArtist().getPrimary(), artistPageViewModel.getArtist().getPrimary(), CustomGlideRequest.ARTIST_PIC)
.build()
.into(bind.artistBackdropImageView);
}

View file

@ -4,6 +4,7 @@ import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -16,16 +17,19 @@ import androidx.recyclerview.widget.PagerSnapHelper;
import androidx.viewpager2.widget.ViewPager2;
import com.cappielloantonio.play.R;
import com.cappielloantonio.play.adapter.AlbumAdapter;
import com.cappielloantonio.play.adapter.DiscoverSongAdapter;
import com.cappielloantonio.play.adapter.RecentMusicAdapter;
import com.cappielloantonio.play.adapter.SongResultSearchAdapter;
import com.cappielloantonio.play.adapter.YearAdapter;
import com.cappielloantonio.play.databinding.FragmentHomeBinding;
import com.cappielloantonio.play.interfaces.MediaCallback;
import com.cappielloantonio.play.model.Song;
import com.cappielloantonio.play.ui.activity.MainActivity;
import com.cappielloantonio.play.util.Util;
import com.cappielloantonio.play.viewmodel.HomeViewModel;
import java.util.List;
public class HomeFragment extends Fragment {
private static final String TAG = "CategoriesFragment";
@ -33,14 +37,17 @@ public class HomeFragment extends Fragment {
private MainActivity activity;
private HomeViewModel homeViewModel;
private DiscoverSongAdapter discoverSongAdapter;
private RecentMusicAdapter recentlyAddedMusicAdapter;
private YearAdapter yearAdapter;
private SongResultSearchAdapter favoriteSongAdapter;
private RecentMusicAdapter recentlyPlayedMusicAdapter;
private RecentMusicAdapter mostPlayedMusicAdapter;
private RecentMusicAdapter dowanloadedMusicAdapter;
// ---------------------------------------------------- SUBSONIC ADAPTER
private DiscoverSongAdapter discoverSongAdapter;
private AlbumAdapter recentlyAddedAlbumAdapter;
private AlbumAdapter recentlyPlayedAlbumAdapter;
private AlbumAdapter mostPlayedAlbumAdapter;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
@ -60,11 +67,11 @@ public class HomeFragment extends Fragment {
super.onViewCreated(view, savedInstanceState);
initDiscoverSongSlideView();
initMostPlayedSongView();
initRecentPlayedSongView();
initMostPlayedAlbumView();
initRecentPlayedAlbumView();
initFavoritesSongView();
initYearSongView();
initRecentAddedSongView();
initRecentAddedAlbumView();
initDownloadedSongView();
}
@ -82,19 +89,19 @@ public class HomeFragment extends Fragment {
}
private void init() {
bind.recentlyAddedTracksTextViewClickable.setOnClickListener(v -> {
bind.recentlyAddedAlbumsTextViewClickable.setOnClickListener(v -> {
Bundle bundle = new Bundle();
bundle.putString(Song.RECENTLY_ADDED, Song.RECENTLY_ADDED);
activity.navController.navigate(R.id.action_homeFragment_to_songListPageFragment, bundle);
});
bind.recentlyPlayedTracksTextViewClickable.setOnClickListener(v -> {
bind.recentlyPlayedAlbumsTextViewClickable.setOnClickListener(v -> {
Bundle bundle = new Bundle();
bundle.putString(Song.RECENTLY_PLAYED, Song.RECENTLY_PLAYED);
activity.navController.navigate(R.id.action_homeFragment_to_songListPageFragment, bundle);
});
bind.mostPlayedTracksTextViewClickable.setOnClickListener(v -> {
bind.mostPlayedAlbumsTextViewClickable.setOnClickListener(v -> {
Bundle bundle = new Bundle();
bundle.putString(Song.MOST_PLAYED, Song.MOST_PLAYED);
activity.navController.navigate(R.id.action_homeFragment_to_songListPageFragment, bundle);
@ -118,34 +125,44 @@ public class HomeFragment extends Fragment {
private void initDiscoverSongSlideView() {
bind.discoverSongViewPager.setOrientation(ViewPager2.ORIENTATION_HORIZONTAL);
discoverSongAdapter = new DiscoverSongAdapter(activity, requireContext(), homeViewModel.getDiscoverSongList());
bind.discoverSongViewPager.setAdapter(discoverSongAdapter);
bind.discoverSongViewPager.setOffscreenPageLimit(3);
setDiscoverSongSlideViewOffset(20, 16);
}
homeViewModel.getSongRepository().getRandomSample(10, new MediaCallback() {
@Override
public void onError(Exception exception) {
Toast.makeText(requireContext(), exception.getMessage(), Toast.LENGTH_SHORT).show();
}
private void initMostPlayedSongView() {
bind.mostPlayedTracksRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
bind.mostPlayedTracksRecyclerView.setHasFixedSize(true);
mostPlayedMusicAdapter = new RecentMusicAdapter(activity, requireContext(), getChildFragmentManager());
bind.mostPlayedTracksRecyclerView.setAdapter(mostPlayedMusicAdapter);
homeViewModel.getMostPlayedSongList().observe(requireActivity(), songs -> {
if(songs.size() < 10) reorder();
if(bind != null) bind.homeMostPlayedTracksSector.setVisibility(!songs.isEmpty() ? View.VISIBLE : View.GONE);
mostPlayedMusicAdapter.setItems(songs);
@Override
public void onLoadMedia(List<?> media) {
discoverSongAdapter = new DiscoverSongAdapter(activity, requireContext(), (List<Song>) media);
bind.discoverSongViewPager.setAdapter(discoverSongAdapter);
bind.discoverSongViewPager.setOffscreenPageLimit(3);
setDiscoverSongSlideViewOffset(20, 16);
}
});
}
private void initRecentPlayedSongView() {
bind.recentlyPlayedTracksRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
bind.recentlyPlayedTracksRecyclerView.setHasFixedSize(true);
private void initMostPlayedAlbumView() {
bind.mostPlayedAlbumsRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
bind.mostPlayedAlbumsRecyclerView.setHasFixedSize(true);
recentlyPlayedMusicAdapter = new RecentMusicAdapter(activity, requireContext(), getChildFragmentManager());
bind.recentlyPlayedTracksRecyclerView.setAdapter(recentlyPlayedMusicAdapter);
homeViewModel.getRecentlyPlayedSongList().observe(requireActivity(), songs -> {
if(bind != null) bind.homeRecentlyPlayedTracksSector.setVisibility(!songs.isEmpty() ? View.VISIBLE : View.GONE);
recentlyPlayedMusicAdapter.setItems(songs);
mostPlayedAlbumAdapter = new AlbumAdapter(requireContext());
bind.mostPlayedAlbumsRecyclerView.setAdapter(mostPlayedAlbumAdapter);
homeViewModel.getMostPlayedAlbums().observe(requireActivity(), albums -> {
if(albums.size() < 10) reorder();
if(bind != null) bind.homeMostPlayedAlbumsSector.setVisibility(!albums.isEmpty() ? View.VISIBLE : View.GONE);
mostPlayedAlbumAdapter.setItems(albums);
});
}
private void initRecentPlayedAlbumView() {
bind.recentlyPlayedAlbumsRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
bind.recentlyPlayedAlbumsRecyclerView.setHasFixedSize(true);
recentlyPlayedAlbumAdapter = new AlbumAdapter(requireContext());
bind.recentlyPlayedAlbumsRecyclerView.setAdapter(recentlyPlayedAlbumAdapter);
homeViewModel.getRecentlyPlayedAlbumList().observe(requireActivity(), albums -> {
if(bind != null) bind.homeRecentlyPlayedAlbumsSector.setVisibility(!albums.isEmpty() ? View.VISIBLE : View.GONE);
recentlyPlayedAlbumAdapter.setItems(albums);
});
}
@ -178,13 +195,15 @@ public class HomeFragment extends Fragment {
pagerSnapHelper.attachToRecyclerView(bind.favoritesTracksRecyclerView);
}
private void initRecentAddedSongView() {
bind.recentlyAddedTracksRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
bind.recentlyAddedTracksRecyclerView.setHasFixedSize(true);
private void initRecentAddedAlbumView() {
bind.recentlyAddedAlbumsRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
bind.recentlyAddedAlbumsRecyclerView.setHasFixedSize(true);
recentlyAddedMusicAdapter = new RecentMusicAdapter(activity, requireContext(), getChildFragmentManager());
bind.recentlyAddedTracksRecyclerView.setAdapter(recentlyAddedMusicAdapter);
homeViewModel.getRecentlyAddedSongList().observe(requireActivity(), songs -> recentlyAddedMusicAdapter.setItems(songs));
recentlyAddedAlbumAdapter = new AlbumAdapter(requireContext());
bind.recentlyAddedAlbumsRecyclerView.setAdapter(recentlyAddedAlbumAdapter);
homeViewModel.getMostRecentlyAddedAlbums().observe(requireActivity(), albums -> {
recentlyAddedAlbumAdapter.setItems(albums);
});
}
private void initDownloadedSongView() {
@ -225,12 +244,12 @@ public class HomeFragment extends Fragment {
if(bind != null) {
bind.homeLinearLayoutContainer.removeAllViews();
bind.homeLinearLayoutContainer.addView(bind.homeDiscoverSector);
bind.homeLinearLayoutContainer.addView(bind.homeRecentlyAddedTracksSector);
bind.homeLinearLayoutContainer.addView(bind.homeRecentlyAddedAlbumsSector);
bind.homeLinearLayoutContainer.addView(bind.homeFlashbackSector);
bind.homeLinearLayoutContainer.addView(bind.homeFavoriteTracksSector);
bind.homeLinearLayoutContainer.addView(bind.homeDownloadedTracksSector);
bind.homeLinearLayoutContainer.addView(bind.homeMostPlayedTracksSector);
bind.homeLinearLayoutContainer.addView(bind.homeRecentlyPlayedTracksSector);
bind.homeLinearLayoutContainer.addView(bind.homeMostPlayedAlbumsSector);
bind.homeLinearLayoutContainer.addView(bind.homeRecentlyPlayedAlbumsSector);
}
}
}

View file

@ -60,7 +60,6 @@ public class LibraryFragment extends Fragment {
initArtistView();
initGenreView();
initPlaylistSlideView();
initCatalogueSyncCheck();
}
@Override
@ -126,17 +125,6 @@ public class LibraryFragment extends Fragment {
setDiscoverSongSlideViewOffset(20, 16);
}
private void initCatalogueSyncCheck() {
if (!PreferenceUtil.getInstance(requireContext()).getSongGenreSync()) {
AlertDialog.Builder builder = new AlertDialog.Builder(requireContext());
builder.setMessage("Sync song's genres otherwise nothing will be shown in each genre category")
.setTitle("Song's genres not synchronized")
.setNegativeButton(R.string.ignore, null)
.setPositiveButton("Sync", (dialog, id) -> activity.goToSync())
.show();
}
}
private void setDiscoverSongSlideViewOffset(float pageOffset, float pageMargin) {
bind.playlistViewPager.setPageTransformer((page, position) -> {
float myOffset = position * -(2 * pageOffset + pageMargin);

View file

@ -263,7 +263,7 @@ public class PlayerBottomSheetFragment extends Fragment implements MusicServiceE
bind.playerHeaderLayout.playerHeaderSongArtistLabel.setText(song.getArtistName());
CustomGlideRequest.Builder
.from(requireContext(), song.getPrimary(), song.getBlurHash(), CustomGlideRequest.PRIMARY, PreferenceUtil.getInstance(requireContext()).getImageQuality(), CustomGlideRequest.SONG_PIC)
.from(requireContext(), song.getPrimary(), song.getBlurHash(), CustomGlideRequest.SONG_PIC)
.build()
.into(bind.playerHeaderLayout.playerHeaderSongCoverImage);

View file

@ -150,7 +150,7 @@ public class PlaylistPageFragment extends Fragment {
private void initBackCover() {
CustomGlideRequest.Builder
.from(requireContext(), playlistPageViewModel.getPlaylist().getPrimary(), playlistPageViewModel.getPlaylist().getBlurHash(), CustomGlideRequest.PRIMARY, PreferenceUtil.getInstance(requireContext()).getImageQuality(), CustomGlideRequest.ALBUM_PIC)
.from(requireContext(), playlistPageViewModel.getPlaylist().getPrimary(), playlistPageViewModel.getPlaylist().getBlurHash(), CustomGlideRequest.ALBUM_PIC)
.build()
.into(bind.albumBackCoverImageView);
}

View file

@ -53,36 +53,5 @@ public class SettingsFragment extends PreferenceFragmentCompat {
return true;
});
}
Preference music_sync_button = findPreference(getString(R.string.music_sync));
music_sync_button.setOnPreferenceClickListener(preference -> {
AlertDialog.Builder builder = new AlertDialog.Builder(requireContext());
builder.setMessage("Force reload your entire music library")
.setTitle("Force sync")
.setNegativeButton(R.string.ignore, null)
.setPositiveButton("Sync", (dialog, id) -> {
PreferenceUtil.getInstance(requireContext()).setSync(false);
PreferenceUtil.getInstance(requireContext()).setSongGenreSync(false);
Bundle bundle = SyncUtil.getSyncBundle(true, true, true, true, true);
activity.goFromSettingsToSync(bundle);
})
.show();
return true;
});
Preference playlist_sync_button = findPreference(getString(R.string.playlist_song_cross_sync));
playlist_sync_button.setOnPreferenceClickListener(preference -> {
AlertDialog.Builder builder = new AlertDialog.Builder(requireContext());
builder.setMessage("Sync playlists' songs")
.setTitle("Force sync playlist")
.setNegativeButton(R.string.ignore, null)
.setPositiveButton("Sync", (dialog, id) -> {
Bundle bundle = SyncUtil.getSyncBundle(false, false, false, true, false);
activity.goFromSettingsToSync(bundle);
})
.show();
return true;
});
}
}

View file

@ -1,239 +1,94 @@
package com.cappielloantonio.play.ui.fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import com.cappielloantonio.play.R;
import com.cappielloantonio.play.databinding.FragmentSyncBinding;
import com.cappielloantonio.play.interfaces.MediaCallback;
import com.cappielloantonio.play.model.Album;
import com.cappielloantonio.play.model.AlbumArtistCross;
import com.cappielloantonio.play.model.Artist;
import com.cappielloantonio.play.model.Playlist;
import com.cappielloantonio.play.model.PlaylistSongCross;
import com.cappielloantonio.play.model.Song;
import com.cappielloantonio.play.model.SongArtistCross;
import com.cappielloantonio.play.repository.AlbumArtistRepository;
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 com.cappielloantonio.play.repository.PlaylistSongRepository;
import com.cappielloantonio.play.repository.SongArtistRepository;
import com.cappielloantonio.play.repository.SongGenreRepository;
import com.cappielloantonio.play.repository.SongRepository;
import com.cappielloantonio.play.subsonic.models.AlbumID3;
import com.cappielloantonio.play.subsonic.models.ArtistID3;
import com.cappielloantonio.play.subsonic.models.Child;
import com.cappielloantonio.play.subsonic.models.Genre;
import com.cappielloantonio.play.ui.activity.MainActivity;
import com.cappielloantonio.play.util.DownloadUtil;
import com.cappielloantonio.play.util.PreferenceUtil;
import com.cappielloantonio.play.util.SyncUtil;
import com.cappielloantonio.play.util.Util;
import com.cappielloantonio.play.viewmodel.SyncViewModel;
import java.util.ArrayList;
import java.util.List;
public class SyncFragment extends Fragment {
private static final String TAG = "SyncFragment";
private MainActivity activity;
private FragmentSyncBinding bind;
private SyncViewModel syncViewModel;
private SongRepository songRepository;
private AlbumRepository albumRepository;
private ArtistRepository artistRepository;
private PlaylistRepository playlistRepository;
private GenreRepository genreRepository;
private PlaylistSongRepository playlistSongRepository;
private final int LIBRARIES = 0;
private final int ALBUMS = 1;
private final int ARTISTS = 2;
private final int GENRES = 3;
private final int PLAYLISTS = 4;
private final int SONGS = 5;
private final int SONG_X_PLAYLIST = 6;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
activity = (MainActivity) getActivity();
bind = FragmentSyncBinding.inflate(inflater, container, false);
View view = bind.getRoot();
syncViewModel = new ViewModelProvider(requireActivity()).get(SyncViewModel.class);
songRepository = new SongRepository(activity.getApplication());
albumRepository = new AlbumRepository(activity.getApplication());
artistRepository = new ArtistRepository(activity.getApplication());
playlistRepository = new PlaylistRepository(activity.getApplication());
genreRepository = new GenreRepository(activity.getApplication());
playlistSongRepository = new PlaylistSongRepository(activity.getApplication());
init();
initView();
initButtonListeners();
syncLibraries();
return view;
}
@Override
public void onDestroyView() {
super.onDestroyView();
bind = null;
}
private void init() {
syncViewModel.setArguemnts(getArguments());
bind.syncingDateLabel.setText(Util.getDate());
}
private void initView() {
if (!syncViewModel.isSyncAlbum()) bind.syncAlbumsSector.setVisibility(View.GONE);
if (!syncViewModel.isSyncArtist()) bind.syncArtistsSector.setVisibility(View.GONE);
if (!syncViewModel.isSyncGenres()) bind.syncGenresSector.setVisibility(View.GONE);
if (!syncViewModel.isSyncPlaylist()) bind.syncPlaylistsSector.setVisibility(View.GONE);
if (!syncViewModel.isSyncPlaylist()) bind.syncSongXPlaylistSector.setVisibility(View.GONE);
if (!syncViewModel.isSyncSong()) bind.syncSongsSector.setVisibility(View.GONE);
}
private void initButtonListeners() {
bind.syncLibrariesRetryImageView.setOnClickListener(v -> {
resetSectorInfo(LIBRARIES);
syncLibraries();
});
bind.syncAlbumsRetryImageView.setOnClickListener(v -> {
resetSectorInfo(ALBUMS);
syncAlbums(500, 0, 0);
});
bind.syncArtistsRetryImageView.setOnClickListener(v -> {
resetSectorInfo(ARTISTS);
syncArtists();
});
bind.syncGenresRetryImageView.setOnClickListener(v -> {
resetSectorInfo(GENRES);
syncGenres();
});
bind.syncPlaylistsRetryImageView.setOnClickListener(v -> {
resetSectorInfo(PLAYLISTS);
syncPlaylist();
});
bind.syncSongXPlaylistRetryImageView.setOnClickListener(v -> {
resetSectorInfo(SONG_X_PLAYLIST);
syncSongsPerPlaylist(syncViewModel.getPlaylistList());
});
bind.syncSongsRetryImageView.setOnClickListener(v -> {
resetSectorInfo(SONGS);
syncSongs();
});
bind.syncingGoHomeImageView.setOnClickListener(v -> {
AlertDialog.Builder builder = new AlertDialog.Builder(requireContext());
builder.setMessage("Make sure each category has been properly synchronized")
.setTitle("Go home")
.setNegativeButton(R.string.ignore, null)
.setPositiveButton("Go", (dialog, id) -> {
PreferenceUtil.getInstance(requireContext()).setSync(true);
activity.goToHome();
})
.show();
});
}
public class SyncFragment {
private Context context;
private void syncLibraries() {
SyncUtil.getLibraries(requireContext(), new MediaCallback() {
SyncUtil.getLibraries(context, new MediaCallback() {
@Override
public void onError(Exception exception) {
loadSectorInfo(LIBRARIES, exception.getMessage(), false);
}
@Override
public void onLoadMedia(List<?> media) {
loadSectorInfo(LIBRARIES, "", true);
}
});
}
private void syncAlbums(int size, int offset, int page) {
SyncUtil.getAlbums(requireContext(), new MediaCallback() {
SyncUtil.getAlbums(context, new MediaCallback() {
@Override
public void onError(Exception exception) {
loadSectorInfo(ALBUMS, exception.getMessage(), false);
}
@Override
public void onLoadMedia(List<?> media) {
syncViewModel.addToAlbumList((List<AlbumID3>) media);
// syncViewModel.addToAlbumList((List<AlbumID3>) media);
if (media.size() == size) {
syncAlbums(size, size * (page + 1), page + 1);
} else {
loadSectorInfo(ALBUMS, "Found " + syncViewModel.getAlbumList().size() + " elements", true);
}
}
}, size, offset);
}
private void syncArtists() {
SyncUtil.getArtists(requireContext(), new MediaCallback() {
SyncUtil.getArtists(context, new MediaCallback() {
@Override
public void onError(Exception exception) {
loadSectorInfo(ARTISTS, exception.getMessage(), false);
}
@Override
public void onLoadMedia(List<?> media) {
syncViewModel.setArtistList((ArrayList<ArtistID3>) media);
loadSectorInfo(ARTISTS, "Found " + syncViewModel.getArtistList().size() + " elements", true);
// syncViewModel.setArtistList((ArrayList<ArtistID3>) media);
}
});
}
private void syncGenres() {
SyncUtil.getGenres(requireContext(), new MediaCallback() {
SyncUtil.getGenres(context, new MediaCallback() {
@Override
public void onError(Exception exception) {
loadSectorInfo(GENRES, exception.getMessage(), false);
}
@Override
public void onLoadMedia(List<?> media) {
syncViewModel.setGenreList((ArrayList<Genre>) media);
loadSectorInfo(GENRES, "Found " + syncViewModel.getGenreList().size() + " elements", true);
// syncViewModel.setGenreList((ArrayList<Genre>) media);
}
});
}
private void syncPlaylist() {
SyncUtil.getPlaylists(requireContext(), new MediaCallback() {
SyncUtil.getPlaylists(context, new MediaCallback() {
@Override
public void onError(Exception exception) {
loadSectorInfo(PLAYLISTS, exception.getMessage(), false);
}
@Override
public void onLoadMedia(List<?> media) {
syncViewModel.setPlaylistList((ArrayList<Playlist>) media);
loadSectorInfo(PLAYLISTS, "Found " + syncViewModel.getPlaylistList().size() + " elements", true);
// syncViewModel.setPlaylistList((ArrayList<Playlist>) media);
}
});
}
private void syncSongsPerPlaylist(List<Playlist> playlists) {
/* for (Playlist playlist : playlists) {
SyncUtil.getSongsPerPlaylist(requireContext(), new MediaCallback() {
SyncUtil.getSongsPerPlaylist(context(), new MediaCallback() {
@Override
public void onError(Exception exception) {
loadSectorInfo(SONG_X_PLAYLIST, exception.getMessage(), false);
@ -246,236 +101,31 @@ public class SyncFragment extends Fragment {
}
}, playlist.getId());
} */
loadSectorInfo(SONG_X_PLAYLIST, "Playlist processed: SEI BRAVO", true);
enableHomeButton(SONG_X_PLAYLIST);
}
private void syncSongs() {
enableHomeButton(SONGS);
for (AlbumID3 album : syncViewModel.getAlbumList()) {
SyncUtil.getSongs(requireContext(), new MediaCallback() {
/* for (AlbumID3 album : syncViewModel.getAlbumList()) {
SyncUtil.getSongs(context, syncViewModel.getCatalogue(), new MediaCallback() {
@Override
public void onError(Exception exception) {
loadSectorInfo(SONGS, exception.getMessage(), false);
}
@Override
public void onLoadMedia(List<?> media) {
syncViewModel.addToChildList((ArrayList<Child>) media);
loadSectorInfo(SONGS, "Found " + syncViewModel.getChildList().size() + " elements", true);
syncViewModel.addToSongList((ArrayList<Song>) media);
}
}, album);
}
}*/
}
private void syncDownloadedSong() {
songRepository.getListLiveDownloadedSong().observe(requireActivity(), songs -> {
/*songRepository.getListLiveDownloadedSong().observe(requireActivity(), songs -> {
for (Song song : songs) {
if (!DownloadUtil.getDownloadTracker(requireContext()).isDownloaded(song)) {
if (!DownloadUtil.getDownloadTracker(context()).isDownloaded(song)) {
song.setOffline(false);
songRepository.setOfflineStatus(song);
}
}
});
}
private void loadSectorInfo(int sector, String message, boolean isSuccess) {
switch (sector) {
case LIBRARIES:
if (isSuccess) {
if (bind != null) {
bind.syncLibrariesStatusLabel.setText("Status: SUCCESS");
bind.syncLibrariesDetailLabel.setVisibility(View.GONE);
bind.syncLibrariesRetryImageView.setVisibility(View.GONE);
}
syncNextSector(LIBRARIES);
} else {
if (bind != null) {
bind.syncLibrariesStatusLabel.setText("Status: ERROR");
bind.syncLibrariesDetailLabel.setText(message);
bind.syncLibrariesDetailLabel.setVisibility(View.VISIBLE);
bind.syncLibrariesRetryImageView.setVisibility(View.VISIBLE);
}
}
break;
case ALBUMS:
if (isSuccess) {
if (bind != null) {
bind.syncAlbumsStatusLabel.setText("Status: SUCCESS");
bind.syncAlbumsDetailLabel.setText(message);
bind.syncAlbumsRetryImageView.setVisibility(View.GONE);
}
syncNextSector(ALBUMS);
} else {
if (bind != null) {
bind.syncLibrariesStatusLabel.setText("Status: ERROR");
bind.syncAlbumsDetailLabel.setText(message);
bind.syncAlbumsRetryImageView.setVisibility(View.VISIBLE);
}
}
break;
case ARTISTS:
if (isSuccess) {
if (bind != null) {
bind.syncArtistsStatusLabel.setText("Status: SUCCESS");
bind.syncArtistsDetailLabel.setText(message);
bind.syncArtistsRetryImageView.setVisibility(View.GONE);
}
syncNextSector(ARTISTS);
} else {
if (bind != null) {
bind.syncArtistsStatusLabel.setText("Status: ERROR");
bind.syncArtistsDetailLabel.setText(message);
bind.syncArtistsRetryImageView.setVisibility(View.VISIBLE);
}
}
break;
case GENRES:
if (isSuccess) {
if (bind != null) {
bind.syncGenresStatusLabel.setText("Status: SUCCESS");
bind.syncGenresDetailLabel.setText(message);
bind.syncGenresRetryImageView.setVisibility(View.GONE);
}
syncNextSector(GENRES);
} else {
if (bind != null) {
bind.syncGenresStatusLabel.setText("Status: ERROR");
bind.syncGenresDetailLabel.setText(message);
bind.syncGenresRetryImageView.setVisibility(View.VISIBLE);
}
}
break;
case PLAYLISTS:
if (isSuccess) {
if (bind != null) {
bind.syncPlaylistsStatusLabel.setText("Status: SUCCESS");
bind.syncPlaylistsDetailLabel.setText(message);
bind.syncPlaylistsRetryImageView.setVisibility(View.GONE);
}
syncNextSector(PLAYLISTS);
} else {
if (bind != null) {
bind.syncPlaylistsStatusLabel.setText("Status: ERROR");
bind.syncPlaylistsDetailLabel.setText(message);
bind.syncPlaylistsRetryImageView.setVisibility(View.VISIBLE);
}
}
break;
case SONG_X_PLAYLIST:
if (isSuccess) {
if (bind != null) {
bind.syncSongXPlaylistStatusLabel.setText("Status: SUCCESS");
bind.syncSongXPlaylistDetailLabel.setText(message);
bind.syncSongXPlaylistRetryImageView.setVisibility(View.GONE);
}
syncNextSector(SONG_X_PLAYLIST);
} else {
if (bind != null) {
bind.syncSongXPlaylistStatusLabel.setText("Status: ERROR");
bind.syncSongXPlaylistDetailLabel.setText(message);
bind.syncSongXPlaylistRetryImageView.setVisibility(View.VISIBLE);
}
}
break;
case SONGS:
if (isSuccess) {
if (bind != null) {
bind.syncSongsStatusLabel.setText("Status: SUCCESS");
bind.syncSongsDetailLabel.setText(message);
bind.syncSongsRetryImageView.setVisibility(View.GONE);
}
} else {
if (bind != null) {
bind.syncSongsStatusLabel.setText("Status: ERROR");
bind.syncSongsDetailLabel.setText(message);
bind.syncSongsRetryImageView.setVisibility(View.VISIBLE);
}
}
break;
}
}
private void resetSectorInfo(int sector) {
if (bind != null) {
switch (sector) {
case LIBRARIES:
bind.syncLibrariesStatusLabel.setText("Loading...");
bind.syncLibrariesDetailLabel.setText(R.string.label_placeholder);
bind.syncLibrariesDetailLabel.setVisibility(View.GONE);
bind.syncLibrariesRetryImageView.setVisibility(View.GONE);
break;
case ALBUMS:
bind.syncAlbumsStatusLabel.setText("Loading...");
bind.syncAlbumsDetailLabel.setText(R.string.label_placeholder);
bind.syncAlbumsRetryImageView.setVisibility(View.GONE);
break;
case ARTISTS:
bind.syncArtistsStatusLabel.setText("Loading...");
bind.syncArtistsDetailLabel.setText(R.string.label_placeholder);
bind.syncArtistsRetryImageView.setVisibility(View.GONE);
break;
case GENRES:
bind.syncGenresStatusLabel.setText("Loading...");
bind.syncGenresDetailLabel.setText(R.string.label_placeholder);
bind.syncGenresRetryImageView.setVisibility(View.GONE);
break;
case PLAYLISTS:
bind.syncPlaylistsStatusLabel.setText("Loading...");
bind.syncPlaylistsDetailLabel.setText(R.string.label_placeholder);
bind.syncPlaylistsRetryImageView.setVisibility(View.GONE);
break;
case SONG_X_PLAYLIST:
bind.syncSongXPlaylistStatusLabel.setText("Loading...");
bind.syncSongXPlaylistDetailLabel.setText(R.string.label_placeholder);
bind.syncSongXPlaylistRetryImageView.setVisibility(View.GONE);
break;
case SONGS:
bind.syncSongsStatusLabel.setText("Loading...");
bind.syncSongsDetailLabel.setText(R.string.label_placeholder);
bind.syncSongsRetryImageView.setVisibility(View.GONE);
break;
}
}
}
private void syncNextSector(int sector) {
switch (sector) {
case LIBRARIES:
if (syncViewModel.isSyncAlbum()) syncAlbums(500, 0, 0);
else syncPlaylist();
break;
case ALBUMS:
syncArtists();
break;
case ARTISTS:
syncGenres();
break;
case GENRES:
syncPlaylist();
break;
case PLAYLISTS:
syncSongsPerPlaylist(syncViewModel.getPlaylistList());
break;
case SONG_X_PLAYLIST:
if (syncViewModel.isSyncSong()) syncSongs();
break;
case SONGS:
break;
}
}
private void enableHomeButton(int sector) {
switch (sector) {
case SONG_X_PLAYLIST:
if (!syncViewModel.isSyncSong()) bind.syncingGoHomeImageView.setVisibility(View.VISIBLE);
break;
case SONGS:
bind.syncingGoHomeImageView.setVisibility(View.VISIBLE);
break;
}
});*/
}
}

View file

@ -72,7 +72,7 @@ public class AlbumBottomSheetDialog extends BottomSheetDialogFragment implements
private void init(View view) {
coverAlbum = view.findViewById(R.id.album_cover_image_view);
CustomGlideRequest.Builder
.from(requireContext(), albumBottomSheetViewModel.getAlbum().getPrimary(), albumBottomSheetViewModel.getAlbum().getBlurHash(), CustomGlideRequest.PRIMARY, PreferenceUtil.getInstance(requireContext()).getImageQuality(), CustomGlideRequest.ALBUM_PIC)
.from(requireContext(), albumBottomSheetViewModel.getAlbum().getPrimary(), albumBottomSheetViewModel.getAlbum().getBlurHash(), CustomGlideRequest.ALBUM_PIC)
.build()
.into(coverAlbum);

View file

@ -63,7 +63,7 @@ public class ArtistBottomSheetDialog extends BottomSheetDialogFragment implement
private void init(View view) {
coverArtist = view.findViewById(R.id.artist_cover_image_view);
CustomGlideRequest.Builder
.from(requireContext(), artistBottomSheetViewModel.getArtist().getPrimary(), artistBottomSheetViewModel.getArtist().getPrimaryBlurHash(), CustomGlideRequest.PRIMARY, PreferenceUtil.getInstance(requireContext()).getImageQuality(), CustomGlideRequest.ARTIST_PIC)
.from(requireContext(), artistBottomSheetViewModel.getArtist().getPrimary(), artistBottomSheetViewModel.getArtist().getPrimaryBlurHash(), CustomGlideRequest.ARTIST_PIC)
.build()
.into(coverArtist);

View file

@ -72,7 +72,7 @@ public class SongBottomSheetDialog extends BottomSheetDialogFragment implements
private void init(View view) {
coverSong = view.findViewById(R.id.song_cover_image_view);
CustomGlideRequest.Builder
.from(requireContext(), songBottomSheetViewModel.getSong().getPrimary(), songBottomSheetViewModel.getSong().getBlurHash(), CustomGlideRequest.PRIMARY, PreferenceUtil.getInstance(requireContext()).getImageQuality(), CustomGlideRequest.SONG_PIC)
.from(requireContext(), songBottomSheetViewModel.getSong().getPrimary(), songBottomSheetViewModel.getSong().getBlurHash(), CustomGlideRequest.SONG_PIC)
.build()
.into(coverSong);