Skip to content
Permalink
Browse files
allow force enabling chat blur
  • Loading branch information
luvletter2333 committed Mar 15, 2022
1 parent de17e63 commit c1a21028e4075513e6b81dee239a8147f004ac6e
Showing 7 changed files with 104 additions and 11 deletions.
@@ -54,6 +54,7 @@

import cn.hutool.core.util.StrUtil;
import okhttp3.HttpUrl;
import tw.nekomimi.nekogram.NekoConfig;
import tw.nekomimi.nekogram.proxy.ProxyManager;
import tw.nekomimi.nekogram.proxy.ShadowsocksLoader;
import tw.nekomimi.nekogram.proxy.ShadowsocksRLoader;
@@ -1227,6 +1228,7 @@ public static void loadConfig() {
smoothKeyboard = preferences.getBoolean("smoothKeyboard2", true);
pauseMusicOnRecord = preferences.getBoolean("pauseMusicOnRecord", false);
chatBlur = preferences.getBoolean("chatBlur", true);
chatBlur = chatBlur || NekoConfig.forceBlurInChat.Bool();
streamAllVideo = preferences.getBoolean("streamAllVideo", BuildVars.DEBUG_VERSION);
streamMkv = preferences.getBoolean("streamMkv", false);
suggestStickers = preferences.getInt("suggestStickers", 0);
@@ -1844,6 +1846,7 @@ public static void togglePauseMusicOnRecord() {

public static void toggleChatBlur() {
chatBlur = !chatBlur;
if (NekoConfig.forceBlurInChat.Bool()) chatBlur = true;
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("chatBlur", chatBlur);
@@ -2329,10 +2332,10 @@ public static void setDontAskManageStorage(boolean b) {
}

public static boolean canBlurChat() {
return getDevicePerformanceClass() == PERFORMANCE_CLASS_HIGH;
return getDevicePerformanceClass() == PERFORMANCE_CLASS_HIGH || NekoConfig.forceBlurInChat.Bool();
}
public static boolean chatBlurEnabled() {
return canBlurChat() && chatBlur;
return (canBlurChat() && chatBlur) || NekoConfig.forceBlurInChat.Bool();
}

public static class BackgroundActivityPrefs {
@@ -41,6 +41,8 @@

import java.util.ArrayList;

import tw.nekomimi.nekogram.NekoConfig;

public class SizeNotifierFrameLayout extends FrameLayout {

private Rect rect = new Rect();
@@ -441,6 +443,7 @@ public void startBlur() {
}

int blurAlpha = Color.alpha(Theme.getColor(Theme.key_chat_BlurAlpha));
if (NekoConfig.forceBlurInChat.Bool()) blurAlpha = NekoConfig.chatBlueAlphaValue.Int();
if (blurAlpha == 255) {
return;
}
@@ -684,6 +687,7 @@ protected void onDetachedFromWindow() {

public void drawBlur(Canvas canvas, float y, Rect rectTmp, Paint blurScrimPaint, boolean top) {
int blurAlpha = Color.alpha(Theme.getColor(Theme.key_chat_BlurAlpha));
if (NekoConfig.forceBlurInChat.Bool()) blurAlpha = NekoConfig.chatBlueAlphaValue.Int();
if (currentBitmap == null || !SharedConfig.chatBlurEnabled()) {
canvas.drawRect(rectTmp, blurScrimPaint);
return;
@@ -57,6 +57,8 @@ public class NekoConfig {
public static ConfigItem nameOrder = addConfig("NameOrder", configTypeInt, 1);
public static ConfigItem mapPreviewProvider = addConfig("MapPreviewProvider", configTypeInt, 0);
public static ConfigItem transparentStatusBar = addConfig("TransparentStatusBar", configTypeBool, false);
public static ConfigItem forceBlurInChat = addConfig("forceBlurInChat", configTypeBool, false);
public static ConfigItem chatBlueAlphaValue = addConfig("forceBlurInChatAlphaValue", configTypeInt, 127);
public static ConfigItem hideProxySponsorChannel = addConfig("HideProxySponsorChannel", configTypeBool, false);
public static ConfigItem showAddToSavedMessages = addConfig("showAddToSavedMessages", configTypeBool, true);
public static ConfigItem showReport = addConfig("showReport", configTypeBool, true);
@@ -3,8 +3,13 @@
import androidx.recyclerview.widget.RecyclerView;

public class ConfigCellCustom extends AbstractConfigCell {

public static final int CUSTOM_ITEM_ProfilePreview = 999;
public static final int CUSTOM_ITEM_StickerSize = 998;
public static final int CUSTOM_ITEM_CharBlurAlpha = 997;

public final int type;
public final boolean enabled;
public boolean enabled;

public ConfigCellCustom(int type, boolean enabled) {
this.type = type;
@@ -64,7 +64,7 @@ public class NekoChatSettingsActivity extends BaseFragment implements Notificati
private final CellGroup cellGroup = new CellGroup(this);

private final AbstractConfigCell header0 = cellGroup.appendCell(new ConfigCellHeader(LocaleController.getString("StickerSize")));
private final AbstractConfigCell stickerSizeRow = cellGroup.appendCell(new ConfigCellCustom(998, true));
private final AbstractConfigCell stickerSizeRow = cellGroup.appendCell(new ConfigCellCustom(ConfigCellCustom.CUSTOM_ITEM_StickerSize, true));
private final AbstractConfigCell divider0 = cellGroup.appendCell(new ConfigCellDivider());
private final AbstractConfigCell header1 = cellGroup.appendCell(new ConfigCellHeader(LocaleController.getString("Chat")));
private final AbstractConfigCell unreadBadgeOnBackButton = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.unreadBadgeOnBackButton));
@@ -584,7 +584,7 @@ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType
view = new TextInfoPrivacyCell(mContext);
// view.setBackground(Theme.getThemedDrawable(mContext, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
break;
case 998:
case ConfigCellCustom.CUSTOM_ITEM_StickerSize:
view = stickerSizeCell = new StickerSizeCell(mContext);
view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
break;
@@ -8,6 +8,9 @@
import android.content.Intent;
import android.content.IntentSender;
import android.content.pm.ResolveInfo;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.text.TextPaint;
import android.transition.TransitionManager;
import android.util.Log;
import android.view.Gravity;
@@ -48,14 +51,12 @@
import org.telegram.ui.Cells.TextSettingsCell;
import org.telegram.ui.Components.LayoutHelper;
import org.telegram.ui.Components.RecyclerListView;
import org.telegram.ui.Components.SeekBarView;
import org.telegram.ui.Components.UndoView;

import java.nio.file.InvalidPathException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;

import cn.hutool.core.util.StrUtil;
import kotlin.Unit;
@@ -144,6 +145,11 @@ public class NekoGeneralSettingsActivity extends BaseFragment {
LocaleController.getString("Enable", R.string.Enable),
LocaleController.getString("Disable", R.string.Disable)
}, null));

private final AbstractConfigCell forceBlurInChatRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.forceBlurInChat));
private final AbstractConfigCell header_chatblur = cellGroup.appendCell(new ConfigCellHeader(LocaleController.getString("ChatBlurAlphaValue")));
private final AbstractConfigCell chatBlurAlphaValueRow = cellGroup.appendCell(new ConfigCellCustom(ConfigCellCustom.CUSTOM_ITEM_CharBlurAlpha, NekoConfig.forceBlurInChat.Bool()));

private final AbstractConfigCell divider5 = cellGroup.appendCell(new ConfigCellDivider());

private final AbstractConfigCell header6 = cellGroup.appendCell(new ConfigCellHeader(LocaleController.getString("PrivacyTitle")));
@@ -172,7 +178,7 @@ public class NekoGeneralSettingsActivity extends BaseFragment {
private final AbstractConfigCell displayPersianCalendarByLatinRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.displayPersianCalendarByLatin));
private final AbstractConfigCell divider7 = cellGroup.appendCell(new ConfigCellDivider());


private ChatBlurAlphaSeekBar chatBlurAlphaSeekbar;
private UndoView restartTooltip;

@Override
@@ -367,6 +373,11 @@ public void onItemClick(int id) {
} else if (key.equals(NekoConfig.disableAppBarShadow.getKey())) {
ActionBarLayout.headerShadowDrawable = (boolean) newValue ? null : parentLayout.getResources().getDrawable(R.drawable.header_shadow).mutate();
parentLayout.rebuildAllFragmentViews(true, true);
} else if (NekoConfig.forceBlurInChat.getKey().equals(key)) {
boolean enabled = (Boolean) newValue;
if (chatBlurAlphaSeekbar != null)
chatBlurAlphaSeekbar.setEnabled(enabled);
((ConfigCellCustom) chatBlurAlphaValueRow).enabled = enabled;
}
};

@@ -381,7 +392,7 @@ public void onItemClick(int id) {

private class ConfigCellDrawerProfilePreview extends AbstractConfigCell {
public int getType() {
return 999;
return ConfigCellCustom.CUSTOM_ITEM_ProfilePreview;
}

public boolean isEnabled() {
@@ -709,10 +720,15 @@ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType
view = new TextInfoPrivacyCell(mContext);
// view.setBackground(Theme.getThemedDrawable(mContext, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
break;
case 999:
case ConfigCellCustom.CUSTOM_ITEM_ProfilePreview:
view = profilePreviewCell = new DrawerProfilePreviewCell(mContext);
view.setBackground(Theme.getThemedDrawable(mContext, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
break;
case ConfigCellCustom.CUSTOM_ITEM_CharBlurAlpha:
view = chatBlurAlphaSeekbar = new ChatBlurAlphaSeekBar(mContext);
chatBlurAlphaSeekbar.setEnabled(NekoConfig.forceBlurInChat.Bool());
view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
break;
}
//noinspection ConstantConditions
view.setLayoutParams(new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT));
@@ -768,4 +784,65 @@ private void customDialog_BottomInputString(int position, ConfigItem bind, Strin
keyField.requestFocus();
AndroidUtilities.showKeyboard(keyField);
}

private class ChatBlurAlphaSeekBar extends FrameLayout {

private final SeekBarView sizeBar;
private final TextPaint textPaint;
private boolean enabled = true;

public ChatBlurAlphaSeekBar(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) {
NekoConfig.chatBlueAlphaValue.setConfigInt(Math.min(255, (int) (255 * progress)));
invalidate();
}

@Override
public void onSeekBarPressed(boolean pressed) {

}
});
sizeBar.setOnTouchListener((v, event) -> !enabled);
sizeBar.setProgress(NekoConfig.chatBlueAlphaValue.Int());
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(String.valueOf(NekoConfig.chatBlueAlphaValue.Int()), getMeasuredWidth() - AndroidUtilities.dp(39), AndroidUtilities.dp(28), textPaint);
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
sizeBar.setProgress((NekoConfig.chatBlueAlphaValue.Int() / 255.0f));
}

@Override
public void invalidate() {
super.invalidate();
sizeBar.invalidate();
}

@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
this.enabled = enabled;
sizeBar.setAlpha(enabled ? 1.0f : 0.5f);
textPaint.setAlpha((int) ((enabled ? 1.0f : 0.3f) * 255));
this.invalidate();
}
}
}
@@ -142,5 +142,7 @@
<string name="customSavePathHint">Leave blank to save directly</string>
<string name="showBottomActionsWhenSelecting">Show bottom actions when selecting</string>
<string name="channelLabel">channel</string>
<string name="forceBlurInChat">Force enable Chat Blur</string>
<string name="ChatBlurAlphaValue">Chat Blur Alpha</string>

</resources>

0 comments on commit c1a2102

Please sign in to comment.