Display profile name in when appropriate

Display in conversation list, conversation actionbar, group
messages, and group members list when address is not in system
contacts

// FREEBIE
This commit is contained in:
Moxie Marlinspike
2017-08-15 19:23:42 -07:00
parent 77a216b705
commit e7c20499ec
14 changed files with 270 additions and 59 deletions

View File

@@ -162,17 +162,22 @@ public class DirectoryHelper {
List<Address> newUsers = DatabaseFactory.getContactsDatabase(context)
.setRegisteredUsers(account.get().getAccount(), activeAddresses, removeMissing);
Cursor cursor = ContactAccessor.getInstance().getAllSystemContacts(context);
Cursor cursor = ContactAccessor.getInstance().getAllSystemContacts(context);
RecipientPreferenceDatabase.BulkOperationsHandle handle = DatabaseFactory.getRecipientPreferenceDatabase(context).resetAllDisplayNames();
while (cursor != null && cursor.moveToNext()) {
String number = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.NUMBER));
try {
while (cursor != null && cursor.moveToNext()) {
String number = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.NUMBER));
if (!TextUtils.isEmpty(number)) {
Address address = Address.fromExternal(context, number);
String displayName = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
if (!TextUtils.isEmpty(number)) {
Address address = Address.fromExternal(context, number);
String displayName = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
DatabaseFactory.getRecipientPreferenceDatabase(context).setSystemDisplayName(address, displayName);
handle.setDisplayName(address, displayName);
}
}
} finally {
handle.finish();
}
return new RefreshResult(newUsers, account.get().isFresh());

View File

@@ -0,0 +1,25 @@
package org.thoughtcrime.securesms.util.spans;
import android.text.TextPaint;
import android.text.style.MetricAffectingSpan;
public class CenterAlignedRelativeSizeSpan extends MetricAffectingSpan {
private final float relativeSize;
public CenterAlignedRelativeSizeSpan(float relativeSize) {
this.relativeSize = relativeSize;
}
@Override
public void updateMeasureState(TextPaint p) {
updateDrawState(p);
}
@Override
public void updateDrawState(TextPaint tp) {
tp.setTextSize(tp.getTextSize() * relativeSize);
tp.baselineShift += (int) (tp.ascent() * relativeSize) / 4;
}
}