     }
 
     
-    // MARK: - CategoryCellDelegate Methods
-    
+    // MARK: - Sub-Categories Addition/Removal
+    
+    func addSubCaterories(toCategoryID categoryTapped: PiwigoAlbumData) {
+        // Build list of categories from complete known list
+        let allCategories: [PiwigoAlbumData] = CategoriesData.sharedInstance().allCategories
+
+        // Proposed list is collected in diff
+        var diff: [PiwigoAlbumData] = []
+
+        // Look for categories which are not already displayed
+        /// - Non-admin Community users can only upload in specific albums
+        /// - Only add sub-categories of tapped category
+        /// - Do not add the current category
+        let filteredCat = allCategories.filter({ Model.sharedInstance().hasAdminRights || $0.hasUploadRights })
+            .filter({ $0.nearestUpperCategory == categoryTapped.albumId })
+        for category in filteredCat {   // Don't use forEach to keep the order
+            // Is this category already in displayed list?
+            if !categories.contains(where: { $0.albumId == category.albumId }) {
+                diff.append(category)
+            }
+        }
+
+        // Build list of categories to be displayed
+        for category in diff {
+            // Should we add sub-categories?
+            if category.upperCategories.count > 0 {
+                var indexOfParent = 0
+                for existingCategory in categories {
+                    if category.containsUpperCategory(existingCategory.albumId) {
+                        categories.insert(category, at: indexOfParent + 1)
+                        break
+                    }
+                    indexOfParent += 1
+                }
+            }
+        }
+
+        // Add tapped category to list of categories having shown sub-categories
+        categoriesThatShowSubCategories.append(categoryTapped.albumId)
+
+        // Reload table view
+        categoriesTableView.reloadData()
+    }
+
+    func removeSubCategories(toCategoryID categoryTapped: PiwigoAlbumData) {
+        // Proposed list is collected in diff
+        var diff: [PiwigoAlbumData] = []
+
+        // Look for sub-categories to remove
+        categories.filter({ $0.albumId != categoryTapped.albumId}).forEach { category in
+            // Remove the sub-categories
+            let upperCategories = category.upperCategories
+            if upperCategories?.contains(String(format: "%ld", Int(categoryTapped.albumId))) ?? false {
+                diff.append(category)
+            }
+        }
+
+        // Remove objects from displayed list
+        categories = categories.filter({ !diff.contains($0) })
+
+        // Remove tapped category from list of categories having shown sub-categories
+        if categoriesThatShowSubCategories.contains(categoryTapped.albumId) {
+            categoriesThatShowSubCategories.removeAll { $0 as AnyObject === NSNumber(value: categoryTapped.albumId) as AnyObject }
+        }
+
+        // Sub-categories will not be known if user closes several layers at once
+        // and caching option loadAllCategoryInfo is not activated
+        if !Model.sharedInstance().loadAllCategoryInfo {
+            //        NSLog(@"subCategories => getAlbumListForCategory(%ld,NO,NO)", (long)categoryTapped.albumId);
+
+            // Show loading HD
+            showHUDwithTitle(NSLocalizedString("loadingHUD_label", comment: "Loading…"))
+
+            AlbumService.getAlbumList(forCategory: categoryTapped.albumId,
+                                      usingCache: false,
+                                      inRecursiveMode: Model.sharedInstance().loadAllCategoryInfo,
+                                      onCompletion: { task, albums in
+                // Hide loading HUD
+                self.hideHUD {
+                    // Reload table view
+                    self.categoriesTableView.reloadData()
+                }
+            }, onFailure: { task, error in
+                // Hide loading HUD
+                self.hideHUD {
+                    print(String(format: "getAlbumListForCategory: %@", error?.localizedDescription ?? ""))
+                }
+            })
+        } else {
+            // Reload table view
+            categoriesTableView.reloadData()
+        }
+    }
+}
+
+
+// MARK: - CategoryCellDelegate Methods
+extension SelectCategoryViewController: CategoryCellDelegate {
+    // Called when the user taps a sub-category button
     func tappedDisclosure(of categoryTapped: PiwigoAlbumData) {
         
         // Build list of categories from list of known categories

}

@objc
class SelectCategoryViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, CategoryCellDelegate {

    @objc weak var delegate: SelectCategoryDelegate?
    

                                    })
        }
    }
}
