mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-02 02:13:33 +00:00
Add favorite view
This commit is contained in:
parent
ae23d268cd
commit
01bdbf49b2
52 changed files with 1064 additions and 317 deletions
|
|
@ -1,5 +1,7 @@
|
|||
package com.cappielloantonio.play.ui.activities;
|
||||
|
||||
import android.content.IntentFilter;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
|
||||
|
|
@ -10,6 +12,7 @@ import androidx.navigation.ui.NavigationUI;
|
|||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.broadcast.receiver.ConnectivityStatusBroadcastReceiver;
|
||||
import com.cappielloantonio.play.databinding.ActivityMainBinding;
|
||||
import com.cappielloantonio.play.ui.activities.base.BaseActivity;
|
||||
import com.cappielloantonio.play.util.PreferenceUtil;
|
||||
|
|
@ -26,23 +29,33 @@ import java.util.Objects;
|
|||
public class MainActivity extends BaseActivity {
|
||||
private static final String TAG = "MainActivity";
|
||||
|
||||
private ActivityMainBinding activityMainBinding;
|
||||
public ActivityMainBinding activityMainBinding;
|
||||
|
||||
private FragmentManager fragmentManager;
|
||||
private NavHostFragment navHostFragment;
|
||||
private BottomNavigationView bottomNavigationView;
|
||||
public NavController navController;
|
||||
|
||||
ConnectivityStatusBroadcastReceiver connectivityStatusBroadcastReceiver;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
activityMainBinding = ActivityMainBinding.inflate(getLayoutInflater());
|
||||
View view = activityMainBinding.getRoot();
|
||||
setContentView(view);
|
||||
connectivityStatusBroadcastReceiver = new ConnectivityStatusBroadcastReceiver(this);
|
||||
connectivityStatusReceiverManager(true);
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
connectivityStatusReceiverManager(false);
|
||||
}
|
||||
|
||||
public void init() {
|
||||
fragmentManager = getSupportFragmentManager();
|
||||
bottomNavigationView = findViewById(R.id.bottom_navigation);
|
||||
|
|
@ -76,7 +89,7 @@ public class MainActivity extends BaseActivity {
|
|||
|
||||
@Override
|
||||
public void onError(Exception exception) {
|
||||
goToLogin();
|
||||
goFromLogin();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -130,4 +143,14 @@ public class MainActivity extends BaseActivity {
|
|||
goToSync();
|
||||
}
|
||||
}
|
||||
|
||||
private void connectivityStatusReceiverManager(boolean isActive) {
|
||||
if(isActive) {
|
||||
IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
|
||||
registerReceiver(connectivityStatusBroadcastReceiver, filter);
|
||||
}
|
||||
else {
|
||||
unregisterReceiver(connectivityStatusBroadcastReceiver);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -38,6 +38,12 @@ public class AlbumCatalogueFragment extends Fragment {
|
|||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
activity.setBottomNavigationBarVisibility(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
|
|
|||
|
|
@ -13,10 +13,9 @@ 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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class AlbumPageFragment extends Fragment {
|
||||
|
||||
private FragmentAlbumPageBinding bind;
|
||||
|
|
@ -26,7 +25,7 @@ public class AlbumPageFragment extends Fragment {
|
|||
private SongResultSearchAdapter songResultSearchAdapter;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
activity = (MainActivity) getActivity();
|
||||
|
||||
bind = FragmentAlbumPageBinding.inflate(inflater, container, false);
|
||||
|
|
@ -34,12 +33,19 @@ public class AlbumPageFragment extends Fragment {
|
|||
albumPageViewModel = new ViewModelProvider(requireActivity()).get(AlbumPageViewModel.class);
|
||||
|
||||
init();
|
||||
initBottomSheetDialog();
|
||||
initBackCover();
|
||||
initSongsView();
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
activity.setBottomNavigationBarVisibility(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
|
@ -59,11 +65,18 @@ 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);
|
||||
|
||||
songResultSearchAdapter = new SongResultSearchAdapter(requireContext(), new ArrayList<>());
|
||||
songResultSearchAdapter = new SongResultSearchAdapter(requireContext(), getChildFragmentManager());
|
||||
bind.songRecyclerView.setAdapter(songResultSearchAdapter);
|
||||
albumPageViewModel.getAlbumSongList().observe(requireActivity(), songs -> songResultSearchAdapter.setItems(songs));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,12 @@ public class ArtistCatalogueFragment extends Fragment {
|
|||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
activity.setBottomNavigationBarVisibility(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
|
|
|||
|
|
@ -18,8 +18,6 @@ import com.cappielloantonio.play.model.Song;
|
|||
import com.cappielloantonio.play.ui.activities.MainActivity;
|
||||
import com.cappielloantonio.play.viewmodel.ArtistPageViewModel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ArtistPageFragment extends Fragment {
|
||||
|
||||
private FragmentArtistPageBinding bind;
|
||||
|
|
@ -45,6 +43,13 @@ public class ArtistPageFragment extends Fragment {
|
|||
return view;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
activity.setBottomNavigationBarVisibility(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
|
@ -74,7 +79,7 @@ public class ArtistPageFragment extends Fragment {
|
|||
bind.mostStreamedSongRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext()));
|
||||
bind.mostStreamedSongRecyclerView.setHasFixedSize(true);
|
||||
|
||||
songResultSearchAdapter = new SongResultSearchAdapter(requireContext(), new ArrayList<>());
|
||||
songResultSearchAdapter = new SongResultSearchAdapter(requireContext(), getChildFragmentManager());
|
||||
bind.mostStreamedSongRecyclerView.setAdapter(songResultSearchAdapter);
|
||||
artistPageViewModel.getArtistTopSongList().observe(requireActivity(), songs -> songResultSearchAdapter.setItems(songs));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import android.os.Bundle;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
|
@ -41,6 +40,12 @@ public class FilterFragment extends Fragment {
|
|||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
activity.setBottomNavigationBarVisibility(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
|
|
|||
|
|
@ -40,6 +40,12 @@ public class GenreCatalogueFragment extends Fragment {
|
|||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
activity.setBottomNavigationBarVisibility(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
|
|
|||
|
|
@ -7,15 +7,18 @@ import android.view.ViewGroup;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.viewpager2.widget.ViewPager2;
|
||||
|
||||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.adapter.DiscoverSongAdapter;
|
||||
import com.cappielloantonio.play.adapter.RecentMusicAdapter;
|
||||
import com.cappielloantonio.play.adapter.SongResultSearchAdapter;
|
||||
import com.cappielloantonio.play.adapter.YearAdapter;
|
||||
import com.cappielloantonio.play.databinding.FragmentHomeBinding;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
|
|
@ -33,6 +36,7 @@ public class HomeFragment extends Fragment {
|
|||
private DiscoverSongAdapter discoverSongAdapter;
|
||||
private RecentMusicAdapter recentlyAddedMusicAdapter;
|
||||
private YearAdapter yearAdapter;
|
||||
private SongResultSearchAdapter favoriteSongAdapter;
|
||||
private RecentMusicAdapter recentlyPlayedMusicAdapter;
|
||||
private RecentMusicAdapter mostPlayedMusicAdapter;
|
||||
|
||||
|
|
@ -46,15 +50,23 @@ public class HomeFragment extends Fragment {
|
|||
homeViewModel = new ViewModelProvider(requireActivity()).get(HomeViewModel.class);
|
||||
|
||||
init();
|
||||
initSwipeToRefresh();
|
||||
initDiscoverSongSlideView();
|
||||
initRecentAddedSongView();
|
||||
initFavoritesSongView();
|
||||
initYearSongView();
|
||||
initRecentPlayedSongView();
|
||||
initMostPlayedSongView();
|
||||
initRecentPlayedSongView();
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
activity.setBottomNavigationBarVisibility(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
|
@ -62,12 +74,6 @@ public class HomeFragment extends Fragment {
|
|||
}
|
||||
|
||||
private void init() {
|
||||
bind.resyncButton.setOnClickListener(v -> {
|
||||
PreferenceUtil.getInstance(requireContext()).setSync(false);
|
||||
PreferenceUtil.getInstance(requireContext()).setSongGenreSync(false);
|
||||
activity.goToSync();
|
||||
});
|
||||
|
||||
bind.recentlyAddedTracksTextViewClickable.setOnClickListener(v -> {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(Song.RECENTLY_ADDED, Song.RECENTLY_ADDED);
|
||||
|
|
@ -85,6 +91,29 @@ public class HomeFragment extends Fragment {
|
|||
bundle.putString(Song.MOST_PLAYED, Song.MOST_PLAYED);
|
||||
activity.navController.navigate(R.id.action_homeFragment_to_songListPageFragment, bundle);
|
||||
});
|
||||
|
||||
bind.favoritesTracksTextViewClickable.setOnClickListener(v -> {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(Song.IS_FAVORITE, Song.IS_FAVORITE);
|
||||
activity.navController.navigate(R.id.action_homeFragment_to_songListPageFragment, bundle);
|
||||
});
|
||||
}
|
||||
|
||||
private void initSwipeToRefresh() {
|
||||
bind.pullToRefreshLayout.setOnRefreshListener(() -> {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(requireContext());
|
||||
builder.setMessage("Force reload your entire music library")
|
||||
.setTitle("Force sync")
|
||||
.setNegativeButton(R.string.ignore, null)
|
||||
.setPositiveButton("Sync", (dialog, id) -> {
|
||||
PreferenceUtil.getInstance(requireContext()).setSync(false);
|
||||
PreferenceUtil.getInstance(requireContext()).setSongGenreSync(false);
|
||||
activity.goToSync();
|
||||
})
|
||||
.show();
|
||||
|
||||
bind.pullToRefreshLayout.setRefreshing(false);
|
||||
});
|
||||
}
|
||||
|
||||
private void initDiscoverSongSlideView() {
|
||||
|
|
@ -119,13 +148,13 @@ public class HomeFragment extends Fragment {
|
|||
bind.yearsRecyclerView.setAdapter(yearAdapter);
|
||||
}
|
||||
|
||||
private void initRecentPlayedSongView() {
|
||||
bind.recentlyPlayedTracksRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
|
||||
bind.recentlyPlayedTracksRecyclerView.setHasFixedSize(true);
|
||||
private void initFavoritesSongView() {
|
||||
bind.favoritesTracksRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), 3, GridLayoutManager.HORIZONTAL, false));
|
||||
bind.favoritesTracksRecyclerView.setHasFixedSize(true);
|
||||
|
||||
recentlyPlayedMusicAdapter = new RecentMusicAdapter(requireContext());
|
||||
bind.recentlyPlayedTracksRecyclerView.setAdapter(recentlyPlayedMusicAdapter);
|
||||
homeViewModel.getRecentlyPlayedSongList().observe(requireActivity(), songs -> recentlyPlayedMusicAdapter.setItems(songs));
|
||||
favoriteSongAdapter = new SongResultSearchAdapter(requireContext(), getChildFragmentManager());
|
||||
bind.favoritesTracksRecyclerView.setAdapter(favoriteSongAdapter);
|
||||
homeViewModel.getFavorites().observe(requireActivity(), songs -> favoriteSongAdapter.setItems(songs));
|
||||
}
|
||||
|
||||
private void initMostPlayedSongView() {
|
||||
|
|
@ -137,6 +166,15 @@ public class HomeFragment extends Fragment {
|
|||
homeViewModel.getMostPlayedSongList().observe(requireActivity(), songs -> mostPlayedMusicAdapter.setItems(songs));
|
||||
}
|
||||
|
||||
private void initRecentPlayedSongView() {
|
||||
bind.recentlyPlayedTracksRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
|
||||
bind.recentlyPlayedTracksRecyclerView.setHasFixedSize(true);
|
||||
|
||||
recentlyPlayedMusicAdapter = new RecentMusicAdapter(requireContext());
|
||||
bind.recentlyPlayedTracksRecyclerView.setAdapter(recentlyPlayedMusicAdapter);
|
||||
homeViewModel.getRecentlyPlayedSongList().observe(requireActivity(), songs -> recentlyPlayedMusicAdapter.setItems(songs));
|
||||
}
|
||||
|
||||
private void settDiscoverSongSlideViewOffset(float pageOffset, float pageMargin) {
|
||||
bind.discoverSongViewPager.setPageTransformer((page, position) -> {
|
||||
float myOffset = position * -(2 * pageOffset + pageMargin);
|
||||
|
|
|
|||
|
|
@ -56,6 +56,12 @@ public class LibraryFragment extends Fragment {
|
|||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
activity.setBottomNavigationBarVisibility(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
|
@ -66,7 +72,6 @@ public class LibraryFragment extends Fragment {
|
|||
bind.albumCatalogueTextViewClickable.setOnClickListener(v -> activity.navController.navigate(R.id.action_libraryFragment_to_albumCatalogueFragment));
|
||||
bind.artistCatalogueTextViewClickable.setOnClickListener(v -> activity.navController.navigate(R.id.action_libraryFragment_to_artistCatalogueFragment));
|
||||
bind.genreCatalogueTextViewClickable.setOnClickListener(v -> activity.navController.navigate(R.id.action_libraryFragment_to_genreCatalogueFragment));
|
||||
bind.syncGenreButton.setOnClickListener(v -> syncSongsPerGenre());
|
||||
}
|
||||
|
||||
private void initAlbumView() {
|
||||
|
|
|
|||
|
|
@ -58,6 +58,12 @@ public class SearchFragment extends Fragment {
|
|||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
activity.setBottomNavigationBarVisibility(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
|
@ -87,7 +93,7 @@ public class SearchFragment extends Fragment {
|
|||
bind.searchResultTracksRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext()));
|
||||
bind.searchResultTracksRecyclerView.setHasFixedSize(true);
|
||||
|
||||
songResultSearchAdapter = new SongResultSearchAdapter(requireContext(), new ArrayList<>());
|
||||
songResultSearchAdapter = new SongResultSearchAdapter(requireContext(), getChildFragmentManager());
|
||||
bind.searchResultTracksRecyclerView.setAdapter(songResultSearchAdapter);
|
||||
|
||||
// Albums
|
||||
|
|
|
|||
|
|
@ -15,8 +15,6 @@ import com.cappielloantonio.play.model.Song;
|
|||
import com.cappielloantonio.play.ui.activities.MainActivity;
|
||||
import com.cappielloantonio.play.viewmodel.SongListPageViewModel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class SongListPageFragment extends Fragment {
|
||||
|
||||
private FragmentSongListPageBinding bind;
|
||||
|
|
@ -39,6 +37,12 @@ public class SongListPageFragment extends Fragment {
|
|||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
activity.setBottomNavigationBarVisibility(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
|
@ -79,13 +83,17 @@ public class SongListPageFragment extends Fragment {
|
|||
songListPageViewModel.year = getArguments().getInt("year_object");
|
||||
bind.pageTitleLabel.setText("Year " + songListPageViewModel.year);
|
||||
}
|
||||
else if(getArguments().getString(Song.IS_FAVORITE) != null) {
|
||||
songListPageViewModel.title = Song.IS_FAVORITE;
|
||||
bind.pageTitleLabel.setText("Favourite song");
|
||||
}
|
||||
}
|
||||
|
||||
private void initSongListView() {
|
||||
bind.songListRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext()));
|
||||
bind.songListRecyclerView.setHasFixedSize(true);
|
||||
|
||||
songResultSearchAdapter = new SongResultSearchAdapter(requireContext(), new ArrayList<>());
|
||||
songResultSearchAdapter = new SongResultSearchAdapter(requireContext(), getChildFragmentManager());
|
||||
bind.songListRecyclerView.setAdapter(songResultSearchAdapter);
|
||||
songListPageViewModel.getSongList().observe(requireActivity(), songs -> songResultSearchAdapter.setItems(songs));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,7 +99,6 @@ public class SyncFragment extends Fragment {
|
|||
}
|
||||
|
||||
private void syncAlbums() {
|
||||
Log.d(TAG, "syncAlbums");
|
||||
SyncUtil.getAlbums(requireContext(), new MediaCallback() {
|
||||
@Override
|
||||
public void onError(Exception exception) {
|
||||
|
|
@ -117,7 +116,6 @@ public class SyncFragment extends Fragment {
|
|||
}
|
||||
|
||||
private void syncArtists() {
|
||||
Log.d(TAG, "syncArtists");
|
||||
SyncUtil.getArtists(requireContext(), new MediaCallback() {
|
||||
@Override
|
||||
public void onError(Exception exception) {
|
||||
|
|
@ -135,7 +133,6 @@ public class SyncFragment extends Fragment {
|
|||
}
|
||||
|
||||
private void syncGenres() {
|
||||
Log.d(TAG, "syncGenres");
|
||||
SyncUtil.getGenres(requireContext(), new MediaCallback() {
|
||||
@Override
|
||||
public void onError(Exception exception) {
|
||||
|
|
@ -156,7 +153,6 @@ public class SyncFragment extends Fragment {
|
|||
}
|
||||
|
||||
private void syncPlaylist() {
|
||||
Log.d(TAG, "syncPlaylist");
|
||||
SyncUtil.getPlaylists(requireContext(), new MediaCallback() {
|
||||
@Override
|
||||
public void onError(Exception exception) {
|
||||
|
|
@ -174,7 +170,6 @@ public class SyncFragment extends Fragment {
|
|||
}
|
||||
|
||||
private void syncSongs() {
|
||||
Log.d(TAG, "syncSongs");
|
||||
SyncUtil.getSongs(requireContext(), syncViewModel.getCatalogue(), new MediaCallback() {
|
||||
@Override
|
||||
public void onError(Exception exception) {
|
||||
|
|
@ -193,8 +188,6 @@ public class SyncFragment extends Fragment {
|
|||
}
|
||||
|
||||
private void syncSongsPerGenre(List<Genre> genres) {
|
||||
Log.d(TAG, "syncSongsPerGenre");
|
||||
|
||||
for (Genre genre : genres) {
|
||||
SyncUtil.getSongsPerGenre(requireContext(), new MediaCallback() {
|
||||
@Override
|
||||
|
|
@ -210,29 +203,23 @@ public class SyncFragment extends Fragment {
|
|||
}, genre.id);
|
||||
}
|
||||
|
||||
Log.d(TAG, "syncSongsPerGenre: set progress");
|
||||
|
||||
animateProgressBar(true);
|
||||
PreferenceUtil.getInstance(requireContext()).setSongGenreSync(true);
|
||||
}
|
||||
|
||||
|
||||
private void animateProgressBar(boolean step) {
|
||||
Log.d(TAG, "animateProgressBar: PROGRESS " + step);
|
||||
syncViewModel.setProgress(step);
|
||||
bind.loadingProgressBar.setProgress(syncViewModel.getProgressBarInfo(), true);
|
||||
countProgress();
|
||||
}
|
||||
|
||||
private void countProgress() {
|
||||
Log.d(TAG, "countProgress = " + syncViewModel.getProgress());
|
||||
Log.d(TAG, "progressbar = " + syncViewModel.getProgressBarInfo());
|
||||
|
||||
if (syncViewModel.getProgress() == syncViewModel.getStep()) {
|
||||
if (syncViewModel.getProgressBarInfo() >= 100)
|
||||
terminate();
|
||||
else
|
||||
if (syncViewModel.getProgressBarInfo() < 100)
|
||||
Toast.makeText(requireContext(), "Sync error", Toast.LENGTH_SHORT).show();
|
||||
|
||||
terminate();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,54 @@
|
|||
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.Button;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.model.Album;
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
|
||||
|
||||
public class AlbumBottomSheetDialog extends BottomSheetDialogFragment implements View.OnClickListener {
|
||||
private static final String TAG = "AlbumBottomSheetDialog";
|
||||
|
||||
private Album album;
|
||||
|
||||
public AlbumBottomSheetDialog(Album album) {
|
||||
this.album = album;
|
||||
}
|
||||
|
||||
@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);
|
||||
|
||||
init(view);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
private void init(View view) {
|
||||
Button button1 = view.findViewById(R.id.button1);
|
||||
Button button2 = view.findViewById(R.id.button2);
|
||||
|
||||
button1.setOnClickListener(v -> {
|
||||
Toast.makeText(requireContext(), album.getTitle(), Toast.LENGTH_SHORT).show();
|
||||
dismiss();
|
||||
});
|
||||
|
||||
button2.setOnClickListener(v -> {
|
||||
Toast.makeText(requireContext(), album.getArtistName(), Toast.LENGTH_SHORT).show();
|
||||
dismiss();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,121 @@
|
|||
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 android.widget.ToggleButton;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.glide.CustomGlideRequest;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.viewmodel.AlbumBottomSheetViewModel;
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
|
||||
|
||||
public class SongBottomSheetDialog extends BottomSheetDialogFragment implements View.OnClickListener {
|
||||
private static final String TAG = "AlbumBottomSheetDialog";
|
||||
|
||||
private AlbumBottomSheetViewModel albumBottomSheetViewModel;
|
||||
private Song song;
|
||||
|
||||
private ImageView coverSong;
|
||||
private TextView titleSong;
|
||||
private TextView artistSong;
|
||||
private ToggleButton thumbToggle;
|
||||
|
||||
private TextView playRadio;
|
||||
private TextView playNext;
|
||||
private TextView addToQueue;
|
||||
private TextView Download;
|
||||
private TextView addToPlaylist;
|
||||
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);
|
||||
|
||||
init(view);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
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)
|
||||
.build()
|
||||
.into(coverSong);
|
||||
|
||||
titleSong = view.findViewById(R.id.song_title_text_view);
|
||||
titleSong.setText(albumBottomSheetViewModel.getSong().getTitle());
|
||||
|
||||
artistSong = view.findViewById(R.id.song_artist_text_view);
|
||||
artistSong.setText(albumBottomSheetViewModel.getSong().getArtistName());
|
||||
|
||||
thumbToggle = view.findViewById(R.id.button_favorite);
|
||||
thumbToggle.setChecked(albumBottomSheetViewModel.getSong().isFavorite());
|
||||
thumbToggle.setOnClickListener(v -> {
|
||||
albumBottomSheetViewModel.setFavorite();
|
||||
dismissBottomSheet();
|
||||
});
|
||||
|
||||
playRadio = view.findViewById(R.id.play_radio_text_view);
|
||||
playRadio.setOnClickListener(v -> {
|
||||
Toast.makeText(requireContext(), "Play radio", 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 -> {
|
||||
Toast.makeText(requireContext(), "Go to artist", Toast.LENGTH_SHORT).show();
|
||||
dismissBottomSheet();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dismissBottomSheet();
|
||||
}
|
||||
|
||||
private void dismissBottomSheet() {
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue