use of com.vodafone360.people.datatypes.Identity in project 360-Engine-for-Android by 360.
the class IdentityEngine method pushIdentitiesToUi.
/**
* Pushes the identities retrieved by get my identities or by get available identities
* to the ui.
*
* @param request The request type: either get my identities, or get available identities.
*/
private void pushIdentitiesToUi(ServiceUiRequest request) {
String requestKey = null;
ArrayList<Identity> idBundle = null;
if (request == ServiceUiRequest.GET_AVAILABLE_IDENTITIES) {
requestKey = KEY_AVAILABLE_IDS;
synchronized (mAvailableIdentityList) {
// provide a shallow copy
idBundle = new ArrayList<Identity>(mAvailableIdentityList);
}
} else {
requestKey = KEY_MY_IDS;
synchronized (mMyIdentityList) {
// provide a shallow copy
idBundle = new ArrayList<Identity>(mMyIdentityList);
}
}
// send update to 3rd party identities ui if it is up
Bundle b = new Bundle();
b.putParcelableArrayList(requestKey, idBundle);
UiAgent uiAgent = mEventCallback.getUiAgent();
if (uiAgent != null && uiAgent.isSubscribed()) {
uiAgent.sendUnsolicitedUiEvent(request, b);
}
// end: send update to 3rd party identities ui if it is up
}
use of com.vodafone360.people.datatypes.Identity in project 360-Engine-for-Android by 360.
the class IdentityEngine method handleGetMyIdentitiesResponse.
/**
* Handle Server response to request for available Identities. The response
* should be a list of Identity items. The request is completed with
* ServiceStatus.SUCCESS or ERROR_UNEXPECTED_RESPONSE if the data-type
* retrieved are not Identity items.
*
* @param data List of BaseDataTypes generated from Server response.
*/
private void handleGetMyIdentitiesResponse(List<BaseDataType> data) {
LogUtils.logD("IdentityEngine: handleGetMyIdentitiesResponse");
ServiceStatus errorStatus = getResponseStatus(BaseDataType.MY_IDENTITY_DATA_TYPE, data);
if (errorStatus == ServiceStatus.SUCCESS) {
synchronized (mMyIdentityList) {
mMyIdentityList.clear();
for (BaseDataType item : data) {
Identity identity = (Identity) item;
if (!identity.isIdentityFieldBlankorNull()) {
mMyIdentityList.add(identity);
}
}
// cache the identities
MyIdentitiesCacheTable.setCachedIdentities(mDatabaseHelper.getWritableDatabase(), mMyIdentityList);
clearPendingIdentities();
}
} else if (errorStatus == ServiceStatus.ERROR_COMMS_TIMEOUT) {
// reset the pending list in case of a timeout
clearPendingIdentities();
}
pushIdentitiesToUi(ServiceUiRequest.GET_MY_IDENTITIES);
// remove any identites returned from the pending list as they are validated by now!
removePendingIdentities(mMyIdentityList);
LogUtils.logD("IdentityEngine: handleGetMyIdentitiesResponse complete request.");
}
use of com.vodafone360.people.datatypes.Identity in project 360-Engine-for-Android by 360.
the class IdentityEngine method handleDeleteIdentity.
/**
* Handle Server response of request to delete the identity. The response
* should be a status that whether the operation is succeeded or not. The
* response will be a status result otherwise ERROR_UNEXPECTED_RESPONSE if
* the response is not as expected.
*
* @param data
* List of BaseDataTypes generated from Server response.
*/
private void handleDeleteIdentity(final List<BaseDataType> data) {
Bundle bu = null;
ServiceStatus errorStatus = getResponseStatus(BaseDataType.IDENTITY_DELETION_DATA_TYPE, data);
if (errorStatus == ServiceStatus.SUCCESS) {
for (BaseDataType item : data) {
if (item.getType() == BaseDataType.IDENTITY_DELETION_DATA_TYPE) {
synchronized (mMyIdentityList) {
// iterating through the subscribed identities
for (Identity identity : mMyIdentityList) {
if (identity.mIdentityId.equals(getIdentityToBeDeleted().mIdentityId)) {
mMyIdentityList.remove(identity);
break;
}
}
// cache the new set of identities
MyIdentitiesCacheTable.setCachedIdentities(mDatabaseHelper.getWritableDatabase(), mMyIdentityList);
}
completeUiRequest(ServiceStatus.SUCCESS);
return;
} else {
completeUiRequest(ServiceStatus.ERROR_UNEXPECTED_RESPONSE);
return;
}
}
}
completeUiRequest(errorStatus, bu);
}
use of com.vodafone360.people.datatypes.Identity in project 360-Engine-for-Android by 360.
the class MyIdentitiesCacheTable method getContentValues.
/**
* Populates the provided ContentValues object with the Identity data.
*
* Note: the ContentValues object is first cleared before being filled.
*
* @param values the ContentValues object to populate
* @param identity the identity to extract the data from
* @return the provided ContentValues object
*/
private static ContentValues getContentValues(ContentValues values, Identity identity) {
int capabilities = FLAG_CAPABILITY_NONE;
values.clear();
values.put(Fields.NAME.toString(), identity.mName);
values.put(Fields.USER_NAME.toString(), identity.mUserName);
values.put(Fields.NETWORK_ID.toString(), identity.mNetwork);
if (identity.mCapabilities != null) {
for (IdentityCapability cap : identity.mCapabilities) {
if (cap.mCapability != null) {
switch(cap.mCapability) {
case chat:
if (cap.mValue)
capabilities |= FLAG_CAPABILITY_CHAT;
break;
case mail:
if (cap.mValue)
capabilities |= FLAG_CAPABILITY_MAIL;
break;
}
}
}
}
values.put(Fields.CAPABILITIES.toString(), capabilities);
return values;
}
use of com.vodafone360.people.datatypes.Identity in project 360-Engine-for-Android by 360.
the class MyIdentitiesCacheTable method getCachedIdentities.
/**
* Retrieves the saved identities.
*
* @param database the database where to read the values
* @param identities the identities array to fill
*/
public static void getCachedIdentities(SQLiteDatabase database, ArrayList<Identity> identities) {
final String[] COLUMNS = { /* 0 */
Fields.NAME.toString(), /* 1 */
Fields.USER_NAME.toString(), /* 2 */
Fields.NETWORK_ID.toString(), /* 3 */
Fields.CAPABILITIES.toString() };
Cursor cursor = null;
try {
cursor = database.query(TABLE_NAME, COLUMNS, null, null, null, null, null);
while (cursor.moveToNext()) {
final Identity identity = new Identity();
final int capabilities = cursor.getInt(3);
identity.mName = cursor.getString(0);
identity.mUserName = cursor.getString(1);
identity.mNetwork = cursor.getString(2);
identity.mCapabilities = getCapabilities(capabilities);
identities.add(identity);
}
} catch (Exception e) {
DatabaseHelper.trace(true, "MyIdentitiesCacheTable.getCachedIdentities() - Exception: " + e);
} finally {
if (cursor != null) {
cursor.close();
cursor = null;
}
}
}
Aggregations