mirror of
https://github.com/gabehf/tempus.git
synced 2026-03-17 03:06:31 -07:00
feat: added the ability to pin playlists to the home screen
This commit is contained in:
parent
078aa87521
commit
fb7296b467
12 changed files with 1288 additions and 8 deletions
|
|
@ -31,6 +31,7 @@ import com.cappielloantonio.tempo.databinding.FragmentHomeTabMusicBinding;
|
|||
import com.cappielloantonio.tempo.helper.recyclerview.CustomLinearSnapHelper;
|
||||
import com.cappielloantonio.tempo.helper.recyclerview.DotsIndicatorDecoration;
|
||||
import com.cappielloantonio.tempo.interfaces.ClickCallback;
|
||||
import com.cappielloantonio.tempo.interfaces.PlaylistCallback;
|
||||
import com.cappielloantonio.tempo.model.Download;
|
||||
import com.cappielloantonio.tempo.model.HomeSector;
|
||||
import com.cappielloantonio.tempo.service.DownloaderManager;
|
||||
|
|
@ -44,12 +45,13 @@ import com.cappielloantonio.tempo.ui.adapter.AlbumHorizontalAdapter;
|
|||
import com.cappielloantonio.tempo.ui.adapter.ArtistAdapter;
|
||||
import com.cappielloantonio.tempo.ui.adapter.ArtistHorizontalAdapter;
|
||||
import com.cappielloantonio.tempo.ui.adapter.DiscoverSongAdapter;
|
||||
import com.cappielloantonio.tempo.ui.adapter.GridTrackAdapter;
|
||||
import com.cappielloantonio.tempo.ui.adapter.PlaylistHorizontalAdapter;
|
||||
import com.cappielloantonio.tempo.ui.adapter.ShareHorizontalAdapter;
|
||||
import com.cappielloantonio.tempo.ui.adapter.SimilarTrackAdapter;
|
||||
import com.cappielloantonio.tempo.ui.adapter.SongHorizontalAdapter;
|
||||
import com.cappielloantonio.tempo.ui.adapter.YearAdapter;
|
||||
import com.cappielloantonio.tempo.ui.dialog.HomeRearrangementDialog;
|
||||
import com.cappielloantonio.tempo.ui.dialog.PlaylistEditorDialog;
|
||||
import com.cappielloantonio.tempo.util.Constants;
|
||||
import com.cappielloantonio.tempo.util.DownloadUtil;
|
||||
import com.cappielloantonio.tempo.util.MappingUtil;
|
||||
|
|
@ -85,7 +87,7 @@ public class HomeTabMusicFragment extends Fragment implements ClickCallback {
|
|||
private AlbumAdapter mostPlayedAlbumAdapter;
|
||||
private AlbumHorizontalAdapter newReleasesAlbumAdapter;
|
||||
private YearAdapter yearAdapter;
|
||||
private GridTrackAdapter gridTrackAdapter;
|
||||
private PlaylistHorizontalAdapter playlistHorizontalAdapter;
|
||||
private ShareHorizontalAdapter shareHorizontalAdapter;
|
||||
|
||||
private ListenableFuture<MediaBrowser> mediaBrowserListenableFuture;
|
||||
|
|
@ -122,6 +124,7 @@ public class HomeTabMusicFragment extends Fragment implements ClickCallback {
|
|||
initYearSongView();
|
||||
initRecentAddedAlbumView();
|
||||
initTopSongsView();
|
||||
initPinnedPlaylistsView();
|
||||
initSharesView();
|
||||
initHomeReorganizer();
|
||||
|
||||
|
|
@ -422,7 +425,8 @@ public class HomeTabMusicFragment extends Fragment implements ClickCallback {
|
|||
} else {
|
||||
if (bind != null) bind.homeGridTracksSector.setVisibility(View.VISIBLE);
|
||||
if (bind != null) bind.afterGridDivider.setVisibility(View.VISIBLE);
|
||||
if (bind != null) bind.topSongsRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), UIUtil.getSpanCount(chronologies.size(), 5), GridLayoutManager.HORIZONTAL, false));
|
||||
if (bind != null)
|
||||
bind.topSongsRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), UIUtil.getSpanCount(chronologies.size(), 5), GridLayoutManager.HORIZONTAL, false));
|
||||
|
||||
List<Child> topSongs = chronologies.stream()
|
||||
.map(cronologia -> (Child) cronologia)
|
||||
|
|
@ -671,6 +675,26 @@ public class HomeTabMusicFragment extends Fragment implements ClickCallback {
|
|||
recentAddedAlbumSnapHelper.attachToRecyclerView(bind.recentlyAddedAlbumsRecyclerView);
|
||||
}
|
||||
|
||||
private void initPinnedPlaylistsView() {
|
||||
if (homeViewModel.checkHomeSectorVisibility(Constants.HOME_SECTOR_PINNED_PLAYLISTS)) return;
|
||||
|
||||
bind.pinnedPlaylistsRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext()));
|
||||
bind.pinnedPlaylistsRecyclerView.setHasFixedSize(true);
|
||||
|
||||
playlistHorizontalAdapter = new PlaylistHorizontalAdapter(this);
|
||||
bind.pinnedPlaylistsRecyclerView.setAdapter(playlistHorizontalAdapter);
|
||||
homeViewModel.getPinnedPlaylists(getViewLifecycleOwner()).observe(getViewLifecycleOwner(), playlists -> {
|
||||
if (playlists == null) {
|
||||
if (bind != null) bind.pinnedPlaylistsSector.setVisibility(View.GONE);
|
||||
} else {
|
||||
if (bind != null)
|
||||
bind.pinnedPlaylistsSector.setVisibility(!playlists.isEmpty() ? View.VISIBLE : View.GONE);
|
||||
|
||||
playlistHorizontalAdapter.setItems(playlists);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initSharesView() {
|
||||
if (homeViewModel.checkHomeSectorVisibility(Constants.HOME_SECTOR_SHARED)) return;
|
||||
|
||||
|
|
@ -708,7 +732,9 @@ public class HomeTabMusicFragment extends Fragment implements ClickCallback {
|
|||
|
||||
private void initHomeReorganizer() {
|
||||
final Handler handler = new Handler();
|
||||
final Runnable runnable = () -> { if (bind != null) bind.homeSectorRearrangementButton.setVisibility(View.VISIBLE); };
|
||||
final Runnable runnable = () -> {
|
||||
if (bind != null) bind.homeSectorRearrangementButton.setVisibility(View.VISIBLE);
|
||||
};
|
||||
handler.postDelayed(runnable, 5000);
|
||||
|
||||
bind.homeSectorRearrangementButton.setOnClickListener(v -> {
|
||||
|
|
@ -789,6 +815,9 @@ public class HomeTabMusicFragment extends Fragment implements ClickCallback {
|
|||
case Constants.HOME_SECTOR_RECENTLY_ADDED:
|
||||
bind.homeLinearLayoutContainer.addView(bind.homeRecentlyAddedAlbumsSector);
|
||||
break;
|
||||
case Constants.HOME_SECTOR_PINNED_PLAYLISTS:
|
||||
bind.homeLinearLayoutContainer.addView(bind.pinnedPlaylistsSector);
|
||||
break;
|
||||
case Constants.HOME_SECTOR_SHARED:
|
||||
bind.homeLinearLayoutContainer.addView(bind.sharesSector);
|
||||
break;
|
||||
|
|
@ -824,6 +853,17 @@ public class HomeTabMusicFragment extends Fragment implements ClickCallback {
|
|||
popup.show();
|
||||
}
|
||||
|
||||
private void refreshPlaylistView() {
|
||||
final Handler handler = new Handler();
|
||||
|
||||
final Runnable runnable = () -> {
|
||||
if (getView() != null && bind != null && homeViewModel != null)
|
||||
homeViewModel.getPinnedPlaylists(getViewLifecycleOwner());
|
||||
};
|
||||
|
||||
handler.postDelayed(runnable, 100);
|
||||
}
|
||||
|
||||
private void initializeMediaBrowser() {
|
||||
mediaBrowserListenableFuture = new MediaBrowser.Builder(requireContext(), new SessionToken(requireContext(), new ComponentName(requireContext(), MediaService.class))).buildAsync();
|
||||
}
|
||||
|
|
@ -922,6 +962,24 @@ public class HomeTabMusicFragment extends Fragment implements ClickCallback {
|
|||
startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlaylistClick(Bundle bundle) {
|
||||
Navigation.findNavController(requireView()).navigate(R.id.playlistPageFragment, bundle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlaylistLongClick(Bundle bundle) {
|
||||
PlaylistEditorDialog dialog = new PlaylistEditorDialog(new PlaylistCallback() {
|
||||
@Override
|
||||
public void onDismiss() {
|
||||
refreshPlaylistView();
|
||||
}
|
||||
});
|
||||
|
||||
dialog.setArguments(bundle);
|
||||
dialog.show(activity.getSupportFragmentManager(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShareLongClick(Bundle bundle) {
|
||||
Navigation.findNavController(requireView()).navigate(R.id.shareBottomSheetDialog, bundle);
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ public class PlaylistPageFragment extends Fragment implements ClickCallback {
|
|||
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
inflater.inflate(R.menu.playlist_page_menu, menu);
|
||||
initMenuOption(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -115,6 +116,12 @@ public class PlaylistPageFragment extends Fragment implements ClickCallback {
|
|||
}
|
||||
});
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.action_pin_playlist) {
|
||||
playlistPageViewModel.setPinned(true);
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.action_unpin_playlist) {
|
||||
playlistPageViewModel.setPinned(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
@ -124,6 +131,13 @@ public class PlaylistPageFragment extends Fragment implements ClickCallback {
|
|||
playlistPageViewModel.setPlaylist(requireArguments().getParcelable(Constants.PLAYLIST_OBJECT));
|
||||
}
|
||||
|
||||
private void initMenuOption(Menu menu) {
|
||||
playlistPageViewModel.isPinned(getViewLifecycleOwner()).observe(getViewLifecycleOwner(), isPinned -> {
|
||||
menu.findItem(R.id.action_unpin_playlist).setVisible(isPinned);
|
||||
menu.findItem(R.id.action_pin_playlist).setVisible(!isPinned);
|
||||
});
|
||||
}
|
||||
|
||||
private void initAppBar() {
|
||||
activity.setSupportActionBar(bind.animToolbar);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue