-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
TableViewRowProxy.java
259 lines (231 loc) Β· 6.74 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2013 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 java.util.HashMap;
import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.TiContext;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.view.TiUIView;
import ti.modules.titanium.ui.widget.TiUITableView;
import ti.modules.titanium.ui.widget.tableview.TableViewModel;
import ti.modules.titanium.ui.widget.tableview.TableViewModel.Item;
import ti.modules.titanium.ui.widget.tableview.TiTableViewRowProxyItem;
import android.app.Activity;
import android.os.Message;
@Kroll.proxy(creatableInModule=UIModule.class,
propertyAccessors = {
TiC.PROPERTY_HAS_CHECK,
TiC.PROPERTY_HAS_CHILD,
TiC.PROPERTY_CLASS_NAME,
TiC.PROPERTY_LAYOUT,
TiC.PROPERTY_LEFT_IMAGE,
TiC.PROPERTY_RIGHT_IMAGE,
TiC.PROPERTY_TITLE,
TiC.PROPERTY_HEADER,
TiC.PROPERTY_FOOTER
})
public class TableViewRowProxy extends TiViewProxy
{
private static final String TAG = "TableViewRowProxy";
protected ArrayList<TiViewProxy> controls;
protected TiTableViewRowProxyItem tableViewItem;
private static final int MSG_SET_DATA = TiViewProxy.MSG_LAST_ID + 5001;
public TableViewRowProxy()
{
super();
}
public TableViewRowProxy(TiContext tiContext)
{
this();
}
@Override
public void setActivity(Activity activity)
{
super.setActivity(activity);
if (controls != null) {
for (TiViewProxy control : controls) {
control.setActivity(activity);
}
}
}
@Override
public void handleCreationDict(KrollDict options)
{
super.handleCreationDict(options);
if (options.containsKey(TiC.PROPERTY_SELECTED_BACKGROUND_COLOR)) {
Log.w(TAG, "selectedBackgroundColor is deprecated, use backgroundSelectedColor instead");
setProperty(TiC.PROPERTY_BACKGROUND_SELECTED_COLOR, options.get(TiC.PROPERTY_SELECTED_BACKGROUND_COLOR));
}
if (options.containsKey(TiC.PROPERTY_SELECTED_BACKGROUND_IMAGE)) {
Log.w(TAG, "selectedBackgroundImage is deprecated, use backgroundSelectedImage instead");
setProperty(TiC.PROPERTY_BACKGROUND_SELECTED_IMAGE, options.get(TiC.PROPERTY_SELECTED_BACKGROUND_IMAGE));
}
}
public void setCreationProperties(KrollDict options)
{
for (String key : options.keySet()) {
setProperty(key, options.get(key));
}
}
@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()
{
if (controls == null) {
return new TiViewProxy[0];
}
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);
if (tableViewItem != null) {
Message message = getMainHandler().obtainMessage(MSG_SET_DATA);
// Message msg = getUIHandler().obtainMessage(MSG_SET_DATA);
message.sendToTarget();
}
}
@Override
public void remove(TiViewProxy control)
{
if (controls == null) {
return;
}
controls.remove(control);
if (tableViewItem != null) {
Message message = getMainHandler().obtainMessage(MSG_SET_DATA);
// Message msg = getUIHandler().obtainMessage(MSG_SET_DATA);
message.sendToTarget();
}
}
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 name, Object value, boolean fireChange)
{
super.setProperty(name, value, fireChange);
if (tableViewItem != null) {
if (TiApplication.isUIThread()) {
tableViewItem.setRowData(this);
} else {
Message message = getMainHandler().obtainMessage(MSG_SET_DATA);
// Message msg = getUIHandler().obtainMessage(MSG_SET_DATA);
message.sendToTarget();
}
}
}
@Override
public boolean handleMessage(Message msg)
{
if (msg.what == MSG_SET_DATA) {
if (tableViewItem != null) {
tableViewItem.setRowData(this);
// update/refresh table view when a row's data changed.
TiUITableView table = getTable().getTableView();
table.setModelDirty();
table.updateView();
}
return true;
}
return super.handleMessage(msg);
}
public static void fillClickEvent(HashMap<String, Object> data, TableViewModel model, Item item)
{
// Don't include rowData if we click on a section
if (!(item.proxy instanceof TableViewSectionProxy)) {
data.put(TiC.PROPERTY_ROW_DATA, item.rowData);
}
data.put(TiC.PROPERTY_SECTION, model.getSection(item.sectionIndex));
data.put(TiC.EVENT_PROPERTY_ROW, item.proxy);
data.put(TiC.EVENT_PROPERTY_INDEX, item.index);
data.put(TiC.EVENT_PROPERTY_DETAIL, false);
}
@Override
public boolean fireEvent(String eventName, Object data, boolean bubbles)
{
// Inject row click data for events coming from row children.
TableViewProxy table = getTable();
Item item = tableViewItem.getRowData();
if (table != null && item != null && data instanceof HashMap) {
// The data object may already be in use by the runtime thread
// due to a child view's event fire. Create a copy to be thread safe.
@SuppressWarnings("unchecked")
KrollDict dataCopy = new KrollDict((HashMap<String, Object>) data);
fillClickEvent(dataCopy, table.getTableView().getModel(), item);
data = dataCopy;
}
return super.fireEvent(eventName, data, bubbles);
}
@Override
public void firePropertyChanged(String name, Object oldValue, Object newValue)
{
super.firePropertyChanged(name, oldValue, newValue);
TableViewProxy table = getTable();
if (table != null) {
table.updateView();
}
}
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();
}
}
}
public TiTableViewRowProxyItem getTableViewRowProxyItem()
{
return tableViewItem;
}
}