@Kroll.method public void replaceItemsAt(int index, int count, Object data) { if (!isIndexValid(index)) { return; } if (TiApplication.isUIThread()) { handleReplaceItemsAt(index, count, data); } else { KrollDict d = new KrollDict(); d.put(TiC.EVENT_PROPERTY_INDEX, index); d.put(TiC.PROPERTY_COUNT, count); d.put(TiC.PROPERTY_DATA, data); TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_REPLACE_ITEMS_AT), d); } }
private void handleUpdateItemAt(int index, Object data) { handleReplaceItemsAt(index, 1, data); setProperty(TiC.PROPERTY_ITEMS, itemProperties.toArray()); }
@Override public boolean handleMessage(Message msg) { switch (msg.what) { case MSG_SET_ITEMS: { AsyncResult result = (AsyncResult) msg.obj; handleSetItems(result.getArg()); result.setResult(null); return true; } case MSG_GET_ITEMS: { AsyncResult result = (AsyncResult) msg.obj; result.setResult(itemProperties.toArray()); return true; } case MSG_APPEND_ITEMS: { AsyncResult result = (AsyncResult) msg.obj; handleAppendItems(result.getArg()); result.setResult(null); return true; } case MSG_INSERT_ITEMS_AT: { AsyncResult result = (AsyncResult) msg.obj; KrollDict data = (KrollDict) result.getArg(); int index = data.getInt(TiC.EVENT_PROPERTY_INDEX); handleInsertItemsAt(index, data.get(TiC.PROPERTY_DATA)); result.setResult(null); return true; } case MSG_DELETE_ITEMS_AT: { AsyncResult result = (AsyncResult) msg.obj; KrollDict data = (KrollDict) result.getArg(); int index = data.getInt(TiC.EVENT_PROPERTY_INDEX); int count = data.getInt(TiC.PROPERTY_COUNT); handleDeleteItemsAt(index, count); result.setResult(null); return true; } case MSG_REPLACE_ITEMS_AT: { AsyncResult result = (AsyncResult) msg.obj; KrollDict data = (KrollDict) result.getArg(); int index = data.getInt(TiC.EVENT_PROPERTY_INDEX); int count = data.getInt(TiC.PROPERTY_COUNT); handleReplaceItemsAt(index, count, data.get(TiC.PROPERTY_DATA)); result.setResult(null); return true; } case MSG_GET_ITEM_AT: { AsyncResult result = (AsyncResult) msg.obj; KrollDict item = handleGetItemAt(TiConvert.toInt(result.getArg())); result.setResult(item); return true; } case MSG_UPDATE_ITEM_AT: { AsyncResult result = (AsyncResult) msg.obj; KrollDict data = (KrollDict) result.getArg(); int index = data.getInt(TiC.EVENT_PROPERTY_INDEX); handleUpdateItemAt(index, data.get(TiC.PROPERTY_DATA)); result.setResult(null); return true; } default: { return super.handleMessage(msg); } } }