summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Howard <showard@google.com>2010-09-27 11:36:33 -0700
committerSteve Howard <showard@google.com>2010-09-27 15:02:44 -0700
commit57427e16d929b34a646dbcac0a16004f4a82cc9c (patch)
tree25d4e083ccea4702e1b16dc343e0dd2f403babef
parentb8bb84731680870be05ea422eb1d269e24a9c660 (diff)
downloadandroid_packages_providers_DownloadProvider-57427e16d929b34a646dbcac0a16004f4a82cc9c.zip
android_packages_providers_DownloadProvider-57427e16d929b34a646dbcac0a16004f4a82cc9c.tar.gz
android_packages_providers_DownloadProvider-57427e16d929b34a646dbcac0a16004f4a82cc9c.tar.bz2
Ensure that downloads UI switches to/from empty view as needed
Change-Id: I0eef5efd7affc34c465ce04234713874c8d6937e Bug: 3038070
-rw-r--r--ui/src/com/android/providers/downloads/ui/DownloadList.java41
1 files changed, 33 insertions, 8 deletions
diff --git a/ui/src/com/android/providers/downloads/ui/DownloadList.java b/ui/src/com/android/providers/downloads/ui/DownloadList.java
index ac73390..cdfe017 100644
--- a/ui/src/com/android/providers/downloads/ui/DownloadList.java
+++ b/ui/src/com/android/providers/downloads/ui/DownloadList.java
@@ -26,6 +26,7 @@ import android.content.DialogInterface.OnCancelListener;
import android.content.Intent;
import android.database.ContentObserver;
import android.database.Cursor;
+import android.database.DataSetObserver;
import android.net.DownloadManager;
import android.net.Uri;
import android.os.Bundle;
@@ -78,6 +79,7 @@ public class DownloadList extends Activity
private Cursor mSizeSortedCursor;
private DownloadAdapter mSizeSortedAdapter;
private MyContentObserver mContentObserver = new MyContentObserver();
+ private MyDataSetObserver mDataSetObserver = new MyDataSetObserver();
private int mStatusColumnId;
private int mIdColumnId;
@@ -106,6 +108,15 @@ public class DownloadList extends Activity
}
}
+ private class MyDataSetObserver extends DataSetObserver {
+ @Override
+ public void onChanged() {
+ // may need to switch to or from the empty view
+ chooseListToShow();
+ ensureSomeGroupIsExpanded();
+ }
+ }
+
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
@@ -142,19 +153,31 @@ public class DownloadList extends Activity
mSizeSortedAdapter = new DownloadAdapter(this, mSizeSortedCursor, this);
mSizeOrderedListView.setAdapter(mSizeSortedAdapter);
- // have the first group be open by default
- mDateOrderedListView.post(new Runnable() {
- public void run() {
- if (mDateSortedAdapter.getGroupCount() > 0) {
- mDateOrderedListView.expandGroup(0);
- }
- }
- });
+ ensureSomeGroupIsExpanded();
}
chooseListToShow();
}
+ /**
+ * If no group is expanded in the date-sorted list, expand the first one.
+ */
+ private void ensureSomeGroupIsExpanded() {
+ mDateOrderedListView.post(new Runnable() {
+ public void run() {
+ if (mDateSortedAdapter.getGroupCount() == 0) {
+ return;
+ }
+ for (int group = 0; group < mDateSortedAdapter.getGroupCount(); group++) {
+ if (mDateOrderedListView.isGroupExpanded(group)) {
+ return;
+ }
+ }
+ mDateOrderedListView.expandGroup(0);
+ }
+ });
+ }
+
private void setupViews() {
setContentView(R.layout.download_list);
setTitle(getText(R.string.download_title));
@@ -183,6 +206,7 @@ public class DownloadList extends Activity
super.onResume();
if (haveCursors()) {
mDateSortedCursor.registerContentObserver(mContentObserver);
+ mDateSortedCursor.registerDataSetObserver(mDataSetObserver);
refresh();
}
}
@@ -192,6 +216,7 @@ public class DownloadList extends Activity
super.onPause();
if (haveCursors()) {
mDateSortedCursor.unregisterContentObserver(mContentObserver);
+ mDateSortedCursor.unregisterDataSetObserver(mDataSetObserver);
}
}