Bug 980152 - Update code style in some Panel classes. r=lucasr

This commit is contained in:
Wes Johnston 2014-03-25 12:44:21 -07:00
parent 8a4fcc5c66
commit d3558bbfb3
3 changed files with 43 additions and 42 deletions

View File

@ -27,18 +27,18 @@ public class PanelGridView extends GridView
implements DatasetBacked, PanelView { implements DatasetBacked, PanelView {
private static final String LOGTAG = "GeckoPanelGridView"; private static final String LOGTAG = "GeckoPanelGridView";
private final ViewConfig mViewConfig; private final ViewConfig viewConfig;
private final PanelViewAdapter mAdapter; private final PanelViewAdapter adapter;
private PanelViewItemHandler mItemHandler; private PanelViewItemHandler itemHandler;
public PanelGridView(Context context, ViewConfig viewConfig) { public PanelGridView(Context context, ViewConfig viewConfig) {
super(context, null, R.attr.panelGridViewStyle); super(context, null, R.attr.panelGridViewStyle);
mViewConfig = viewConfig; this.viewConfig = viewConfig;
mItemHandler = new PanelViewItemHandler(viewConfig); itemHandler = new PanelViewItemHandler(viewConfig);
mAdapter = new PanelViewAdapter(context, viewConfig); adapter = new PanelViewAdapter(context, viewConfig);
setAdapter(mAdapter); setAdapter(adapter);
setOnItemClickListener(new PanelGridItemClickListener()); setOnItemClickListener(new PanelGridItemClickListener());
} }
@ -46,29 +46,29 @@ public class PanelGridView extends GridView
@Override @Override
public void onDetachedFromWindow() { public void onDetachedFromWindow() {
super.onDetachedFromWindow(); super.onDetachedFromWindow();
mItemHandler.setOnItemOpenListener(null); itemHandler.setOnItemOpenListener(null);
} }
@Override @Override
public void setDataset(Cursor cursor) { public void setDataset(Cursor cursor) {
mAdapter.swapCursor(cursor); adapter.swapCursor(cursor);
} }
@Override @Override
public void setOnItemOpenListener(OnItemOpenListener listener) { public void setOnItemOpenListener(OnItemOpenListener listener) {
mItemHandler.setOnItemOpenListener(listener); itemHandler.setOnItemOpenListener(listener);
} }
@Override @Override
public void setFilterManager(FilterManager filterManager) { public void setFilterManager(FilterManager filterManager) {
mAdapter.setFilterManager(filterManager); adapter.setFilterManager(filterManager);
mItemHandler.setFilterManager(filterManager); itemHandler.setFilterManager(filterManager);
} }
private class PanelGridItemClickListener implements AdapterView.OnItemClickListener { private class PanelGridItemClickListener implements AdapterView.OnItemClickListener {
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
mItemHandler.openItemAtPosition(mAdapter.getCursor(), position); itemHandler.openItemAtPosition(adapter.getCursor(), position);
} }
} }
} }

View File

@ -21,55 +21,56 @@ import android.widget.TextView;
import com.squareup.picasso.Picasso; import com.squareup.picasso.Picasso;
class PanelItemView extends LinearLayout { class PanelItemView extends LinearLayout {
private final TextView mTitle; private final TextView title;
private final TextView mDescription; private final TextView description;
private final ImageView mImage; private final ImageView image;
private final LinearLayout mTitleDescContainer; private final LinearLayout titleDescContainer;
private PanelItemView(Context context, int layoutId) { private PanelItemView(Context context, int layoutId) {
super(context); super(context);
LayoutInflater.from(context).inflate(layoutId, this); LayoutInflater.from(context).inflate(layoutId, this);
mTitle = (TextView) findViewById(R.id.title); title = (TextView) findViewById(R.id.title);
mDescription = (TextView) findViewById(R.id.description); description = (TextView) findViewById(R.id.description);
mImage = (ImageView) findViewById(R.id.image); image = (ImageView) findViewById(R.id.image);
mTitleDescContainer = (LinearLayout) findViewById(R.id.title_desc_container); titleDescContainer = (LinearLayout) findViewById(R.id.title_desc_container);
} }
public void updateFromCursor(Cursor cursor) { public void updateFromCursor(Cursor cursor) {
int titleIndex = cursor.getColumnIndexOrThrow(HomeItems.TITLE); int titleIndex = cursor.getColumnIndexOrThrow(HomeItems.TITLE);
final String title = cursor.getString(titleIndex); final String titleText = cursor.getString(titleIndex);
// Only show title if the item has one // Only show title if the item has one
final boolean hasTitle = !TextUtils.isEmpty(title); final boolean hasTitle = !TextUtils.isEmpty(titleText);
mTitle.setVisibility(hasTitle ? View.VISIBLE : View.GONE); title.setVisibility(hasTitle ? View.VISIBLE : View.GONE);
titleDescContainer.setVisibility(hasTitle ? View.VISIBLE : View.GONE);
if (hasTitle) { if (hasTitle) {
mTitle.setText(title); title.setText(titleText);
} }
int descriptionIndex = cursor.getColumnIndexOrThrow(HomeItems.DESCRIPTION); int descriptionIndex = cursor.getColumnIndexOrThrow(HomeItems.DESCRIPTION);
final String description = cursor.getString(descriptionIndex); final String descriptionText = cursor.getString(descriptionIndex);
// Only show description if the item has one // Only show description if the item has one
final boolean hasDescription = !TextUtils.isEmpty(description); final boolean hasDescription = !TextUtils.isEmpty(descriptionText);
mDescription.setVisibility(hasDescription ? View.VISIBLE : View.GONE); description.setVisibility(hasDescription ? View.VISIBLE : View.GONE);
if (hasDescription) { if (hasDescription) {
mDescription.setText(description); description.setText(descriptionText);
} }
mTitleDescContainer.setVisibility(hasTitle || hasDescription ? View.VISIBLE : View.GONE); titleDescContainer.setVisibility(hasTitle || hasDescription ? View.VISIBLE : View.GONE);
int imageIndex = cursor.getColumnIndexOrThrow(HomeItems.IMAGE_URL); int imageIndex = cursor.getColumnIndexOrThrow(HomeItems.IMAGE_URL);
final String imageUrl = cursor.getString(imageIndex); final String imageUrl = cursor.getString(imageIndex);
// Only try to load the image if the item has define image URL // Only try to load the image if the item has define image URL
final boolean hasImageUrl = !TextUtils.isEmpty(imageUrl); final boolean hasImageUrl = !TextUtils.isEmpty(imageUrl);
mImage.setVisibility(hasImageUrl ? View.VISIBLE : View.GONE); image.setVisibility(hasImageUrl ? View.VISIBLE : View.GONE);
if (hasImageUrl) { if (hasImageUrl) {
Picasso.with(getContext()) Picasso.with(getContext())
.load(imageUrl) .load(imageUrl)
.into(mImage); .into(image);
} }
} }

View File

@ -21,18 +21,18 @@ class PanelViewAdapter extends CursorAdapter {
private static final int VIEW_TYPE_ITEM = 0; private static final int VIEW_TYPE_ITEM = 0;
private static final int VIEW_TYPE_BACK = 1; private static final int VIEW_TYPE_BACK = 1;
private final Context mContext; private final ViewConfig viewConfig;
private final ViewConfig mViewConfig; private FilterManager filterManager;
private FilterManager mFilterManager; private final Context context;
public PanelViewAdapter(Context context, ViewConfig viewConfig) { public PanelViewAdapter(Context context, ViewConfig viewConfig) {
super(context, null, 0); super(context, null, 0);
mContext = context; this.context = context;
mViewConfig = viewConfig; this.viewConfig = viewConfig;
} }
public void setFilterManager(FilterManager manager) { public void setFilterManager(FilterManager manager) {
mFilterManager = manager; this.filterManager = manager;
} }
@Override @Override
@ -66,9 +66,9 @@ class PanelViewAdapter extends CursorAdapter {
private View newView(Context context, int position, ViewGroup parent) { private View newView(Context context, int position, ViewGroup parent) {
if (getItemViewType(position) == VIEW_TYPE_BACK) { if (getItemViewType(position) == VIEW_TYPE_BACK) {
return new PanelBackItemView(context, mViewConfig.getBackImageUrl()); return new PanelBackItemView(context, viewConfig.getBackImageUrl());
} else { } else {
return PanelItemView.create(context, mViewConfig.getItemType()); return PanelItemView.create(context, viewConfig.getItemType());
} }
} }
@ -76,7 +76,7 @@ class PanelViewAdapter extends CursorAdapter {
if (isShowingBack()) { if (isShowingBack()) {
if (position == 0) { if (position == 0) {
final PanelBackItemView item = (PanelBackItemView) view; final PanelBackItemView item = (PanelBackItemView) view;
item.updateFromFilter(mFilterManager.getPreviousFilter()); item.updateFromFilter(filterManager.getPreviousFilter());
return; return;
} }
@ -89,7 +89,7 @@ class PanelViewAdapter extends CursorAdapter {
} }
private boolean isShowingBack() { private boolean isShowingBack() {
return (mFilterManager != null ? mFilterManager.canGoBack() : false); return (filterManager != null ? filterManager.canGoBack() : false);
} }
private final Cursor getCursor(int position) { private final Cursor getCursor(int position) {