largeAvatarInDrawer & unreadBadgeOnBackButton

This commit is contained in:
arm64v8a 2021-10-28 23:49:42 +08:00
parent d62d686e6c
commit 26f3498957
3 changed files with 77 additions and 7 deletions

View File

@ -20,9 +20,12 @@ import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.text.Layout;
import android.text.SpannableString;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.text.TextUtils;
import android.transition.ChangeBounds;
@ -53,6 +56,7 @@ import org.telegram.ui.Components.SnowflakesEffect;
import java.util.ArrayList;
import tw.nekomimi.nekogram.NekoConfig;
import tw.nekomimi.nkmr.NekomuraConfig;
public class ActionBar extends FrameLayout {
@ -66,7 +70,7 @@ public class ActionBar extends FrameLayout {
}
}
private ImageView backButtonImageView;
private UnreadImageView backButtonImageView;
private SimpleTextView[] titleTextView = new SimpleTextView[2];
private SimpleTextView subtitleTextView;
private SimpleTextView additionalSubtitleTextView;
@ -148,7 +152,7 @@ public class ActionBar extends FrameLayout {
if (backButtonImageView != null) {
return;
}
backButtonImageView = new ImageView(getContext());
backButtonImageView = new UnreadImageView(getContext());
backButtonImageView.setScaleType(ImageView.ScaleType.CENTER);
backButtonImageView.setBackgroundDrawable(Theme.createSelectorDrawable(itemsBackgroundColor));
if (itemsColor != 0) {
@ -1476,7 +1480,7 @@ public class ActionBar extends FrameLayout {
public void captureEndValues(TransitionValues transitionValues) {
super.captureEndValues(transitionValues);
if (transitionValues.view instanceof SimpleTextView) {
float textSize= ((SimpleTextView) transitionValues.view).getTextPaint().getTextSize();
float textSize = ((SimpleTextView) transitionValues.view).getTextPaint().getTextSize();
transitionValues.values.put("text_size", textSize);
}
}
@ -1530,4 +1534,54 @@ public class ActionBar extends FrameLayout {
}
return color != null ? color : Theme.getColor(key);
}
//Nekomura
private StaticLayout countLayout;
private class UnreadImageView extends ImageView {
public UnreadImageView(Context context) {
super(context);
}
private int unreadCount = 0;
private RectF rect = new RectF();
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (countLayout == null || unreadCount == 0)
return;
Paint paint = Theme.dialogs_countPaint;
String unreadCountString = unreadCount > 99 ? "99+" : Integer.toString(unreadCount);
int countWidth = Math.max(AndroidUtilities.dp(12), (int) Math.ceil(Theme.dialogs_countTextPaint.measureText(unreadCountString)));
int countLeft = getMeasuredWidth() - countWidth - AndroidUtilities.dp(20);
int countTop = 0;
int x = countLeft - AndroidUtilities.dp(5.5f);
rect.set(x, countTop, x + countWidth + AndroidUtilities.dp(11), countTop + AndroidUtilities.dp(23));
canvas.drawRoundRect(rect, 11.5f * AndroidUtilities.density, 11.5f * AndroidUtilities.density, paint);
canvas.save();
canvas.translate(countLeft, countTop + AndroidUtilities.dp(4));
countLayout.draw(canvas);
canvas.restore();
}
public void setUnread(int count) {
if (count != unreadCount) {
unreadCount = count;
String countString = count > 99 ? "99+" : Integer.toString(count);
int countWidth = count == 0 ? 0 : Math.max(AndroidUtilities.dp(12), (int) Math.ceil(Theme.dialogs_countTextPaint.measureText(countString)));
countLayout = new StaticLayout(countString, Theme.dialogs_countTextPaint, countWidth, Layout.Alignment.ALIGN_CENTER, 1.0f, 0.0f, false);
invalidate();
}
}
}
public void unreadBadgeSetCount(int count) {
if (backButtonImageView != null && NekomuraConfig.unreadBadgeOnBackButton.Bool()) {
backButtonImageView.setUnread(count);
}
}
}

View File

@ -13,6 +13,7 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
@ -249,8 +250,15 @@ public class DrawerProfileCell extends FrameLayout {
}
switchTheme(themeInfo, toDark);
});
addView(darkThemeView, LayoutHelper.createFrame(48, 48, Gravity.RIGHT | Gravity.BOTTOM, 0, 0, 6, 90));
LayoutParams lp = NekomuraConfig.largeAvatarInDrawer.Int() == 2 ? // correct the position of this button
LayoutHelper.createFrame(48, 48, Gravity.RIGHT | Gravity.TOP, 0, 10, 6, 0) :
LayoutHelper.createFrame(48, 48, Gravity.RIGHT | Gravity.BOTTOM, 0, 0, 6, 90);
addView(darkThemeView, lp);
if (NekomuraConfig.largeAvatarInDrawer.Int() == 2) { // add shadow
nameTextView.setShadowLayer(6.0f, 2.0f, 2.0f, Color.BLACK);
phoneTextView.getTextView().setShadowLayer(6.0f, 2.0f, 2.0f, Color.BLACK);
}
if (Theme.getEventType() == 0 || NekoConfig.actionBarDecoration == 1) {
snowflakesEffect = new SnowflakesEffect();
@ -293,13 +301,14 @@ public class DrawerProfileCell extends FrameLayout {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int heightBase = NekomuraConfig.largeAvatarInDrawer.Int() == 2 ? MeasureSpec.getSize(widthMeasureSpec) : AndroidUtilities.dp(148);
if (Build.VERSION.SDK_INT >= 21) {
super.onMeasure(MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(148) + AndroidUtilities.statusBarHeight, MeasureSpec.EXACTLY));
super.onMeasure(MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(heightBase, MeasureSpec.EXACTLY));
} else {
try {
super.onMeasure(MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(148), MeasureSpec.EXACTLY));
super.onMeasure(MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(heightBase, MeasureSpec.EXACTLY));
} catch (Exception e) {
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), AndroidUtilities.dp(148));
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), heightBase);
FileLog.e(e);
}
}

View File

@ -16359,6 +16359,10 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
themeDelegate.setCurrentTheme(themeDelegate.chatTheme, true, theme.isDark());
}
}
} else if (id == NotificationCenter.dialogsUnreadCounterChanged) {
if (actionBar != null) {//Nekomura
actionBar.unreadBadgeSetCount(getMessagesStorage().getMainUnreadCount());
}
}
}
@ -25164,6 +25168,9 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
startMessageUnselect();
}
}
if (actionBar != null) {//Nekomura
actionBar.unreadBadgeSetCount(getMessagesStorage().getMainUnreadCount());
}
}
int position = holder.getAdapterPosition();