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

[TIMOB-18069] Android: Add itemCount to ListSection #10040

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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 @@ -705,7 +705,11 @@ public int getContentCount()
/**
* @return number of entries within section
*/
// clang-format off
@Kroll.method(name = "getFilteredItemCount")
@Kroll.getProperty(name = "filteredItemCount")
public int getItemCount()
Copy link
Collaborator

Choose a reason for hiding this comment

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

clang-format specifiers?

// clang-format on
{
int totalCount = 0;

Expand All @@ -729,7 +733,7 @@ public int getItemCount()
private boolean hideHeaderOrFooter()
{
TiListView listview = getListView();
return (listview.getSearchText() != null && filterIndices.isEmpty());
return (listview != null && listview.getSearchText() != null && filterIndices.isEmpty());
}

public boolean hasHeader()
Expand Down
24 changes: 19 additions & 5 deletions apidoc/Titanium/UI/ListSection.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ summary: A list section is a container within a list view used to organize list
description: |
Use the <Titanium.UI.createListSection> method or **`<ListSection>`** Alloy element to create a `ListSection`.

List sections are used to manipulate and organize list items contained within it. For examples
List sections are used to manipulate and organize list items contained within it. For examples
of using list sections, see the examples in <Titanium.UI.ListView> and <Titanium.UI.ListItem>.
platforms: [android, ipad, iphone]
since: '3.1.0'
Expand All @@ -13,7 +13,7 @@ excludes:
methods: [addEventListener, fireEvent, removeEventListener]
properties: [bubbleParent]
properties:

- name: footerTitle
summary: Title of this section footer.
description: |
Expand All @@ -23,13 +23,27 @@ properties:
- name: footerView
summary: View to use for this section footer.
description: |
Using this property and `footerTitle` together is not supported. Use one or the other.
Using this property and `footerTitle` together is not supported. Use one or the other.
In Alloy you can specify this property with a `<FooterView>` child element of a `<ListSection>`
element (see Examples).
type: Titanium.UI.View
since: 3.2.0
platforms: [android, iphone, ipad]

- name: itemCount
summary: Returns the item count of the section.
type: Number
since: 7.3.0
permission: read-only
platforms: [iphone, ipad]

- name: filteredItemCount
summary: Returns the item count of the section, also incorporating the search filter if active.
type: Number
since: 9.3.0
permission: read-only
platforms: [android]

- name: headerTitle
summary: Title of this section header.
description: |
Expand All @@ -39,7 +53,7 @@ properties:
- name: headerView
summary: View to use for this section header.
description: |
Using this property and `headerTitle` together is not supported. Use one or the other.
Using this property and `headerTitle` together is not supported. Use one or the other.
In Alloy you can specify this property with a `<HeaderView>` child element of a `<ListSection>`
element (see Examples).
type: Titanium.UI.View
Expand Down Expand Up @@ -185,7 +199,7 @@ examples:
<HeaderView>
<View backgroundColor="#DDD" height="Ti.UI.SIZE">
<Label>Fruits</Label>
</View>>
</View>
</HeaderView>

<ListItem title="Apple" />
Expand Down
1 change: 1 addition & 0 deletions tests/Resources/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ function loadTests() {
}
require('./ti.ui.label.test');
require('./ti.ui.layout.test');
require('./ti.ui.listsection.test');
require('./ti.ui.listview.test');
require('./ti.ui.maskedimage.test');
require('./ti.ui.matrix2d.test');
Expand Down
127 changes: 127 additions & 0 deletions tests/Resources/ti.ui.listsection.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
* Appcelerator Titanium Mobile
* Copyright (c) 2015-Present 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.
*/
/* eslint-env mocha */
/* eslint no-unused-expressions: "off" */
'use strict';
const should = require('./utilities/assertions');

describe('Titanium.UI.ListSection', function () {
this.timeout(5000);

let win;
afterEach(done => { // fires after every test in sub-suites too...
if (win && !win.closed) {
win.addEventListener('close', function listener () {
win.removeEventListener('close', listener);
win = null;
done();
});
win.close();
} else {
win = null;
done();
}
});

it('.apiName', function () {
const section = Ti.UI.createListSection();
should(section).have.readOnlyProperty('apiName').which.is.a.String();
should(section.apiName).be.eql('Ti.UI.ListSection');
});

it.android('.filteredItemCount', function (finished) {
win = Ti.UI.createWindow({
fullscreen: true
});
function genData() {
const data = [];
for (let i = 1; i <= 10; i++) {
data.push({
properties: {
title: `ROW ${i}`,
searchableText: (i % 2) ? 'a' : 'b'
}
});
}
return data;
}
const section = Ti.UI.createListSection();
section.items = genData();

const listView = Ti.UI.createListView({
sections: [ section ],
height: Ti.UI.FILL,
width: Ti.UI.FILL
});
win.add(listView);
win.addEventListener('open', function open() {
win.removeEventListener('open', open);
try {
should(section.getFilteredItemCount()).eql(10);
setTimeout(() => {
try {
listView.searchText = 'a';
// search narrows the count
should(section.filteredItemCount).eql(5);
} catch (err2) {
return finished(err2);
}
finished();
}, 1);
} catch (err) {
return finished(err);
}
});
win.open();
});

it.ios('.itemCount', function (finished) {
win = Ti.UI.createWindow({
fullscreen: true
});
function genData() {
const data = [];
for (let i = 1; i <= 10; i++) {
data.push({
properties: {
title: `ROW ${i}`,
searchableText: (i % 2) ? 'a' : 'b'
}
});
}
return data;
}
const section = Ti.UI.createListSection();
section.items = genData();

const listView = Ti.UI.createListView({
sections: [ section ],
height: Ti.UI.FILL,
width: Ti.UI.FILL
});
win.add(listView);
win.addEventListener('open', function open() {
win.removeEventListener('open', open);
try {
should(section.getItemCount()).eql(10);
setTimeout(() => {
try {
listView.searchText = 'a';
// Seraching doesn't alter the value
should(section.itemCount).eql(10);
} catch (err2) {
return finished(err2);
}
finished();
}, 1);
} catch (err) {
return finished(err);
}
});
win.open();
});
});