mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
fix: minor refactor of sync album observer
This commit is contained in:
parent
31d91f7215
commit
eaf2710054
1 changed files with 14 additions and 10 deletions
|
|
@ -7,6 +7,7 @@ import androidx.annotation.NonNull;
|
||||||
import androidx.lifecycle.AndroidViewModel;
|
import androidx.lifecycle.AndroidViewModel;
|
||||||
import androidx.lifecycle.LifecycleOwner;
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
import androidx.lifecycle.LiveData;
|
import androidx.lifecycle.LiveData;
|
||||||
|
import androidx.lifecycle.Observer;
|
||||||
import androidx.lifecycle.MutableLiveData;
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
import com.cappielloantonio.tempo.repository.AlbumRepository;
|
import com.cappielloantonio.tempo.repository.AlbumRepository;
|
||||||
|
|
@ -49,19 +50,22 @@ public class StarredAlbumsSyncViewModel extends AndroidViewModel {
|
||||||
CountDownLatch latch = new CountDownLatch(albums.size());
|
CountDownLatch latch = new CountDownLatch(albums.size());
|
||||||
|
|
||||||
for (AlbumID3 album : albums) {
|
for (AlbumID3 album : albums) {
|
||||||
albumRepository.getAlbumTracks(album.getId()).observeForever(songs -> {
|
LiveData<List<Child>> albumTracks = albumRepository.getAlbumTracks(album.getId());
|
||||||
if (songs != null) {
|
albumTracks.observeForever(new Observer<List<Child>>() {
|
||||||
allSongs.addAll(songs);
|
@Override
|
||||||
}
|
public void onChanged(List<Child> songs) {
|
||||||
latch.countDown();
|
if (songs != null) {
|
||||||
|
allSongs.addAll(songs);
|
||||||
if (latch.getCount() == 0) {
|
}
|
||||||
callback.onSongsCollected(allSongs);
|
latch.countDown();
|
||||||
|
|
||||||
|
if (latch.getCount() == 0) {
|
||||||
|
callback.onSongsCollected(allSongs);
|
||||||
|
albumTracks.removeObserver(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
albumRepository.removeObserver(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private interface AlbumSongsCallback {
|
private interface AlbumSongsCallback {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue