mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 09:53:33 +00:00
Fix filtering
This commit is contained in:
parent
76037e487b
commit
4848d4f3d0
25 changed files with 575 additions and 124 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue