Fix overwriting of data in song_genre_cross table

This commit is contained in:
CappielloAntonio 2021-05-02 16:16:05 +02:00
parent c6254c8416
commit 0305af2f9f
4 changed files with 17 additions and 16 deletions

View file

@ -53,9 +53,17 @@ public class GenreRepository {
}
public void insertAll(ArrayList<Genre> genres) {
InsertAllThreadSafe insertAll = new InsertAllThreadSafe(genreDao, genres);
Thread thread = new Thread(insertAll);
thread.start();
try {
final Thread deleteAll = new Thread(new DeleteAllGenreThreadSafe(genreDao));
final Thread insertAll = new Thread(new InsertAllThreadSafe(genreDao, genres));
deleteAll.start();
deleteAll.join();
insertAll.start();
insertAll.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void deleteAll() {

View file

@ -21,17 +21,9 @@ public class SongGenreRepository {
}
public void insertAll(List<SongGenreCross> crosses) {
try {
final Thread delete = new Thread(new DeleteAllSongGenreCrossThreadSafe(songGenreCrossDao));
final Thread insertAll = new Thread(new InsertAllThreadSafe(songGenreCrossDao, crosses));
delete.start();
delete.join();
insertAll.start();
insertAll.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
InsertAllThreadSafe insert = new InsertAllThreadSafe(songGenreCrossDao, crosses);
Thread thread = new Thread(insert);
thread.start();
}
public void deleteAll() {

View file

@ -231,6 +231,7 @@ public class SyncFragment extends Fragment {
@Override
public void onLoadMedia(List<?> media) {
syncViewModel.setGenreList((ArrayList<Genre>) media);
songGenreRepository.deleteAll();
genreRepository.insertAll(syncViewModel.getGenreList());
loadSectorInfo(GENRES, "Found " + syncViewModel.getGenreList().size() + " elements", true);
}
@ -264,7 +265,6 @@ public class SyncFragment extends Fragment {
@Override
public void onLoadMedia(List<?> media) {
syncViewModel.setSongList((ArrayList<Song>) media);
songGenreRepository.deleteAll();
songRepository.insertAll(syncViewModel.getSongList());
syncSongArtistCross(syncViewModel.getSongList());
syncDownloadedSong();

View file

@ -30,10 +30,11 @@ import java.util.List;
import java.util.Map;
public class SyncUtil {
private static final String TAG = "SyncUtil";
public static final String SONG = "song";
public static final String ALBUM = "album";
public static final String ARTIST = "artist";
private static final String TAG = "SyncUtil";
public static void getLibraries(Context context, MediaCallback callback) {
String id = App.getApiClientInstance(context).getCurrentUserId();