diff options
author | Jesse Morgan <jesse@jesterpm.net> | 2014-07-01 07:22:43 -0700 |
---|---|---|
committer | Jesse Morgan <jesse@jesterpm.net> | 2014-07-01 07:22:43 -0700 |
commit | 96b757060a802cf906ce56e19a99e2ad10351600 (patch) | |
tree | 0372793e4ee85cfa91313e760f3eccb63e9c3d77 /src/com/p4square/grow/model | |
parent | 1e1092ee66c03642b6a3004ece982b6ca83c3c0a (diff) |
Adding support for moving videos between chapters.
Also moved the Playlist related tests to their own class.
Diffstat (limited to 'src/com/p4square/grow/model')
-rw-r--r-- | src/com/p4square/grow/model/Chapter.java | 8 | ||||
-rw-r--r-- | src/com/p4square/grow/model/Playlist.java | 42 |
2 files changed, 39 insertions, 11 deletions
diff --git a/src/com/p4square/grow/model/Chapter.java b/src/com/p4square/grow/model/Chapter.java index 4d59983..7b6e27c 100644 --- a/src/com/p4square/grow/model/Chapter.java +++ b/src/com/p4square/grow/model/Chapter.java @@ -49,6 +49,14 @@ public class Chapter implements Cloneable { } /** + * Remove the VideoRecord for a video id. + * @param videoId The id to remove. + */ + public void removeVideoRecord(String videoId) { + mVideos.remove(videoId); + } + + /** * @return true if every required video has been completed. */ @JsonIgnore diff --git a/src/com/p4square/grow/model/Playlist.java b/src/com/p4square/grow/model/Playlist.java index 79ce68e..b697e66 100644 --- a/src/com/p4square/grow/model/Playlist.java +++ b/src/com/p4square/grow/model/Playlist.java @@ -49,6 +49,22 @@ public class Playlist { } /** + * @param videoId The video to search for. + * @return the Chapter containing videoId. + */ + private Chapter findChapter(String videoId) { + for (Chapter chapter : mPlaylist.values()) { + VideoRecord r = chapter.getVideoRecord(videoId); + + if (r != null) { + return chapter; + } + } + + return null; + } + + /** * @return The last modified date of the source playlist. */ public Date getLastUpdated() { @@ -141,26 +157,30 @@ public class Playlist { Chapter myChapter = mPlaylist.get(entry.getKey()); if (myChapter == null) { - // Add entire chapter - try { - mPlaylist.put(chapterName, theirChapter.clone()); - } catch (CloneNotSupportedException e) { - throw new RuntimeException(e); // Unexpected... - } + // Add new chapter + myChapter = new Chapter(); + addChapter(chapterName, myChapter); + } - } else { - // Check chapter for missing videos - for (Map.Entry<String, VideoRecord> videoEntry : theirChapter.getVideos().entrySet()) { - String videoId = videoEntry.getKey(); - VideoRecord myVideo = myChapter.getVideoRecord(videoId); + // Check chapter for missing videos + for (Map.Entry<String, VideoRecord> videoEntry : theirChapter.getVideos().entrySet()) { + String videoId = videoEntry.getKey(); + VideoRecord myVideo = myChapter.getVideoRecord(videoId); + if (myVideo == null) { + myVideo = find(videoId); if (myVideo == null) { + // New Video try { myVideo = videoEntry.getValue().clone(); myChapter.setVideoRecord(videoId, myVideo); } catch (CloneNotSupportedException e) { throw new RuntimeException(e); // Unexpected... } + } else { + // Video moved + findChapter(videoId).removeVideoRecord(videoId); + myChapter.setVideoRecord(videoId, myVideo); } } } |