Ejemplo n.º 1
0
  private static boolean expandMediaSet(
      ArrayList<MediaPath> items, MediaSet set, int maxSelection) {
    int subCount = set.getSubMediaSetCount();
    for (int i = 0; i < subCount; i++) {
      if (!expandMediaSet(items, set.getSubMediaSet(i), maxSelection)) {
        return false;
      }
    }
    int total = set.getMediaItemCount();
    int batch = 50;
    int index = 0;

    while (index < total) {
      int count = index + batch < total ? batch : total - index;
      ArrayList<MediaItem> list = set.getMediaItem(index, count);
      if (list != null && list.size() > (maxSelection - items.size())) {
        return false;
      }
      for (MediaItem item : list) {
        items.add(item.getPath());
      }
      index += batch;
    }
    return true;
  }
Ejemplo n.º 2
0
 public ArrayList<MediaPath> getSelected(boolean expandSet, int maxSelection) {
   ArrayList<MediaPath> selected = new ArrayList<MediaPath>();
   if (mIsAlbumSet) {
     if (mInverseSelection) {
       int total = getTotalCount();
       for (int i = 0; i < total; i++) {
         MediaSet set = mSourceMediaSet.getSubMediaSet(i);
         MediaPath id = set.getPath();
         if (!mClickedSet.contains(id)) {
           if (expandSet) {
             if (!expandMediaSet(selected, set, maxSelection)) {
               return null;
             }
           } else {
             selected.add(id);
             if (selected.size() > maxSelection) {
               return null;
             }
           }
         }
       }
     } else {
       for (MediaPath id : mClickedSet) {
         if (expandSet) {
           if (!expandMediaSet(selected, mDataManager.getMediaSet(id), maxSelection)) {
             return null;
           }
         } else {
           selected.add(id);
           if (selected.size() > maxSelection) {
             return null;
           }
         }
       }
     }
   } else {
     if (mInverseSelection) {
       int total = getTotalCount();
       int index = 0;
       while (index < total) {
         int count = Math.min(total - index, MediaSet.MEDIAITEM_BATCH_FETCH_COUNT);
         ArrayList<MediaItem> list = mSourceMediaSet.getMediaItem(index, count);
         for (MediaItem item : list) {
           MediaPath id = item.getPath();
           if (!mClickedSet.contains(id)) {
             selected.add(id);
             if (selected.size() > maxSelection) {
               return null;
             }
           }
         }
         index += count;
       }
     } else {
       for (MediaPath id : mClickedSet) {
         selected.add(id);
         if (selected.size() > maxSelection) {
           return null;
         }
       }
     }
   }
   return selected;
 }