forked from tidev/titanium-sdk
/
TableViewRowProxy.java
142 lines (122 loc) · 3.54 KB
/
TableViewRowProxy.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2010 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
package ti.modules.titanium.ui;
import java.util.ArrayList;
import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.titanium.TiContext;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.view.TiUIView;
import ti.modules.titanium.ui.widget.tableview.TableViewModel;
import ti.modules.titanium.ui.widget.tableview.TiTableViewRowProxyItem;
import ti.modules.titanium.ui.widget.tableview.TableViewModel.Item;
import android.app.Activity;
import android.os.Message;
@Kroll.proxy(creatableInModule=UIModule.class)
public class TableViewRowProxy extends TiViewProxy
{
protected ArrayList<TiViewProxy> controls;
protected TiTableViewRowProxyItem tableViewItem;
private static final int MSG_SET_DATA = TiViewProxy.MSG_LAST_ID + 5001;
public TableViewRowProxy(TiContext tiContext) {
super(tiContext);
}
@Override
public TiUIView createView(Activity activity) {
return null;
}
public ArrayList<TiViewProxy> getControls() {
return controls;
}
public boolean hasControls() {
return (controls != null && controls.size() > 0);
}
@Override
public TiViewProxy[] getChildren() {
return controls.toArray(new TiViewProxy[controls.size()]);
}
public void add(TiViewProxy control) {
if (controls == null) {
controls = new ArrayList<TiViewProxy>();
}
controls.add(control);
control.setParent(this);
}
public void setTableViewItem(TiTableViewRowProxyItem item) {
this.tableViewItem = item;
}
public TableViewProxy getTable() {
TiViewProxy parent = getParent();
while (!(parent instanceof TableViewProxy) && parent != null) {
parent = parent.getParent();
}
return (TableViewProxy)parent;
}
@Override
public void setProperty(String key, Object value) {
super.setProperty(key, value);
if (tableViewItem != null) {
Message msg = getUIHandler().obtainMessage(MSG_SET_DATA);
msg.sendToTarget();
}
}
@Override
public boolean handleMessage(Message msg) {
if (msg.what == MSG_SET_DATA) {
if (tableViewItem != null) {
tableViewItem.setRowData(this);
}
return true;
}
return super.handleMessage(msg);
}
@Override
public String toString() {
return "[object TiUITableViewRow]";
}
@Override
public boolean fireEvent(String eventName, KrollDict data) {
if (eventName.equals("click")) {
// inject row click data for events coming from row children
TableViewProxy table = getTable();
Item item = tableViewItem.getRowData();
if (table != null && item != null) {
TableViewModel model = table.getTableView().getModel();
data.put("rowData", item.rowData);
data.put("section", model.getSection(item.sectionIndex));
data.put("row", item.proxy);
data.put("index", item.index);
data.put("detail", false);
}
}
return super.fireEvent(eventName, data);
}
public void setLabelsClickable(boolean clickable) {
if (controls != null) {
for (TiViewProxy control : controls) {
if (control instanceof LabelProxy) {
((LabelProxy)control).setClickable(clickable);
}
}
}
}
@Override
public void releaseViews()
{
super.releaseViews();
if (tableViewItem != null) {
tableViewItem.release();
tableViewItem = null;
}
if (controls != null){
for (TiViewProxy control : controls) {
control.releaseViews();
}
controls.clear();
}
}
}