From a550b630fca5957939bea9ea7319e6a248407fd8 Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Fri, 9 Feb 2018 22:05:08 -0800 Subject: Playlist Merge Improvements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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). --- .../java/com/p4square/grow/model/Playlist.java | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/main/java/com') 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 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 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()); + } } } } -- cgit v1.2.3