mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 09:33:33 +00:00
Added similar items in album page
This commit is contained in:
parent
d24b14453d
commit
e7713ce19c
10 changed files with 148 additions and 11 deletions
|
|
@ -42,6 +42,7 @@ public class AlbumArtistPageAdapter extends RecyclerView.Adapter<AlbumArtistPage
|
|||
Album album = albums.get(position);
|
||||
|
||||
holder.textAlbumName.setText(album.getTitle());
|
||||
holder.textArtistName.setText(album.getArtistName());
|
||||
|
||||
CustomGlideRequest.Builder
|
||||
.from(context, album.getPrimary(), album.getBlurHash(), CustomGlideRequest.PRIMARY, CustomGlideRequest.LOW_QUALITY, CustomGlideRequest.ALBUM_PIC)
|
||||
|
|
@ -65,12 +66,14 @@ public class AlbumArtistPageAdapter extends RecyclerView.Adapter<AlbumArtistPage
|
|||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||
TextView textAlbumName;
|
||||
TextView textArtistName;
|
||||
ImageView cover;
|
||||
|
||||
ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
textAlbumName = itemView.findViewById(R.id.album_name_label);
|
||||
textArtistName = itemView.findViewById(R.id.artist_name_label);
|
||||
cover = itemView.findViewById(R.id.artist_page_album_cover_image_view);
|
||||
|
||||
itemView.setOnClickListener(this);
|
||||
|
|
@ -81,14 +84,14 @@ public class AlbumArtistPageAdapter extends RecyclerView.Adapter<AlbumArtistPage
|
|||
public void onClick(View view) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("album_object", albums.get(getBindingAdapterPosition()));
|
||||
Navigation.findNavController(view).navigate(R.id.action_artistPageFragment_to_albumPageFragment, bundle);
|
||||
Navigation.findNavController(view).navigate(R.id.albumPageFragment, bundle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
public boolean onLongClick(View view) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("album_object", albums.get(getBindingAdapterPosition()));
|
||||
Navigation.findNavController(v).navigate(R.id.albumBottomSheetDialog, bundle);
|
||||
Navigation.findNavController(view).navigate(R.id.albumBottomSheetDialog, bundle);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,18 +21,26 @@ import androidx.recyclerview.widget.LinearLayoutManager;
|
|||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.adapter.AlbumArtistPageAdapter;
|
||||
import com.cappielloantonio.play.adapter.SongResultSearchAdapter;
|
||||
import com.cappielloantonio.play.databinding.FragmentAlbumPageBinding;
|
||||
import com.cappielloantonio.play.glide.CustomGlideRequest;
|
||||
import com.cappielloantonio.play.interfaces.MediaCallback;
|
||||
import com.cappielloantonio.play.model.Album;
|
||||
import com.cappielloantonio.play.model.Artist;
|
||||
import com.cappielloantonio.play.model.Playlist;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.service.MusicPlayerRemote;
|
||||
import com.cappielloantonio.play.repository.QueueRepository;
|
||||
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.viewmodel.AlbumPageViewModel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class AlbumPageFragment extends Fragment {
|
||||
|
|
@ -43,6 +51,7 @@ public class AlbumPageFragment extends Fragment {
|
|||
private AlbumPageViewModel albumPageViewModel;
|
||||
|
||||
private SongResultSearchAdapter songResultSearchAdapter;
|
||||
private AlbumArtistPageAdapter albumArtistPageAdapter;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
|
|
@ -63,6 +72,7 @@ public class AlbumPageFragment extends Fragment {
|
|||
initAppBar();
|
||||
initAlbumInfoTextButton();
|
||||
initMusicButton();
|
||||
initSimilarAlbumsView();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -197,4 +207,24 @@ public class AlbumPageFragment extends Fragment {
|
|||
songResultSearchAdapter.setItems(songs);
|
||||
});
|
||||
}
|
||||
|
||||
private void initSimilarAlbumsView() {
|
||||
SyncUtil.getSimilarItems(requireContext(), new MediaCallback() {
|
||||
@Override
|
||||
public void onError(Exception exception) {
|
||||
Toast.makeText(requireContext(), "Error retrieving similar items", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadMedia(List<?> media) {
|
||||
bind.similarAlbumSector.setVisibility(View.VISIBLE);
|
||||
|
||||
bind.similarAlbumsRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
|
||||
|
||||
albumArtistPageAdapter = new AlbumArtistPageAdapter(requireContext());
|
||||
bind.similarAlbumsRecyclerView.setAdapter(albumArtistPageAdapter);
|
||||
albumArtistPageAdapter.setItems((ArrayList<Album>) media);
|
||||
}
|
||||
}, SyncUtil.ALBUM, albumPageViewModel.getAlbum().getId(), PreferenceUtil.getInstance(requireContext()).getSimilarItemsNumber());
|
||||
}
|
||||
}
|
||||
|
|
@ -26,6 +26,7 @@ public class PreferenceUtil {
|
|||
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 SIMILAR_ITEMS_NUMBER = "similar_items_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";
|
||||
|
|
@ -139,6 +140,10 @@ public class PreferenceUtil {
|
|||
return Integer.parseInt(mPreferences.getString(INSTANT_MIX_SONG_NUMBER, "10"));
|
||||
}
|
||||
|
||||
public final int getSimilarItemsNumber() {
|
||||
return Integer.parseInt(mPreferences.getString(SIMILAR_ITEMS_NUMBER, "10"));
|
||||
}
|
||||
|
||||
public final int getSearchElementPerCategory() {
|
||||
return Integer.parseInt(mPreferences.getString(SEARCH_ELEMENT_PER_CATEGORY, "10"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -274,6 +274,39 @@ public class SyncUtil {
|
|||
});
|
||||
}
|
||||
|
||||
public static void getSimilarItems(Context context, MediaCallback callback, String resultType, String itemID, int limit) {
|
||||
SimilarItemsQuery query = new SimilarItemsQuery();
|
||||
|
||||
query.setId(itemID);
|
||||
query.setUserId(App.getApiClientInstance(context).getCurrentUserId());
|
||||
query.setFields(new ItemFields[]{ItemFields.MediaSources});
|
||||
query.setLimit(limit);
|
||||
|
||||
App.getApiClientInstance(context).GetSimilarItems(query, new Response<ItemsResult>() {
|
||||
@Override
|
||||
public void onResponse(ItemsResult result) {
|
||||
List<Object> items = new ArrayList<>();
|
||||
|
||||
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) {
|
||||
items.add(new Album(itemDto));
|
||||
} else if (resultType.equals(SONG) && itemDto.getBaseItemType() == BaseItemType.Audio) {
|
||||
items.add(new Song(itemDto));
|
||||
}
|
||||
}
|
||||
|
||||
callback.onLoadMedia(items);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception exception) {
|
||||
callback.onError(exception);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static Bundle getSyncBundle(Boolean syncAlbum, Boolean syncArtist, Boolean syncGenres, Boolean syncPlaylist, Boolean syncSong, Boolean crossSyncSongGenre) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putBoolean("sync_album", syncAlbum);
|
||||
|
|
|
|||
|
|
@ -146,13 +146,49 @@
|
|||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/song_recycler_view"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clipToPadding="false"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingBottom="@dimen/global_padding_bottom"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
android:orientation="vertical">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/song_recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clipToPadding="false"
|
||||
android:paddingTop="8dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/similar_album_sector"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone">
|
||||
|
||||
<TextView
|
||||
style="@style/HeadlineTextView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingTop="32dp"
|
||||
android:paddingEnd="20dp"
|
||||
android:text="More like this" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/similar_albums_recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:clipToPadding="false"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:paddingBottom="8dp" />
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
</LinearLayout>
|
||||
|
|
@ -46,7 +46,6 @@
|
|||
</com.google.android.material.appbar.CollapsingToolbarLayout>
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
|||
|
|
@ -23,10 +23,19 @@
|
|||
android:maxWidth="256dp"
|
||||
android:maxLines="2"
|
||||
android:paddingTop="8dp"
|
||||
|
||||
android:singleLine="false"
|
||||
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/artist_page_album_cover_image_view" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/artist_name_label"
|
||||
style="@style/ItemSubtitleTextView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/album_name_label" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
@ -51,6 +51,18 @@
|
|||
<item>50</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="similar_items_number_titles">
|
||||
<item>10</item>
|
||||
<item>25</item>
|
||||
<item>50</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="similar_items_number_values">
|
||||
<item>10</item>
|
||||
<item>25</item>
|
||||
<item>50</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="search_element_per_category_titles">
|
||||
<item>10</item>
|
||||
<item>20</item>
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
<string name="label_dot_separator">•</string>
|
||||
<string name="save_filters">Save filters between sessions</string>
|
||||
<string name="instant_mix_song_number">Number of songs generated by Instant Mix</string>
|
||||
<string name="similar_items_number">Number of similar items</string>
|
||||
<string name="search_element_per_category">Number of items searched for each category</string>
|
||||
|
||||
<string name="sync_header">Synchronization</string>
|
||||
|
|
|
|||
|
|
@ -37,6 +37,15 @@
|
|||
app:title="@string/instant_mix_song_number"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
|
||||
<ListPreference
|
||||
app:defaultValue="10"
|
||||
app:dialogTitle="@string/similar_items_number"
|
||||
app:entries="@array/similar_items_number_titles"
|
||||
app:entryValues="@array/similar_items_number_values"
|
||||
app:key="similar_items_number"
|
||||
app:title="@string/similar_items_number"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
|
||||
<ListPreference
|
||||
app:defaultValue="10"
|
||||
app:dialogTitle="@string/search_element_per_category"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue