1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.gallery3d.data; 18 19 import com.android.gallery3d.R; 20 import com.android.gallery3d.app.GalleryApp; 21 import com.android.gallery3d.util.Future; 22 23 // ComboAlbumSet combines multiple media sets into one. It lists all sub 24 // media sets from the input album sets. 25 // This only handles SubMediaSets, not MediaItems. (That's all we need now) 26 public class ComboAlbumSet extends MediaSet implements ContentListener { 27 private static final String TAG = "ComboAlbumSet"; 28 private final MediaSet[] mSets; 29 private final String mName; 30 ComboAlbumSet(Path path, GalleryApp application, MediaSet[] mediaSets)31 public ComboAlbumSet(Path path, GalleryApp application, MediaSet[] mediaSets) { 32 super(path, nextVersionNumber()); 33 mSets = mediaSets; 34 for (MediaSet set : mSets) { 35 set.addContentListener(this); 36 } 37 mName = application.getResources().getString( 38 R.string.set_label_all_albums); 39 } 40 41 @Override getSubMediaSet(int index)42 public MediaSet getSubMediaSet(int index) { 43 for (MediaSet set : mSets) { 44 int size = set.getSubMediaSetCount(); 45 if (index < size) { 46 return set.getSubMediaSet(index); 47 } 48 index -= size; 49 } 50 return null; 51 } 52 53 @Override getSubMediaSetCount()54 public int getSubMediaSetCount() { 55 int count = 0; 56 for (MediaSet set : mSets) { 57 count += set.getSubMediaSetCount(); 58 } 59 return count; 60 } 61 62 @Override getName()63 public String getName() { 64 return mName; 65 } 66 67 @Override reload()68 public long reload() { 69 boolean changed = false; 70 for (int i = 0, n = mSets.length; i < n; ++i) { 71 long version = mSets[i].reload(); 72 if (version > mDataVersion) changed = true; 73 } 74 if (changed) mDataVersion = nextVersionNumber(); 75 return mDataVersion; 76 } 77 onContentDirty()78 public void onContentDirty() { 79 notifyContentChanged(); 80 } 81 82 @Override requestSync(SyncListener listener)83 public Future<Integer> requestSync(SyncListener listener) { 84 return requestSyncOnEmptySets(mSets, listener); 85 } 86 } 87