tempus/app/src/main/java/com/cappielloantonio/play/viewmodel/SyncViewModel.java

110 lines
2.6 KiB
Java
Raw Normal View History

2020-11-25 08:21:30 +01:00
package com.cappielloantonio.play.viewmodel;
import android.app.Application;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import com.cappielloantonio.play.model.Song;
import com.cappielloantonio.play.repository.SongRepository;
2020-11-27 09:06:50 +01:00
import java.util.HashMap;
import java.util.Map;
2020-11-25 08:21:30 +01:00
public class SyncViewModel extends AndroidViewModel {
private static final String TAG = "SyncViewModel";
2020-11-27 09:06:50 +01:00
private SongRepository songRepository;
2020-11-25 08:21:30 +01:00
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);
2020-11-27 09:06:50 +01:00
songRepository = new SongRepository(application);
2020-11-25 08:21:30 +01:00
}
public void setArguemnts(Bundle bundle) {
2020-11-27 09:06:50 +01:00
step = 0;
progress = 0;
2020-11-25 08:21:30 +01:00
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);
}
2020-11-27 09:06:50 +01:00
public Map<Integer, Song> getCatalogue() {
Map<Integer, Song> map = new HashMap<>();
for(Song song: songRepository.getCatalogue()){
map.put(song.hashCode(), song);
}
return map;
}
2020-11-25 08:21:30 +01:00
}