mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-30 13:35:18 +00:00
Show profile avatar in toolbar.
This commit is contained in:
parent
a3cba66450
commit
f725dd5a7e
BIN
res/drawable-hdpi/ic_profile_default.png
Normal file
BIN
res/drawable-hdpi/ic_profile_default.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 475 B |
BIN
res/drawable-mdpi/ic_profile_default.png
Normal file
BIN
res/drawable-mdpi/ic_profile_default.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 332 B |
BIN
res/drawable-xhdpi/ic_profile_default.png
Normal file
BIN
res/drawable-xhdpi/ic_profile_default.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 575 B |
BIN
res/drawable-xxhdpi/ic_profile_default.png
Normal file
BIN
res/drawable-xxhdpi/ic_profile_default.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 979 B |
BIN
res/drawable-xxxhdpi/ic_profile_default.png
Normal file
BIN
res/drawable-xxxhdpi/ic_profile_default.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
@ -23,7 +23,8 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<ImageView android:layout_width="36dp"
|
<ImageView android:id="@+id/toolbar_icon"
|
||||||
|
android:layout_width="36dp"
|
||||||
android:layout_height="36dp"
|
android:layout_height="36dp"
|
||||||
android:layout_marginLeft="8dp"
|
android:layout_marginLeft="8dp"
|
||||||
android:layout_marginStart="8dp"
|
android:layout_marginStart="8dp"
|
||||||
|
@ -21,11 +21,13 @@ import android.annotation.SuppressLint;
|
|||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.support.v7.widget.TooltipCompat;
|
import android.support.v7.widget.TooltipCompat;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
@ -33,11 +35,19 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.color.MaterialColor;
|
||||||
import org.thoughtcrime.securesms.components.RatingManager;
|
import org.thoughtcrime.securesms.components.RatingManager;
|
||||||
import org.thoughtcrime.securesms.components.SearchToolbar;
|
import org.thoughtcrime.securesms.components.SearchToolbar;
|
||||||
|
import org.thoughtcrime.securesms.contacts.avatars.ContactColors;
|
||||||
|
import org.thoughtcrime.securesms.contacts.avatars.GeneratedContactPhoto;
|
||||||
|
import org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto;
|
||||||
|
import org.thoughtcrime.securesms.database.Address;
|
||||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||||
import org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo;
|
import org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo;
|
||||||
import org.thoughtcrime.securesms.lock.RegistrationLockDialog;
|
import org.thoughtcrime.securesms.lock.RegistrationLockDialog;
|
||||||
|
import org.thoughtcrime.securesms.mms.GlideApp;
|
||||||
import org.thoughtcrime.securesms.notifications.MarkReadReceiver;
|
import org.thoughtcrime.securesms.notifications.MarkReadReceiver;
|
||||||
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
||||||
import org.thoughtcrime.securesms.permissions.Permissions;
|
import org.thoughtcrime.securesms.permissions.Permissions;
|
||||||
@ -48,6 +58,7 @@ import org.thoughtcrime.securesms.util.DynamicLanguage;
|
|||||||
import org.thoughtcrime.securesms.util.DynamicNoActionBarTheme;
|
import org.thoughtcrime.securesms.util.DynamicNoActionBarTheme;
|
||||||
import org.thoughtcrime.securesms.util.DynamicTheme;
|
import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
|
import org.whispersystems.libsignal.util.guava.Optional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -97,6 +108,8 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
|
|||||||
super.onResume();
|
super.onResume();
|
||||||
dynamicTheme.onResume(this);
|
dynamicTheme.onResume(this);
|
||||||
dynamicLanguage.onResume(this);
|
dynamicLanguage.onResume(this);
|
||||||
|
|
||||||
|
initializeProfileIcon();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -161,6 +174,23 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initializeProfileIcon() {
|
||||||
|
ImageView icon = findViewById(R.id.toolbar_icon);
|
||||||
|
Address localAddress = Address.fromSerialized(TextSecurePreferences.getLocalNumber(this));
|
||||||
|
String profileName = Optional.fromNullable(TextSecurePreferences.getProfileName(this)).or("");
|
||||||
|
MaterialColor fallbackColor = TextUtils.isEmpty(profileName) ? MaterialColor.STEEL : ContactColors.generateFor(profileName);
|
||||||
|
Drawable fallback = new GeneratedContactPhoto(profileName, R.drawable.ic_profile_default).asDrawable(this, fallbackColor.toAvatarColor(this));
|
||||||
|
|
||||||
|
GlideApp.with(this)
|
||||||
|
.load(new ProfileContactPhoto(localAddress, String.valueOf(TextSecurePreferences.getProfileAvatarId(this))))
|
||||||
|
.error(fallback)
|
||||||
|
.circleCrop()
|
||||||
|
.diskCacheStrategy(DiskCacheStrategy.ALL)
|
||||||
|
.into(icon);
|
||||||
|
|
||||||
|
icon.setOnClickListener(v -> handleDisplaySettings());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
super.onOptionsItemSelected(item);
|
super.onOptionsItemSelected(item);
|
||||||
|
@ -15,6 +15,7 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
|||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
import org.thoughtcrime.securesms.contacts.avatars.ContactColors;
|
import org.thoughtcrime.securesms.contacts.avatars.ContactColors;
|
||||||
import org.thoughtcrime.securesms.contacts.avatars.GeneratedContactPhoto;
|
import org.thoughtcrime.securesms.contacts.avatars.GeneratedContactPhoto;
|
||||||
|
import org.thoughtcrime.securesms.contacts.avatars.ResourceContactPhoto;
|
||||||
import org.thoughtcrime.securesms.mms.GlideRequests;
|
import org.thoughtcrime.securesms.mms.GlideRequests;
|
||||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||||
|
|
||||||
@ -57,7 +58,7 @@ public class AvatarImageView extends AppCompatImageView {
|
|||||||
.into(this);
|
.into(this);
|
||||||
setAvatarClickHandler(recipient, quickContactEnabled);
|
setAvatarClickHandler(recipient, quickContactEnabled);
|
||||||
} else {
|
} else {
|
||||||
setImageDrawable(new GeneratedContactPhoto("#").asDrawable(getContext(), ContactColors.UNKNOWN_COLOR.toConversationColor(getContext()), inverted));
|
setImageDrawable(new ResourceContactPhoto(R.drawable.ic_profile_default).asDrawable(getContext(), ContactColors.UNKNOWN_COLOR.toConversationColor(getContext()), inverted));
|
||||||
super.setOnClickListener(listener);
|
super.setOnClickListener(listener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,8 @@ import android.graphics.Typeface;
|
|||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.graphics.drawable.LayerDrawable;
|
import android.graphics.drawable.LayerDrawable;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.DrawableRes;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.content.res.AppCompatResources;
|
import android.support.v7.content.res.AppCompatResources;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
@ -23,20 +25,24 @@ public class GeneratedContactPhoto implements FallbackContactPhoto {
|
|||||||
private static final Typeface TYPEFACE = Typeface.create("sans-serif-medium", Typeface.NORMAL);
|
private static final Typeface TYPEFACE = Typeface.create("sans-serif-medium", Typeface.NORMAL);
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
private final int fallbackResId;
|
||||||
|
|
||||||
public GeneratedContactPhoto(@NonNull String name) {
|
public GeneratedContactPhoto(@NonNull String name, @DrawableRes int fallbackResId) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.fallbackResId = fallbackResId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Drawable asDrawable(Context context, int color) {
|
public Drawable asDrawable(Context context, int color) {
|
||||||
return asDrawable(context, color, false);
|
return asDrawable(context, color,false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Drawable asDrawable(Context context, int color, boolean inverted) {
|
public Drawable asDrawable(Context context, int color, boolean inverted) {
|
||||||
int targetSize = context.getResources().getDimensionPixelSize(R.dimen.contact_photo_target_size);
|
int targetSize = context.getResources().getDimensionPixelSize(R.dimen.contact_photo_target_size);
|
||||||
|
String character = getAbbreviation(name);
|
||||||
|
|
||||||
|
if (!TextUtils.isEmpty(character)) {
|
||||||
Drawable base = TextDrawable.builder()
|
Drawable base = TextDrawable.builder()
|
||||||
.beginConfig()
|
.beginConfig()
|
||||||
.width(targetSize)
|
.width(targetSize)
|
||||||
@ -45,15 +51,17 @@ public class GeneratedContactPhoto implements FallbackContactPhoto {
|
|||||||
.fontSize(ViewUtil.dpToPx(context, 24))
|
.fontSize(ViewUtil.dpToPx(context, 24))
|
||||||
.textColor(inverted ? color : Color.WHITE)
|
.textColor(inverted ? color : Color.WHITE)
|
||||||
.endConfig()
|
.endConfig()
|
||||||
.buildRound(getAbbreviation(name), inverted ? Color.WHITE : color);
|
.buildRound(character, inverted ? Color.WHITE : color);
|
||||||
|
|
||||||
Drawable gradient = context.getResources().getDrawable(ThemeUtil.isDarkTheme(context) ? R.drawable.avatar_gradient_dark
|
Drawable gradient = context.getResources().getDrawable(ThemeUtil.isDarkTheme(context) ? R.drawable.avatar_gradient_dark
|
||||||
: R.drawable.avatar_gradient_light);
|
: R.drawable.avatar_gradient_light);
|
||||||
|
|
||||||
return new LayerDrawable(new Drawable[] { base, gradient });
|
return new LayerDrawable(new Drawable[] { base, gradient });
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getAbbreviation(String name) {
|
return new ResourceContactPhoto(fallbackResId).asDrawable(context, color, inverted);
|
||||||
|
}
|
||||||
|
|
||||||
|
private @Nullable String getAbbreviation(String name) {
|
||||||
String[] parts = name.split(" ");
|
String[] parts = name.split(" ");
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
int count = 0;
|
int count = 0;
|
||||||
@ -67,7 +75,7 @@ public class GeneratedContactPhoto implements FallbackContactPhoto {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (builder.length() == 0) {
|
if (builder.length() == 0) {
|
||||||
return "#";
|
return null;
|
||||||
} else {
|
} else {
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
setContentTitle(context.getString(R.string.SingleRecipientNotificationBuilder_signal));
|
setContentTitle(context.getString(R.string.SingleRecipientNotificationBuilder_signal));
|
||||||
setLargeIcon(new GeneratedContactPhoto("Unknown").asDrawable(context, ContactColors.UNKNOWN_COLOR.toConversationColor(context)));
|
setLargeIcon(new GeneratedContactPhoto("Unknown", R.drawable.ic_profile_default).asDrawable(context, ContactColors.UNKNOWN_COLOR.toConversationColor(context)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -425,8 +425,8 @@ public class Recipient implements RecipientModifiedListener {
|
|||||||
public synchronized @NonNull FallbackContactPhoto getFallbackContactPhoto() {
|
public synchronized @NonNull FallbackContactPhoto getFallbackContactPhoto() {
|
||||||
if (isResolving()) return new TransparentContactPhoto();
|
if (isResolving()) return new TransparentContactPhoto();
|
||||||
else if (isGroupRecipient()) return new ResourceContactPhoto(R.drawable.ic_group_white_24dp, R.drawable.ic_group_large);
|
else if (isGroupRecipient()) return new ResourceContactPhoto(R.drawable.ic_group_white_24dp, R.drawable.ic_group_large);
|
||||||
else if (!TextUtils.isEmpty(name)) return new GeneratedContactPhoto(name);
|
else if (!TextUtils.isEmpty(name)) return new GeneratedContactPhoto(name, R.drawable.ic_profile_default);
|
||||||
else return new GeneratedContactPhoto("#");
|
else return new ResourceContactPhoto(R.drawable.ic_profile_default);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized @Nullable ContactPhoto getContactPhoto() {
|
public synchronized @Nullable ContactPhoto getContactPhoto() {
|
||||||
|
Loading…
Reference in New Issue
Block a user