Search in sources :

Example 6 with Song

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();
        }
    }));
}
Also used : Song(se.zinokader.spotiq.model.Song) DatabaseError(com.google.firebase.database.DatabaseError) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot)

Aggregations

Song (se.zinokader.spotiq.model.Song)6 Context (android.content.Context)2 Bundle (android.os.Bundle)2 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)2 Schedulers (io.reactivex.schedulers.Schedulers)2 List (java.util.List)2 TimeUnit (java.util.concurrent.TimeUnit)2 Inject (javax.inject.Inject)2 ApplicationConstants (se.zinokader.spotiq.constant.ApplicationConstants)2 DataBindingUtil (android.databinding.DataBindingUtil)1 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1 Fragment (android.support.v4.app.Fragment)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 Log (android.util.Log)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)1 ImageButton (android.widget.ImageButton)1