mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 18:03:33 +00:00
Add bottomsheet everywhere
This commit is contained in:
parent
01bdbf49b2
commit
9af0afa441
41 changed files with 866 additions and 359 deletions
|
|
@ -9,10 +9,9 @@ import androidx.fragment.app.Fragment;
|
|||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
|
||||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.adapter.AlbumCatalogueAdapter;
|
||||
import com.cappielloantonio.play.databinding.FragmentAlbumCatalogueBinding;
|
||||
import com.cappielloantonio.play.helper.recyclerview.ItemDecoration;
|
||||
import com.cappielloantonio.play.helper.recyclerview.GridItemDecoration;
|
||||
import com.cappielloantonio.play.ui.activities.MainActivity;
|
||||
import com.cappielloantonio.play.viewmodel.AlbumCatalogueViewModel;
|
||||
|
||||
|
|
@ -52,15 +51,10 @@ public class AlbumCatalogueFragment extends Fragment {
|
|||
|
||||
private void initAlbumCatalogueView() {
|
||||
bind.albumCatalogueRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), 2));
|
||||
bind.albumCatalogueRecyclerView.addItemDecoration(new ItemDecoration(2, 20, false));
|
||||
bind.albumCatalogueRecyclerView.addItemDecoration(new GridItemDecoration(2, 20, false));
|
||||
bind.albumCatalogueRecyclerView.setHasFixedSize(true);
|
||||
|
||||
albumAdapter = new AlbumCatalogueAdapter(requireContext());
|
||||
albumAdapter.setClickListener((view, position) -> {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("album_object", albumAdapter.getItem(position));
|
||||
activity.navController.navigate(R.id.action_albumCatalogueFragment_to_albumPageFragment, bundle);
|
||||
});
|
||||
bind.albumCatalogueRecyclerView.setAdapter(albumAdapter);
|
||||
albumCatalogueViewModel.getAlbumList().observe(requireActivity(), albums -> {
|
||||
bind.loadingProgressBar.setVisibility(View.GONE);
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ import com.cappielloantonio.play.adapter.SongResultSearchAdapter;
|
|||
import com.cappielloantonio.play.databinding.FragmentAlbumPageBinding;
|
||||
import com.cappielloantonio.play.glide.CustomGlideRequest;
|
||||
import com.cappielloantonio.play.ui.activities.MainActivity;
|
||||
import com.cappielloantonio.play.ui.fragment.bottomsheetdialog.AlbumBottomSheetDialog;
|
||||
import com.cappielloantonio.play.viewmodel.AlbumPageViewModel;
|
||||
|
||||
public class AlbumPageFragment extends Fragment {
|
||||
|
|
@ -33,7 +32,6 @@ public class AlbumPageFragment extends Fragment {
|
|||
albumPageViewModel = new ViewModelProvider(requireActivity()).get(AlbumPageViewModel.class);
|
||||
|
||||
init();
|
||||
initBottomSheetDialog();
|
||||
initBackCover();
|
||||
initSongsView();
|
||||
|
||||
|
|
@ -65,13 +63,6 @@ public class AlbumPageFragment extends Fragment {
|
|||
bind.albumTitleLabel.setText(albumPageViewModel.getAlbum().getTitle());
|
||||
}
|
||||
|
||||
private void initBottomSheetDialog() {
|
||||
bind.albumSettingsImageButton.setOnClickListener(v -> {
|
||||
AlbumBottomSheetDialog albumBottomSheetDialog = new AlbumBottomSheetDialog(albumPageViewModel.getAlbum());
|
||||
albumBottomSheetDialog.show(this.getChildFragmentManager(), null);
|
||||
});
|
||||
}
|
||||
|
||||
private void initSongsView() {
|
||||
bind.songRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext()));
|
||||
bind.songRecyclerView.setHasFixedSize(true);
|
||||
|
|
|
|||
|
|
@ -9,10 +9,9 @@ import androidx.fragment.app.Fragment;
|
|||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
|
||||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.adapter.ArtistCatalogueAdapter;
|
||||
import com.cappielloantonio.play.databinding.FragmentArtistCatalogueBinding;
|
||||
import com.cappielloantonio.play.helper.recyclerview.ItemDecoration;
|
||||
import com.cappielloantonio.play.helper.recyclerview.GridItemDecoration;
|
||||
import com.cappielloantonio.play.ui.activities.MainActivity;
|
||||
import com.cappielloantonio.play.viewmodel.ArtistCatalogueViewModel;
|
||||
|
||||
|
|
@ -52,15 +51,10 @@ public class ArtistCatalogueFragment extends Fragment {
|
|||
|
||||
private void initArtistCatalogueView() {
|
||||
bind.artistCatalogueRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), 2));
|
||||
bind.artistCatalogueRecyclerView.addItemDecoration(new ItemDecoration(2, 20, false));
|
||||
bind.artistCatalogueRecyclerView.addItemDecoration(new GridItemDecoration(2, 20, false));
|
||||
bind.artistCatalogueRecyclerView.setHasFixedSize(true);
|
||||
|
||||
artistAdapter = new ArtistCatalogueAdapter(requireContext());
|
||||
artistAdapter.setClickListener((view, position) -> {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("artist_object", artistAdapter.getItem(position));
|
||||
activity.navController.navigate(R.id.action_artistCatalogueFragment_to_artistPageFragment, bundle);
|
||||
});
|
||||
bind.artistCatalogueRecyclerView.setAdapter(artistAdapter);
|
||||
artistCatalogueViewModel.getArtistList().observe(requireActivity(), artists -> {
|
||||
bind.loadingProgressBar.setVisibility(View.GONE);
|
||||
|
|
|
|||
|
|
@ -89,11 +89,6 @@ public class ArtistPageFragment extends Fragment {
|
|||
bind.albumsRecyclerView.setHasFixedSize(true);
|
||||
|
||||
albumArtistPageAdapter = new AlbumArtistPageAdapter(requireContext());
|
||||
albumArtistPageAdapter.setClickListener((view, position) -> {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("album_object", albumArtistPageAdapter.getItem(position));
|
||||
activity.navController.navigate(R.id.action_artistPageFragment_to_albumPageFragment, bundle);
|
||||
});
|
||||
bind.albumsRecyclerView.setAdapter(albumArtistPageAdapter);
|
||||
artistPageViewModel.getAlbumList().observe(requireActivity(), songs -> albumArtistPageAdapter.setItems(songs));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import androidx.recyclerview.widget.GridLayoutManager;
|
|||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.adapter.GenreCatalogueAdapter;
|
||||
import com.cappielloantonio.play.databinding.FragmentGenreCatalogueBinding;
|
||||
import com.cappielloantonio.play.helper.recyclerview.ItemDecoration;
|
||||
import com.cappielloantonio.play.helper.recyclerview.GridItemDecoration;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.ui.activities.MainActivity;
|
||||
import com.cappielloantonio.play.viewmodel.GenreCatalogueViewModel;
|
||||
|
|
@ -58,7 +58,7 @@ public class GenreCatalogueFragment extends Fragment {
|
|||
|
||||
private void initArtistCatalogueView() {
|
||||
bind.genreCatalogueRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), 2));
|
||||
bind.genreCatalogueRecyclerView.addItemDecoration(new ItemDecoration(2, 16, false));
|
||||
bind.genreCatalogueRecyclerView.addItemDecoration(new GridItemDecoration(2, 16, false));
|
||||
bind.genreCatalogueRecyclerView.setHasFixedSize(true);
|
||||
|
||||
genreCatalogueAdapter = new GenreCatalogueAdapter(requireContext());
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ 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.viewpager2.widget.ViewPager2;
|
||||
|
||||
import com.cappielloantonio.play.R;
|
||||
|
|
@ -129,7 +130,7 @@ public class HomeFragment extends Fragment {
|
|||
bind.recentlyAddedTracksRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
|
||||
bind.recentlyAddedTracksRecyclerView.setHasFixedSize(true);
|
||||
|
||||
recentlyAddedMusicAdapter = new RecentMusicAdapter(requireContext());
|
||||
recentlyAddedMusicAdapter = new RecentMusicAdapter(requireContext(), getChildFragmentManager());
|
||||
bind.recentlyAddedTracksRecyclerView.setAdapter(recentlyAddedMusicAdapter);
|
||||
homeViewModel.getRecentlyAddedSongList().observe(requireActivity(), songs -> recentlyAddedMusicAdapter.setItems(songs));
|
||||
}
|
||||
|
|
@ -149,19 +150,22 @@ public class HomeFragment extends Fragment {
|
|||
}
|
||||
|
||||
private void initFavoritesSongView() {
|
||||
bind.favoritesTracksRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), 3, GridLayoutManager.HORIZONTAL, false));
|
||||
bind.favoritesTracksRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), 5, GridLayoutManager.HORIZONTAL, false));
|
||||
bind.favoritesTracksRecyclerView.setHasFixedSize(true);
|
||||
|
||||
favoriteSongAdapter = new SongResultSearchAdapter(requireContext(), getChildFragmentManager());
|
||||
bind.favoritesTracksRecyclerView.setAdapter(favoriteSongAdapter);
|
||||
homeViewModel.getFavorites().observe(requireActivity(), songs -> favoriteSongAdapter.setItems(songs));
|
||||
|
||||
PagerSnapHelper pagerSnapHelper = new PagerSnapHelper();
|
||||
pagerSnapHelper.attachToRecyclerView(bind.favoritesTracksRecyclerView);
|
||||
}
|
||||
|
||||
private void initMostPlayedSongView() {
|
||||
bind.mostPlayedTracksRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
|
||||
bind.mostPlayedTracksRecyclerView.setHasFixedSize(true);
|
||||
|
||||
mostPlayedMusicAdapter = new RecentMusicAdapter(requireContext());
|
||||
mostPlayedMusicAdapter = new RecentMusicAdapter(requireContext(), getChildFragmentManager());
|
||||
bind.mostPlayedTracksRecyclerView.setAdapter(mostPlayedMusicAdapter);
|
||||
homeViewModel.getMostPlayedSongList().observe(requireActivity(), songs -> mostPlayedMusicAdapter.setItems(songs));
|
||||
}
|
||||
|
|
@ -170,7 +174,7 @@ public class HomeFragment extends Fragment {
|
|||
bind.recentlyPlayedTracksRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
|
||||
bind.recentlyPlayedTracksRecyclerView.setHasFixedSize(true);
|
||||
|
||||
recentlyPlayedMusicAdapter = new RecentMusicAdapter(requireContext());
|
||||
recentlyPlayedMusicAdapter = new RecentMusicAdapter(requireContext(), getChildFragmentManager());
|
||||
bind.recentlyPlayedTracksRecyclerView.setAdapter(recentlyPlayedMusicAdapter);
|
||||
homeViewModel.getRecentlyPlayedSongList().observe(requireActivity(), songs -> recentlyPlayedMusicAdapter.setItems(songs));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,11 +79,6 @@ public class LibraryFragment extends Fragment {
|
|||
bind.albumRecyclerView.setHasFixedSize(true);
|
||||
|
||||
albumAdapter = new AlbumAdapter(requireContext());
|
||||
albumAdapter.setClickListener((view, position) -> {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("album_object", albumAdapter.getItem(position));
|
||||
activity.navController.navigate(R.id.action_libraryFragment_to_albumPageFragment, bundle);
|
||||
});
|
||||
bind.albumRecyclerView.setAdapter(albumAdapter);
|
||||
libraryViewModel.getAlbumSample().observe(requireActivity(), albums -> albumAdapter.setItems(albums));
|
||||
}
|
||||
|
|
@ -93,11 +88,6 @@ public class LibraryFragment extends Fragment {
|
|||
bind.artistRecyclerView.setHasFixedSize(true);
|
||||
|
||||
artistAdapter = new ArtistAdapter(requireContext());
|
||||
artistAdapter.setClickListener((view, position) -> {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("artist_object", artistAdapter.getItem(position));
|
||||
activity.navController.navigate(R.id.action_libraryFragment_to_artistPageFragment, bundle);
|
||||
});
|
||||
bind.artistRecyclerView.setAdapter(artistAdapter);
|
||||
libraryViewModel.getArtistSample().observe(requireActivity(), artists -> artistAdapter.setItems(artists));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,13 +13,12 @@ import androidx.lifecycle.ViewModelProvider;
|
|||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
||||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.adapter.AlbumCatalogueAdapter;
|
||||
import com.cappielloantonio.play.adapter.ArtistCatalogueAdapter;
|
||||
import com.cappielloantonio.play.adapter.RecentSearchAdapter;
|
||||
import com.cappielloantonio.play.adapter.SongResultSearchAdapter;
|
||||
import com.cappielloantonio.play.databinding.FragmentSearchBinding;
|
||||
import com.cappielloantonio.play.helper.recyclerview.ItemDecoration;
|
||||
import com.cappielloantonio.play.helper.recyclerview.GridItemDecoration;
|
||||
import com.cappielloantonio.play.model.RecentSearch;
|
||||
import com.cappielloantonio.play.ui.activities.MainActivity;
|
||||
import com.cappielloantonio.play.viewmodel.SearchViewModel;
|
||||
|
|
@ -98,28 +97,18 @@ public class SearchFragment extends Fragment {
|
|||
|
||||
// Albums
|
||||
bind.searchResultAlbumRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), 2));
|
||||
bind.searchResultAlbumRecyclerView.addItemDecoration(new ItemDecoration(2, 20, false));
|
||||
bind.searchResultAlbumRecyclerView.addItemDecoration(new GridItemDecoration(2, 20, false));
|
||||
bind.searchResultAlbumRecyclerView.setHasFixedSize(true);
|
||||
|
||||
albumResultSearchAdapter = new AlbumCatalogueAdapter(requireContext());
|
||||
albumResultSearchAdapter.setClickListener((view, position) -> {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("album_object", albumResultSearchAdapter.getItem(position));
|
||||
activity.navController.navigate(R.id.action_searchFragment_to_albumPageFragment, bundle);
|
||||
});
|
||||
bind.searchResultAlbumRecyclerView.setAdapter(albumResultSearchAdapter);
|
||||
|
||||
// Artist
|
||||
bind.searchResultArtistRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), 2));
|
||||
bind.searchResultArtistRecyclerView.addItemDecoration(new ItemDecoration(2, 20, false));
|
||||
bind.searchResultArtistRecyclerView.addItemDecoration(new GridItemDecoration(2, 20, false));
|
||||
bind.searchResultArtistRecyclerView.setHasFixedSize(true);
|
||||
|
||||
artistResultSearchAdapter = new ArtistCatalogueAdapter(requireContext());
|
||||
artistResultSearchAdapter.setClickListener((view, position) -> {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("artist_object", artistResultSearchAdapter.getItem(position));
|
||||
activity.navController.navigate(R.id.action_searchFragment_to_artistPageFragment, bundle);
|
||||
});
|
||||
bind.searchResultArtistRecyclerView.setAdapter(artistResultSearchAdapter);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,51 +4,123 @@ import android.os.Bundle;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.navigation.fragment.NavHostFragment;
|
||||
|
||||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.glide.CustomGlideRequest;
|
||||
import com.cappielloantonio.play.model.Album;
|
||||
import com.cappielloantonio.play.model.Artist;
|
||||
import com.cappielloantonio.play.viewmodel.AlbumBottomSheetViewModel;
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
|
||||
|
||||
public class AlbumBottomSheetDialog extends BottomSheetDialogFragment implements View.OnClickListener {
|
||||
private static final String TAG = "AlbumBottomSheetDialog";
|
||||
|
||||
private AlbumBottomSheetViewModel albumBottomSheetViewModel;
|
||||
private Album album;
|
||||
|
||||
public AlbumBottomSheetDialog(Album album) {
|
||||
this.album = album;
|
||||
}
|
||||
private ImageView coverAlbum;
|
||||
private TextView titleAlbum;
|
||||
private TextView artistAlbum;
|
||||
|
||||
private TextView playRadio;
|
||||
private TextView playRandom;
|
||||
private TextView playNext;
|
||||
private TextView addToQueue;
|
||||
private TextView Download;
|
||||
private TextView addToPlaylist;
|
||||
private TextView goToArtist;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.bottom_sheet_album_dialog, container, false);
|
||||
|
||||
album = this.getArguments().getParcelable("album_object");
|
||||
|
||||
albumBottomSheetViewModel = new ViewModelProvider(requireActivity()).get(AlbumBottomSheetViewModel.class);
|
||||
albumBottomSheetViewModel.setAlbum(album);
|
||||
|
||||
init(view);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
private void init(View view) {
|
||||
Button button1 = view.findViewById(R.id.button1);
|
||||
Button button2 = view.findViewById(R.id.button2);
|
||||
coverAlbum = view.findViewById(R.id.album_cover_image_view);
|
||||
CustomGlideRequest.Builder
|
||||
.from(requireContext(), albumBottomSheetViewModel.getAlbum().getPrimary(), albumBottomSheetViewModel.getAlbum().getBlurHash(), CustomGlideRequest.PRIMARY, CustomGlideRequest.TOP_QUALITY)
|
||||
.build()
|
||||
.into(coverAlbum);
|
||||
|
||||
button1.setOnClickListener(v -> {
|
||||
Toast.makeText(requireContext(), album.getTitle(), Toast.LENGTH_SHORT).show();
|
||||
dismiss();
|
||||
titleAlbum = view.findViewById(R.id.album_title_text_view);
|
||||
titleAlbum.setText(albumBottomSheetViewModel.getAlbum().getTitle());
|
||||
|
||||
artistAlbum = view.findViewById(R.id.album_artist_text_view);
|
||||
artistAlbum.setText(albumBottomSheetViewModel.getAlbum().getArtistName());
|
||||
|
||||
playRadio = view.findViewById(R.id.play_radio_text_view);
|
||||
playRadio.setOnClickListener(v -> {
|
||||
Toast.makeText(requireContext(), "Play radio", Toast.LENGTH_SHORT).show();
|
||||
dismissBottomSheet();
|
||||
});
|
||||
|
||||
button2.setOnClickListener(v -> {
|
||||
Toast.makeText(requireContext(), album.getArtistName(), Toast.LENGTH_SHORT).show();
|
||||
dismiss();
|
||||
playRandom = view.findViewById(R.id.play_random_text_view);
|
||||
playRandom.setOnClickListener(v -> {
|
||||
Toast.makeText(requireContext(), "Play next", Toast.LENGTH_SHORT).show();
|
||||
dismissBottomSheet();
|
||||
});
|
||||
|
||||
playNext = view.findViewById(R.id.play_next_text_view);
|
||||
playNext.setOnClickListener(v -> {
|
||||
Toast.makeText(requireContext(), "Play next", Toast.LENGTH_SHORT).show();
|
||||
dismissBottomSheet();
|
||||
});
|
||||
|
||||
addToQueue = view.findViewById(R.id.add_to_queue_text_view);
|
||||
addToQueue.setOnClickListener(v -> {
|
||||
Toast.makeText(requireContext(), "Add to queue", Toast.LENGTH_SHORT).show();
|
||||
dismissBottomSheet();
|
||||
});
|
||||
|
||||
Download = view.findViewById(R.id.download_text_view);
|
||||
Download.setOnClickListener(v -> {
|
||||
Toast.makeText(requireContext(), "Download", Toast.LENGTH_SHORT).show();
|
||||
dismissBottomSheet();
|
||||
});
|
||||
|
||||
addToPlaylist = view.findViewById(R.id.add_to_playlist_text_view);
|
||||
addToPlaylist.setOnClickListener(v -> {
|
||||
Toast.makeText(requireContext(), "Add to playlist", Toast.LENGTH_SHORT).show();
|
||||
dismissBottomSheet();
|
||||
});
|
||||
|
||||
goToArtist = view.findViewById(R.id.go_to_artist_text_view);
|
||||
goToArtist.setOnClickListener(v -> {
|
||||
Artist artist = albumBottomSheetViewModel.getArtist();
|
||||
if(artist != null) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("artist_object", artist);
|
||||
NavHostFragment.findNavController(this).navigate(R.id.artistPageFragment, bundle);
|
||||
}
|
||||
else Toast.makeText(requireContext(), "Error retrieving artist", Toast.LENGTH_SHORT).show();
|
||||
|
||||
dismissBottomSheet();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dismissBottomSheet();
|
||||
}
|
||||
|
||||
private void dismissBottomSheet() {
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
package com.cappielloantonio.play.ui.fragment.bottomsheetdialog;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.glide.CustomGlideRequest;
|
||||
import com.cappielloantonio.play.model.Artist;
|
||||
import com.cappielloantonio.play.viewmodel.ArtistBottomSheetViewModel;
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
|
||||
|
||||
public class ArtistBottomSheetDialog extends BottomSheetDialogFragment implements View.OnClickListener {
|
||||
private static final String TAG = "AlbumBottomSheetDialog";
|
||||
|
||||
private ArtistBottomSheetViewModel artistBottomSheetViewModel;
|
||||
private Artist artist;
|
||||
|
||||
private ImageView coverArtist;
|
||||
private TextView nameArtist;
|
||||
|
||||
private TextView playRadio;
|
||||
private TextView playRandom;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.bottom_sheet_artist_dialog, container, false);
|
||||
|
||||
artist = this.getArguments().getParcelable("artist_object");
|
||||
|
||||
artistBottomSheetViewModel = new ViewModelProvider(requireActivity()).get(ArtistBottomSheetViewModel.class);
|
||||
artistBottomSheetViewModel.setArtist(artist);
|
||||
|
||||
init(view);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
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, CustomGlideRequest.TOP_QUALITY)
|
||||
.build()
|
||||
.into(coverArtist);
|
||||
|
||||
nameArtist = view.findViewById(R.id.song_title_text_view);
|
||||
nameArtist.setText(artistBottomSheetViewModel.getArtist().getName());
|
||||
|
||||
playRadio = view.findViewById(R.id.play_radio_text_view);
|
||||
playRadio.setOnClickListener(v -> {
|
||||
Toast.makeText(requireContext(), "Play radio", Toast.LENGTH_SHORT).show();
|
||||
dismissBottomSheet();
|
||||
});
|
||||
|
||||
playRandom = view.findViewById(R.id.play_random_text_view);
|
||||
playRandom.setOnClickListener(v -> {
|
||||
Toast.makeText(requireContext(), "Play random", Toast.LENGTH_SHORT).show();
|
||||
dismissBottomSheet();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dismissBottomSheet();
|
||||
}
|
||||
|
||||
private void dismissBottomSheet() {
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
|
|
@ -11,17 +11,20 @@ import android.widget.ToggleButton;
|
|||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.navigation.fragment.NavHostFragment;
|
||||
|
||||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.glide.CustomGlideRequest;
|
||||
import com.cappielloantonio.play.model.Album;
|
||||
import com.cappielloantonio.play.model.Artist;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.viewmodel.AlbumBottomSheetViewModel;
|
||||
import com.cappielloantonio.play.viewmodel.SongBottomSheetViewModel;
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
|
||||
|
||||
public class SongBottomSheetDialog extends BottomSheetDialogFragment implements View.OnClickListener {
|
||||
private static final String TAG = "AlbumBottomSheetDialog";
|
||||
private static final String TAG = "SongBottomSheetDialog";
|
||||
|
||||
private AlbumBottomSheetViewModel albumBottomSheetViewModel;
|
||||
private SongBottomSheetViewModel songBottomSheetViewModel;
|
||||
private Song song;
|
||||
|
||||
private ImageView coverSong;
|
||||
|
|
@ -34,19 +37,18 @@ public class SongBottomSheetDialog extends BottomSheetDialogFragment implements
|
|||
private TextView addToQueue;
|
||||
private TextView Download;
|
||||
private TextView addToPlaylist;
|
||||
private TextView goToAlbum;
|
||||
private TextView goToArtist;
|
||||
|
||||
|
||||
public SongBottomSheetDialog(Song song) {
|
||||
this.song = song;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.bottom_sheet_song_dialog, container, false);
|
||||
albumBottomSheetViewModel = new ViewModelProvider(requireActivity()).get(AlbumBottomSheetViewModel.class);
|
||||
albumBottomSheetViewModel.setSong(song);
|
||||
|
||||
song = this.getArguments().getParcelable("song_object");
|
||||
|
||||
songBottomSheetViewModel = new ViewModelProvider(requireActivity()).get(SongBottomSheetViewModel.class);
|
||||
songBottomSheetViewModel.setSong(song);
|
||||
|
||||
init(view);
|
||||
|
||||
|
|
@ -56,20 +58,20 @@ public class SongBottomSheetDialog extends BottomSheetDialogFragment implements
|
|||
private void init(View view) {
|
||||
coverSong = view.findViewById(R.id.song_cover_image_view);
|
||||
CustomGlideRequest.Builder
|
||||
.from(requireContext(), albumBottomSheetViewModel.getSong().getPrimary(), albumBottomSheetViewModel.getSong().getBlurHash(), CustomGlideRequest.PRIMARY, CustomGlideRequest.TOP_QUALITY)
|
||||
.from(requireContext(), songBottomSheetViewModel.getSong().getPrimary(), songBottomSheetViewModel.getSong().getBlurHash(), CustomGlideRequest.PRIMARY, CustomGlideRequest.TOP_QUALITY)
|
||||
.build()
|
||||
.into(coverSong);
|
||||
|
||||
titleSong = view.findViewById(R.id.song_title_text_view);
|
||||
titleSong.setText(albumBottomSheetViewModel.getSong().getTitle());
|
||||
titleSong.setText(songBottomSheetViewModel.getSong().getTitle());
|
||||
|
||||
artistSong = view.findViewById(R.id.song_artist_text_view);
|
||||
artistSong.setText(albumBottomSheetViewModel.getSong().getArtistName());
|
||||
artistSong.setText(songBottomSheetViewModel.getSong().getArtistName());
|
||||
|
||||
thumbToggle = view.findViewById(R.id.button_favorite);
|
||||
thumbToggle.setChecked(albumBottomSheetViewModel.getSong().isFavorite());
|
||||
thumbToggle.setChecked(songBottomSheetViewModel.getSong().isFavorite());
|
||||
thumbToggle.setOnClickListener(v -> {
|
||||
albumBottomSheetViewModel.setFavorite();
|
||||
songBottomSheetViewModel.setFavorite();
|
||||
dismissBottomSheet();
|
||||
});
|
||||
|
||||
|
|
@ -103,9 +105,30 @@ public class SongBottomSheetDialog extends BottomSheetDialogFragment implements
|
|||
dismissBottomSheet();
|
||||
});
|
||||
|
||||
goToAlbum = view.findViewById(R.id.go_to_album_text_view);
|
||||
goToAlbum.setOnClickListener(v -> {
|
||||
Album album = songBottomSheetViewModel.getAlbum();
|
||||
|
||||
if(album != null) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("album_object", album);
|
||||
NavHostFragment.findNavController(this).navigate(R.id.albumPageFragment, bundle);
|
||||
}
|
||||
else Toast.makeText(requireContext(), "Error retrieving album", Toast.LENGTH_SHORT).show();
|
||||
|
||||
dismissBottomSheet();
|
||||
});
|
||||
|
||||
goToArtist = view.findViewById(R.id.go_to_artist_text_view);
|
||||
goToArtist.setOnClickListener(v -> {
|
||||
Toast.makeText(requireContext(), "Go to artist", Toast.LENGTH_SHORT).show();
|
||||
Artist artist = songBottomSheetViewModel.getArtist();
|
||||
if(artist != null) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("artist_object", artist);
|
||||
NavHostFragment.findNavController(this).navigate(R.id.artistPageFragment, bundle);
|
||||
}
|
||||
else Toast.makeText(requireContext(), "Error retrieving artist", Toast.LENGTH_SHORT).show();
|
||||
|
||||
dismissBottomSheet();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue