Skip to content

Commit

Permalink
feat: custom gif size
Browse files Browse the repository at this point in the history
Signed-off-by: Next Alone <[email protected]>
  • Loading branch information
NextAlone committed Mar 29, 2024
1 parent 1bd26eb commit 9941afc
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7951,6 +7951,10 @@ private void setMessageContent(MessageObject messageObject, MessageObject.Groupe
}
}
}
if (messageObject.type == MessageObject.TYPE_GIF) {
w = w * Config.getGifSize() / 100;
h = h * Config.getGifSize() / 100;
}

if (w == 0 || h == 0) {
w = h = AndroidUtilities.dp(150);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public abstract class BaseActivity extends BaseFragment {
public static final int TYPE_RADIO = 10;
public static final int TYPE_ACCOUNT = 11;
public static final int TYPE_STICKER_SIZE = 12;
public static final int TYPE_GIF_SIZE = 13;
protected HashMap<String, Integer> rowMap = new HashMap<>(20);
protected HashMap<Integer, String> rowMapReverse = new HashMap<>(20);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,13 @@ public class ChatSettingActivity extends BaseActivity {

private ActionBarMenuItem resetItem;
private StickerSizeCell stickerSizeCell;
private GifSizeCell gifSizeCell;

private int stickerSizeHeaderRow;
private int stickerSizeRow;
private int stickerSize2Row;
private int gifSizeHeaderRow;
private int gifSizeRow;

private int chatRow;
private int ignoreBlockedUserMessagesRow;
Expand Down Expand Up @@ -180,6 +183,7 @@ public View createView(Context context) {
animator.addUpdateListener(valueAnimator -> {
ConfigManager.putFloat(Defines.stickerSize, (Float) valueAnimator.getAnimatedValue());
stickerSizeCell.invalidate();
gifSizeCell.invalidate();
});
animator.start();
});
Expand Down Expand Up @@ -465,7 +469,8 @@ protected void updateRows() {
stickerSizeHeaderRow = addRow();
stickerSizeRow = addRow("stickerSize");
stickerSize2Row = addRow();

gifSizeHeaderRow = addRow();
gifSizeRow = addRow("gifSize");
chatRow = addRow();
ignoreBlockedUserMessagesRow = addRow("ignoreBlockedUserMessages");
hideGroupStickerRow = addRow("hideGroupSticker");
Expand Down Expand Up @@ -547,6 +552,11 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position, boole
if (position == stickerSizeRow) {
textCell.setTextAndValue(LocaleController.getString("StickerSize", R.string.StickerSize),
String.valueOf(Math.round(ConfigManager.getFloatOrDefault(Defines.stickerSize, 14.0f))), payload, true);
} else if (position == gifSizeHeaderRow) {
textCell.setTextAndValue(LocaleController.getString("gifSize", R.string.gifSize),
String.valueOf(ConfigManager.getIntOrDefault(Defines.gifSize, 150)), payload, true);
} else if (position == chatRow) {
textCell.setText(LocaleController.getString("Chat", R.string.Chat), false);
} else if (position == messageMenuRow) {
textCell.setText(LocaleController.getString("MessageMenu", R.string.MessageMenu), false);
} else if (position == textStyleSettingsRow) {
Expand Down Expand Up @@ -684,6 +694,8 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position, boole
headerCell.setText(LocaleController.getString("Chat", R.string.Chat));
} else if (position == stickerSizeHeaderRow) {
headerCell.setText(LocaleController.getString("StickerSize", R.string.StickerSize));
} else if (position == gifSizeHeaderRow) {
headerCell.setText(LocaleController.getString("gifSize", R.string.gifSize));
} else if (position == markdownRow) {
headerCell.setText(LocaleController.getString("Markdown", R.string.Markdown));
}
Expand Down Expand Up @@ -748,6 +760,10 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
view = stickerSizeCell = new StickerSizeCell(mContext);
view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
break;
case TYPE_GIF_SIZE:
view = gifSizeCell = new GifSizeCell(mContext);
view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
break;
}
// noinspection ConstantConditions
view.setLayoutParams(new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT));
Expand All @@ -761,10 +777,12 @@ public int getItemViewType(int position) {
} else if (position == messageMenuRow || position == customDoubleClickTapRow || position == maxRecentStickerRow || position == customQuickMessageRow || position == markdownParserRow
|| position == messageFiltersRow || position == textStyleSettingsRow) {
return TYPE_SETTINGS;
} else if (position == chatRow || position == stickerSizeHeaderRow || position == markdownRow) {
} else if (position == chatRow || position == stickerSizeHeaderRow || position == markdownRow || position == gifSizeHeaderRow) {
return TYPE_HEADER;
} else if (position == stickerSizeRow) {
return TYPE_STICKER_SIZE;
} else if (position == gifSizeRow) {
return TYPE_GIF_SIZE;
} else if ((position > chatRow && position < chat2Row) || (position > markdownRow && position < markdown2Row) || (position > stickerSizeRow && position < stickerSize2Row)) {
return TYPE_CHECK;
} else if (position == markdown2Row) {
Expand Down Expand Up @@ -1183,5 +1201,81 @@ public boolean performAccessibilityAction(int action, Bundle arguments) {
return super.performAccessibilityAction(action, arguments) || sizeBar.getSeekBarAccessibilityDelegate().performAccessibilityActionInternal(this, action, arguments);
}
}


public class GifSizeCell extends FrameLayout {

private final SeekBarView sizeBar;
private final int startGifSize = 50;
private final int endGifSize = 100;

private final TextPaint textPaint;
private int lastWidth;

public GifSizeCell(Context context) {
super(context);

setWillNotDraw(false);

textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
textPaint.setTextSize(AndroidUtilities.dp(16));

sizeBar = new SeekBarView(context);
sizeBar.setReportChanges(true);
sizeBar.setDelegate(new SeekBarView.SeekBarViewDelegate() {
@Override
public void onSeekBarDrag(boolean stop, float progress) {
sizeBar.getSeekBarAccessibilityDelegate().postAccessibilityEventRunnable(GifSizeCell.this);
ConfigManager.putInt(Defines.gifSize, (int) (startGifSize + (endGifSize - startGifSize) * progress));
GifSizeCell.this.invalidate();
}

@Override
public void onSeekBarPressed(boolean pressed) {

}
});
sizeBar.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
addView(sizeBar, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 38, Gravity.LEFT | Gravity.TOP, 9, 5, 43, 11));
}

@Override
protected void onDraw(Canvas canvas) {
textPaint.setColor(Theme.getColor(Theme.key_windowBackgroundWhiteValueText));
canvas.drawText(ConfigManager.getIntOrDefault(Defines.gifSize, 100) + "%", getMeasuredWidth() - AndroidUtilities.dp(45), AndroidUtilities.dp(28), textPaint);
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = MeasureSpec.getSize(widthMeasureSpec);
if (lastWidth != width) {
sizeBar.setProgress((ConfigManager.getIntOrDefault(Defines.gifSize, 100) - startGifSize) / (float) (endGifSize - startGifSize));
lastWidth = width;
}
}

@Override
public void invalidate() {
super.invalidate();
lastWidth = -1;
sizeBar.invalidate();
}

@Override
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
super.onInitializeAccessibilityEvent(event);
sizeBar.getSeekBarAccessibilityDelegate().onInitializeAccessibilityEvent(this, event);
}

@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(info);
sizeBar.getSeekBarAccessibilityDelegate().onInitializeAccessibilityNodeInfoInternal(this, info);
}

@Override
public boolean performAccessibilityAction(int action, Bundle arguments) {
return super.performAccessibilityAction(action, arguments) || sizeBar.getSeekBarAccessibilityDelegate().performAccessibilityActionInternal(this, action, arguments);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ object Defines {
@BooleanConfig const val hideFilterMuteAll = "hideFilterMuteAll"
@BooleanConfig const val hideKeyboardWhenScrolling = "hideKeyboardWhenScrolling"
@BooleanConfig const val searchInPlace = "searchInPlace"
@IntConfig(100) const val gifSize = "gifSize"

// Drawer List
@BooleanConfig(true) const val showNewGroup = "showNewGroup"
Expand Down
1 change: 1 addition & 0 deletions TMessagesProj/src/main/res/values-zh/strings_nullgram.xml
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@
<string name="hideFilterMuteAll">隐藏文件夹中的\"全部取消静音\"</string>
<string name="hideKeyboardWhenScrolling">滑动时隐藏键盘</string>
<string name="searchInPlace">从当前位置中开始搜索</string>
<string name="gifSize">GIF 大小</string>

<string name="Quote">引用</string>
<string name="QuoteTo">引用到...</string>
Expand Down
1 change: 1 addition & 0 deletions TMessagesProj/src/main/res/values/strings_nullgram.xml
Original file line number Diff line number Diff line change
Expand Up @@ -373,4 +373,5 @@
<string name="hideFilterMuteAll">Hide filter mute all</string>
<string name="hideKeyboardWhenScrolling">Hide keyboard when scrolling</string>
<string name="searchInPlace">Search in place</string>
<string name="gifSize">GIF size</string>
</resources>

0 comments on commit 9941afc

Please sign in to comment.