use of org.awesomeapp.messenger.service.IContactListManager in project Zom-Android by zom.
the class ContactsListFragment method archiveContact.
private static void archiveContact(Activity activity, String address, int contactType, long providerId, long accountId) {
try {
IImConnection mConn;
ImApp app = ((ImApp) activity.getApplication());
mConn = app.getConnection(providerId, accountId);
// then delete the contact from our list
IContactListManager manager = mConn.getContactListManager();
int res = manager.archiveContact(address, contactType, true);
if (res != ImErrorInfo.NO_ERROR) {
// mHandler.showAlert(R.string.error,
// ErrorResUtils.getErrorRes(getResources(), res, address));
}
} catch (RemoteException re) {
}
}
use of org.awesomeapp.messenger.service.IContactListManager in project Zom-Android by zom.
the class ConversationView method unregisterChatListener.
void unregisterChatListener() {
if (Log.isLoggable(ImApp.LOG_TAG, Log.DEBUG)) {
log("unregisterChatListener " + mLastChatId);
}
try {
if (getChatSession() != null) {
getChatSession().unregisterChatListener(mChatListener);
}
checkConnection();
if (mConn != null) {
IContactListManager listMgr = mConn.getContactListManager();
listMgr.unregisterContactListListener(mContactListListener);
listMgr.unregisterSubscriptionListener(mSubscriptionListener);
}
} catch (Exception e) {
Log.w(ImApp.LOG_TAG, "<ChatView> unregisterChatListener fail:" + e.getMessage());
}
}
use of org.awesomeapp.messenger.service.IContactListManager in project Zom-Android by zom.
the class GroupDisplayActivity method updateMembers.
private synchronized void updateMembers() {
if (mThreadUpdate != null) {
mThreadUpdate.interrupt();
mThreadUpdate = null;
}
mThreadUpdate = new Thread(new Runnable() {
@Override
public void run() {
final HashMap<String, GroupMemberDisplay> members = new HashMap<>();
IContactListManager contactManager = null;
try {
if (mConn != null) {
contactManager = mConn.getContactListManager();
}
} catch (RemoteException re) {
}
String[] projection = { Imps.GroupMembers.USERNAME, Imps.GroupMembers.NICKNAME, Imps.GroupMembers.ROLE, Imps.GroupMembers.AFFILIATION };
Uri memberUri = ContentUris.withAppendedId(Imps.GroupMembers.CONTENT_URI, mLastChatId);
ContentResolver cr = getContentResolver();
Cursor c = cr.query(memberUri, projection, null, null, null);
if (c != null) {
int colUsername = c.getColumnIndex(Imps.GroupMembers.USERNAME);
int colNickname = c.getColumnIndex(Imps.GroupMembers.NICKNAME);
int colRole = c.getColumnIndex(Imps.GroupMembers.ROLE);
int colAffiliation = c.getColumnIndex(Imps.GroupMembers.AFFILIATION);
while (c.moveToNext()) {
GroupMemberDisplay member = new GroupMemberDisplay();
member.username = new XmppAddress(c.getString(colUsername)).getBareAddress();
member.nickname = c.getString(colNickname);
member.role = c.getString(colRole);
member.affiliation = c.getString(colAffiliation);
try {
member.avatar = DatabaseUtils.getAvatarFromAddress(cr, member.username, ImApp.SMALL_AVATAR_WIDTH, ImApp.SMALL_AVATAR_HEIGHT);
} catch (DecoderException e) {
e.printStackTrace();
}
if (member.affiliation != null) {
if (member.affiliation.contentEquals("owner") || member.affiliation.contentEquals("admin")) {
if (member.username.equals(mLocalAddress))
mIsOwner = true;
}
}
members.put(member.username, member);
}
c.close();
}
if (!Thread.currentThread().isInterrupted()) {
final ArrayList<GroupMemberDisplay> listMembers = new ArrayList<>(members.values());
// Sort members by name, but keep owners at the top
Collections.sort(listMembers, new Comparator<GroupMemberDisplay>() {
@Override
public int compare(GroupMemberDisplay member1, GroupMemberDisplay member2) {
if (member1.affiliation == null || member2.affiliation == null)
return 1;
boolean member1isImportant = (member1.affiliation.contentEquals("owner") || member1.affiliation.contentEquals("admin"));
boolean member2isImportant = (member2.affiliation.contentEquals("owner") || member2.affiliation.contentEquals("admin"));
if (member1isImportant != member2isImportant) {
if (member1isImportant) {
return -1;
} else {
return 1;
}
}
return member1.nickname.compareTo(member2.nickname);
}
});
runOnUiThread(new Runnable() {
@Override
public void run() {
mMembers = listMembers;
if (mRecyclerView != null && mRecyclerView.getAdapter() != null)
mRecyclerView.getAdapter().notifyDataSetChanged();
}
});
}
}
});
mThreadUpdate.start();
}
use of org.awesomeapp.messenger.service.IContactListManager in project Zom-Android by zom.
the class ContactListFilterView method blockContact.
void blockContact(Cursor c) {
final IImConnection conn = getConnection(c);
String nickname = c.getString(c.getColumnIndexOrThrow(Imps.Contacts.NICKNAME));
final String address = c.getString(c.getColumnIndexOrThrow(Imps.Contacts.USERNAME));
DialogInterface.OnClickListener confirmListener = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
try {
IContactListManager manager = conn.getContactListManager();
int res = -1;
if (manager.isBlocked(address))
res = manager.unBlockContact(address);
else {
res = manager.blockContact(address);
if (res != ImErrorInfo.NO_ERROR) {
mHandler.showAlert(R.string.error, ErrorResUtils.getErrorRes(getResources(), res, address));
}
}
} catch (RemoteException e) {
mHandler.showServiceErrorAlert(e.getLocalizedMessage());
LogCleaner.error(ImApp.LOG_TAG, "remote error", e);
}
}
};
Resources r = getResources();
new AlertDialog.Builder(mContext).setTitle(R.string.confirm).setMessage(r.getString(R.string.confirm_block_contact, nickname)).setPositiveButton(R.string.yes, // default button
confirmListener).setNegativeButton(R.string.no, null).setCancelable(false).show();
}
use of org.awesomeapp.messenger.service.IContactListManager in project Zom-Android by zom.
the class ContactListFilterView method setContactNickname.
protected void setContactNickname(String aAddress, String aNickname, IImConnection conn) {
try {
IContactListManager listManager = conn.getContactListManager();
int result = listManager.setContactName(aAddress, aNickname);
if (result != ImErrorInfo.NO_ERROR) {
// TODO -LS error handling
Toast.makeText(mContext, mContext.getString(R.string.error_prefix) + result, Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
// TODO -LS error handling
Toast.makeText(mContext, mContext.getString(R.string.error_prefix) + e.getMessage(), Toast.LENGTH_LONG).show();
}
mFilterList.invalidate();
final InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getWindowToken(), 0);
}
Aggregations