Skip to content
This repository has been archived by the owner on Sep 15, 2024. It is now read-only.

Commit

Permalink
fix: UI fix for perfectionists
Browse files Browse the repository at this point in the history
  • Loading branch information
mkx173 committed Feb 21, 2024
1 parent c5a7d36 commit c9b808b
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 42 deletions.
15 changes: 14 additions & 1 deletion app/src/main/java/gm/tieba/tabswitch/dao/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ public static boolean getIsEULAAccepted() {
public static void putAutoSignEnabled() {
final SharedPreferences.Editor editor = sTsConfig.edit();
editor.putBoolean("auto_sign", true);
editor.apply();
editor.commit();
}

public static void putAutoSignDisabled() {
final SharedPreferences.Editor editor = sTsConfig.edit();
editor.putBoolean("auto_sign", false);
editor.commit();
}

public static boolean getIsAutoSignEnabled() {
Expand All @@ -95,6 +101,13 @@ public static void putPurgeEnabled() {
editor.commit();
}

@SuppressLint("ApplySharedPref")
public static void putPurgeDisabled() {
final SharedPreferences.Editor editor = sTsConfig.edit();
editor.putBoolean("ze", false);
editor.commit();
}

public static boolean getIsPurgeEnabled() {
return sTsConfig.getBoolean("ze", false);
}
Expand Down
62 changes: 37 additions & 25 deletions app/src/main/java/gm/tieba/tabswitch/hooker/TSPreference.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import gm.tieba.tabswitch.dao.AcRules;
import gm.tieba.tabswitch.dao.Preferences;
import gm.tieba.tabswitch.hooker.TSPreferenceHelper.SwitchButtonHolder;
import gm.tieba.tabswitch.hooker.add.MyAttention;
import gm.tieba.tabswitch.hooker.deobfuscation.DeobfuscationHelper;
import gm.tieba.tabswitch.hooker.deobfuscation.Matcher;
import gm.tieba.tabswitch.hooker.deobfuscation.StringResMatcher;
Expand All @@ -47,7 +46,7 @@
public class TSPreference extends XposedContext implements IHooker, Obfuscated {
public final static String MAIN = "贴吧TS设置";
public final static String MODIFY_TAB = "修改页面";
public final static String NOTES = "备注关注的人";
// public final static String NOTES = "备注关注的人";
public final static String TRACE = "痕迹";
private final static String PROXY_ACTIVITY = "com.baidu.tieba.setting.im.more.SecretSettingActivity";
private static int sCount = 0;
Expand Down Expand Up @@ -110,9 +109,9 @@ protected void afterHookedMethod(final MethodHookParam param) throws Throwable {
case MODIFY_TAB:
proxyPage(activity, navigationBar, MODIFY_TAB, createModifyTabPreference(activity));
break;
case NOTES:
proxyPage(activity, navigationBar, NOTES, MyAttention.createNotesPreference(activity));
break;
// case NOTES:
// proxyPage(activity, navigationBar, NOTES, MyAttention.createNotesPreference(activity));
// break;
case TRACE:
proxyPage(activity, navigationBar, TRACE, createHidePreference(activity));
break;
Expand Down Expand Up @@ -140,6 +139,7 @@ protected void afterHookedMethod(final MethodHookParam param) throws Throwable {
private void proxyPage(final Activity activity, final NavigationBar navigationBar, final String title,
final LinearLayout preferenceLayout) throws Throwable {
navigationBar.setTitleText(title);
navigationBar.setCenterTextTitle("");
navigationBar.addTextButton("重启", v -> DisplayUtils.restart(activity));
final var contentView = (ViewGroup) activity.findViewById(android.R.id.content);
final var parent = (LinearLayout) contentView.getChildAt(0);
Expand Down Expand Up @@ -216,8 +216,8 @@ private LinearLayout createRootPreference(final Activity activity) {

preferenceLayout.addView(TSPreferenceHelper.createTextView(isPurgeEnabled ? "垂手可得" : "自动化"));
final SwitchButtonHolder autoSign = new SwitchButtonHolder(activity, "自动签到", "auto_sign", SwitchButtonHolder.TYPE_SWITCH);
if (!Preferences.getIsAutoSignEnabled()) {
autoSign.setOnButtonClickListener(v -> {
autoSign.setOnButtonClickListener(v -> {
if (!Preferences.getIsAutoSignEnabled()) {
final TbDialog bdalert = new TbDialog(activity, "提示",
"这是一个需要网络请求并且有封号风险的功能,您需要自行承担使用此功能的风险,请谨慎使用!", true, null);
bdalert.setOnNoButtonClickListener(v2 -> bdalert.dismiss());
Expand All @@ -227,14 +227,26 @@ private LinearLayout createRootPreference(final Activity activity) {
bdalert.dismiss();
});
bdalert.show();
});
}
} else {
autoSign.bdSwitch.changeState();
}
});
preferenceLayout.addView(autoSign);
preferenceLayout.addView(new SwitchButtonHolder(activity, "自动打开一键签到", "open_sign", SwitchButtonHolder.TYPE_SWITCH));
preferenceLayout.addView(new SwitchButtonHolder(activity, "吧页面起始页面改为最新", "frs_tab", SwitchButtonHolder.TYPE_SWITCH));
preferenceLayout.addView(new SwitchButtonHolder(activity, "消息页面起始页面改为通知", "msg_center_tab", SwitchButtonHolder.TYPE_SWITCH));
preferenceLayout.addView(new SwitchButtonHolder(activity, "自动查看原图", "origin_src", SwitchButtonHolder.TYPE_SWITCH));
preferenceLayout.addView(new SwitchButtonHolder(activity, "自动查看原图仅WiFi下生效", "origin_src_only_wifi", SwitchButtonHolder.TYPE_SWITCH));

var originSrcOnlyWifiButton = new SwitchButtonHolder(activity, "自动查看原图仅WiFi下生效", "origin_src_only_wifi", SwitchButtonHolder.TYPE_SWITCH);
var originSrcButton = new SwitchButtonHolder(activity, "自动查看原图", "origin_src", SwitchButtonHolder.TYPE_SWITCH);
originSrcButton.setOnButtonClickListener(v -> {
originSrcButton.bdSwitch.changeState();
originSrcOnlyWifiButton.switchButton.setVisibility(Preferences.getBoolean("origin_src") ? View.VISIBLE : View.GONE);
}
);
originSrcOnlyWifiButton.switchButton.setVisibility(Preferences.getBoolean("origin_src") ? View.VISIBLE : View.GONE);

preferenceLayout.addView(originSrcButton);
preferenceLayout.addView(originSrcOnlyWifiButton);

preferenceLayout.addView(TSPreferenceHelper.createTextView(isPurgeEnabled ? "奇怪怪" : "其它"));
preferenceLayout.addView(new SwitchButtonHolder(activity, "禁用帖子手势", "forbid_gesture", SwitchButtonHolder.TYPE_SWITCH));
Expand All @@ -246,11 +258,15 @@ private LinearLayout createRootPreference(final Activity activity) {
}));

preferenceLayout.addView(TSPreferenceHelper.createTextView(isPurgeEnabled ? "关于就是关于" : "关于"));
preferenceLayout.addView(TSPreferenceHelper.createButton("版本", BuildConfig.VERSION_NAME, true, v -> {
final Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
intent.setData(Uri.parse("https://github.com/GuhDoy/TiebaTS/releases/latest"));
activity.startActivity(intent);
preferenceLayout.addView(TSPreferenceHelper.createButton("作者", "GM", true, v -> {
sCount++;
if (sCount % 3 == 0) {
TbToast.showTbToast(TSPreferenceHelper.randomToast(), TbToast.LENGTH_SHORT);
}
if (!isPurgeEnabled && sCount >= 10) {
Preferences.putPurgeEnabled();
activity.recreate();
}
}));
preferenceLayout.addView(TSPreferenceHelper.createButton("源代码", "想要小星星", true, v -> {
final Intent intent = new Intent();
Expand All @@ -264,15 +280,11 @@ private LinearLayout createRootPreference(final Activity activity) {
intent.setData(Uri.parse("https://t.me/TabSwitch"));
activity.startActivity(intent);
}));
preferenceLayout.addView(TSPreferenceHelper.createButton("作者", "GM", true, v -> {
sCount++;
if (sCount % 3 == 0) {
TbToast.showTbToast(TSPreferenceHelper.randomToast(), TbToast.LENGTH_SHORT);
}
if (!isPurgeEnabled && sCount >= 10) {
Preferences.putPurgeEnabled();
activity.recreate();
}
preferenceLayout.addView(TSPreferenceHelper.createButton("版本", BuildConfig.VERSION_NAME, true, v -> {
final Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
intent.setData(Uri.parse("https://github.com/GuhDoy/TiebaTS/releases/latest"));
activity.startActivity(intent);
}));
return preferenceLayout;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ public static TextView createTextView(final String text) {
final TextView textView = new TextView(getContext());
textView.setText(text);
textView.setTextColor(ReflectUtils.getColor("CAM_X0108"));
textView.setTextSize(ReflectUtils.getDimenDip("fontsize28"));
textView.setTextSize(ReflectUtils.getDimenDip("fontsize22"));
final LinearLayout.LayoutParams layoutParams;
if (text != null) {
textView.setPaddingRelative((int) ReflectUtils.getDimen("ds30"),
(int) ReflectUtils.getDimen("ds32"), 0,
(int) ReflectUtils.getDimen("ds10"));
(int) ReflectUtils.getDimen("ds20"), 0,
(int) ReflectUtils.getDimen("ds20"));
layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
} else {
Expand Down Expand Up @@ -154,7 +154,10 @@ static class SwitchButtonHolder {

void setOnButtonClickListener(final View.OnClickListener l) {
switchButton.setOnClickListener(l);
bdSwitch.bdSwitch.setOnTouchListener((View v, MotionEvent event) -> false);
bdSwitch.bdSwitch.setOnTouchListener((View v, MotionEvent event) -> {
XposedHelpers.callMethod(bdSwitch.getVibrator(), "vibrate", 30L);
return false;
});
}

private void showRegexDialog(final Activity activity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,18 @@ protected void beforeHookedMethod(final MethodHookParam param) throws Throwable
}
});
});
if (Preferences.getBoolean("dynamic_style")) {
XposedBridge.hookAllMethods(XposedHelpers.findClass("com.baidu.adp.framework.MessageManager",
sClassLoader), "dispatchResponsedMessage", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(final MethodHookParam param) throws Throwable {
final Object responsedMessage = param.args[0];
if ((int) XposedHelpers.getObjectField(responsedMessage, "mCmd") == 2921551) {
param.setResult(null);
}
}
});
}
// Merged with Purge
// if (Preferences.getBoolean("dynamic_style")) {
// XposedBridge.hookAllMethods(XposedHelpers.findClass("com.baidu.adp.framework.MessageManager",
// sClassLoader), "dispatchResponsedMessage", new XC_MethodHook() {
// @Override
// protected void beforeHookedMethod(final MethodHookParam param) throws Throwable {
// final Object responsedMessage = param.args[0];
// if ((int) XposedHelpers.getObjectField(responsedMessage, "mCmd") == 2921551) {
// param.setResult(null);
// }
// }
// });
// }
}
}
4 changes: 4 additions & 0 deletions app/src/main/java/gm/tieba/tabswitch/util/ReflectUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public static float getDimen(final String fieldName) {
switch (fieldName) {
case "ds10":
return DisplayUtils.dipToPx(getContext(), 5F);
case "ds20":
return DisplayUtils.dipToPx(getContext(), 10F);
case "ds30":
return DisplayUtils.dipToPx(getContext(), 15F);
case "ds32":
Expand All @@ -43,6 +45,8 @@ public static float getDimen(final String fieldName) {

public static float getDimenDip(final String fieldName) {
switch (fieldName) {
case "fontsize22":
return 11F;
case "fontsize28":
return 14F;
case "fontsize36":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ public void addTextButton(final String text, final View.OnClickListener l) {
public void setTitleText(final String title) {
XposedHelpers.callMethod(mNavigationBar, "setTitleText", title);
}

public void setCenterTextTitle(final String title) {
XposedHelpers.callMethod(mNavigationBar, "setCenterTextTitle", title);
}
}
5 changes: 5 additions & 0 deletions app/src/main/java/gm/tieba/tabswitch/widget/Switch.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gm.tieba.tabswitch.widget;

import android.os.Vibrator;
import android.view.View;

import java.lang.reflect.InvocationHandler;
Expand Down Expand Up @@ -66,4 +67,8 @@ public void turnOff() {
ReflectUtils.callMethod(mMethods[8], bdSwitch);
}
}

public Vibrator getVibrator() {
return ReflectUtils.getObjectField(bdSwitch, Vibrator.class);
}
}

0 comments on commit c9b808b

Please sign in to comment.