summaryrefslogtreecommitdiff
path: root/java/com/android/pump/db/MediaDb.java
blob: d0cbf31a0416311e17058b65a66dc56dbb92422e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
/*
 * Copyright 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.pump.db;

import android.Manifest;
import android.content.ContentResolver;

import com.android.pump.concurrent.Executors;
import com.android.pump.util.Clog;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicBoolean;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresPermission;
import androidx.annotation.UiThread;
import androidx.collection.ArraySet;

@UiThread
public class MediaDb implements MediaProvider {
    private static final String TAG = Clog.tag(MediaDb.class);

    private final AtomicBoolean mLoaded = new AtomicBoolean();

    private final Executor mExecutor;

    private final AudioStore mAudioStore;
    private final VideoStore mVideoStore;
    private final DataProvider mDataProvider;

    private final List<Audio> mAudios = new ArrayList<>();
    private final List<Artist> mArtists = new ArrayList<>();
    private final List<Album> mAlbums = new ArrayList<>();
    private final List<Genre> mGenres = new ArrayList<>();
    private final List<Playlist> mPlaylists = new ArrayList<>();

    private final List<Movie> mMovies = new ArrayList<>();
    private final List<Series> mSeries = new ArrayList<>();
    private final List<Episode> mEpisodes = new ArrayList<>();
    private final List<Other> mOthers = new ArrayList<>();

    private final Set<UpdateCallback> mAudioUpdateCallbacks = new ArraySet<>();
    private final Set<UpdateCallback> mArtistUpdateCallbacks = new ArraySet<>();
    private final Set<UpdateCallback> mAlbumUpdateCallbacks = new ArraySet<>();
    private final Set<UpdateCallback> mGenreUpdateCallbacks = new ArraySet<>();
    private final Set<UpdateCallback> mPlaylistUpdateCallbacks = new ArraySet<>();

    private final Set<UpdateCallback> mMovieUpdateCallbacks = new ArraySet<>();
    private final Set<UpdateCallback> mSeriesUpdateCallbacks = new ArraySet<>();
    private final Set<UpdateCallback> mEpisodeUpdateCallbacks = new ArraySet<>();
    private final Set<UpdateCallback> mOtherUpdateCallbacks = new ArraySet<>();

    public interface UpdateCallback {
        void onItemsInserted(int index, int count);
        void onItemsUpdated(int index, int count);
        void onItemsRemoved(int index, int count);
    }

    public MediaDb(@NonNull ContentResolver contentResolver, @NonNull DataProvider dataProvider,
            @NonNull Executor executor) {
        Clog.i(TAG, "MediaDb(" + contentResolver + ", " + dataProvider + ", " + executor + ")");
        mDataProvider = dataProvider;
        mExecutor = executor;

        mAudioStore = new AudioStore(contentResolver, new AudioStore.ChangeListener() {
            @Override
            public void onAudiosAdded(@NonNull Collection<Audio> audios) {
                Executors.uiThreadExecutor().execute(() -> addAudios(audios));
            }

            @Override
            public void onArtistsAdded(@NonNull Collection<Artist> artists) {
                Executors.uiThreadExecutor().execute(() -> addArtists(artists));
            }

            @Override
            public void onAlbumsAdded(@NonNull Collection<Album> albums) {
                Executors.uiThreadExecutor().execute(() -> addAlbums(albums));
            }

            @Override
            public void onGenresAdded(@NonNull Collection<Genre> genres) {
                Executors.uiThreadExecutor().execute(() -> addGenres(genres));
            }

            @Override
            public void onPlaylistsAdded(@NonNull Collection<Playlist> playlists) {
                Executors.uiThreadExecutor().execute(() -> addPlaylists(playlists));
            }
        }, this);

        mVideoStore = new VideoStore(contentResolver, new VideoStore.ChangeListener() {
            @Override
            public void onMoviesAdded(@NonNull Collection<Movie> movies) {
                Executors.uiThreadExecutor().execute(() -> addMovies(movies));
            }

            @Override
            public void onSeriesAdded(@NonNull Collection<Series> series) {
                Executors.uiThreadExecutor().execute(() -> addSeries(series));
            }

            @Override
            public void onEpisodesAdded(@NonNull Collection<Episode> episodes) {
                Executors.uiThreadExecutor().execute(() -> addEpisodes(episodes));
            }

            @Override
            public void onOthersAdded(@NonNull Collection<Other> others) {
                Executors.uiThreadExecutor().execute(() -> addOthers(others));
            }
        }, this);
    }

    public void addAudioUpdateCallback(@NonNull UpdateCallback callback) {
        addUpdateCallback(mAudioUpdateCallbacks, callback);
    }

    public void removeAudioUpdateCallback(@NonNull UpdateCallback callback) {
        removeUpdateCallback(mAudioUpdateCallbacks, callback);
    }

    public void addArtistUpdateCallback(@NonNull UpdateCallback callback) {
        addUpdateCallback(mArtistUpdateCallbacks, callback);
    }

    public void removeArtistUpdateCallback(@NonNull UpdateCallback callback) {
        removeUpdateCallback(mArtistUpdateCallbacks, callback);
    }

    public void addAlbumUpdateCallback(@NonNull UpdateCallback callback) {
        addUpdateCallback(mAlbumUpdateCallbacks, callback);
    }

    public void removeAlbumUpdateCallback(@NonNull UpdateCallback callback) {
        removeUpdateCallback(mAlbumUpdateCallbacks, callback);
    }

    public void addGenreUpdateCallback(@NonNull UpdateCallback callback) {
        addUpdateCallback(mGenreUpdateCallbacks, callback);
    }

    public void removeGenreUpdateCallback(@NonNull UpdateCallback callback) {
        removeUpdateCallback(mGenreUpdateCallbacks, callback);
    }

    public void addPlaylistUpdateCallback(@NonNull UpdateCallback callback) {
        addUpdateCallback(mPlaylistUpdateCallbacks, callback);
    }

    public void removePlaylistUpdateCallback(@NonNull UpdateCallback callback) {
        removeUpdateCallback(mPlaylistUpdateCallbacks, callback);
    }

    public void addMovieUpdateCallback(@NonNull UpdateCallback callback) {
        addUpdateCallback(mMovieUpdateCallbacks, callback);
    }

    public void removeMovieUpdateCallback(@NonNull UpdateCallback callback) {
        removeUpdateCallback(mMovieUpdateCallbacks, callback);
    }

    public void addSeriesUpdateCallback(@NonNull UpdateCallback callback) {
        addUpdateCallback(mSeriesUpdateCallbacks, callback);
    }

    public void removeSeriesUpdateCallback(@NonNull UpdateCallback callback) {
        removeUpdateCallback(mSeriesUpdateCallbacks, callback);
    }

    public void addEpisodeUpdateCallback(@NonNull UpdateCallback callback) {
        addUpdateCallback(mEpisodeUpdateCallbacks, callback);
    }

    public void removeEpisodeUpdateCallback(@NonNull UpdateCallback callback) {
        removeUpdateCallback(mEpisodeUpdateCallbacks, callback);
    }

    public void addOtherUpdateCallback(@NonNull UpdateCallback callback) {
        addUpdateCallback(mOtherUpdateCallbacks, callback);
    }

    public void removeOtherUpdateCallback(@NonNull UpdateCallback callback) {
        removeUpdateCallback(mOtherUpdateCallbacks, callback);
    }

    @RequiresPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
    public void load() {
        Clog.i(TAG, "load()");
        if (mLoaded.getAndSet(true)) {
            return;
        }

        mExecutor.execute(mAudioStore::load);
        mExecutor.execute(mVideoStore::load);
    }

    public @NonNull List<Audio> getAudios() {
        return Collections.unmodifiableList(mAudios);
    }
    public @NonNull List<Artist> getArtists() {
        return Collections.unmodifiableList(mArtists);
    }
    public @NonNull List<Album> getAlbums() {
        return Collections.unmodifiableList(mAlbums);
    }
    public @NonNull List<Genre> getGenres() {
        return Collections.unmodifiableList(mGenres);
    }
    public @NonNull List<Playlist> getPlaylists() {
        return Collections.unmodifiableList(mPlaylists);
    }

    public @NonNull List<Movie> getMovies() {
        return Collections.unmodifiableList(mMovies);
    }
    public @NonNull List<Series> getSeries() {
        return Collections.unmodifiableList(mSeries);
    }
    public @NonNull List<Episode> getEpisodes() {
        return Collections.unmodifiableList(mEpisodes);
    }
    public @NonNull List<Other> getOthers() {
        return Collections.unmodifiableList(mOthers);
    }

    public void loadData(@NonNull Audio audio) {
        // TODO(b/123707632) Ensure no concurrent runs for the same item !!
        if (audio.isLoaded()) return;

        mExecutor.execute(() -> {
            boolean updated = mAudioStore.loadData(audio);

            audio.setLoaded();
            if (updated) {
                Executors.uiThreadExecutor().execute(() -> updateAudio(audio));
            }
        });
    }

    public void loadData(@NonNull Artist artist) {
        // TODO(b/123707632) Ensure no concurrent runs for the same item !!
        if (artist.isLoaded()) return;

        mExecutor.execute(() -> {
            boolean updated = mAudioStore.loadData(artist);

            artist.setLoaded();
            if (updated) {
                Executors.uiThreadExecutor().execute(() -> updateArtist(artist));
            }
        });
    }

    public void loadData(@NonNull Album album) {
        // TODO(b/123707632) Ensure no concurrent runs for the same item !!
        if (album.isLoaded()) return;

        mExecutor.execute(() -> {
            boolean updated = mAudioStore.loadData(album);

            album.setLoaded();
            if (updated) {
                Executors.uiThreadExecutor().execute(() -> updateAlbum(album));
            }
        });
    }

    public void loadData(@NonNull Genre genre) {
        // TODO(b/123707632) Ensure no concurrent runs for the same item !!
        if (genre.isLoaded()) return;

        mExecutor.execute(() -> {
            boolean updated = mAudioStore.loadData(genre);

            genre.setLoaded();
            if (updated) {
                Executors.uiThreadExecutor().execute(() -> updateGenre(genre));
            }
        });
    }

    public void loadData(@NonNull Playlist playlist) {
        // TODO(b/123707632) Ensure no concurrent runs for the same item !!
        if (playlist.isLoaded()) return;

        mExecutor.execute(() -> {
            boolean updated = mAudioStore.loadData(playlist);

            playlist.setLoaded();
            if (updated) {
                Executors.uiThreadExecutor().execute(() -> updatePlaylist(playlist));
            }
        });
    }

    // TODO(b/123707018) Merge with loadData(episode)/loadData(other)
    public void loadData(@NonNull Movie movie) {
        // TODO(b/123707632) Ensure no concurrent runs for the same item !!
        if (movie.isLoaded()) return;

        mExecutor.execute(() -> {
            try {
                boolean updated = mDataProvider.populateMovie(movie);

                updated |= mVideoStore.loadData(movie);

                movie.setLoaded();
                if (updated) {
                    Executors.uiThreadExecutor().execute(() -> updateMovie(movie));
                }
            } catch (IOException e) {
                Clog.e(TAG, "Search for " + movie + " failed", e);
            }
        });
    }

    public void loadData(@NonNull Series series) {
        // TODO(b/123707632) Ensure no concurrent runs for the same item !!
        if (series.isLoaded()) return;

        mExecutor.execute(() -> {
            try {
                boolean updated = mDataProvider.populateSeries(series);

                updated |= mVideoStore.loadData(series);

                series.setLoaded();
                if (updated) {
                    Executors.uiThreadExecutor().execute(() -> updateSeries(series));
                }
            } catch (IOException e) {
                Clog.e(TAG, "Search for " + series + " failed", e);
            }
        });
    }

    // TODO(b/123707018) Merge with loadData(movie)/loadData(other)
    public void loadData(@NonNull Episode episode) {
        // TODO(b/123707632) Ensure no concurrent runs for the same item !!
        if (episode.isLoaded()) return;

        mExecutor.execute(() -> {
            try {
                boolean updated = mDataProvider.populateEpisode(episode);

                updated |= mVideoStore.loadData(episode);

                episode.setLoaded();
                if (updated) {
                    Executors.uiThreadExecutor().execute(() -> updateEpisode(episode));
                }
            } catch (IOException e) {
                Clog.e(TAG, "Search for " + episode + " failed", e);
            }
        });
    }

    // TODO(b/123707018) Merge with loadData(movie)/loadData(episode)
    public void loadData(@NonNull Other other) {
        // TODO(b/123707632) Ensure no concurrent runs for the same item !!
        if (other.isLoaded()) return;

        mExecutor.execute(() -> {
            boolean updated = mVideoStore.loadData(other);

            other.setLoaded();
            if (updated) {
                Executors.uiThreadExecutor().execute(() -> updateOther(other));
            }
        });
    }

    @Override
    public @NonNull Audio getAudioById(long id) {
        for (Audio audio : mAudios) {
            if (audio.getId() == id) {
                return audio;
            }
        }
        throw new IllegalArgumentException("Audio with id " + id + " was not found");
    }

    @Override
    public @NonNull Artist getArtistById(long id) {
        for (Artist artist : mArtists) {
            if (artist.getId() == id) {
                return artist;
            }
        }
        throw new IllegalArgumentException("Artist with id " + id + " was not found");
    }

    @Override
    public @NonNull Album getAlbumById(long id) {
        for (Album album : mAlbums) {
            if (album.getId() == id) {
                return album;
            }
        }
        throw new IllegalArgumentException("Album with id " + id + " was not found");
    }

    @Override
    public @NonNull Genre getGenreById(long id) {
        for (Genre genre : mGenres) {
            if (genre.getId() == id) {
                return genre;
            }
        }
        throw new IllegalArgumentException("Genre with id " + id + " was not found");
    }

    @Override
    public @NonNull Playlist getPlaylistById(long id) {
        for (Playlist playlist : mPlaylists) {
            if (playlist.getId() == id) {
                return playlist;
            }
        }
        throw new IllegalArgumentException("Playlist with id " + id + " was not found");
    }

    @Override
    public @NonNull Movie getMovieById(long id) {
        for (Movie movie : mMovies) {
            if (movie.getId() == id) {
                return movie;
            }
        }
        throw new IllegalArgumentException("Movie with id " + id + " was not found");
    }

    @Override
    public @NonNull Series getSeriesById(@NonNull String title) {
        for (Series series : mSeries) {
            if (!series.hasYear() && series.getTitle().equals(title)) {
                return series;
            }
        }
        throw new IllegalArgumentException("Series '" + title + "' was not found");
    }

    @Override
    public @NonNull Series getSeriesById(@NonNull String title, int year) {
        for (Series series : mSeries) {
            if (series.hasYear() && series.getTitle().equals(title) && series.getYear() == year) {
                return series;
            }
        }
        throw new IllegalArgumentException("Series '" + title + "' (" + year + ") was not found");
    }

    @Override
    public @NonNull Episode getEpisodeById(long id) {
        for (Episode episode : mEpisodes) {
            if (episode.getId() == id) {
                return episode;
            }
        }
        throw new IllegalArgumentException("Episode with id " + id + " was not found");
    }

    @Override
    public @NonNull Other getOtherById(long id) {
        for (Other other : mOthers) {
            if (other.getId() == id) {
                return other;
            }
        }
        throw new IllegalArgumentException("Other with id " + id + " was not found");
    }

    private void addUpdateCallback(@NonNull Set<UpdateCallback> callbacks,
            @NonNull UpdateCallback callback) {
        if (!callbacks.add(callback)) {
            throw new IllegalArgumentException("Callback " + callback + " already added in " +
                    callbacks);
        }
    }

    private void removeUpdateCallback(@NonNull Set<UpdateCallback> callbacks,
            @NonNull UpdateCallback callback) {
        if (!callbacks.remove(callback)) {
            throw new IllegalArgumentException("Callback " + callback + " not found in " +
                    callbacks);
        }
    }

    private void addAudios(@NonNull Collection<Audio> audios) {
        int audiosIndex = mAudios.size();
        int audiosCount = 0;

        mAudios.addAll(audios);
        audiosCount += audios.size();

        if (audiosCount > 0) {
            for (UpdateCallback callback : mAudioUpdateCallbacks) {
                callback.onItemsInserted(audiosIndex, audiosCount);
            }
        }
    }

    private void addArtists(@NonNull Collection<Artist> artists) {
        int artistsIndex = mArtists.size();
        int artistsCount = 0;

        mArtists.addAll(artists);
        artistsCount += artists.size();

        if (artistsCount > 0) {
            for (UpdateCallback callback : mArtistUpdateCallbacks) {
                callback.onItemsInserted(artistsIndex, artistsCount);
            }
        }
    }

    private void addAlbums(@NonNull Collection<Album> albums) {
        int albumsIndex = mAlbums.size();
        int albumsCount = 0;

        mAlbums.addAll(albums);
        albumsCount += albums.size();

        if (albumsCount > 0) {
            for (UpdateCallback callback : mAlbumUpdateCallbacks) {
                callback.onItemsInserted(albumsIndex, albumsCount);
            }
        }
    }

    private void addGenres(@NonNull Collection<Genre> genres) {
        int genresIndex = mGenres.size();
        int genresCount = 0;

        mGenres.addAll(genres);
        genresCount += genres.size();

        if (genresCount > 0) {
            for (UpdateCallback callback : mGenreUpdateCallbacks) {
                callback.onItemsInserted(genresIndex, genresCount);
            }
        }
    }

    private void addPlaylists(@NonNull Collection<Playlist> playlists) {
        int playlistsIndex = mPlaylists.size();
        int playlistsCount = 0;

        mPlaylists.addAll(playlists);
        playlistsCount += playlists.size();

        if (playlistsCount > 0) {
            for (UpdateCallback callback : mPlaylistUpdateCallbacks) {
                callback.onItemsInserted(playlistsIndex, playlistsCount);
            }
        }
    }

    private void addMovies(@NonNull Collection<Movie> movies) {
        int moviesIndex = mMovies.size();
        int moviesCount = 0;

        mMovies.addAll(movies);
        moviesCount += movies.size();

        if (moviesCount > 0) {
            for (UpdateCallback callback : mMovieUpdateCallbacks) {
                callback.onItemsInserted(moviesIndex, moviesCount);
            }
        }
    }

    private void addSeries(@NonNull Collection<Series> series) {
        int seriesIndex = mSeries.size();
        int seriesCount = 0;

        mSeries.addAll(series);
        seriesCount += series.size();

        if (seriesCount > 0) {
            for (UpdateCallback callback : mSeriesUpdateCallbacks) {
                callback.onItemsInserted(seriesIndex, seriesCount);
            }
        }
    }

    private void addEpisodes(@NonNull Collection<Episode> episodes) {
        int episodesIndex = mEpisodes.size();
        int episodesCount = 0;

        mEpisodes.addAll(episodes);
        episodesCount += episodes.size();

        if (episodesCount > 0) {
            for (UpdateCallback callback : mEpisodeUpdateCallbacks) {
                callback.onItemsInserted(episodesIndex, episodesCount);
            }
        }
    }

    private void addOthers(@NonNull Collection<Other> others) {
        int othersIndex = mOthers.size();
        int othersCount = 0;

        mOthers.addAll(others);
        othersCount += others.size();

        if (othersCount > 0) {
            for (UpdateCallback callback : mOtherUpdateCallbacks) {
                callback.onItemsInserted(othersIndex, othersCount);
            }
        }
    }

    private void updateAudio(@NonNull Audio audio) {
        int index = mAudios.indexOf(audio);
        if (index != -1) {
            for (UpdateCallback callback : mAudioUpdateCallbacks) {
                callback.onItemsUpdated(index, 1);
            }
        }
    }

    private void updateArtist(@NonNull Artist artist) {
        int index = mArtists.indexOf(artist);
        if (index != -1) {
            for (UpdateCallback callback : mArtistUpdateCallbacks) {
                callback.onItemsUpdated(index, 1);
            }
        }
    }

    private void updateAlbum(@NonNull Album album) {
        int index = mAlbums.indexOf(album);
        if (index != -1) {
            for (UpdateCallback callback : mAlbumUpdateCallbacks) {
                callback.onItemsUpdated(index, 1);
            }
        }
    }

    private void updateGenre(@NonNull Genre genre) {
        int index = mGenres.indexOf(genre);
        if (index != -1) {
            for (UpdateCallback callback : mGenreUpdateCallbacks) {
                callback.onItemsUpdated(index, 1);
            }
        }
    }

    private void updatePlaylist(@NonNull Playlist playlist) {
        int index = mPlaylists.indexOf(playlist);
        if (index != -1) {
            for (UpdateCallback callback : mPlaylistUpdateCallbacks) {
                callback.onItemsUpdated(index, 1);
            }
        }
    }

    private void updateMovie(@NonNull Movie movie) {
        int index = mMovies.indexOf(movie);
        if (index != -1) {
            for (UpdateCallback callback : mMovieUpdateCallbacks) {
                callback.onItemsUpdated(index, 1);
            }
        }
    }

    private void updateSeries(@NonNull Series series) {
        int index = mSeries.indexOf(series);
        if (index != -1) {
            for (UpdateCallback callback : mSeriesUpdateCallbacks) {
                callback.onItemsUpdated(index, 1);
            }
        }
    }

    private void updateEpisode(@NonNull Episode episode) {
        int index = mEpisodes.indexOf(episode);
        if (index != -1) {
            for (UpdateCallback callback : mEpisodeUpdateCallbacks) {
                callback.onItemsUpdated(index, 1);
            }
        }
    }

    private void updateOther(@NonNull Other other) {
        int index = mOthers.indexOf(other);
        if (index != -1) {
            for (UpdateCallback callback : mOtherUpdateCallbacks) {
                callback.onItemsUpdated(index, 1);
            }
        }
    }
}