Skip to content

Commit

Permalink
feat: Show Square Avatar
Browse files Browse the repository at this point in the history
Co-authored-by: 23rd <[email protected]>
  • Loading branch information
omg-xtao and 23rd committed Jan 9, 2024
1 parent 26a4835 commit 1ef4a41
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2447,6 +2447,10 @@ public void setRoundRadius(int tl, int tr, int br, int bl) {
}

public void setRoundRadius(int[] value) {
if (NaConfig.INSTANCE.getShowSquareAvatar().Bool()) {
java.util.Arrays.fill(value, 0);
}

boolean changed = false;
int firstValue = value[0];
isRoundRect = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import org.telegram.ui.Components.CubicBezierInterpolator;
import org.telegram.ui.Components.LayoutHelper;

import xyz.nextalone.nagram.NaConfig;

public class GroupCreateUserCell extends FrameLayout {

private BackupImageView avatarImageView;
Expand Down Expand Up @@ -430,7 +432,12 @@ protected void onDraw(Canvas canvas) {
paint.setColor(Theme.getColor(Theme.key_checkboxSquareBackground, resourcesProvider));
float cx = avatarImageView.getLeft() + avatarImageView.getMeasuredWidth() / 2;
float cy = avatarImageView.getTop() + avatarImageView.getMeasuredHeight() / 2;
canvas.drawCircle(cx, cy, AndroidUtilities.dp(18) + AndroidUtilities.dp(4) * checkProgress, paint);
if (NaConfig.INSTANCE.getShowSquareAvatar().Bool()) {
float dp = AndroidUtilities.dp(18) + AndroidUtilities.dp(4) * checkProgress;
canvas.drawRect(cx - dp, cy - dp, cx + dp, cy + dp, paint);
} else {
canvas.drawCircle(cx, cy, AndroidUtilities.dp(18) + AndroidUtilities.dp(4) * checkProgress, paint);
}
}
if (drawDivider) {
int start = AndroidUtilities.dp(LocaleController.isRTL ? 0 : 72 + padding);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
import org.telegram.ui.Components.LayoutHelper;
import org.telegram.ui.Components.RLottieDrawable;

import xyz.nextalone.nagram.NaConfig;

public class ShareDialogCell extends FrameLayout {

private final BackupImageView imageView;
Expand Down Expand Up @@ -316,7 +318,11 @@ protected void onDraw(Canvas canvas) {
Theme.checkboxSquare_checkPaint.setAlpha((int) (checkBox.getProgress() * 255));
int radius = dp(currentType == TYPE_CREATE ? 24 : 28);
AndroidUtilities.rectTmp.set(cx - radius, cy - radius, cx + radius, cy + radius);
canvas.drawRoundRect(AndroidUtilities.rectTmp, imageView.getRoundRadius()[0], imageView.getRoundRadius()[0], Theme.checkboxSquare_checkPaint);
if (NaConfig.INSTANCE.getShowSquareAvatar().Bool()) {
canvas.drawRoundRect(AndroidUtilities.rectTmp, 0, 0, Theme.checkboxSquare_checkPaint);
} else {
canvas.drawRoundRect(AndroidUtilities.rectTmp, imageView.getRoundRadius()[0], imageView.getRoundRadius()[0], Theme.checkboxSquare_checkPaint);
}
super.onDraw(canvas);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@

import java.util.ArrayList;

import xyz.nextalone.nagram.NaConfig;

public class AvatarDrawable extends Drawable {

private TextPaint namePaint;
Expand Down Expand Up @@ -465,6 +467,8 @@ public void draw(Canvas canvas) {
if (roundRadius > 0) {
AndroidUtilities.rectTmp.set(0, 0, size, size);
canvas.drawRoundRect(AndroidUtilities.rectTmp, roundRadius, roundRadius, Theme.avatar_backgroundPaint);
} else if (NaConfig.INSTANCE.getShowSquareAvatar().Bool()) {
canvas.drawRect(0f, 0f, size, size, Theme.avatar_backgroundPaint);
} else {
canvas.drawCircle(size / 2.0f, size / 2.0f, size / 2.0f, Theme.avatar_backgroundPaint);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.telegram.tgnet.TLRPC;
import org.telegram.ui.ActionBar.Theme;

import xyz.nextalone.nagram.NaConfig;

public class SenderSelectView extends View {
private final static float SPRING_MULTIPLIER = 100f;
private final static FloatPropertyCompat<SenderSelectView> MENU_PROGRESS = new SimpleFloatPropertyCompat<SenderSelectView>("menuProgress", obj -> obj.menuProgress, (obj, value) -> {
Expand Down Expand Up @@ -56,7 +58,8 @@ public SenderSelectView(Context context) {
private void updateColors() {
backgroundPaint.setColor(Theme.getColor(Theme.key_chat_messagePanelVoiceBackground));
menuPaint.setColor(Theme.getColor(Theme.key_chat_messagePanelVoicePressed));
selectorDrawable = Theme.createSimpleSelectorRoundRectDrawable(AndroidUtilities.dp(16), Color.TRANSPARENT, Theme.getColor(Theme.key_windowBackgroundWhite));
int value = NaConfig.INSTANCE.getShowSquareAvatar().Bool() ? 0 : 16;
selectorDrawable = Theme.createSimpleSelectorRoundRectDrawable(AndroidUtilities.dp(value), Color.TRANSPARENT, Theme.getColor(Theme.key_windowBackgroundWhite));
selectorDrawable.setCallback(this);
}

Expand Down Expand Up @@ -99,7 +102,12 @@ protected void onDraw(Canvas canvas) {

int alpha = (int) (menuProgress * 0xFF);
backgroundPaint.setAlpha(alpha);
canvas.drawCircle(getWidth() / 2f, getHeight() / 2f, Math.min(getWidth(), getHeight()) / 2f, backgroundPaint);
if (NaConfig.INSTANCE.getShowSquareAvatar().Bool()) {
AndroidUtilities.rectTmp.set(0, 0, getWidth(), getHeight());
canvas.drawRoundRect(AndroidUtilities.rectTmp, 0, 0, backgroundPaint);
} else {
canvas.drawCircle(getWidth() / 2f, getHeight() / 2f, Math.min(getWidth(), getHeight()) / 2f, backgroundPaint);
}

canvas.save();
menuPaint.setAlpha(alpha);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.telegram.tgnet.TLObject;
import org.telegram.ui.ActionBar.Theme;

import xyz.nextalone.nagram.NaConfig;

public class SimpleAvatarView extends View {
public final static int SELECT_ANIMATION_DURATION = 200;

Expand Down Expand Up @@ -70,7 +72,12 @@ protected void onDraw(Canvas canvas) {
selectPaint.setAlpha((int) (Color.alpha(selectPaint.getColor()) * selectProgress));
float stroke = selectPaint.getStrokeWidth();
AndroidUtilities.rectTmp.set(stroke, stroke, getWidth() - stroke, getHeight() - stroke);
canvas.drawArc(AndroidUtilities.rectTmp, -90, selectProgress * 360, false, selectPaint);
if (NaConfig.INSTANCE.getShowSquareAvatar().Bool()) {
final float w = selectPaint.getStrokeWidth();
canvas.drawRect(w, w, getWidth() - w, getHeight() - w, selectPaint);
} else {
canvas.drawArc(AndroidUtilities.rectTmp, -90, selectProgress * 360, false, selectPaint);
}
canvas.restore();

if (!isAvatarHidden) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
import java.util.Collections;
import java.util.List;

import xyz.nextalone.nagram.NaConfig;

public class ProfileStoriesView extends View implements NotificationCenter.NotificationCenterDelegate {

private static final int CIRCLES_MAX = 3;
Expand Down Expand Up @@ -813,6 +815,10 @@ private StoryCircle nearest(StoryCircle a, StoryCircle b, StoryCircle c) {
}

private void drawArcs(Canvas canvas, StoryCircle A, StoryCircle B, StoryCircle C, Paint paint) {
if (NaConfig.INSTANCE.getShowSquareAvatar().Bool()) {
return;
}

if (A == null && C == null) {
canvas.drawArc(B.borderRect, 0, 360, false, paint);
} else if (A != null && C != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public class NekoGeneralSettingsActivity extends BaseNekoXSettingsActivity {
private final AbstractConfigCell largeAvatarInDrawerRow = cellGroup.appendCell(new ConfigCellSelectBox(null, NekoConfig.largeAvatarInDrawer, LocaleController.getString("valuesLargeAvatarInDrawer"), null));
private final AbstractConfigCell avatarBackgroundBlurRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.avatarBackgroundBlur));
private final AbstractConfigCell avatarBackgroundDarkenRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.avatarBackgroundDarken));
private final AbstractConfigCell showSquareAvatarRow = cellGroup.appendCell(new ConfigCellTextCheck(NaConfig.INSTANCE.getShowSquareAvatar()));
private final AbstractConfigCell hidePhoneRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.hidePhone));
private final AbstractConfigCell divider0 = cellGroup.appendCell(new ConfigCellDivider());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,12 @@ object NaConfig {
ConfigItem.configTypeBool,
false
)
val showSquareAvatar =
addConfig(
"ShowSquareAvatar",
ConfigItem.configTypeBool,
false
)

private fun addConfig(
k: String,
Expand Down
1 change: 1 addition & 0 deletions TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,5 @@
<string name="DisableSendReadStories">偷偷看动态</string>
<string name="HideFilterMuteAll">隐藏文件夹中的\"全部取消静音\"</string>
<string name="UseLocalQuoteColor">本地名称颜色</string>
<string name="ShowSquareAvatar">显示方形头像</string>
</resources>
1 change: 1 addition & 0 deletions TMessagesProj/src/main/res/values/strings_na.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,5 @@
<string name="DisableSendReadStories">Disable Send Read Stories</string>
<string name="HideFilterMuteAll">Hide filter mute all</string>
<string name="UseLocalQuoteColor">Use local quote color</string>
<string name="ShowSquareAvatar">Show square avatar</string>
</resources>

0 comments on commit 1ef4a41

Please sign in to comment.