mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 01:53:31 +00:00
First implementation of the panel dedicated to the download, divided by type of the downloaded resource
This commit is contained in:
parent
8789b44e26
commit
23568bae9b
16 changed files with 609 additions and 102 deletions
|
|
@ -52,6 +52,14 @@ public class Album implements Parcelable {
|
|||
this.songs = MappingUtil.mapSong(albumWithSongsID3.getSongs());
|
||||
}
|
||||
|
||||
public Album(Download download) {
|
||||
this.id = download.getAlbumId();
|
||||
this.title = download.getAlbumName();
|
||||
this.artistId = download.getArtistId();
|
||||
this.artistName = download.getArtistName();
|
||||
this.primary = download.getPrimary();
|
||||
}
|
||||
|
||||
public Album(AlbumInfo info) {
|
||||
this.notes = info.getNotes();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,6 +76,11 @@ public class Artist implements Parcelable {
|
|||
this.name = name;
|
||||
}
|
||||
|
||||
public Artist(Download download) {
|
||||
this.id = download.getArtistId();
|
||||
this.name = download.getArtistName();
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,240 @@
|
|||
package com.cappielloantonio.play.ui.fragment;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.PagerSnapHelper;
|
||||
import androidx.recyclerview.widget.SnapHelper;
|
||||
import androidx.viewpager2.widget.ViewPager2;
|
||||
|
||||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.adapter.AlbumAdapter;
|
||||
import com.cappielloantonio.play.adapter.AlbumHorizontalAdapter;
|
||||
import com.cappielloantonio.play.adapter.ArtistAdapter;
|
||||
import com.cappielloantonio.play.adapter.ArtistHorizontalAdapter;
|
||||
import com.cappielloantonio.play.adapter.DiscoverSongAdapter;
|
||||
import com.cappielloantonio.play.adapter.SimilarTrackAdapter;
|
||||
import com.cappielloantonio.play.adapter.SongHorizontalAdapter;
|
||||
import com.cappielloantonio.play.adapter.TrackAdapter;
|
||||
import com.cappielloantonio.play.adapter.YearAdapter;
|
||||
import com.cappielloantonio.play.databinding.FragmentDownloadBinding;
|
||||
import com.cappielloantonio.play.databinding.FragmentHomeBinding;
|
||||
import com.cappielloantonio.play.helper.recyclerview.CustomLinearSnapHelper;
|
||||
import com.cappielloantonio.play.helper.recyclerview.DotsIndicatorDecoration;
|
||||
import com.cappielloantonio.play.model.Album;
|
||||
import com.cappielloantonio.play.model.Artist;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.ui.activity.MainActivity;
|
||||
import com.cappielloantonio.play.util.MappingUtil;
|
||||
import com.cappielloantonio.play.util.UIUtil;
|
||||
import com.cappielloantonio.play.viewmodel.DownloadViewModel;
|
||||
import com.cappielloantonio.play.viewmodel.HomeViewModel;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class DownloadFragment extends Fragment {
|
||||
private static final String TAG = "CategoriesFragment";
|
||||
|
||||
private FragmentDownloadBinding bind;
|
||||
private MainActivity activity;
|
||||
private DownloadViewModel downloadViewModel;
|
||||
|
||||
private ArtistHorizontalAdapter downloadedArtistAdapter;
|
||||
private AlbumHorizontalAdapter downloadedAlbumAdapter;
|
||||
private SongHorizontalAdapter downloadedTrackAdapter;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
inflater.inflate(R.menu.main_page_menu, menu);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
activity = (MainActivity) getActivity();
|
||||
|
||||
bind = FragmentDownloadBinding.inflate(inflater, container, false);
|
||||
View view = bind.getRoot();
|
||||
downloadViewModel = new ViewModelProvider(requireActivity()).get(DownloadViewModel.class);
|
||||
|
||||
init();
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
initAppBar();
|
||||
initDownloadedArtistView();
|
||||
initDownloadedAlbumView();
|
||||
initDownloadedSongView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
activity.setBottomNavigationBarVisibility(true);
|
||||
activity.setBottomSheetVisibility(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
bind = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_search:
|
||||
activity.navController.navigate(R.id.action_downloadFragment_to_searchFragment);
|
||||
return true;
|
||||
case R.id.action_settings:
|
||||
activity.navController.navigate(R.id.action_downloadFragment_to_settingsFragment);
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void init() {
|
||||
bind.downloadedArtistTextViewClickable.setOnClickListener(v -> {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(Song.DOWNLOADED, Song.DOWNLOADED);
|
||||
activity.navController.navigate(R.id.action_downloadFragment_to_artistListPageFragment, bundle);
|
||||
});
|
||||
|
||||
bind.downloadedAlbumTextViewClickable.setOnClickListener(v -> {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(Song.DOWNLOADED, Song.DOWNLOADED);
|
||||
activity.navController.navigate(R.id.action_downloadFragment_to_albumListPageFragment, bundle);
|
||||
});
|
||||
|
||||
bind.downloadedTracksTextViewClickable.setOnClickListener(v -> {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(Song.DOWNLOADED, Song.DOWNLOADED);
|
||||
activity.navController.navigate(R.id.action_downloadFragment_to_songListPageFragment, bundle);
|
||||
});
|
||||
}
|
||||
|
||||
private void initAppBar() {
|
||||
activity.setSupportActionBar(bind.toolbar);
|
||||
Objects.requireNonNull(bind.toolbar.getOverflowIcon()).setTint(requireContext().getResources().getColor(R.color.titleTextColor, null));
|
||||
}
|
||||
|
||||
private void initDownloadedArtistView() {
|
||||
bind.downloadedArtistRecyclerView.setHasFixedSize(true);
|
||||
|
||||
downloadedArtistAdapter = new ArtistHorizontalAdapter(requireContext());
|
||||
bind.downloadedArtistRecyclerView.setAdapter(downloadedArtistAdapter);
|
||||
downloadViewModel.getDownloadedArtists(requireActivity(), 20).observe(requireActivity(), artists -> {
|
||||
if (artists == null) {
|
||||
if (bind != null) bind.downloadDownloadedArtistPlaceholder.placeholder.setVisibility(View.VISIBLE);
|
||||
if (bind != null) bind.downloadDownloadedArtistSector.setVisibility(View.GONE);
|
||||
} else {
|
||||
if (bind != null) bind.downloadDownloadedArtistPlaceholder.placeholder.setVisibility(View.GONE);
|
||||
if (bind != null) bind.downloadDownloadedArtistSector.setVisibility(!artists.isEmpty() ? View.VISIBLE : View.GONE);
|
||||
if (bind != null) bind.downloadedArtistRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), UIUtil.getSpanCount(artists.size(), 5), GridLayoutManager.HORIZONTAL, false));
|
||||
|
||||
downloadedArtistAdapter.setItems(artists);
|
||||
}
|
||||
});
|
||||
|
||||
SnapHelper starredArtistSnapHelper = new PagerSnapHelper();
|
||||
starredArtistSnapHelper.attachToRecyclerView(bind.downloadedArtistRecyclerView);
|
||||
|
||||
bind.downloadedArtistRecyclerView.addItemDecoration(
|
||||
new DotsIndicatorDecoration(
|
||||
getResources().getDimensionPixelSize(R.dimen.radius),
|
||||
getResources().getDimensionPixelSize(R.dimen.radius) * 4,
|
||||
getResources().getDimensionPixelSize(R.dimen.dots_height),
|
||||
requireContext().getResources().getColor(R.color.titleTextColor, null),
|
||||
requireContext().getResources().getColor(R.color.titleTextColor, null))
|
||||
);
|
||||
}
|
||||
|
||||
private void initDownloadedAlbumView() {
|
||||
bind.downloadedAlbumRecyclerView.setHasFixedSize(true);
|
||||
|
||||
downloadedAlbumAdapter = new AlbumHorizontalAdapter(requireContext());
|
||||
bind.downloadedAlbumRecyclerView.setAdapter(downloadedAlbumAdapter);
|
||||
downloadViewModel.getDownloadedAlbums(requireActivity(), 20).observe(requireActivity(), albums -> {
|
||||
if (albums == null) {
|
||||
if (bind != null) bind.downloadDownloadedAlbumPlaceholder.placeholder.setVisibility(View.VISIBLE);
|
||||
if (bind != null) bind.downloadDownloadedAlbumSector.setVisibility(View.GONE);
|
||||
} else {
|
||||
if (bind != null) bind.downloadDownloadedAlbumPlaceholder.placeholder.setVisibility(View.GONE);
|
||||
if (bind != null) bind.downloadDownloadedAlbumSector.setVisibility(!albums.isEmpty() ? View.VISIBLE : View.GONE);
|
||||
if (bind != null) bind.downloadedAlbumRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), UIUtil.getSpanCount(albums.size(), 5), GridLayoutManager.HORIZONTAL, false));
|
||||
|
||||
downloadedAlbumAdapter.setItems(albums);
|
||||
}
|
||||
});
|
||||
|
||||
SnapHelper starredAlbumSnapHelper = new PagerSnapHelper();
|
||||
starredAlbumSnapHelper.attachToRecyclerView(bind.downloadedAlbumRecyclerView);
|
||||
|
||||
bind.downloadedAlbumRecyclerView.addItemDecoration(
|
||||
new DotsIndicatorDecoration(
|
||||
getResources().getDimensionPixelSize(R.dimen.radius),
|
||||
getResources().getDimensionPixelSize(R.dimen.radius) * 4,
|
||||
getResources().getDimensionPixelSize(R.dimen.dots_height),
|
||||
requireContext().getResources().getColor(R.color.titleTextColor, null),
|
||||
requireContext().getResources().getColor(R.color.titleTextColor, null))
|
||||
);
|
||||
}
|
||||
|
||||
private void initDownloadedSongView() {
|
||||
bind.downloadedTracksRecyclerView.setHasFixedSize(true);
|
||||
|
||||
downloadedTrackAdapter = new SongHorizontalAdapter(activity, requireContext());
|
||||
bind.downloadedTracksRecyclerView.setAdapter(downloadedTrackAdapter);
|
||||
downloadViewModel.getDownloadedTracks(requireActivity(), 20).observe(requireActivity(), songs -> {
|
||||
if (songs == null) {
|
||||
if (bind != null) bind.downloadDownloadedTracksPlaceholder.placeholder.setVisibility(View.VISIBLE);
|
||||
if (bind != null) bind.downloadDownloadedTracksSector.setVisibility(View.GONE);
|
||||
} else {
|
||||
if (bind != null) bind.downloadDownloadedTracksPlaceholder.placeholder.setVisibility(View.GONE);
|
||||
if (bind != null) bind.downloadDownloadedTracksSector.setVisibility(!songs.isEmpty() ? View.VISIBLE : View.GONE);
|
||||
if (bind != null) bind.downloadedTracksRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), UIUtil.getSpanCount(songs.size(), 5), GridLayoutManager.HORIZONTAL, false));
|
||||
|
||||
downloadedTrackAdapter.setItems(songs);
|
||||
}
|
||||
});
|
||||
|
||||
SnapHelper starredTrackSnapHelper = new PagerSnapHelper();
|
||||
starredTrackSnapHelper.attachToRecyclerView(bind.downloadedTracksRecyclerView);
|
||||
|
||||
bind.downloadedTracksRecyclerView.addItemDecoration(
|
||||
new DotsIndicatorDecoration(
|
||||
getResources().getDimensionPixelSize(R.dimen.radius),
|
||||
getResources().getDimensionPixelSize(R.dimen.radius) * 4,
|
||||
getResources().getDimensionPixelSize(R.dimen.dots_height),
|
||||
requireContext().getResources().getColor(R.color.titleTextColor, null),
|
||||
requireContext().getResources().getColor(R.color.titleTextColor, null))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -103,7 +103,6 @@ public class HomeFragment extends Fragment {
|
|||
initStarredArtistsView();
|
||||
initYearSongView();
|
||||
initRecentAddedAlbumView();
|
||||
initDownloadedSongView();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -172,12 +171,6 @@ public class HomeFragment extends Fragment {
|
|||
activity.navController.navigate(R.id.action_homeFragment_to_artistListPageFragment, bundle);
|
||||
});
|
||||
|
||||
bind.downloadedTracksTextViewClickable.setOnClickListener(v -> {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(Song.DOWNLOADED, Song.DOWNLOADED);
|
||||
activity.navController.navigate(R.id.action_homeFragment_to_songListPageFragment, bundle);
|
||||
});
|
||||
|
||||
bind.musicDiscoveryTextViewRefreshable.setOnLongClickListener(v -> {
|
||||
homeViewModel.refreshDiscoverySongSample(requireActivity());
|
||||
return true;
|
||||
|
|
@ -455,28 +448,6 @@ public class HomeFragment extends Fragment {
|
|||
recentAddedAlbumSnapHelper.attachToRecyclerView(bind.recentlyAddedAlbumsRecyclerView);
|
||||
}
|
||||
|
||||
private void initDownloadedSongView() {
|
||||
bind.downloadedTracksRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
|
||||
bind.downloadedTracksRecyclerView.setHasFixedSize(true);
|
||||
|
||||
dowanloadedMusicAdapter = new TrackAdapter(activity, requireContext());
|
||||
bind.downloadedTracksRecyclerView.setAdapter(dowanloadedMusicAdapter);
|
||||
homeViewModel.getDownloaded(requireActivity()).observe(requireActivity(), downloads -> {
|
||||
if (downloads == null) {
|
||||
if (bind != null) bind.homeDownloadedTracksPlaceholder.placeholder.setVisibility(View.VISIBLE);
|
||||
if (bind != null) bind.homeDownloadedTracksSector.setVisibility(View.GONE);
|
||||
} else {
|
||||
if (bind != null) bind.homeDownloadedTracksPlaceholder.placeholder.setVisibility(View.GONE);
|
||||
if (bind != null) bind.homeDownloadedTracksSector.setVisibility(!downloads.isEmpty() ? View.VISIBLE : View.GONE);
|
||||
|
||||
dowanloadedMusicAdapter.setItems(MappingUtil.mapDownload(downloads));
|
||||
}
|
||||
});
|
||||
|
||||
CustomLinearSnapHelper downloadedSongSnapHelper = new CustomLinearSnapHelper();
|
||||
downloadedSongSnapHelper.attachToRecyclerView(bind.downloadedTracksRecyclerView);
|
||||
}
|
||||
|
||||
private void setDiscoverSongSlideViewOffset(float pageOffset, float pageMargin) {
|
||||
bind.discoverSongViewPager.setPageTransformer((page, position) -> {
|
||||
float myOffset = position * -(2 * pageOffset + pageMargin);
|
||||
|
|
@ -509,7 +480,6 @@ public class HomeFragment extends Fragment {
|
|||
bind.homeLinearLayoutContainer.addView(bind.homeStarredTracksSector);
|
||||
bind.homeLinearLayoutContainer.addView(bind.homeStarredAlbumsSector);
|
||||
bind.homeLinearLayoutContainer.addView(bind.homeStarredArtistsSector);
|
||||
bind.homeLinearLayoutContainer.addView(bind.homeDownloadedTracksSector);
|
||||
bind.homeLinearLayoutContainer.addView(bind.homeMostPlayedAlbumsSector);
|
||||
bind.homeLinearLayoutContainer.addView(bind.homeRecentlyPlayedAlbumsSector);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ public class SearchFragment extends Fragment {
|
|||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
activity.setBottomNavigationBarVisibility(true);
|
||||
activity.setBottomNavigationBarVisibility(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -105,16 +105,45 @@ public class MappingUtil {
|
|||
return playlist;
|
||||
}
|
||||
|
||||
public static ArrayList<Song> mapDownload(List<Download> downloads) {
|
||||
public static ArrayList<Song> mapDownloadToSong(List<Download> downloads) {
|
||||
ArrayList<Song> songs = new ArrayList();
|
||||
|
||||
for (Download download : downloads) {
|
||||
songs.add(new Song(download));
|
||||
Song song = new Song(download);
|
||||
if(!songs.contains(song)) {
|
||||
songs.add(song);
|
||||
}
|
||||
}
|
||||
|
||||
return songs;
|
||||
}
|
||||
|
||||
public static ArrayList<Album> mapDownloadToAlbum(List<Download> downloads) {
|
||||
ArrayList<Album> albums = new ArrayList();
|
||||
|
||||
for (Download download : downloads) {
|
||||
Album album = new Album(download);
|
||||
if(!albums.contains(album)) {
|
||||
albums.add(album);
|
||||
}
|
||||
}
|
||||
|
||||
return albums;
|
||||
}
|
||||
|
||||
public static ArrayList<Artist> mapDownloadToArtist(List<Download> downloads) {
|
||||
ArrayList<Artist> artists = new ArrayList();
|
||||
|
||||
for (Download download : downloads) {
|
||||
Artist artist = new Artist(download);
|
||||
if(!artists.contains(artist)) {
|
||||
artists.add(artist);
|
||||
}
|
||||
}
|
||||
|
||||
return artists;
|
||||
}
|
||||
|
||||
public static ArrayList<Download> mapToDownload(List<Song> songs) {
|
||||
ArrayList<Download> downloads = new ArrayList();
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,52 @@
|
|||
package com.cappielloantonio.play.viewmodel;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.cappielloantonio.play.model.Album;
|
||||
import com.cappielloantonio.play.model.Artist;
|
||||
import com.cappielloantonio.play.model.Download;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.repository.AlbumRepository;
|
||||
import com.cappielloantonio.play.repository.ArtistRepository;
|
||||
import com.cappielloantonio.play.repository.DownloadRepository;
|
||||
import com.cappielloantonio.play.repository.SongRepository;
|
||||
import com.cappielloantonio.play.util.MappingUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DownloadViewModel extends AndroidViewModel {
|
||||
private static final String TAG = "HomeViewModel";
|
||||
|
||||
private final DownloadRepository downloadRepository;
|
||||
|
||||
private final MutableLiveData<List<Artist>> downloadedArtistSample = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Album>> downloadedAlbumSample = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Song>> downloadedTrackSample = new MutableLiveData<>(null);
|
||||
|
||||
public DownloadViewModel(@NonNull Application application) {
|
||||
super(application);
|
||||
|
||||
downloadRepository = new DownloadRepository(application);
|
||||
}
|
||||
|
||||
public LiveData<List<Artist>> getDownloadedArtists(LifecycleOwner owner, int size) {
|
||||
downloadRepository.getLiveDownloadSample(size).observe(owner, downloads -> downloadedArtistSample.postValue(MappingUtil.mapDownloadToArtist(downloads)));
|
||||
return downloadedArtistSample;
|
||||
}
|
||||
|
||||
public LiveData<List<Album>> getDownloadedAlbums(LifecycleOwner owner, int size) {
|
||||
downloadRepository.getLiveDownloadSample(size).observe(owner, downloads -> downloadedAlbumSample.postValue(MappingUtil.mapDownloadToAlbum(downloads)));
|
||||
return downloadedAlbumSample;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getDownloadedTracks(LifecycleOwner owner, int size) {
|
||||
downloadRepository.getLiveDownloadSample(size).observe(owner, downloads -> downloadedTrackSample.postValue(MappingUtil.mapDownloadToSong(downloads)));
|
||||
return downloadedTrackSample;
|
||||
}
|
||||
}
|
||||
|
|
@ -25,7 +25,6 @@ public class HomeViewModel extends AndroidViewModel {
|
|||
private final SongRepository songRepository;
|
||||
private final AlbumRepository albumRepository;
|
||||
private final ArtistRepository artistRepository;
|
||||
private final DownloadRepository downloadRepository;
|
||||
|
||||
private final MutableLiveData<List<Song>> dicoverSongSample = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Song>> starredTracksSample = new MutableLiveData<>(null);
|
||||
|
|
@ -36,7 +35,6 @@ public class HomeViewModel extends AndroidViewModel {
|
|||
private final MutableLiveData<List<Song>> starredTracks = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Album>> starredAlbums = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Artist>> starredArtists = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Download>> downloadedSongSample = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Album>> recentlyAddedAlbumSample = new MutableLiveData<>(null);
|
||||
|
||||
public HomeViewModel(@NonNull Application application) {
|
||||
|
|
@ -45,7 +43,6 @@ public class HomeViewModel extends AndroidViewModel {
|
|||
songRepository = new SongRepository(application);
|
||||
albumRepository = new AlbumRepository(application);
|
||||
artistRepository = new ArtistRepository(application);
|
||||
downloadRepository = new DownloadRepository(application);
|
||||
|
||||
songRepository.getRandomSample(10, null, null).observeForever(dicoverSongSample::postValue);
|
||||
songRepository.getStarredSongs(true, 10).observeForever(starredTracksSample::postValue);
|
||||
|
|
@ -79,11 +76,6 @@ public class HomeViewModel extends AndroidViewModel {
|
|||
return starredArtists;
|
||||
}
|
||||
|
||||
public LiveData<List<Download>> getDownloaded(LifecycleOwner owner) {
|
||||
downloadRepository.getLiveDownloadSample(10).observe(owner, downloadedSongSample::postValue);
|
||||
return downloadedSongSample;
|
||||
}
|
||||
|
||||
public LiveData<List<Album>> getMostPlayedAlbums(LifecycleOwner owner) {
|
||||
albumRepository.getAlbums("frequent", 20).observe(owner, mostPlayedAlbumSample::postValue);
|
||||
return mostPlayedAlbumSample;
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ public class SongListPageViewModel extends AndroidViewModel {
|
|||
songList = songRepository.getStarredSongs(false, -1);
|
||||
break;
|
||||
case Song.DOWNLOADED:
|
||||
songList.setValue(MappingUtil.mapDownload(downloadRepository.getLiveDownload()));
|
||||
songList.setValue(MappingUtil.mapDownloadToSong(downloadRepository.getLiveDownload()));
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue