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-23390] Android: Implement contacts offset and max #8112
Conversation
Test code:- Ti.UI.backgroundColor = 'white';
var win = Ti.UI.createWindow({
exitOnClose : true,
layout : 'vertical'
});
var button = Titanium.UI.createButton({
title: 'Get Contacts Here',
top: 60
});
win.add(button);
win.open();
var performAddressBookFunction = function(){
var singleValue = [
'recordId', 'firstName', 'middleName', 'lastName', 'fullName', 'prefix', 'suffix',
'nickname', 'firstPhonetic', 'middlePhonetic', 'lastPhonetic', 'organization',
'jobTitle', 'department', 'note', 'birthday', 'created', 'modified', 'kind'
];
var multiValue = [
'email', 'address', 'phone', 'instantMessage', 'relatedNames', 'date', 'url'
];
Ti.API.info('getSizeOfAllPeople Total contacts: ' + Ti.Contacts.getSizeOfAllPeople());
var people = Ti.Contacts.getAllPeople({max:30,offset:20});
Ti.API.info('Total contacts: ' + people.length);
for (var i=0, ilen=people.length; i<ilen; i++){
Ti.API.info('---------------------'+i);
var person = people[i];
if(person != null) {
var firstname = person.firstName || "Null";
var lastname = person.lastName || "Null"
Ti.API.info(firstname+"-"+lastname);
} else {
Ti.API.info("Person is null at"+i);
}
/*
for (var j=0, jlen=singleValue.length; j<jlen; j++){
Ti.API.info(singleValue[j] + ': ' + person[singleValue[j]]);
}
for (var j=0, jlen=multiValue.length; j<jlen; j++){
Ti.API.info(multiValue[j] + ': ' + JSON.stringify(person[multiValue[j]]));
}
*/
}
};
var addressBookDisallowed = function(){
alert("Not Allowed");
};
button.addEventListener('click',function(e)
{
if (Ti.Contacts.hasContactsPermissions()) {
performAddressBookFunction();
} else {
Ti.Contacts.requestContactsPermissions(function(e) {
if (e.success) {
performAddressBookFunction();
} else {
addressBookDisallowed();
}
});
}
}); |
Do not merge yet |
@ashcoding We're trying to merge this into a new branch we are maintaining off of 5_3_X. Do you have a timeline for resolving these merge conflicts? It'd help greatly. Thanks! |
@mrkiley can you direct me to your repo/branch? This PR is being merged into master and it might be very different from your 5_3_X. In any case, I'll get this merged conflict resolved. |
This is only for Android. This to implement Pagination in Ti.Contacts.getAllPeople(). An example for usage is as follows: ```javascript var people = Ti.Contacts.getAllPeople({max:5,offset:10}); ``` This will set the max number of persons returned to be 5 and sets the offset to be from index 10 onwards. Eg, Persons number 10, 11, 12, 13 and 14.
Implemented a method called ```Ti.Contacts.getSizeOfAllPeople()``` that will get the total size of all the contacts for Android. This is to be used with the properties ```max`` and ```offset``` in ```Ti.Contacts.getAllPeople()```.
@sgtcoolguy Could you take a look and review this? Thank you. |
Thanks for getting back to me so quickly @ashcoding, and thanks for resolving the merge conflicts. We are still experiencing some issues. We set our max to 500, with an offset of 0 (to start). We have a total of 2708 contacts to loop through. After retrieving the first 500, the offset gets set to 500. Upon the second retrieval attempt, the JNI error pops up again:
I only adjusted you sample code above a tiny bit in order to accommodate looping over multiple iterations to retrieve all of the contacts in the user's address book. See below: `
};` I also attempted to call the same Thoughts on what's going on here, and a potential fix? Is the workaround still hitting the underlying issue? |
It looks like it might still be the same issue. |
@ashcoding, we are still having issues with it, and none of our lower-level workarounds have been successful. The developer (@nbannister85) who has been taking point on it will add in some details around that below. |
I think the issue goes beyond contacts in general, but could represents a deeper problem. I could be wrong but in getting contacts, appcelerator creates an array of PersonProxy's.... |
@nbannister85 thanks for the info. You could be on to something. Will need to investigate this further. cc: @sgtcoolguy fyi. |
Any updates on this @ashcoding? |
@ashcoding @mrkiley I think this PR doesn't address the root cause. I believe this should fix the issue: #8147 |
Not to say we wouldn't want to improve the API to allow more control over the number of records returned... |
Closing this PR as it is unnecessary. #8147 PR aims to solve the root of the issue. |
JIRA: https://jira.appcelerator.org/browse/TIMOB-23390
Description:
This is only for Android.
This to implement Pagination in Ti.Contacts.getAllPeople(). An example
for usage is as follows:
This will set the max number of persons returned to be 5 and sets the
offset to be from index 10 onwards. Eg, Persons number 10, 11, 12, 13
and 14.