Permalink
Browse files

Move some of the changes in AccountFolder to CategoryFolder.

Just for code organization -- no functional change.
  • Loading branch information...
tlc
tlc committed Jan 30, 2011
1 parent 691054b commit 41daa9284424f770b9076bcdb290993d6b3458e4
Showing with 47 additions and 38 deletions.
  1. +5 −38 src/net/pms/external/smugmug/AccountFolder.java
  2. +42 −0 src/net/pms/external/smugmug/CategoryFolder.java
@@ -18,21 +18,16 @@
*/
package net.pms.external.smugmug;
-import java.util.Map.Entry;
-
import static net.pms.external.smugmug.SmugMugPlugin.getAccount;
import net.pms.PMS;
import net.pms.dlna.virtual.VirtualFolder;
import com.kallasoft.smugmug.api.json.entity.Album;
-import com.kallasoft.smugmug.api.json.entity.Category;
import com.kallasoft.smugmug.api.json.v1_2_1.APIVersionConstants;
import com.kallasoft.smugmug.api.json.v1_2_1.albums.Get;
import com.kallasoft.smugmug.api.json.v1_2_1.albums.Get.GetResponse;
-import net.pms.external.smugmug.CategoryFolder.AlbumList;
-import net.pms.external.smugmug.CategoryFolder.Cat;
-import net.pms.external.smugmug.CategoryFolder.CatListMap;
+import net.pms.external.smugmug.CategoryFolder;
public class AccountFolder extends VirtualFolder {
@@ -47,7 +42,6 @@ public AccountFolder(String id) {
public void discoverChildren() {
addChild(new RecentAdditionsFolder(accountId));
Account account = getAccount(accountId);
-
Get get = new Get();
final GetResponse getResponse = get.execute(APIVersionConstants.UNSECURE_SERVER_URL,
account.getApikey(),
@@ -61,42 +55,15 @@ public void discoverChildren() {
}
// categories
- // Some albums in categories have subcategories, some don't.
- // Sort them into our structures.
- final CatListMap catMap = new CatListMap();
- for (Album album : getResponse.getAlbumList()) {
- Cat cat;
- // get or create the Cat representation
- cat = catMap.get(album.getCategory().getName());
- if (cat == null) {
- cat = new Cat();
- catMap.put(album.getCategory().getName(), cat);
- }
-
- // is a subcatagory specified?
- Category subCat = album.getSubCategory();
- if (subCat == null) {
- cat.albums.add(album);
- } else {
- // get or create the subCat representation
- String scName = subCat.getName();
- Cat sub = cat.subCats.get(scName);
- if (sub == null) {
- sub = new Cat();
- cat.subCats.put(scName, sub);
- }
-
- sub.albums.add(album);
- }
- }
-
addChild(new VirtualFolder("Categories", null) {
@Override
public void discoverChildren() {
super.discoverChildren();
- for (Entry<String,Cat> e : catMap.entrySet()) {
- addChild(new CategoryFolder(accountId, e.getKey(), e.getValue().subCats, e.getValue().albums));
+ for (CategoryFolder cf : CategoryFolder.getFolders(accountId, getResponse.getAlbumList())) {
+ addChild(cf);
}
+
+
}
});
@@ -20,11 +20,13 @@
import java.util.ArrayList;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map.Entry;
import net.pms.dlna.virtual.VirtualFolder;
import com.kallasoft.smugmug.api.json.entity.Album;
+import com.kallasoft.smugmug.api.json.entity.Category;
public class CategoryFolder extends VirtualFolder {
@@ -65,4 +67,44 @@ public void discoverChildren() {
}
}
}
+
+ static List<CategoryFolder> getFolders(final String accountId, List<Album> albumList)
+ {
+ // categories
+ // Some albums in categories have subcategories, some don't.
+ // Sort them into our structures.
+ final CatListMap catMap = new CatListMap();
+ for (Album album : albumList) {
+ Cat cat;
+ // get or create the Cat representation
+ cat = catMap.get(album.getCategory().getName());
+ if (cat == null) {
+ cat = new Cat();
+ catMap.put(album.getCategory().getName(), cat);
+ }
+
+ // is a subcatagory specified?
+ Category subCat = album.getSubCategory();
+ if (subCat == null) {
+ cat.albums.add(album);
+ } else {
+ // get or create the subCat representation
+ String scName = subCat.getName();
+ Cat sub = cat.subCats.get(scName);
+ if (sub == null) {
+ sub = new Cat();
+ cat.subCats.put(scName, sub);
+ }
+
+ sub.albums.add(album);
+ }
+ }
+
+ List<CategoryFolder> folders = new ArrayList<CategoryFolder>();
+ for (Entry<String,Cat> e : catMap.entrySet()) {
+ folders.add(new CategoryFolder(accountId, e.getKey(), e.getValue().subCats, e.getValue().albums));
+ }
+
+ return folders;
+ }
}

0 comments on commit 41daa92

Please sign in to comment.