Fix filtering

This commit is contained in:
Antonio Cappiello 2020-11-25 08:21:30 +01:00
parent 76037e487b
commit 4848d4f3d0
25 changed files with 575 additions and 124 deletions

View file

@ -10,6 +10,7 @@ import androidx.room.Update;
import com.cappielloantonio.play.model.Song;
import java.util.ArrayList;
import java.util.List;
@Dao
@ -44,6 +45,9 @@ public interface SongDao {
@Query("SELECT * FROM song INNER Join song_genre_cross ON song.id = song_genre_cross.song_id AND song_genre_cross.genre_id = :genreID")
LiveData<List<Song>> getSongByGenre(String genreID);
@Query("SELECT * FROM song INNER Join song_genre_cross ON song.id = song_genre_cross.song_id AND song_genre_cross.genre_id IN (:filters) GROUP BY song.id")
LiveData<List<Song>> getFilteredSong(ArrayList<String> filters);
@Query("SELECT EXISTS(SELECT * FROM song WHERE id = :id)")
boolean exist(String id);

View file

@ -31,6 +31,9 @@ public class Song implements Parcelable {
@Ignore
public static final String BY_GENRE = "BY_GENRE";
@Ignore
public static final String BY_GENRES = "BY_GENRES";
@Ignore
public static final String BY_ARTIST = "BY_ARTIST";

View file

@ -21,6 +21,7 @@ public class SongRepository {
private LiveData<List<Song>> listLiveSampleArtistTopSongs;
private LiveData<List<Song>> listLiveAlbumSongs;
private LiveData<List<Song>> listLiveSongByGenre;
private LiveData<List<Song>> listLiveFilteredSongs;
public SongRepository(Application application) {
@ -68,6 +69,11 @@ public class SongRepository {
return listLiveAlbumSongs;
}
public LiveData<List<Song>> getFilteredListLiveSong(ArrayList<String> filters) {
listLiveFilteredSongs = songDao.getFilteredSong(filters);
return listLiveFilteredSongs;
}
public boolean exist(Song song) {
boolean exist = false;

View file

@ -13,6 +13,7 @@ import com.cappielloantonio.play.R;
import com.cappielloantonio.play.databinding.ActivityMainBinding;
import com.cappielloantonio.play.ui.activities.base.BaseActivity;
import com.cappielloantonio.play.util.PreferenceUtil;
import com.cappielloantonio.play.util.SyncUtil;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import org.jellyfin.apiclient.interaction.EmptyResponse;
@ -86,12 +87,15 @@ public class MainActivity extends BaseActivity {
}
public void goToSync() {
bottomNavigationView.setVisibility(View.GONE);
Bundle bundle = SyncUtil.getSyncBundle(true, true, true, true, true, false);
if (Objects.requireNonNull(navController.getCurrentDestination()).getId() == R.id.landingFragment) {
navController.navigate(R.id.action_landingFragment_to_syncFragment);
navController.navigate(R.id.action_landingFragment_to_syncFragment, bundle);
} else if (Objects.requireNonNull(navController.getCurrentDestination()).getId() == R.id.loginFragment) {
navController.navigate(R.id.action_loginFragment_to_syncFragment);
navController.navigate(R.id.action_loginFragment_to_syncFragment, bundle);
} else if (Objects.requireNonNull(navController.getCurrentDestination()).getId() == R.id.homeFragment) {
navController.navigate(R.id.action_homeFragment_to_syncFragment);
navController.navigate(R.id.action_homeFragment_to_syncFragment, bundle);
}
}

View file

@ -4,6 +4,7 @@ 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;
@ -14,12 +15,15 @@ import androidx.lifecycle.ViewModelProvider;
import com.cappielloantonio.play.R;
import com.cappielloantonio.play.databinding.FragmentFilterBinding;
import com.cappielloantonio.play.model.Genre;
import com.cappielloantonio.play.model.Song;
import com.cappielloantonio.play.ui.activities.MainActivity;
import com.cappielloantonio.play.viewmodel.FilterViewModel;
import com.google.android.material.chip.Chip;
public class FilterFragment extends Fragment {
private static final String TAG = "FilterFragment";
private MainActivity activity;
private FragmentFilterBinding bind;
private FilterViewModel filterViewModel;
@ -27,10 +31,12 @@ public class FilterFragment extends Fragment {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
activity = (MainActivity) getActivity();
bind = FragmentFilterBinding.inflate(inflater, container, false);
View view = bind.getRoot();
filterViewModel = new ViewModelProvider(requireActivity()).get(FilterViewModel.class);
init();
setFilterChips();
return view;
}
@ -41,17 +47,30 @@ public class FilterFragment extends Fragment {
bind = null;
}
private void init() {
Bundle bundle = new Bundle();
bundle.putString(Song.BY_GENRES, Song.BY_GENRES);
bundle.putStringArrayList("filters_list", filterViewModel.getFilters());
bundle.putStringArrayList("filter_name_list", filterViewModel.getFilterNames());
bind.finishFilteringTextViewClickable.setOnClickListener(v -> {
if(filterViewModel.getFilters().size() > 1) activity.navController.navigate(R.id.action_filterFragment_to_songListPageFragment, bundle);
else Toast.makeText(requireContext(), "Select two or more filters", Toast.LENGTH_SHORT).show();
});
}
private void setFilterChips() {
filterViewModel.getGenreList().observe(requireActivity(), genres -> {
bind.loadingProgressBar.setVisibility(View.GONE);
bind.filterContainer.setVisibility(View.VISIBLE);
for (Genre genre : genres) {
Chip mChip = (Chip) requireActivity().getLayoutInflater().inflate(R.layout.chip_search_filter_genre, null, false);
mChip.setText(genre.getName());
mChip.setOnCheckedChangeListener((buttonView, isChecked) -> Toast.makeText(requireContext(), buttonView.getText() + ": " + isChecked, Toast.LENGTH_SHORT).show());
bind.filtersChipsGroup.addView(mChip);
Chip chip = (Chip) requireActivity().getLayoutInflater().inflate(R.layout.chip_search_filter_genre, null, false);
chip.setText(genre.getName());
chip.setChecked(filterViewModel.getFilters().contains(genre.getId()));
chip.setOnCheckedChangeListener((buttonView, isChecked) -> {
if(isChecked) filterViewModel.addFilter(genre.getId(), buttonView.getText().toString());
else filterViewModel.removeFilter(genre.getId(), buttonView.getText().toString());
});
bind.filtersChipsGroup.addView(chip);
}
});
}

View file

@ -53,6 +53,7 @@ public class GenreCatalogueFragment extends Fragment {
View view = bind.getRoot();
genreCatalogueViewModel = new ViewModelProvider(requireActivity()).get(GenreCatalogueViewModel.class);
init();
initArtistCatalogueView();
return view;
@ -64,9 +65,13 @@ public class GenreCatalogueFragment extends Fragment {
bind = null;
}
private void init() {
bind.filterGenresTextViewClickable.setOnClickListener(v -> activity.navController.navigate(R.id.action_genreCatalogueFragment_to_filterFragment));
}
private void initArtistCatalogueView() {
bind.genreCatalogueRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), 2));
bind.genreCatalogueRecyclerView.addItemDecoration(new ItemlDecoration(2, 20, false));
bind.genreCatalogueRecyclerView.addItemDecoration(new ItemlDecoration(2, 16, false));
bind.genreCatalogueRecyclerView.setHasFixedSize(true);
genreCatalogueAdapter = new GenreCatalogueAdapter(requireContext(), new ArrayList<>());

View file

@ -83,6 +83,7 @@ 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() {
@ -118,14 +119,11 @@ public class LibraryFragment extends Fragment {
bind.genreRecyclerView.setHasFixedSize(true);
genreAdapter = new GenreAdapter(requireContext(), new ArrayList<>());
genreAdapter.setClickListener(new GenreAdapter.ItemClickListener() {
@Override
public void onItemClick(View view, int position) {
Bundle bundle = new Bundle();
bundle.putString(Song.BY_GENRE, Song.BY_GENRE);
bundle.putParcelable("genre_object", genreAdapter.getItem(position));
activity.navController.navigate(R.id.action_libraryFragment_to_songListPageFragment, bundle);
}
genreAdapter.setClickListener((view, position) -> {
Bundle bundle = new Bundle();
bundle.putString(Song.BY_GENRE, Song.BY_GENRE);
bundle.putParcelable("genre_object", genreAdapter.getItem(position));
activity.navController.navigate(R.id.action_libraryFragment_to_songListPageFragment, bundle);
});
bind.genreRecyclerView.setAdapter(genreAdapter);
libraryViewModel.getGenreSample().observe(requireActivity(), genres -> genreAdapter.setItems(genres));
@ -147,32 +145,13 @@ public class LibraryFragment extends Fragment {
builder.setMessage("Sync song's genres otherwise nothing will be shown in each genre category")
.setTitle("Song's genres not synchronized")
.setNegativeButton(R.string.ignore, null)
.setPositiveButton("Sync", (dialog, id) -> syncSongsPerGenre(libraryViewModel.getGenreList()))
.setPositiveButton("Sync", (dialog, id) -> syncSongsPerGenre())
.show();
}
}
private void syncSongsPerGenre(List<Genre> genres) {
Snackbar.make(requireView(), "This may take a while...", BaseTransientBottomBar.LENGTH_LONG)
.setBackgroundTint(ContextCompat.getColor(requireContext(), R.color.cardColor))
.setTextColor(ContextCompat.getColor(requireContext(), R.color.titleTextColor))
.show();
for (Genre genre : genres) {
SyncUtil.getSongsPerGenre(requireContext(), new MediaCallback() {
@Override
public void onError(Exception exception) {
Log.e(TAG, "onError: " + exception.getMessage());
}
@Override
public void onLoadMedia(List<?> media) {
GenreRepository repository = new GenreRepository(App.getInstance());
repository.insertPerGenre((ArrayList<SongGenreCross>) media);
}
}, genre.id);
}
PreferenceUtil.getInstance(requireContext()).setSongGenreSync(true);
private void syncSongsPerGenre() {
Bundle bundle = SyncUtil.getSyncBundle(false, false, true, false, false, true);
activity.navController.navigate(R.id.action_libraryFragment_to_syncFragment, bundle);
}
}

View file

@ -26,15 +26,10 @@ public class LoginFragment extends Fragment {
private FragmentLoginBinding bind;
private MainActivity activity;
// private TextView usernameTextView;
// private TextView passwordTextView;
// private TextView serverTextView;
private String username;
private String password;
private String server;
// private Button loginButton;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

View file

@ -128,10 +128,6 @@ public class SearchFragment extends Fragment {
bind.persistentSearchView.setOnLeftBtnClickListener(view -> {
});
bind.persistentSearchView.setOnRightBtnClickListener(view -> {
activity.navController.navigate(R.id.action_searchFragment_to_filterFragment);
});
bind.persistentSearchView.setOnSearchConfirmedListener((searchView, query) -> {
search(query);
});

View file

@ -9,7 +9,6 @@ import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.cappielloantonio.play.adapter.AlbumArtistPageAdapter;
import com.cappielloantonio.play.adapter.SongResultSearchAdapter;
import com.cappielloantonio.play.databinding.FragmentSongListPageBinding;
import com.cappielloantonio.play.model.Song;
@ -49,25 +48,31 @@ public class SongListPageFragment extends Fragment {
private void init() {
if(getArguments().getString(Song.RECENTLY_PLAYED) != null) {
songListPageViewModel.title = Song.RECENTLY_PLAYED;
bind.pageTitleLabel.setText(Song.RECENTLY_PLAYED);
bind.pageTitleLabel.setText("Recently played songs");
}
else if(getArguments().getString(Song.MOST_PLAYED) != null) {
songListPageViewModel.title = Song.MOST_PLAYED;
bind.pageTitleLabel.setText(Song.MOST_PLAYED);
bind.pageTitleLabel.setText("Most played songs");
}
else if(getArguments().getString(Song.RECENTLY_ADDED) != null) {
songListPageViewModel.title = Song.RECENTLY_ADDED;
bind.pageTitleLabel.setText(Song.RECENTLY_ADDED);
bind.pageTitleLabel.setText("Recently added song");
}
else if(getArguments().getString(Song.BY_GENRE) != null) {
songListPageViewModel.title = Song.BY_GENRE;
songListPageViewModel.genre = getArguments().getParcelable("genre_object");
bind.pageTitleLabel.setText(Song.BY_GENRE);
bind.pageTitleLabel.setText(songListPageViewModel.genre.getName() + ": all songs");
}
else if(getArguments().getString(Song.BY_ARTIST) != null) {
songListPageViewModel.title = Song.BY_ARTIST;
songListPageViewModel.artist = getArguments().getParcelable("artist_object");
bind.pageTitleLabel.setText(Song.BY_ARTIST);
bind.pageTitleLabel.setText(songListPageViewModel.artist.getName() + "'s top songs");
}
else if(getArguments().getString(Song.BY_GENRES) != null) {
songListPageViewModel.title = Song.BY_GENRES;
songListPageViewModel.filters = getArguments().getStringArrayList("filters_list");
songListPageViewModel.filterNames = getArguments().getStringArrayList("filter_name_list");
bind.pageTitleLabel.setText(songListPageViewModel.getFiltersTitle());
}
}

View file

@ -13,6 +13,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import com.cappielloantonio.play.App;
import com.cappielloantonio.play.R;
@ -32,6 +33,7 @@ import com.cappielloantonio.play.repository.SongRepository;
import com.cappielloantonio.play.ui.activities.MainActivity;
import com.cappielloantonio.play.util.PreferenceUtil;
import com.cappielloantonio.play.util.SyncUtil;
import com.cappielloantonio.play.viewmodel.SyncViewModel;
import com.google.android.material.snackbar.BaseTransientBottomBar;
import com.google.android.material.snackbar.Snackbar;
@ -45,12 +47,7 @@ public class SyncFragment extends Fragment {
private MainActivity activity;
private FragmentSyncBinding bind;
private ArrayList<Integer> progressing;
private List<Genre> genres;
private int stepMax = 5;
private int increment = 25;
private SyncViewModel syncViewModel;
@Nullable
@Override
@ -59,6 +56,7 @@ public class SyncFragment extends Fragment {
bind = FragmentSyncBinding.inflate(inflater, container, false);
View view = bind.getRoot();
syncViewModel = new ViewModelProvider(requireActivity()).get(SyncViewModel.class);
init();
syncLibraries();
@ -73,13 +71,11 @@ public class SyncFragment extends Fragment {
}
private void init() {
syncViewModel.setArguemnts(getArguments());
bind.loadingProgressBar.setVisibility(View.VISIBLE);
}
private void syncLibraries() {
Log.d(TAG, "syncLibraries");
progressing = new ArrayList<>();
SyncUtil.getLibraries(requireContext(), new MediaCallback() {
@Override
public void onError(Exception exception) {
@ -101,11 +97,11 @@ public class SyncFragment extends Fragment {
}
private void startSyncing() {
syncAlbums();
syncArtists();
syncGenres();
syncPlaylist();
syncSongs();
if(syncViewModel.isSyncAlbum()) syncAlbums();
if(syncViewModel.isSyncArtist()) syncArtists();
if(syncViewModel.isSyncGenres()) syncGenres();
if(syncViewModel.isSyncPlaylist()) syncPlaylist();
if(syncViewModel.isSyncSong()) syncSongs();
}
private void syncAlbums() {
@ -114,14 +110,14 @@ public class SyncFragment extends Fragment {
@Override
public void onError(Exception exception) {
Log.e(TAG, "onError: " + exception.getMessage());
setProgress(false, "Album");
animateProgressBar(false);
}
@Override
public void onLoadMedia(List<?> media) {
AlbumRepository repository = new AlbumRepository(activity.getApplication());
repository.insertAll((ArrayList<Album>) media);
setProgress(true, "Album");
animateProgressBar(true);
}
});
}
@ -132,14 +128,14 @@ public class SyncFragment extends Fragment {
@Override
public void onError(Exception exception) {
Log.e(TAG, "onError: " + exception.getMessage());
setProgress(false, "Artist");
animateProgressBar(false);
}
@Override
public void onLoadMedia(List<?> media) {
ArtistRepository repository = new ArtistRepository(activity.getApplication());
repository.insertAll((ArrayList<Artist>) media);
setProgress(true, "Artist");
animateProgressBar(true);
}
});
}
@ -150,14 +146,17 @@ public class SyncFragment extends Fragment {
@Override
public void onError(Exception exception) {
Log.e(TAG, "onError: " + exception.getMessage());
setProgress(false, "Genres");
animateProgressBar(false);
}
@Override
public void onLoadMedia(List<?> media) {
GenreRepository repository = new GenreRepository(activity.getApplication());
repository.insertAll((ArrayList<Genre>) media);
setProgress(true, "Genres");
animateProgressBar(true);
if(syncViewModel.isCrossSyncSongGenre()) syncSongsPerGenre((ArrayList<Genre>) media);
}
});
}
@ -168,14 +167,14 @@ public class SyncFragment extends Fragment {
@Override
public void onError(Exception exception) {
Log.e(TAG, "onError: " + exception.getMessage());
setProgress(false, "PlayList");
animateProgressBar(false);
}
@Override
public void onLoadMedia(List<?> media) {
PlaylistRepository repository = new PlaylistRepository(activity.getApplication());
repository.insertAll((ArrayList<Playlist>) media);
setProgress(true, "PlayList");
animateProgressBar(true);
}
});
}
@ -186,41 +185,52 @@ public class SyncFragment extends Fragment {
@Override
public void onError(Exception exception) {
Log.e(TAG, "onError: " + exception.getMessage());
setProgress(false, "Songs");
animateProgressBar(false);
}
@Override
public void onLoadMedia(List<?> media) {
SongRepository repository = new SongRepository(activity.getApplication());
repository.insertAll((ArrayList<Song>) media);
setProgress(true, "Songs");
animateProgressBar(true);
}
});
}
private void syncSongsPerGenre(List<Genre> genres) {
for (Genre genre : genres) {
SyncUtil.getSongsPerGenre(requireContext(), new MediaCallback() {
@Override
public void onError(Exception exception) {
Log.e(TAG, "onError: " + exception.getMessage());
}
private void setProgress(boolean step, String who) {
if (step) {
Log.d(TAG, "setProgress " + who + ": adding " + increment);
progressing.add(increment);
bind.loadingProgressBar.setProgress(bind.loadingProgressBar.getProgress() + increment, true);
} else {
Log.d(TAG, "setProgress" + who + ": adding " + 0);
progressing.add(0);
@Override
public void onLoadMedia(List<?> media) {
GenreRepository repository = new GenreRepository(App.getInstance());
repository.insertPerGenre((ArrayList<SongGenreCross>) media);
}
}, genre.id);
}
animateProgressBar(true);
PreferenceUtil.getInstance(requireContext()).setSongGenreSync(true);
}
private void animateProgressBar(boolean step) {
syncViewModel.setProgress(step);
bind.loadingProgressBar.setProgress(syncViewModel.getProgressBarInfo(), true);
countProgress();
}
private void countProgress() {
if (progressing.size() == stepMax) {
if (bind.loadingProgressBar.getProgress() == 100)
if (syncViewModel.getProgress() == syncViewModel.getStep()) {
if (syncViewModel.getProgressBarInfo() >= 100)
terminate();
else
Toast.makeText(requireContext(), "Sync error", Toast.LENGTH_SHORT).show();
}
Log.d(TAG, "countProgress: SIZE: " + progressing.size() + " - SUM: " + bind.loadingProgressBar.getProgress());
}
private void terminate() {

View file

@ -1,6 +1,7 @@
package com.cappielloantonio.play.util;
import android.content.Context;
import android.os.Bundle;
import com.cappielloantonio.play.App;
import com.cappielloantonio.play.interfaces.MediaCallback;
@ -202,4 +203,16 @@ public class SyncUtil {
}
});
}
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);
bundle.putBoolean("sync_artist", syncArtist);
bundle.putBoolean("sync_genres", syncGenres);
bundle.putBoolean("sync_playlist", syncPlaylist);
bundle.putBoolean("sync_song", syncSong);
bundle.putBoolean("cross_sync_song_genre", crossSyncSongGenre);
return bundle;
}
}

View file

@ -7,18 +7,17 @@ import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import com.cappielloantonio.play.model.Genre;
import com.cappielloantonio.play.model.RecentSearch;
import com.cappielloantonio.play.model.Song;
import com.cappielloantonio.play.repository.GenreRepository;
import com.cappielloantonio.play.repository.RecentSearchRepository;
import com.cappielloantonio.play.repository.SongRepository;
import java.util.ArrayList;
import java.util.List;
public class FilterViewModel extends AndroidViewModel {
private GenreRepository genreRepository;
private LiveData<List<Genre>> allGenres;
private ArrayList<String> selectedFiltersID = new ArrayList<>();
private ArrayList<String> selectedFilters = new ArrayList<>();
public FilterViewModel(@NonNull Application application) {
super(application);
@ -30,4 +29,22 @@ public class FilterViewModel extends AndroidViewModel {
allGenres = genreRepository.getListLiveGenres();
return allGenres;
}
public void addFilter(String filterID, String filterName) {
selectedFiltersID.add(filterID);
selectedFilters.add(filterName);
}
public void removeFilter(String filterID, String filterName) {
selectedFiltersID.remove(filterID);
selectedFilters.remove(filterName);
}
public ArrayList<String> getFilters() {
return selectedFiltersID;
}
public ArrayList<String> getFilterNames() {
return selectedFilters;
}
}

View file

@ -1,6 +1,7 @@
package com.cappielloantonio.play.viewmodel;
import android.app.Application;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
@ -11,6 +12,7 @@ import com.cappielloantonio.play.model.Genre;
import com.cappielloantonio.play.model.Song;
import com.cappielloantonio.play.repository.SongRepository;
import java.util.ArrayList;
import java.util.List;
public class SongListPageViewModel extends AndroidViewModel {
@ -21,6 +23,8 @@ public class SongListPageViewModel extends AndroidViewModel {
public String title;
public Genre genre;
public Artist artist;
public ArrayList<String> filters = new ArrayList<>();
public ArrayList<String> filterNames = new ArrayList<>();
public SongListPageViewModel(@NonNull Application application) {
super(application);
@ -45,8 +49,15 @@ public class SongListPageViewModel extends AndroidViewModel {
case Song.BY_ARTIST:
songList = songRepository.getArtistListLiveTopSong(artist.getId());
break;
case Song.BY_GENRES:
songList = songRepository.getFilteredListLiveSong(filters);
break;
}
return songList;
}
public String getFiltersTitle() {
return TextUtils.join(", ", filterNames);
}
}

View file

@ -0,0 +1,93 @@
package com.cappielloantonio.play.viewmodel;
import android.app.Application;
import android.os.Bundle;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import com.cappielloantonio.play.model.Song;
import com.cappielloantonio.play.repository.SongRepository;
import java.util.List;
public class SyncViewModel extends AndroidViewModel {
private static final String TAG = "SyncViewModel";
private boolean syncAlbum = false;
private boolean syncArtist = false;
private boolean syncGenres = false;
private boolean syncPlaylist = false;
private boolean syncSong = false;
private boolean crossSyncSongGenre = false;
private int step = 0;
private int progress = 0;
public SyncViewModel(@NonNull Application application) {
super(application);
}
public void setArguemnts(Bundle bundle) {
syncAlbum = bundle.getBoolean("sync_album", false);
syncArtist = bundle.getBoolean("sync_artist", false);
syncGenres = bundle.getBoolean("sync_genres", false);
syncPlaylist = bundle.getBoolean("sync_playlist", false);
syncSong = bundle.getBoolean("sync_song", false);
crossSyncSongGenre = bundle.getBoolean("cross_sync_song_genre", false);
countStep();
}
private void countStep() {
if(syncAlbum) step++;
if(syncArtist) step++;
if(syncGenres) step++;
if(syncPlaylist) step++;
if(syncSong) step++;
if(crossSyncSongGenre) step++;
}
public boolean isSyncAlbum() {
return syncAlbum;
}
public boolean isSyncArtist() {
return syncArtist;
}
public boolean isSyncGenres() {
return syncGenres;
}
public boolean isSyncPlaylist() {
return syncPlaylist;
}
public boolean isSyncSong() {
return syncSong;
}
public boolean isCrossSyncSongGenre() {
return crossSyncSongGenre;
}
public int getStep() {
return step;
}
public int getProgress() {
return progress;
}
public void setProgress(Boolean step) {
if(step) progress++;
}
public int getProgressBarInfo() {
return progress * (100 / step);
}
}

View file

@ -28,17 +28,40 @@
android:orientation="vertical"
android:paddingBottom="8dp">
<TextView
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/open_sans_font_family"
android:paddingStart="16dp"
android:paddingTop="20dp"
android:paddingEnd="16dp"
android:text="Filter"
android:textColor="@color/titleTextColor"
android:textSize="22sp"
android:textStyle="bold" />
android:orientation="horizontal"
android:paddingStart="8dp"
android:paddingTop="8dp"
android:paddingEnd="8dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fontFamily="@font/open_sans_font_family"
android:paddingStart="8dp"
android:paddingTop="12dp"
android:paddingEnd="8dp"
android:text="Filter"
android:textColor="@color/titleTextColor"
android:textSize="22sp"
android:textStyle="bold" />
<TextView
android:id="@+id/finish_filtering_text_view_clickable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/open_sans_font_family"
android:paddingStart="8dp"
android:paddingTop="12dp"
android:paddingEnd="8dp"
android:text="Finish"
android:textColor="@color/subtitleTextColor"
android:textSize="14sp" />
</LinearLayout>
<com.google.android.material.chip.ChipGroup
android:id="@+id/filters_chips_group"

View file

@ -28,17 +28,41 @@
android:orientation="vertical"
android:paddingBottom="8dp">
<TextView
<!-- Label and button -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/open_sans_font_family"
android:paddingStart="16dp"
android:paddingTop="20dp"
android:paddingEnd="16dp"
android:text="Genre Catalogue"
android:textColor="@color/titleTextColor"
android:textSize="22sp"
android:textStyle="bold" />
android:orientation="horizontal"
android:paddingStart="8dp"
android:paddingTop="8dp"
android:paddingEnd="8dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fontFamily="@font/open_sans_font_family"
android:paddingStart="8dp"
android:paddingTop="12dp"
android:paddingEnd="8dp"
android:text="Genre Catalogue"
android:textColor="@color/titleTextColor"
android:textSize="22sp"
android:textStyle="bold" />
<TextView
android:id="@+id/filter_genres_text_view_clickable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/open_sans_font_family"
android:paddingStart="8dp"
android:paddingTop="12dp"
android:paddingEnd="8dp"
android:text="Filter"
android:textColor="@color/subtitleTextColor"
android:textSize="14sp" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/genre_catalogue_recycler_view"

View file

@ -194,8 +194,21 @@
android:clipToPadding="false"
android:paddingStart="16dp"
android:paddingTop="8dp"
android:paddingEnd="8dp"
android:paddingBottom="8dp" />
android:paddingEnd="8dp"/>
<Button
android:id="@+id/sync_genre_button"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="16dp"
android:paddingBottom="12dp"
android:text="Sync Genres"
android:textAllCaps="false"
android:textColor="@color/normalTextColor"
app:cornerRadius="24dp" />
</LinearLayout>
</LinearLayout>

View file

@ -14,7 +14,7 @@
app:areSuggestionsDisabled="true"
app:cardBackgroundColor="@color/cardColor"
app:cardCornerRadius="4dp"
app:cardElevation="0dp"
app:cardElevation="2dp"
app:clearInputButtonDrawable="@drawable/ic_close"
app:dividerColor="@color/dividerColor"
app:isClearInputButtonEnabled="true"
@ -28,7 +28,6 @@
app:queryInputHint="@string/search_hint"
app:queryInputHintColor="@color/hintTextColor"
app:queryInputTextColor="@color/hintTextColor"
app:rightButtonDrawable="@drawable/ic_filter"
app:shouldDimBehind="false" />
<LinearLayout

View file

@ -40,7 +40,7 @@
<action
android:id="@+id/action_loginFragment_to_homeFragment"
app:destination="@id/homeFragment"
app:popUpTo="@id/landingFragment"
app:popUpTo="@id/loginFragment"
app:popUpToInclusive="true" />
</fragment>
@ -91,6 +91,11 @@
<action
android:id="@+id/action_libraryFragment_to_songListPageFragment"
app:destination="@id/songListPageFragment" />
<action
android:id="@+id/action_libraryFragment_to_syncFragment"
app:destination="@id/syncFragment"
app:popUpTo="@id/libraryFragment"
app:popUpToInclusive="true" />
</fragment>
<fragment
android:id="@+id/settingsFragment"
@ -102,9 +107,6 @@
android:name="com.cappielloantonio.play.ui.fragment.SearchFragment"
android:label="SearchFragment"
tools:layout="@layout/fragment_search">
<action
android:id="@+id/action_searchFragment_to_filterFragment"
app:destination="@id/filterFragment" />
<action
android:id="@+id/action_searchFragment_to_artistPageFragment"
app:destination="@id/artistPageFragment"/>
@ -116,7 +118,11 @@
android:id="@+id/filterFragment"
android:name="com.cappielloantonio.play.ui.fragment.FilterFragment"
android:label="FilterFragment"
tools:layout="@layout/fragment_filter" />
tools:layout="@layout/fragment_filter" >
<action
android:id="@+id/action_filterFragment_to_songListPageFragment"
app:destination="@id/songListPageFragment" />
</fragment>
<fragment
android:id="@+id/artistCatalogueFragment"
android:name="com.cappielloantonio.play.ui.fragment.ArtistCatalogueFragment"
@ -143,6 +149,9 @@
<action
android:id="@+id/action_genreCatalogueFragment_to_songListPageFragment"
app:destination="@id/songListPageFragment" />
<action
android:id="@+id/action_genreCatalogueFragment_to_filterFragment"
app:destination="@id/filterFragment" />
</fragment>
<fragment

View file

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nav_graph"
app:startDestination="@id/landingFragment">
<fragment
android:id="@+id/landingFragment"
android:name="com.cappielloantonio.play.ui.fragment.LandingFragment"
android:label="fragment_landing"
tools:layout="@layout/fragment_landing" >
<action
android:id="@+id/action_landingFragment_to_loginFragment"
app:destination="@id/loginFragment"
app:popUpTo="@id/landingFragment"
app:popUpToInclusive="true" />
<action
android:id="@+id/action_landingFragment_to_homeFragment"
app:destination="@id/homeFragment"
app:popUpTo="@id/landingFragment"
app:popUpToInclusive="true" />
<action
android:id="@+id/action_landingFragment_to_syncFragment"
app:destination="@id/syncFragment"
app:popUpTo="@id/landingFragment"
app:popUpToInclusive="true" />
</fragment>
<fragment
android:id="@+id/loginFragment"
android:name="com.cappielloantonio.play.ui.fragment.LoginFragment"
android:label="LoginFragment"
tools:layout="@layout/fragment_login">
<action
android:id="@+id/action_loginFragment_to_syncFragment"
app:destination="@id/syncFragment"
app:popUpTo="@id/loginFragment"
app:popUpToInclusive="true" />
<action
android:id="@+id/action_loginFragment_to_homeFragment"
app:destination="@id/homeFragment"
app:popUpTo="@id/loginFragment"
app:popUpToInclusive="true" />
</fragment>
<fragment
android:id="@+id/syncFragment"
android:name="com.cappielloantonio.play.ui.fragment.SyncFragment"
android:label="SyncFragment"
tools:layout="@layout/fragment_sync">
<action
android:id="@+id/action_syncFragment_to_homeFragment"
app:destination="@id/homeFragment"
app:popUpTo="@id/syncFragment"
app:popUpToInclusive="true" />
</fragment>
<fragment
android:id="@+id/homeFragment"
android:name="com.cappielloantonio.play.ui.fragment.HomeFragment"
android:label="HomeFragment"
tools:layout="@layout/fragment_home">
<action
android:id="@+id/action_homeFragment_to_syncFragment"
app:destination="@id/syncFragment" />
<action
android:id="@+id/action_homeFragment_to_songListPageFragment"
app:destination="@id/songListPageFragment" />
</fragment>
<fragment
android:id="@+id/songListPageFragment"
android:name="com.cappielloantonio.play.ui.fragment.SongListPageFragment"
android:label="SongListPageFragment"
tools:layout="@layout/fragment_song_list_page"/>
</navigation>

View file

@ -0,0 +1,82 @@
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nav_graph">
<fragment
android:id="@+id/libraryFragment"
android:name="com.cappielloantonio.play.ui.fragment.LibraryFragment"
android:label="LibraryFragment"
tools:layout="@layout/fragment_library">
<action
android:id="@+id/action_libraryFragment_to_artistCatalogueFragment"
app:destination="@id/artistCatalogueFragment" />
<action
android:id="@+id/action_libraryFragment_to_albumCatalogueFragment"
app:destination="@id/albumCatalogueFragment" />
<action
android:id="@+id/action_libraryFragment_to_genreCatalogueFragment"
app:destination="@id/genreCatalogueFragment" />
<action
android:id="@+id/action_libraryFragment_to_artistPageFragment"
app:destination="@id/artistPageFragment"/>
<action
android:id="@+id/action_libraryFragment_to_albumPageFragment"
app:destination="@id/albumPageFragment" />
<action
android:id="@+id/action_libraryFragment_to_songListPageFragment"
app:destination="@id/songListPageFragment" />
</fragment>
<fragment
android:id="@+id/artistCatalogueFragment"
android:name="com.cappielloantonio.play.ui.fragment.ArtistCatalogueFragment"
android:label="ArtistCatalogueFragment"
tools:layout="@layout/fragment_artist_catalogue">
<action
android:id="@+id/action_artistCatalogueFragment_to_artistPageFragment"
app:destination="@id/artistPageFragment"/>
</fragment>
<fragment
android:id="@+id/albumCatalogueFragment"
android:name="com.cappielloantonio.play.ui.fragment.AlbumCatalogueFragment"
android:label="AlbumCatalogueFragment"
tools:layout="@layout/fragment_album_catalogue">
<action
android:id="@+id/action_albumCatalogueFragment_to_albumPageFragment"
app:destination="@id/albumPageFragment" />
</fragment>
<fragment
android:id="@+id/genreCatalogueFragment"
android:name="com.cappielloantonio.play.ui.fragment.GenreCatalogueFragment"
android:label="GenreCatalogueFragment"
tools:layout="@layout/fragment_genre_catalogue">
<action
android:id="@+id/action_genreCatalogueFragment_to_songListPageFragment"
app:destination="@id/songListPageFragment" />
</fragment>
<fragment
android:id="@+id/artistPageFragment"
android:name="com.cappielloantonio.play.ui.fragment.ArtistPageFragment"
android:label="ArtistPageFragment"
tools:layout="@layout/fragment_artist_page">
<action
android:id="@+id/action_artistPageFragment_to_albumPageFragment"
app:destination="@id/albumPageFragment" />
<action
android:id="@+id/action_artistPageFragment_to_songListPageFragment"
app:destination="@id/songListPageFragment" />
</fragment>
<fragment
android:id="@+id/albumPageFragment"
android:name="com.cappielloantonio.play.ui.fragment.AlbumPageFragment"
android:label="AlbumPageFragment"
tools:layout="@layout/fragment_album_page"/>
<fragment
android:id="@+id/songListPageFragment"
android:name="com.cappielloantonio.play.ui.fragment.SongListPageFragment"
android:label="SongListPageFragment"
tools:layout="@layout/fragment_song_list_page"/>
</navigation>

View file

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nav_graph">
<fragment
android:id="@+id/searchFragment"
android:name="com.cappielloantonio.play.ui.fragment.SearchFragment"
android:label="SearchFragment"
tools:layout="@layout/fragment_search">
<action
android:id="@+id/action_searchFragment_to_filterFragment"
app:destination="@id/filterFragment" />
<action
android:id="@+id/action_searchFragment_to_artistPageFragment"
app:destination="@id/artistPageFragment"/>
<action
android:id="@+id/action_searchFragment_to_albumPageFragment"
app:destination="@id/albumPageFragment" />
</fragment>
<fragment
android:id="@+id/filterFragment"
android:name="com.cappielloantonio.play.ui.fragment.FilterFragment"
android:label="FilterFragment"
tools:layout="@layout/fragment_filter" />
<fragment
android:id="@+id/artistPageFragment"
android:name="com.cappielloantonio.play.ui.fragment.ArtistPageFragment"
android:label="ArtistPageFragment"
tools:layout="@layout/fragment_artist_page">
<action
android:id="@+id/action_artistPageFragment_to_albumPageFragment"
app:destination="@id/albumPageFragment" />
<action
android:id="@+id/action_artistPageFragment_to_songListPageFragment"
app:destination="@id/songListPageFragment" />
</fragment>
<fragment
android:id="@+id/albumPageFragment"
android:name="com.cappielloantonio.play.ui.fragment.AlbumPageFragment"
android:label="AlbumPageFragment"
tools:layout="@layout/fragment_album_page"/>
<fragment
android:id="@+id/songListPageFragment"
android:name="com.cappielloantonio.play.ui.fragment.SongListPageFragment"
android:label="SongListPageFragment"
tools:layout="@layout/fragment_song_list_page"/>
</navigation>

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nav_graph">
<fragment
android:id="@+id/settingsFragment"
android:name="com.cappielloantonio.play.ui.fragment.SettingsFragment"
android:label="SettingsFragment"
tools:layout="@layout/fragment_settings"/>
</navigation>

View file

@ -36,7 +36,7 @@
<color name="bottomNavIconColor">#707070</color>
<color name="chipBorderColor">#707070</color>
<color name="chipSelectedBackgroundColor">#444444</color>
<color name="chipSelectedBackgroundColor">#606060</color>
<color name="chipUnelectedBackgroundColor">#1D1D1D</color>
</resources>