summaryrefslogtreecommitdiff
path: root/src/com/p4square/grow/model/Playlist.java
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2014-07-01 07:22:43 -0700
committerJesse Morgan <jesse@jesterpm.net>2014-07-01 07:22:43 -0700
commit96b757060a802cf906ce56e19a99e2ad10351600 (patch)
tree0372793e4ee85cfa91313e760f3eccb63e9c3d77 /src/com/p4square/grow/model/Playlist.java
parent1e1092ee66c03642b6a3004ece982b6ca83c3c0a (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/Playlist.java')
-rw-r--r--src/com/p4square/grow/model/Playlist.java42
1 files changed, 31 insertions, 11 deletions
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);
}
}
}