summaryrefslogtreecommitdiffstats
path: root/src/com/android/dreams/phototable/AlbumDataAdapter.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/dreams/phototable/AlbumDataAdapter.java')
-rw-r--r--src/com/android/dreams/phototable/AlbumDataAdapter.java28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/com/android/dreams/phototable/AlbumDataAdapter.java b/src/com/android/dreams/phototable/AlbumDataAdapter.java
index a0c039b..699fe14 100644
--- a/src/com/android/dreams/phototable/AlbumDataAdapter.java
+++ b/src/com/android/dreams/phototable/AlbumDataAdapter.java
@@ -45,6 +45,7 @@ public class AlbumDataAdapter extends ArrayAdapter<PhotoSource.AlbumData> {
private final LayoutInflater mInflater;
private final int mLayout;
private final ItemClickListener mListener;
+ private final HashSet<String> mValidAlbumIds;
public AlbumDataAdapter(Context context, SharedPreferences settings,
int resource, List<PhotoSource.AlbumData> objects) {
@@ -54,11 +55,29 @@ public class AlbumDataAdapter extends ArrayAdapter<PhotoSource.AlbumData> {
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mListener = new ItemClickListener();
- HashSet<String> validAlbumIds = new HashSet<String>(objects.size());
+ mValidAlbumIds = new HashSet<String>(objects.size());
for (PhotoSource.AlbumData albumData: objects) {
- validAlbumIds.add(albumData.id);
+ mValidAlbumIds.add(albumData.id);
}
- mSettings.pruneObsoleteSettings(validAlbumIds);
+ mSettings.pruneObsoleteSettings(mValidAlbumIds);
+ }
+
+ public boolean isSelected(int position) {
+ PhotoSource.AlbumData data = getItem(position);
+ return mSettings.isAlbumEnabled(data.id);
+ }
+
+ public boolean areAllSelected() {
+ return mSettings.areAllEnabled(mValidAlbumIds);
+ }
+
+ public void selectAll(boolean select) {
+ if (select) {
+ mSettings.enableAllAlbums(mValidAlbumIds);
+ } else {
+ mSettings.disableAllAlbums();
+ }
+ notifyDataSetChanged();
}
@Override
@@ -72,7 +91,7 @@ public class AlbumDataAdapter extends ArrayAdapter<PhotoSource.AlbumData> {
View vCheckBox = item.findViewById(R.id.enabled);
if (vCheckBox != null && vCheckBox instanceof CheckBox) {
CheckBox checkBox = (CheckBox) vCheckBox;
- checkBox.setChecked(mSettings.isAlbumEnabled(data.id));
+ checkBox.setChecked(isSelected(position));
checkBox.setTag(R.id.data_payload, data);
}
@@ -159,6 +178,7 @@ public class AlbumDataAdapter extends ArrayAdapter<PhotoSource.AlbumData> {
final boolean isChecked = !checkBox.isChecked();
checkBox.setChecked(isChecked);
mSettings.setAlbumEnabled(data.id, isChecked);
+ notifyDataSetChanged();
if (DEBUG) Log.i(TAG, data.title + " is " +
(isChecked ? "" : "not") + " enabled");
} else {