From: David ‘Bombe’ Roden Date: Sun, 10 Apr 2011 10:40:29 +0000 (+0200) Subject: Implement album structure loading. X-Git-Tag: beta-freefall-0.6.2-1~62 X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=4448c88ba0401366f4566eb42a850ded674f8ceb Implement album structure loading. --- diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 4e3df64..6a90c7a 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -1319,6 +1319,40 @@ public class Core implements IdentityListener, UpdateListener { friends.add(friendId); } + /* load albums. */ + Map albums = new HashMap(); + List topLevelAlbums = new ArrayList(); + while (true) { + String albumPrefix = sonePrefix + "/Albums/" + albums.size(); + String albumId = configuration.getStringValue(albumPrefix + "/ID").getValue(null); + if (albumId == null) { + break; + } + String albumName = configuration.getStringValue(albumPrefix + "/Name").getValue(null); + String albumDescription = configuration.getStringValue(albumPrefix + "/Description").getValue(null); + String albumParentId = configuration.getStringValue(albumPrefix + "/Parent").getValue(null); + if ((albumName == null) || (albumDescription == null)) { + logger.log(Level.WARNING, "Invalid album found, aborting load!"); + return; + } + Album album = new Album(albumId).setSone(sone).setName(albumName).setDescription(albumDescription); + albums.put(albumId, album); + if (albumParentId != null) { + Album parentAlbum = albums.get(albumParentId); + if (parentAlbum == null) { + logger.log(Level.WARNING, "Invalid parent album ID: " + albumParentId); + return; + } + parentAlbum.addAlbum(album); + } else { + topLevelAlbums.add(album); + } + } + + /* load options. */ + sone.getOptions().addBooleanOption("AutoFollow", new DefaultOption(false)); + sone.getOptions().getBooleanOption("AutoFollow").set(configuration.getBooleanValue(sonePrefix + "/Options/AutoFollow").getValue(null)); + /* if we’re still here, Sone was loaded successfully. */ synchronized (sone) { sone.setTime(soneTime); @@ -1328,6 +1362,7 @@ public class Core implements IdentityListener, UpdateListener { sone.setLikePostIds(likedPostIds); sone.setLikeReplyIds(likedReplyIds); sone.setFriends(friends); + sone.setAlbums(topLevelAlbums); soneInserters.get(sone).setLastInsertFingerprint(lastInsertFingerprint); } synchronized (newSones) {