Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-10458] Android: TableSection - header views are not sorted correc... #3033

Merged
merged 3 commits into from
Oct 4, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

import ti.modules.titanium.ui.TableViewProxy;
import ti.modules.titanium.ui.TableViewRowProxy;
import ti.modules.titanium.ui.widget.TiUILabel;
import ti.modules.titanium.ui.widget.TiView;
import ti.modules.titanium.ui.widget.searchbar.TiUISearchBar.OnSearchChangeListener;
import ti.modules.titanium.ui.widget.tableview.TableViewModel.Item;
import android.graphics.Color;
Expand Down Expand Up @@ -190,10 +192,9 @@ public View getView(int position, View convertView, ViewGroup parent) {
if (v == null) {
if (item.className.equals(TableViewProxy.CLASSNAME_HEADERVIEW)) {
TiViewProxy vproxy = item.proxy;
View headerView = layoutHeaderOrFooter(vproxy);
TiUIView headerView = layoutHeaderOrFooter(vproxy);
v = new TiTableViewHeaderItem(proxy.getActivity(), headerView);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return was removed here because it bypassed setRowData(). With the fix,
setRowData() is necessary to populate the data for a TiTableViewHeaderItem.

v.setClassName(TableViewProxy.CLASSNAME_HEADERVIEW);
return v;
} else if (item.className.equals(TableViewProxy.CLASSNAME_HEADER)) {
v = new TiTableViewHeaderItem(proxy.getActivity());
v.setClassName(TableViewProxy.CLASSNAME_HEADER);
Expand Down Expand Up @@ -319,11 +320,11 @@ public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCoun
adapter = new TTVListAdapter(viewModel);
if (proxy.hasProperty(TiC.PROPERTY_HEADER_VIEW)) {
TiViewProxy view = (TiViewProxy) proxy.getProperty(TiC.PROPERTY_HEADER_VIEW);
listView.addHeaderView(layoutHeaderOrFooter(view), null, false);
listView.addHeaderView(layoutHeaderOrFooter(view).getNativeView(), null, false);
}
if (proxy.hasProperty(TiC.PROPERTY_FOOTER_VIEW)) {
TiViewProxy view = (TiViewProxy) proxy.getProperty(TiC.PROPERTY_FOOTER_VIEW);
listView.addFooterView(layoutHeaderOrFooter(view), null, false);
listView.addFooterView(layoutHeaderOrFooter(view).getNativeView(), null, false);
}

listView.setAdapter(adapter);
Expand Down Expand Up @@ -429,7 +430,7 @@ protected boolean rowClicked(TiBaseTableViewItem rowView, int position, boolean
}
}

private View layoutHeaderOrFooter(TiViewProxy viewProxy)
private TiUIView layoutHeaderOrFooter(TiViewProxy viewProxy)
{
TiUIView tiView = viewProxy.getOrCreateView();
View nativeView = tiView.getNativeView();
Expand All @@ -453,7 +454,7 @@ private View layoutHeaderOrFooter(TiViewProxy viewProxy)
}
AbsListView.LayoutParams p = new AbsListView.LayoutParams(width, height);
nativeView.setLayoutParams(p);
return nativeView;
return tiView;
}

public void dataSetChanged() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,25 @@
*/
package ti.modules.titanium.ui.widget.tableview;


import org.appcelerator.titanium.TiContext;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.TiUIHelper;
import org.appcelerator.titanium.view.TiUIView;

import ti.modules.titanium.ui.widget.tableview.TableViewModel.Item;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Handler;
import android.view.Gravity;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class TiTableViewHeaderItem extends TiBaseTableViewItem
{
private RowView rowView;
private View headerView;
private TiUIView headerView;
private boolean isHeaderView = false;

class RowView extends RelativeLayout
Expand Down Expand Up @@ -75,11 +77,11 @@ public TiTableViewHeaderItem(Activity activity) {
setMinimumHeight((int)TiUIHelper.getRawDIPSize(18, activity));
}

public TiTableViewHeaderItem(Activity activity, View headerView) {
public TiTableViewHeaderItem(Activity activity, TiUIView headerView) {
super(activity);

this.handler = new Handler(this);
this.addView(headerView, headerView.getLayoutParams());
this.addView(headerView.getNativeView(), headerView.getLayoutParams());
this.setLayoutParams(headerView.getLayoutParams());
setMinimumHeight((int)TiUIHelper.getRawDIPSize(18, activity));
this.headerView = headerView;
Expand All @@ -89,10 +91,30 @@ public TiTableViewHeaderItem(TiContext tiContext, Activity activity)
{
this(activity);
}

public void setRowData(Item item) {
if (!isHeaderView) {
rowView.setRowData(item);
}
else
{
setHeaderData(item);
}
}

private void setHeaderData(Item item)
{
if (headerView != null && headerView.getChildren() != null && headerView.getChildren().size() > 0 &&
item != null && item.proxy != null && item.proxy.getChildren() != null &&
item.proxy.getChildren().length > 0) {
TiUIView labelView = headerView.getChildren().get(0);
TiViewProxy labelProxy = item.proxy.getChildren()[0];
if (labelView != null && labelProxy != null)
{
labelView.processProperties(labelProxy.getProperties());
}

}
}

public Item getRowData() {
Expand All @@ -113,7 +135,7 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
if (!isHeaderView) {
rowView.layout(left, 0, right, bottom - top);
} else {
headerView.layout(left, 0, right, bottom - top);
headerView.getNativeView().layout(left, 0, right, bottom - top);
}
}
}