summaryrefslogtreecommitdiff
path: root/src/com/p4square
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/p4square')
-rw-r--r--src/com/p4square/grow/model/Chapter.java8
-rw-r--r--src/com/p4square/grow/model/Playlist.java42
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);
}
}
}