mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 09:33:33 +00:00
Added download UI in home screen
This commit is contained in:
parent
e0569c3901
commit
bf70863f84
8 changed files with 109 additions and 3 deletions
|
|
@ -67,6 +67,12 @@ public interface SongDao {
|
|||
@Query("SELECT * FROM song WHERE favorite = 1")
|
||||
LiveData<List<Song>> getFavoriteSong();
|
||||
|
||||
@Query("SELECT * FROM song WHERE offline = 1 ORDER BY RANDOM() LIMIT :number")
|
||||
LiveData<List<Song>> getDownloadedSongSample(int number);
|
||||
|
||||
@Query("SELECT * FROM song WHERE offline = 1")
|
||||
LiveData<List<Song>> getDownloadedSong();
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
void insertAll(List<Song> songs);
|
||||
|
||||
|
|
|
|||
|
|
@ -48,6 +48,9 @@ public class Song implements Parcelable {
|
|||
@Ignore
|
||||
public static final String IS_FAVORITE = "IS_FAVORITE";
|
||||
|
||||
@Ignore
|
||||
public static final String DOWNLOADED = "DOWNLOADED";
|
||||
|
||||
@Ignore
|
||||
public static final String RADIO = "RADIO";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package com.cappielloantonio.play.repository;
|
||||
|
||||
import android.app.Application;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
|
||||
|
|
@ -33,6 +32,8 @@ public class SongRepository {
|
|||
private LiveData<List<Song>> listLiveSongByYear;
|
||||
private LiveData<List<Song>> listLiveSampleFavoritesSong;
|
||||
private LiveData<List<Song>> listLiveFavoritesSong;
|
||||
private LiveData<List<Song>> listLiveSampleDownloadedSong;
|
||||
private LiveData<List<Song>> listLiveDownloadedSong;
|
||||
|
||||
public SongRepository(Application application) {
|
||||
AppDatabase database = AppDatabase.getInstance(application);
|
||||
|
|
@ -314,6 +315,16 @@ public class SongRepository {
|
|||
return listLiveFavoritesSong;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getListLiveDownloadedSampleSong(int number) {
|
||||
listLiveSampleDownloadedSong = songDao.getDownloadedSongSample(number);
|
||||
return listLiveSampleDownloadedSong;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getListLiveDownloadedSong() {
|
||||
listLiveDownloadedSong = songDao.getDownloadedSong();
|
||||
return listLiveDownloadedSong;
|
||||
}
|
||||
|
||||
public void insertAll(ArrayList<Song> songs) {
|
||||
InsertAllThreadSafe insertAll = new InsertAllThreadSafe(songDao, songGenreCrossDao, songs);
|
||||
Thread thread = new Thread(insertAll);
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ public class HomeFragment extends Fragment {
|
|||
private SongResultSearchAdapter favoriteSongAdapter;
|
||||
private RecentMusicAdapter recentlyPlayedMusicAdapter;
|
||||
private RecentMusicAdapter mostPlayedMusicAdapter;
|
||||
private RecentMusicAdapter dowanloadedMusicAdapter;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
|
|
@ -67,6 +68,7 @@ public class HomeFragment extends Fragment {
|
|||
initFavoritesSongView();
|
||||
initYearSongView();
|
||||
initRecentAddedSongView();
|
||||
initDownloadedSongView();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -106,6 +108,12 @@ public class HomeFragment extends Fragment {
|
|||
bundle.putString(Song.IS_FAVORITE, Song.IS_FAVORITE);
|
||||
activity.navController.navigate(R.id.action_homeFragment_to_songListPageFragment, 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);
|
||||
});
|
||||
}
|
||||
|
||||
private void initDiscoverSongSlideView() {
|
||||
|
|
@ -180,6 +188,18 @@ public class HomeFragment extends Fragment {
|
|||
homeViewModel.getRecentlyAddedSongList().observe(requireActivity(), songs -> recentlyAddedMusicAdapter.setItems(songs));
|
||||
}
|
||||
|
||||
private void initDownloadedSongView() {
|
||||
bind.downloadedTracksRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
|
||||
bind.downloadedTracksRecyclerView.setHasFixedSize(true);
|
||||
|
||||
dowanloadedMusicAdapter = new RecentMusicAdapter(activity, requireContext(), getChildFragmentManager());
|
||||
bind.downloadedTracksRecyclerView.setAdapter(dowanloadedMusicAdapter);
|
||||
homeViewModel.getDownloaded().observe(requireActivity(), songs -> {
|
||||
if(bind != null) bind.homeDownloadedTracksSector.setVisibility(!songs.isEmpty() ? View.VISIBLE : View.GONE);
|
||||
dowanloadedMusicAdapter.setItems(songs);
|
||||
});
|
||||
}
|
||||
|
||||
private void setDiscoverSongSlideViewOffset(float pageOffset, float pageMargin) {
|
||||
bind.discoverSongViewPager.setPageTransformer((page, position) -> {
|
||||
float myOffset = position * -(2 * pageOffset + pageMargin);
|
||||
|
|
@ -197,10 +217,10 @@ public class HomeFragment extends Fragment {
|
|||
|
||||
/*
|
||||
* Il layout di default prevede questa sequenza:
|
||||
* - Discovery - Most_played - Last_played - Year - Favorite - Recently_added
|
||||
* - Discovery - Most_played - Last_played - Year - Favorite - Downloaded - Recently_added
|
||||
*
|
||||
* Se però non ho ancora ascoltato nessuna canzone e quindi Most_played e Last_played sono vuoti, modifico come segue
|
||||
* - Discovery - Recently_added - Year - Favorite - Most_played - Last_played
|
||||
* - Discovery - Recently_added - Year - Favorite - Downloaded - Most_played - Last_played
|
||||
*/
|
||||
public void reorder() {
|
||||
if(bind != null) {
|
||||
|
|
@ -209,6 +229,7 @@ public class HomeFragment extends Fragment {
|
|||
bind.homeLinearLayoutContainer.addView(bind.homeRecentlyAddedTracksSector);
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,6 +89,10 @@ public class SongListPageFragment extends Fragment {
|
|||
songListPageViewModel.title = Song.IS_FAVORITE;
|
||||
bind.pageTitleLabel.setText("Favourite song");
|
||||
}
|
||||
else if(getArguments().getString(Song.DOWNLOADED) != null) {
|
||||
songListPageViewModel.title = Song.DOWNLOADED;
|
||||
bind.pageTitleLabel.setText("Downloaded");
|
||||
}
|
||||
else if(getArguments().getString(Song.RADIO) != null) {
|
||||
songListPageViewModel.title = Song.IS_FAVORITE;
|
||||
songListPageViewModel.year = getArguments().getInt("radio_object");
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ public class HomeViewModel extends AndroidViewModel {
|
|||
private LiveData<List<Song>> recentlyAddedSongSample;
|
||||
private LiveData<List<Song>> mostPlayedSongSample;
|
||||
private LiveData<List<Song>> favoritesSongSample;
|
||||
private LiveData<List<Song>> downloadedSongSample;
|
||||
private List<Integer> years;
|
||||
|
||||
public HomeViewModel(@NonNull Application application) {
|
||||
|
|
@ -32,6 +33,7 @@ public class HomeViewModel extends AndroidViewModel {
|
|||
recentlyAddedSongSample = songRepository.getListLiveRecentlyAddedSampleSong(20);
|
||||
mostPlayedSongSample = songRepository.getListLiveMostPlayedSampleSong(20);
|
||||
favoritesSongSample = songRepository.getListLiveFavoritesSampleSong(20);
|
||||
downloadedSongSample = songRepository.getListLiveDownloadedSampleSong(20);
|
||||
years = songRepository.getYearList();
|
||||
}
|
||||
|
||||
|
|
@ -63,4 +65,8 @@ public class HomeViewModel extends AndroidViewModel {
|
|||
public LiveData<List<Song>> getFavorites() {
|
||||
return favoritesSongSample;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getDownloaded() {
|
||||
return downloadedSongSample;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,6 +59,9 @@ public class SongListPageViewModel extends AndroidViewModel {
|
|||
case Song.IS_FAVORITE:
|
||||
songList = songRepository.getListLiveFavoritesSong();
|
||||
break;
|
||||
case Song.DOWNLOADED:
|
||||
songList = songRepository.getListLiveDownloadedSong();
|
||||
break;
|
||||
}
|
||||
|
||||
return songList;
|
||||
|
|
|
|||
|
|
@ -222,6 +222,58 @@
|
|||
android:paddingBottom="8dp" />
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Downloaded tracks -->
|
||||
<LinearLayout
|
||||
android:id="@+id/home_downloaded_tracks_sector"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<!-- Label and button -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:paddingStart="8dp"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingEnd="8dp">
|
||||
|
||||
<TextView
|
||||
style="@style/HeadlineTextView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:paddingStart="8dp"
|
||||
android:paddingTop="12dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:text="Downloaded" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/downloaded_tracks_text_view_clickable"
|
||||
style="@style/SubheadTextView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="8dp"
|
||||
android:paddingTop="12dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:text="See all" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/downloaded_tracks_recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:clipToPadding="false"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:paddingBottom="8dp" />
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Recently added tracks -->
|
||||
<LinearLayout
|
||||
android:id="@+id/home_recently_added_tracks_sector"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue