@@ -695,7 +695,7 @@ public void searchDevices() {
695695 * @return the player
696696 */
697697 public List <Player > initializePlayers (DIDLObject didlObject ) {
698- return initializePlayers (toItemList (didlObject , 3 ));
698+ return initializePlayers (toItemList (didlObject ));
699699 }
700700
701701 /**
@@ -886,17 +886,18 @@ public List<Player> getCurrentPlayers(AvTransport transport) {
886886 * @param didlContent the content
887887 * @return all items included in the content
888888 **/
889- public List <Item > toItemList (DIDLContent didlContent , int depth ) {
890- List < Item > items = new ArrayList <>();
889+ public List <Item > toItemList (DIDLContent didlContent ) {
890+
891891 if (didlContent == null ) {
892- return items ;
892+ return new ArrayList <>() ;
893893 }
894+ List <Item > items = new ArrayList <>();
894895 items .addAll (didlContent .getItems ());
895- if (depth == 0 ) {
896- return items ;
897- }
896+ int itemCount = items .size ();
898897 for (Container c : didlContent .getContainers ()) {
899- items .addAll (toItemList (c , depth - 1 ));
898+ List <Item > containerItems = toItemList (c , itemCount );
899+ itemCount += containerItems .size ();
900+ items .addAll (containerItems );
900901 }
901902 return items ;
902903 }
@@ -907,14 +908,27 @@ public List<Item> toItemList(DIDLContent didlContent, int depth) {
907908 * @param didlObject the content
908909 * @return the list of cling items
909910 */
910- public List <Item > toItemList (DIDLObject didlObject , int depth ) {
911+ public List <Item > toItemList (DIDLObject didlObject ) {
912+ return toItemList (didlObject , 0 );
913+ }
914+
915+ private List <Item > toItemList (DIDLObject didlObject , int currentResultSize ) {
916+ if (currentResultSize >= Integer .parseInt (getPreferences ().getString (getContext ().getString (R .string .settings_browse_max_results_key ), "1000" ))) {
917+ return new ArrayList <>();
918+ }
911919 List <Item > items = new ArrayList <>();
912- if (didlObject instanceof Container && depth != 0 ) {
920+ if (didlObject instanceof Container ) {
913921 DIDLContent content = loadContainer ((Container ) didlObject );
914922 if (content != null ) {
915923 items .addAll (content .getItems ());
924+ int itemCount = currentResultSize + items .size ();
925+ if (itemCount >= Integer .parseInt (getPreferences ().getString (getContext ().getString (R .string .settings_browse_max_results_key ), "1000" ))) {
926+ return items ;
927+ }
916928 for (Container includedContainer : content .getContainers ()) {
917- items .addAll (toItemList (includedContainer , depth - 1 ));
929+ List <Item > containerItems = toItemList (includedContainer , itemCount );
930+ itemCount += containerItems .size ();
931+ items .addAll (containerItems );
918932 }
919933 }
920934 } else if (didlObject instanceof Item ) {
0 commit comments