-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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-12176: fix list view issues #3972
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
36db095
timob-12176: fix a bunch of issues
hieupham007 0ad28a9
timob-12176: address comments
hieupham007 af5b9ee
timob-12176: fix various problems
hieupham007 3411993
timob-12176: add disclosure image
hieupham007 49f8552
Merge branch 'master' of git://github.com/appcelerator/titanium_mobil…
hieupham007 35f778e
Merge branch 'master' of git://github.com/appcelerator/titanium_mobil…
hieupham007 63d3d09
timob-12176: row should be highlighted when clicked
hieupham007 352d93d
timob-12176: fix crash
hieupham007 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,11 @@ public class ListSectionProxy extends ViewProxy{ | |
private static final int MSG_DELETE_ITEMS_AT = MSG_FIRST_ID + 703; | ||
private static final int MSG_GET_ITEM_AT = MSG_FIRST_ID + 704; | ||
private static final int MSG_REPLACE_ITEMS_AT = MSG_FIRST_ID + 705; | ||
private static final int MSG_UPDATE_ITEM_AT = MSG_FIRST_ID + 706; | ||
private static final int MSG_GET_ITEMS = MSG_FIRST_ID + 707; | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
@@ -91,6 +96,9 @@ public void handleCreationDict(KrollDict dict) { | |
if (dict.containsKey(TiC.PROPERTY_FOOTER_TITLE)) { | ||
footerTitle = TiConvert.toString(dict, TiC.PROPERTY_FOOTER_TITLE); | ||
} | ||
if (dict.containsKey(TiC.PROPERTY_ITEMS)) { | ||
handleSetItems(dict.get(TiC.PROPERTY_ITEMS)); | ||
} | ||
} | ||
|
||
public void setAdapter(TiBaseAdapter a) { | ||
|
@@ -143,6 +151,12 @@ public boolean handleMessage(Message msg) | |
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; | ||
|
@@ -186,14 +200,23 @@ public boolean handleMessage(Message msg) | |
result.setResult(item); | ||
return true; | ||
} | ||
|
||
case MSG_UPDATE_ITEM_AT: { | ||
AsyncResult result = (AsyncResult) msg.obj; | ||
KrollDict data = (KrollDict) result.getArg(); | ||
int index = data.getInt("index"); | ||
handleUpdateItemAt(index, data.get("data")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TiC constant |
||
result.setResult(null); | ||
return true; | ||
} | ||
|
||
default : { | ||
return super.handleMessage(msg); | ||
} | ||
|
||
} | ||
} | ||
|
||
@Kroll.method | ||
public KrollDict getItemAt(int index) { | ||
if (TiApplication.isUIThread()) { | ||
|
@@ -210,14 +233,22 @@ private KrollDict handleGetItemAt(int index) { | |
return null; | ||
} | ||
|
||
@Kroll.method | ||
@Kroll.method @Kroll.setProperty | ||
public void setItems(Object data) { | ||
if (TiApplication.isUIThread()) { | ||
handleSetItems(data); | ||
} else { | ||
TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_SET_ITEMS), data); | ||
} | ||
|
||
} | ||
|
||
@Kroll.method @Kroll.getProperty | ||
public Object[] getItems() { | ||
if (TiApplication.isUIThread()) { | ||
return itemProperties.toArray(); | ||
} else { | ||
return (Object[]) TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_GET_ITEMS)); | ||
} | ||
} | ||
|
||
@Kroll.method | ||
|
@@ -282,12 +313,33 @@ public void replaceItemsAt(int index, int count, Object data) { | |
} | ||
} | ||
|
||
@Kroll.method | ||
public void updateItemAt(int index, Object data) { | ||
if (!isIndexValid(index) || !(data instanceof HashMap)) { | ||
return; | ||
} | ||
|
||
if (TiApplication.isUIThread()) { | ||
handleUpdateItemAt(index, new Object[]{data}); | ||
} else { | ||
KrollDict d = new KrollDict(); | ||
d.put("index", index); | ||
d.put("data", new Object[]{data}); | ||
TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_UPDATE_ITEM_AT), d); | ||
} | ||
} | ||
|
||
|
||
public void processPreloadData() { | ||
if (itemProperties != null && preload) { | ||
handleSetItems(itemProperties.toArray()); | ||
preload = false; | ||
} | ||
} | ||
|
||
public void refreshItems() { | ||
handleSetItems(itemProperties.toArray()); | ||
} | ||
|
||
private void processData(Object[] items, int offset) { | ||
if (listItemData == null) { | ||
|
@@ -399,17 +451,20 @@ private void handleInsertItemsAt(int index, Object data) { | |
} | ||
} | ||
|
||
private void deleteItems(int index, int count) { | ||
private boolean deleteItems(int index, int count) { | ||
boolean delete = false; | ||
while (count > 0) { | ||
if (index < itemProperties.size()) { | ||
itemProperties.remove(index); | ||
itemCount--; | ||
delete = true; | ||
} | ||
if (index < listItemData.size()) { | ||
listItemData.remove(index); | ||
} | ||
count--; | ||
} | ||
return delete; | ||
} | ||
|
||
private void handleDeleteItemsAt(int index, int count) { | ||
|
@@ -420,8 +475,14 @@ private void handleDeleteItemsAt(int index, int count) { | |
} | ||
|
||
private void handleReplaceItemsAt(int index, int count, Object data) { | ||
deleteItems(index, count); | ||
handleInsertItemsAt(index, data); | ||
if (deleteItems(index, count)) { | ||
handleInsertItemsAt(index, data); | ||
} | ||
} | ||
|
||
private void handleUpdateItemAt(int index, Object data) { | ||
handleReplaceItemsAt(index, 1, data); | ||
setProperty(TiC.PROPERTY_ITEMS, itemProperties.toArray()); | ||
} | ||
|
||
private TiListViewTemplate processTemplate(KrollDict itemData, int index) { | ||
|
@@ -487,7 +548,7 @@ private TiListViewTemplate processDefaultTemplate(KrollDict data, int index) { | |
* @param index Entry's index relative to its section | ||
* @return | ||
*/ | ||
public void generateCellContent(int index, KrollDict data, TiListViewTemplate template, TiBaseListViewItem itemContent, int itemPosition, View item_layout) { | ||
public void generateCellContent(int sectionIndex, KrollDict data, TiListViewTemplate template, TiBaseListViewItem itemContent, int itemPosition, View item_layout) { | ||
//Here we create an item content and populate it with data | ||
//Get item proxy | ||
TiViewProxy itemProxy = template.getRootItem().getViewProxy(); | ||
|
@@ -498,7 +559,7 @@ public void generateCellContent(int index, KrollDict data, TiListViewTemplate te | |
|
||
if (data != null && template != null) { | ||
generateChildContentViews(template.getRootItem(), null, itemContent, true); | ||
populateViews(data, itemContent, template, itemPosition, index, item_layout); | ||
populateViews(data, itemContent, template, itemPosition, sectionIndex, item_layout); | ||
} | ||
} | ||
|
||
|
@@ -524,25 +585,24 @@ public void generateChildContentViews(DataItem item, TiUIView parentContent, TiB | |
} | ||
} | ||
|
||
public void appendExtraEventData(TiUIView view, int itemPosition, int sectionIndex, String bindId) { | ||
public void appendExtraEventData(TiUIView view, int itemIndex, int sectionIndex, String bindId) { | ||
KrollDict existingData = view.getAdditionalEventData(); | ||
if (existingData == null) { | ||
existingData = new KrollDict(); | ||
view.setAdditionalEventData(existingData); | ||
} | ||
|
||
if (headerTitle != null) { | ||
itemPosition -= 1; | ||
sectionIndex -= 1; | ||
itemIndex -= 1; | ||
} | ||
|
||
existingData.put(TiC.PROPERTY_SECTION, this); | ||
existingData.put(TiC.PROPERTY_SECTION_INDEX, sectionIndex); | ||
existingData.put(TiC.PROPERTY_BIND_ID, bindId); | ||
existingData.put(TiC.PROPERTY_ITEM_INDEX, itemPosition); | ||
existingData.put(TiC.PROPERTY_ITEM_INDEX, itemIndex); | ||
} | ||
|
||
public void populateViews(KrollDict data, TiBaseListViewItem cellContent, TiListViewTemplate template, int itemPosition, int sectionIndex, View item_layout) { | ||
public void populateViews(KrollDict data, TiBaseListViewItem cellContent, TiListViewTemplate template, int itemIndex, int sectionIndex, View item_layout) { | ||
Object cell = cellContent.getTag(); | ||
|
||
HashMap<String, ViewItem> views = (HashMap<String, ViewItem>) cellContent.getViewsMap(); | ||
|
@@ -552,7 +612,7 @@ public void populateViews(KrollDict data, TiBaseListViewItem cellContent, TiList | |
ViewItem viewItem = views.get(binding); | ||
TiUIView view = viewItem.getView(); | ||
if (view != null) { | ||
appendExtraEventData(view, itemPosition, sectionIndex, binding); | ||
appendExtraEventData(view, itemIndex, sectionIndex, binding); | ||
} | ||
//if binding is contain in data given to us, process that data, otherwise | ||
//apply default properties. | ||
|
@@ -581,7 +641,7 @@ public void populateViews(KrollDict data, TiBaseListViewItem cellContent, TiList | |
} | ||
|
||
TiListItem listItem = (TiListItem) cell; | ||
appendExtraEventData(listItem, itemPosition, sectionIndex, TiC.PROPERTY_PROPERTIES); | ||
appendExtraEventData(listItem, itemIndex, sectionIndex, TiC.PROPERTY_PROPERTIES); | ||
if (data.containsKey(TiC.PROPERTY_PROPERTIES)) { | ||
KrollDict properties = new KrollDict((HashMap)data.get(TiC.PROPERTY_PROPERTIES)); | ||
KrollDict diffProperties = cellContent.getViewItem().generateDiffProperties(properties); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use TiC constant.