Bug 839854 - Protect against getChildAt returning a null view during a rotation. r=mfinkle

This commit is contained in:
Wes Johnston 2013-07-09 15:18:56 -07:00
parent 07f8b773ce
commit 44c4084a64

View File

@ -124,6 +124,11 @@ public class TopSitesView extends GridView {
// We can assume that the adapter count and view count are the same in this case because our grid view
// force all items to be visible all the time
View view = getChildAt(info.position);
// The grid view might get temporarily out of sync with the
// adapter refreshes (e.g. on device rotation)
if (view == null) {
return;
}
TopSitesViewHolder holder = (TopSitesViewHolder) view.getTag();
if (TextUtils.isEmpty(holder.getUrl())) {
menu.findItem(R.id.abouthome_open_new_tab).setVisible(false);
@ -288,8 +293,9 @@ public class TopSitesView extends GridView {
// The grid view might get temporarily out of sync with the
// adapter refreshes (e.g. on device rotation)
if (view == null)
if (view == null) {
continue;
}
TopSitesViewHolder holder = (TopSitesViewHolder)view.getTag();
final String url = holder.getUrl();
@ -510,6 +516,11 @@ public class TopSitesView extends GridView {
private void clearThumbnailsWithUrl(final String url) {
for (int i = 0; i < mTopSitesAdapter.getCount(); i++) {
final View view = getChildAt(i);
// The grid view might get temporarily out of sync with the
// adapter refreshes (e.g. on device rotation)
if (view == null) {
continue;
}
final TopSitesViewHolder holder = (TopSitesViewHolder) view.getTag();
if (holder.getUrl().equals(url)) {
@ -550,6 +561,11 @@ public class TopSitesView extends GridView {
final int position = info.position;
final View v = getChildAt(position);
// The grid view might get temporarily out of sync with the
// adapter refreshes (e.g. on device rotation)
if (v == null) {
return;
}
final TopSitesViewHolder holder = (TopSitesViewHolder) v.getTag();
final String url = holder.getUrl();
// Quickly update the view so that there isn't as much lag between the request and response
@ -568,6 +584,11 @@ public class TopSitesView extends GridView {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
final int position = info.position;
View v = getChildAt(position);
// The grid view might get temporarily out of sync with the
// adapter refreshes (e.g. on device rotation)
if (v == null) {
return;
}
final TopSitesViewHolder holder = (TopSitesViewHolder) v.getTag();
holder.setPinned(true);
@ -599,6 +620,11 @@ public class TopSitesView extends GridView {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
int position = info.position;
View v = getChildAt(position);
// The grid view might get temporarily out of sync with the
// adapter refreshes (e.g. on device rotation)
if (v == null) {
return;
}
TopSitesViewHolder holder = (TopSitesViewHolder) v.getTag();
// Decode "user-entered" URLs before showing them to the user to edit.
@ -621,6 +647,11 @@ public class TopSitesView extends GridView {
return;
final View v = getChildAt(position);
// The grid view might get temporarily out of sync with the
// adapter refreshes (e.g. on device rotation)
if (v == null) {
return;
}
final TopSitesViewHolder holder = (TopSitesViewHolder) v.getTag();
String title = data.getStringExtra(AwesomeBar.TITLE_KEY);