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

[6_1_0][TIMOB-24181] Android: fix ListItem template property inconsistencies #9017

Merged
merged 3 commits into from
May 17, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -454,7 +454,7 @@ private void processData(Object[] items, int offset) {
for (int i = 0; i < items.length; i++) {
Object itemData = items[i];
if (itemData instanceof HashMap) {
KrollDict d = new KrollDict((HashMap)itemData);
KrollDict d = new KrollDict((HashMap) itemData);
TiListViewTemplate template = processTemplate(d, i + offset);
template.updateOrMergeWithDefaultProperties(d, true);
temps[i] = template;
Expand All @@ -464,7 +464,7 @@ private void processData(Object[] items, int offset) {
for (int i = 0; i < items.length; i++) {
Object itemData = items[i];
if (itemData instanceof HashMap) {
KrollDict d = new KrollDict((HashMap)itemData);
KrollDict d = new KrollDict((HashMap) itemData);
TiListViewTemplate template = temps[i];
if (template != null) {
template.updateOrMergeWithDefaultProperties(d, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ public void handleCreationDict(KrollDict options) {
addPreloadSections((Object[]) obj, -1, true);
}
}
if (options.containsKey(TiC.PROPERTY_DEFAULT_ITEM_TEMPLATE)) {
setProperty(TiC.PROPERTY_DEFAULT_ITEM_TEMPLATE, options.get(TiC.PROPERTY_DEFAULT_ITEM_TEMPLATE));
}
}

public void clearPreloadSections() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ public void processProperties(KrollDict d) {
if (d.containsKey(TiC.PROPERTY_TEMPLATES)) {
Object templates = d.get(TiC.PROPERTY_TEMPLATES);
if (templates != null) {
processTemplates(new KrollDict((HashMap)templates));
processTemplates(new KrollDict((HashMap) templates));
}
}

Expand Down Expand Up @@ -815,7 +815,7 @@ private void refreshItems() {
protected void processTemplates(KrollDict templates) {
for (String key : templates.keySet()) {
//Here we bind each template with a key so we can use it to look up later
KrollDict properties = new KrollDict((HashMap)templates.get(key));
KrollDict properties = new KrollDict((HashMap) templates.get(key));
TiListViewTemplate template = new TiListViewTemplate(key, properties);
//Set type to template, for recycling purposes.
template.setType(getItemType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.appcelerator.kroll.KrollDict;
Expand Down Expand Up @@ -222,26 +223,35 @@ public DataItem getRootItem() {
return rootItem;
}

/**
*
* @param data dictionary holding properties for template
* @param update if true update entry else copy non-null values into data parameter
*/
public void updateOrMergeWithDefaultProperties(KrollDict data, boolean update) {
for (String binding: data.keySet()) {
DataItem dataItem = dataItems.get(binding);
if (dataItem == null) continue;

KrollDict defaultProps = dataItem.getDefaultProperties();
KrollDict props = new KrollDict((HashMap)data.get(binding));
KrollDict newProps = new KrollDict((HashMap) data.get(binding));
if (defaultProps != null) {
if (update) {
//update default properties
Set<String> existingKeys = defaultProps.keySet();
for (String key: props.keySet()) {
if (!existingKeys.contains(key)) {
Set<String> defaultPropsKeys = defaultProps.keySet();
for (String key: newProps.keySet()) {
if (!defaultPropsKeys.contains(key)) {
defaultProps.put(key, null);
}
}
} else {
//merge default properties with new properties and update data
HashMap<String, Object> newData = ((HashMap<String, Object>)defaultProps.clone());
newData.putAll(props);
HashMap<String, Object> newData = ((HashMap<String, Object>) defaultProps.clone());
for (Map.Entry<String, Object> entry : newProps.entrySet()) {
if (entry.getValue() != null) {
newData.put(entry.getKey(), entry.getValue());
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Your code change in the "else" statement here no longer updates the "data" argument. It's making changes to a temporary "newData" local and then throwing it away.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated.

data.put(binding, newData);
}
}
Expand Down