Skip to content

Commit

Permalink
feat(android): implement delete event for ListView and TableView (#12649
Browse files Browse the repository at this point in the history
)

Fixes TIMOB-28402
  • Loading branch information
build committed Mar 23, 2021
1 parent 0749a30 commit 6b60f5f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,12 @@ public void swipeItem(int adapterIndex)
final TiTableView tableView = getTableView();

if (tableView != null) {
final TableViewRowProxy item = tableView.getAdapterItem(adapterIndex);
final TableViewSectionProxy section = (TableViewSectionProxy) item.getParent();
final TableViewRowProxy row = tableView.getAdapterItem(adapterIndex);
final TableViewSectionProxy section = (TableViewSectionProxy) row.getParent();

section.remove(item);
row.fireSyncEvent(TiC.EVENT_DELETE, null);

section.remove(row);
}
}

Expand Down Expand Up @@ -420,6 +422,17 @@ private TableViewSectionProxy getSectionByIndex(int index)
return this.sections.get(index);
}

/**
* Obtain section index from section.
*
* @param section Section in table.
* @return Integer of index.
*/
private int getIndexOfSection(TableViewSectionProxy section)
{
return this.sections.indexOf(section);
}

/**
* Get current section count.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ public void swipeItem(int adapterIndex)
final ListItemProxy item = listView.getAdapterItem(adapterIndex);
final ListSectionProxy section = (ListSectionProxy) item.getParent();

item.fireSyncEvent(TiC.EVENT_DELETE, null);

section.deleteItemsAt(item.getIndexInSection(), 1, null);
}
}
Expand Down
5 changes: 5 additions & 0 deletions android/titanium/src/java/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ public class TiC
*/
public static final String EVENT_COMPLETE = "complete";

/**
* @module.api
*/
public static final String EVENT_DELETE = "delete";

/**
* @module.api
*/
Expand Down
4 changes: 2 additions & 2 deletions apidoc/Titanium/UI/ListView.yml
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ events:
Note that the `sectionIndex` and `itemIndex` properties of this event correspond to the List View state
before the user action.
platforms: [iphone, ipad, macos]
since: 3.2.0
platforms: [android, iphone, ipad, macos]
since: {android: "10.0.0", iphone: "3.2.0", ipad: "3.2.0", macos: "9.2.0"}
properties:
- name: section
summary: List section from which the item is deleted.
Expand Down
3 changes: 2 additions & 1 deletion apidoc/Titanium/UI/TableView.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ events:

- name: delete
summary: Fired when a table row is deleted by the user.
platforms: [iphone, ipad, macos]
platforms: [android, iphone, ipad, macos]
since: {android: "10.0.0"}
properties:
- name: detail
summary: Indicates whether the delete button was clicked. Always `false` for this event.
Expand Down

0 comments on commit 6b60f5f

Please sign in to comment.