mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 09:53:33 +00:00
Fix playlist sample visualization
This commit is contained in:
parent
c55f639368
commit
4fc29b47be
9 changed files with 123 additions and 34 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
package com.cappielloantonio.play.adapter;
|
package com.cappielloantonio.play.adapter;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
|
@ -17,6 +18,7 @@ import com.cappielloantonio.play.model.Playlist;
|
||||||
import com.cappielloantonio.play.ui.activity.MainActivity;
|
import com.cappielloantonio.play.ui.activity.MainActivity;
|
||||||
import com.cappielloantonio.play.util.PreferenceUtil;
|
import com.cappielloantonio.play.util.PreferenceUtil;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class PlaylistAdapter extends RecyclerView.Adapter<PlaylistAdapter.ViewHolder> {
|
public class PlaylistAdapter extends RecyclerView.Adapter<PlaylistAdapter.ViewHolder> {
|
||||||
|
|
@ -27,11 +29,11 @@ public class PlaylistAdapter extends RecyclerView.Adapter<PlaylistAdapter.ViewHo
|
||||||
private Context context;
|
private Context context;
|
||||||
private MainActivity activity;
|
private MainActivity activity;
|
||||||
|
|
||||||
public PlaylistAdapter(MainActivity activity, Context context, List<Playlist> playlists) {
|
public PlaylistAdapter(MainActivity activity, Context context) {
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.mInflater = LayoutInflater.from(context);
|
this.mInflater = LayoutInflater.from(context);
|
||||||
this.playlists = playlists;
|
this.playlists = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -45,6 +47,7 @@ public class PlaylistAdapter extends RecyclerView.Adapter<PlaylistAdapter.ViewHo
|
||||||
Playlist playlist = playlists.get(position);
|
Playlist playlist = playlists.get(position);
|
||||||
|
|
||||||
holder.textPlaylistName.setText(playlist.getName());
|
holder.textPlaylistName.setText(playlist.getName());
|
||||||
|
holder.textPlaylistSongCount.setText("Song count: " + String.valueOf(playlist.getSongCount()));
|
||||||
|
|
||||||
CustomGlideRequest.Builder
|
CustomGlideRequest.Builder
|
||||||
.from(context, playlist.getPrimary(), playlist.getBlurHash(), CustomGlideRequest.PLAYLIST_PIC)
|
.from(context, playlist.getPrimary(), playlist.getBlurHash(), CustomGlideRequest.PLAYLIST_PIC)
|
||||||
|
|
@ -68,12 +71,14 @@ public class PlaylistAdapter extends RecyclerView.Adapter<PlaylistAdapter.ViewHo
|
||||||
|
|
||||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||||
TextView textPlaylistName;
|
TextView textPlaylistName;
|
||||||
|
TextView textPlaylistSongCount;
|
||||||
ImageView cover;
|
ImageView cover;
|
||||||
|
|
||||||
ViewHolder(View itemView) {
|
ViewHolder(View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
|
|
||||||
textPlaylistName = itemView.findViewById(R.id.playlist_name_text);
|
textPlaylistName = itemView.findViewById(R.id.playlist_name_text);
|
||||||
|
textPlaylistSongCount = itemView.findViewById(R.id.playlist_song_counter_text);
|
||||||
cover = itemView.findViewById(R.id.playlist_cover_image_view);
|
cover = itemView.findViewById(R.id.playlist_cover_image_view);
|
||||||
|
|
||||||
itemView.setOnClickListener(this);
|
itemView.setOnClickListener(this);
|
||||||
|
|
|
||||||
|
|
@ -8,30 +8,23 @@ import androidx.room.ColumnInfo;
|
||||||
import androidx.room.Entity;
|
import androidx.room.Entity;
|
||||||
import androidx.room.PrimaryKey;
|
import androidx.room.PrimaryKey;
|
||||||
|
|
||||||
@Entity(tableName = "playlist")
|
|
||||||
public class Playlist implements Parcelable {
|
public class Playlist implements Parcelable {
|
||||||
@NonNull
|
|
||||||
@PrimaryKey
|
|
||||||
@ColumnInfo(name = "id")
|
|
||||||
public String id;
|
public String id;
|
||||||
|
|
||||||
@ColumnInfo(name = "name")
|
|
||||||
public String name;
|
public String name;
|
||||||
|
|
||||||
@ColumnInfo(name = "primary")
|
|
||||||
public String primary;
|
public String primary;
|
||||||
|
|
||||||
@ColumnInfo(name = "blurHash")
|
|
||||||
public String blurHash;
|
public String blurHash;
|
||||||
|
public int songCount;
|
||||||
|
public int duration;
|
||||||
|
|
||||||
public Playlist(@NonNull String id, String name, String primary, String blurHash) {
|
public Playlist(com.cappielloantonio.play.subsonic.models.Playlist playlist) {
|
||||||
this.id = id;
|
this.id = playlist.getId();
|
||||||
this.name = name;
|
this.name = playlist.getName();
|
||||||
this.primary = primary;
|
this.primary = playlist.getCoverArtId();
|
||||||
this.blurHash = blurHash;
|
this.blurHash = playlist.getCoverArtId();
|
||||||
|
this.songCount = playlist.getSongCount();
|
||||||
|
this.duration = playlist.getDuration();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
@ -44,16 +37,16 @@ public class Playlist implements Parcelable {
|
||||||
return primary;
|
return primary;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPrimary(String primary) {
|
|
||||||
this.primary = primary;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getBlurHash() {
|
public String getBlurHash() {
|
||||||
return blurHash;
|
return blurHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBlurHash(String blurHash) {
|
public int getSongCount() {
|
||||||
this.blurHash = blurHash;
|
return songCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDuration() {
|
||||||
|
return duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -70,7 +63,6 @@ public class Playlist implements Parcelable {
|
||||||
return id.hashCode();
|
return id.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return id;
|
return id;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,53 @@ package com.cappielloantonio.play.repository;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
|
||||||
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
|
import com.cappielloantonio.play.App;
|
||||||
|
import com.cappielloantonio.play.model.Artist;
|
||||||
|
import com.cappielloantonio.play.model.Playlist;
|
||||||
|
import com.cappielloantonio.play.subsonic.models.ResponseStatus;
|
||||||
|
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
|
||||||
|
import com.cappielloantonio.play.util.MappingUtil;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import retrofit2.Call;
|
||||||
|
import retrofit2.Callback;
|
||||||
|
import retrofit2.Response;
|
||||||
|
|
||||||
public class PlaylistRepository {
|
public class PlaylistRepository {
|
||||||
|
private Application application;
|
||||||
|
|
||||||
|
private MutableLiveData<List<Playlist>> listLivePlaylists = new MutableLiveData<>(new ArrayList<>());
|
||||||
|
private MutableLiveData<List<Playlist>> listLiveRandomPlaylist = new MutableLiveData<>(new ArrayList<>());
|
||||||
|
|
||||||
public PlaylistRepository(Application application) {
|
public PlaylistRepository(Application application) {
|
||||||
|
this.application = application;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MutableLiveData<List<Playlist>> getPlaylists(boolean random, int size) {
|
||||||
|
App.getSubsonicClientInstance(application, false)
|
||||||
|
.getPlaylistClient()
|
||||||
|
.getPlaylists()
|
||||||
|
.enqueue(new Callback<SubsonicResponse>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(Call<SubsonicResponse> call, Response<SubsonicResponse> response) {
|
||||||
|
if (response.body().getStatus().getValue().equals(ResponseStatus.OK)) {
|
||||||
|
List<Playlist> playlists = new ArrayList<>(MappingUtil.mapPlaylist(response.body().getPlaylists().getPlaylists()));
|
||||||
|
listLivePlaylists.setValue(playlists);
|
||||||
|
Collections.shuffle(playlists);
|
||||||
|
listLiveRandomPlaylist.setValue(playlists);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Call<SubsonicResponse> call, Throwable t) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return listLivePlaylists;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import java.util.List;
|
||||||
|
|
||||||
@Xml
|
@Xml
|
||||||
public class Playlists {
|
public class Playlists {
|
||||||
@Element
|
@Element(name = "playlist")
|
||||||
protected List<Playlist> playlists;
|
protected List<Playlist> playlists;
|
||||||
|
|
||||||
public List<Playlist> getPlaylists() {
|
public List<Playlist> getPlaylists() {
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ import androidx.viewpager2.widget.ViewPager2;
|
||||||
import com.cappielloantonio.play.R;
|
import com.cappielloantonio.play.R;
|
||||||
import com.cappielloantonio.play.adapter.AlbumAdapter;
|
import com.cappielloantonio.play.adapter.AlbumAdapter;
|
||||||
import com.cappielloantonio.play.adapter.ArtistAdapter;
|
import com.cappielloantonio.play.adapter.ArtistAdapter;
|
||||||
|
import com.cappielloantonio.play.adapter.DiscoverSongAdapter;
|
||||||
import com.cappielloantonio.play.adapter.GenreAdapter;
|
import com.cappielloantonio.play.adapter.GenreAdapter;
|
||||||
import com.cappielloantonio.play.adapter.PlaylistAdapter;
|
import com.cappielloantonio.play.adapter.PlaylistAdapter;
|
||||||
import com.cappielloantonio.play.databinding.FragmentLibraryBinding;
|
import com.cappielloantonio.play.databinding.FragmentLibraryBinding;
|
||||||
|
|
@ -119,9 +120,13 @@ public class LibraryFragment extends Fragment {
|
||||||
private void initPlaylistSlideView() {
|
private void initPlaylistSlideView() {
|
||||||
bind.playlistViewPager.setOrientation(ViewPager2.ORIENTATION_HORIZONTAL);
|
bind.playlistViewPager.setOrientation(ViewPager2.ORIENTATION_HORIZONTAL);
|
||||||
|
|
||||||
playlistAdapter = new PlaylistAdapter(activity, requireContext(), libraryViewModel.getPlaylistSample());
|
playlistAdapter = new PlaylistAdapter(activity, requireContext());
|
||||||
bind.playlistViewPager.setAdapter(playlistAdapter);
|
bind.playlistViewPager.setAdapter(playlistAdapter);
|
||||||
bind.playlistViewPager.setOffscreenPageLimit(3);
|
bind.playlistViewPager.setOffscreenPageLimit(3);
|
||||||
|
libraryViewModel.getPlaylistSample().observe(requireActivity(), playlists -> {
|
||||||
|
playlistAdapter.setItems(playlists);
|
||||||
|
});
|
||||||
|
|
||||||
setDiscoverSongSlideViewOffset(20, 16);
|
setDiscoverSongSlideViewOffset(20, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,14 @@ package com.cappielloantonio.play.util;
|
||||||
|
|
||||||
import com.cappielloantonio.play.model.Album;
|
import com.cappielloantonio.play.model.Album;
|
||||||
import com.cappielloantonio.play.model.Artist;
|
import com.cappielloantonio.play.model.Artist;
|
||||||
|
import com.cappielloantonio.play.model.Playlist;
|
||||||
import com.cappielloantonio.play.model.Queue;
|
import com.cappielloantonio.play.model.Queue;
|
||||||
import com.cappielloantonio.play.model.Song;
|
import com.cappielloantonio.play.model.Song;
|
||||||
import com.cappielloantonio.play.subsonic.models.AlbumID3;
|
import com.cappielloantonio.play.subsonic.models.AlbumID3;
|
||||||
import com.cappielloantonio.play.subsonic.models.ArtistID3;
|
import com.cappielloantonio.play.subsonic.models.ArtistID3;
|
||||||
import com.cappielloantonio.play.subsonic.models.ArtistWithAlbumsID3;
|
import com.cappielloantonio.play.subsonic.models.ArtistWithAlbumsID3;
|
||||||
import com.cappielloantonio.play.subsonic.models.Child;
|
import com.cappielloantonio.play.subsonic.models.Child;
|
||||||
|
import com.cappielloantonio.play.subsonic.models.Playlists;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -56,4 +58,14 @@ public class MappingUtil {
|
||||||
|
|
||||||
return songs;
|
return songs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ArrayList<Playlist> mapPlaylist(List<com.cappielloantonio.play.subsonic.models.Playlist> playlists) {
|
||||||
|
ArrayList<Playlist> playlist = new ArrayList();
|
||||||
|
|
||||||
|
for(com.cappielloantonio.play.subsonic.models.Playlist item : playlists){
|
||||||
|
playlist.add(new Playlist(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
return playlist;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ public class LibraryViewModel extends AndroidViewModel {
|
||||||
private GenreRepository genreRepository;
|
private GenreRepository genreRepository;
|
||||||
private PlaylistRepository playlistRepository;
|
private PlaylistRepository playlistRepository;
|
||||||
|
|
||||||
private List<Playlist> playlistSample;
|
private LiveData<List<Playlist>> playlistSample;
|
||||||
private LiveData<List<Album>> sampleAlbum;
|
private LiveData<List<Album>> sampleAlbum;
|
||||||
private LiveData<List<Artist>> sampleArtist;
|
private LiveData<List<Artist>> sampleArtist;
|
||||||
private LiveData<List<Genre>> sampleGenres;
|
private LiveData<List<Genre>> sampleGenres;
|
||||||
|
|
@ -48,14 +48,10 @@ public class LibraryViewModel extends AndroidViewModel {
|
||||||
sampleAlbum = albumRepository.getAlbums("random", 20);
|
sampleAlbum = albumRepository.getAlbums("random", 20);
|
||||||
sampleArtist = artistRepository.getArtists(true, 20);
|
sampleArtist = artistRepository.getArtists(true, 20);
|
||||||
sampleGenres = new MutableLiveData<>();
|
sampleGenres = new MutableLiveData<>();
|
||||||
playlistSample = new ArrayList<>();
|
playlistSample = playlistRepository.getPlaylists(true, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Playlist> getPlaylistSample() {
|
public LiveData<List<Playlist>> getPlaylistSample() {
|
||||||
if (playlistSample.isEmpty()) {
|
|
||||||
// playlistSample = playlistRepository.getRandomSample(5);
|
|
||||||
}
|
|
||||||
|
|
||||||
return playlistSample;
|
return playlistSample;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,25 @@
|
||||||
android:layout_marginTop="18dp"
|
android:layout_marginTop="18dp"
|
||||||
android:layout_marginRight="16dp"
|
android:layout_marginRight="16dp"
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
|
android:fontFamily="@font/inter"
|
||||||
android:maxLines="2"
|
android:maxLines="2"
|
||||||
android:textColor="@color/gradientTitleColor"
|
android:textColor="@color/gradientTitleColor"
|
||||||
|
android:textFontWeight="400"
|
||||||
android:textSize="20sp" />
|
android:textSize="20sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/playlist_song_counter_text"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@id/playlist_name_text"
|
||||||
|
android:layout_marginLeft="16dp"
|
||||||
|
android:layout_marginRight="16dp"
|
||||||
|
android:drawablePadding="10dp"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:fontFamily="@font/inter"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:textColor="@color/gradientSubtitleColor"
|
||||||
|
android:textFontWeight="400"
|
||||||
|
android:textSize="14sp" />
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
</androidx.cardview.widget.CardView>
|
</androidx.cardview.widget.CardView>
|
||||||
|
|
@ -32,9 +32,26 @@
|
||||||
android:layout_marginTop="18dp"
|
android:layout_marginTop="18dp"
|
||||||
android:layout_marginRight="16dp"
|
android:layout_marginRight="16dp"
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
|
android:fontFamily="@font/inter"
|
||||||
android:maxLines="2"
|
android:maxLines="2"
|
||||||
android:textColor="@color/gradientTitleColor"
|
android:textColor="@color/gradientTitleColor"
|
||||||
|
android:textFontWeight="400"
|
||||||
android:textSize="20sp" />
|
android:textSize="20sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/playlist_song_counter_text"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@id/playlist_name_text"
|
||||||
|
android:layout_marginLeft="16dp"
|
||||||
|
android:layout_marginRight="16dp"
|
||||||
|
android:drawablePadding="10dp"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:fontFamily="@font/inter"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:textColor="@color/gradientSubtitleColor"
|
||||||
|
android:textFontWeight="400"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
</androidx.cardview.widget.CardView>
|
</androidx.cardview.widget.CardView>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue