use of se.zinokader.spotiq.model.Song in project SpotiQ by ZinoKader.
the class TracklistRepository method checkSongInDbPlaylist.
public Observable<Pair<Song, Boolean>> checkSongInDbPlaylist(Song song, String partyTitle) {
return Observable.create(subscriber -> databaseReference.child(partyTitle).child(FirebaseConstants.CHILD_TRACKLIST).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot songSnapshot : dataSnapshot.getChildren()) {
Song dbSong = songSnapshot.getValue(Song.class);
if (dbSong == null)
continue;
if (SongComparator.isEqual(song, dbSong)) {
subscriber.onNext(new Pair<>(song, true));
subscriber.onComplete();
break;
}
}
subscriber.onNext(new Pair<>(song, false));
subscriber.onComplete();
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.d(LogTag.LOG_TRACKLIST_REPOSITORY, "Something went wrong when checking " + "if song exists in db: " + databaseError.getMessage());
databaseError.toException().printStackTrace();
}
}));
}
Aggregations