diff options
author | Jesse Morgan <jesse@jesterpm.net> | 2018-02-09 22:05:08 -0800 |
---|---|---|
committer | Jesse Morgan <jesse@jesterpm.net> | 2018-02-09 22:05:08 -0800 |
commit | a550b630fca5957939bea9ea7319e6a248407fd8 (patch) | |
tree | 22832b90510dc205524110bd7abd7cfb2dfeb160 /src/main/java | |
parent | b4b71b902493cac1e5b57c70ab53961c26ceb323 (diff) |
Playlist Merge Improvements
Don’t force a user to revisit a previously completed chapter if a new required
video is added.
Don’t force the user to complete videos which have been removed (because they
can’t).
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/com/p4square/grow/model/Playlist.java | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/main/java/com/p4square/grow/model/Playlist.java b/src/main/java/com/p4square/grow/model/Playlist.java index 201b3e2..39976a6 100644 --- a/src/main/java/com/p4square/grow/model/Playlist.java +++ b/src/main/java/com/p4square/grow/model/Playlist.java @@ -152,6 +152,12 @@ public class Playlist { * * Merge is accomplished by adding all missing Chapters and VideoRecords to * this playlist. + * + * Additionally, + * * any "required" videos that are only present in this playlist are + * marked as "not required". + * * any new "required" videos in a completed chapter are marked as + * "not required". */ public void merge(Playlist source) { if (source.getLastUpdated().before(mLastUpdated)) { @@ -170,6 +176,18 @@ public class Playlist { addChapter(chapterName, myChapter); } + // If my chapter is already complete, no new videos will be required. + boolean myChapterComplete = true; + + for (Map.Entry<String, VideoRecord> videoEntry : myChapter.getVideos().entrySet()) { + VideoRecord myVideo = videoEntry.getValue(); + myChapterComplete &= (myVideo.getComplete() || !myVideo.getRequired()); + + // Mark all existing, uncompleted videos as not required. + // We'll mark them as required again if they are required in the new playlist. + myVideo.setRequired(myVideo.getRequired() && myVideo.getComplete()); + } + // Check chapter for missing videos for (Map.Entry<String, VideoRecord> videoEntry : theirChapter.getVideos().entrySet()) { String videoId = videoEntry.getKey(); @@ -182,6 +200,9 @@ public class Playlist { try { myVideo = videoEntry.getValue().clone(); myChapter.setVideoRecord(videoId, myVideo); + if (myChapterComplete) { + myVideo.setRequired(false); + } } catch (CloneNotSupportedException e) { throw new RuntimeException(e); // Unexpected... } @@ -190,6 +211,13 @@ public class Playlist { findChapter(videoId).removeVideoRecord(videoId); myChapter.setVideoRecord(videoId, myVideo); } + } else { + // Copy the required property from the newer video. + // However, like new videos, newly required videos aren't applied to completed + // chapters. + if (!myChapterComplete) { + myVideo.setRequired(videoEntry.getValue().getRequired()); + } } } } |