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

Commit

Permalink
fix: add back Ripple
Browse files Browse the repository at this point in the history
  • Loading branch information
mkx173 committed Apr 12, 2024
1 parent 6f58f1f commit 5735970
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/gm/tieba/tabswitch/XposedInit.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import gm.tieba.tabswitch.hooker.Obfuscated;
import gm.tieba.tabswitch.hooker.TSPreference;
import gm.tieba.tabswitch.hooker.add.HistoryCache;
import gm.tieba.tabswitch.hooker.add.Ripple;
import gm.tieba.tabswitch.hooker.add.SaveImages;
import gm.tieba.tabswitch.hooker.add.SelectClipboard;
import gm.tieba.tabswitch.hooker.auto.AgreeNum;
Expand Down Expand Up @@ -141,6 +142,7 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
new ContentFilter(),
new FrsPageFilter(),
new HistoryCache(),
new Ripple(),
new SaveImages(),
new AutoSign(),
new OpenSign(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ private LinearLayout createRootPreference(final Activity activity) {

preferenceLayout.addView(TSPreferenceHelper.createTextView(isPurgeEnabled ? "别出新意" : "增加功能"));
preferenceLayout.addView(new SwitchButtonHolder(activity, "浏览历史增加搜索", "history_cache", SwitchButtonHolder.TYPE_SWITCH));
preferenceLayout.addView(new SwitchButtonHolder(activity, "楼层增加点按效果", "ripple", SwitchButtonHolder.TYPE_SWITCH));
preferenceLayout.addView(new SwitchButtonHolder(activity, "长按下载保存全部图片", "save_images", SwitchButtonHolder.TYPE_SWITCH));
preferenceLayout.addView(new SwitchButtonHolder(activity, "弹窗自由复制", "select_clipboard", SwitchButtonHolder.TYPE_SWITCH));

Expand Down
86 changes: 86 additions & 0 deletions app/src/main/java/gm/tieba/tabswitch/hooker/add/Ripple.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package gm.tieba.tabswitch.hooker.add;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.InsetDrawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.PaintDrawable;
import android.graphics.drawable.StateListDrawable;
import android.util.AttributeSet;
import android.util.SparseArray;
import android.view.View;
import android.widget.RelativeLayout;

import androidx.annotation.NonNull;

import java.lang.reflect.Method;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import gm.tieba.tabswitch.XposedContext;
import gm.tieba.tabswitch.hooker.IHooker;
import gm.tieba.tabswitch.util.DisplayUtils;
import gm.tieba.tabswitch.util.ReflectUtils;

public class Ripple extends XposedContext implements IHooker {

@NonNull
@Override
public String key() {
return "ripple";
}

public void hook() throws Throwable {
final var subPbLayoutClass = XposedHelpers.findClass("com.baidu.tieba.pb.pb.sub.SubPbLayout", sClassLoader);
// 楼中楼
try {
Method md;
try {
md = subPbLayoutClass.getDeclaredFields()[4].getType().getDeclaredMethod("createView");
} catch (final NoSuchMethodException e) {
md = subPbLayoutClass.getDeclaredFields()[4].getType().getDeclaredMethod("b");
}
XposedBridge.hookMethod(md, new XC_MethodHook() {
@Override
protected void afterHookedMethod(final MethodHookParam param) throws Throwable {
final var newSubPbListItem = (View) param.getResult();
final var tag = (SparseArray) newSubPbListItem.getTag();
final var b = tag.valueAt(0);
// R.id.new_sub_pb_list_richText
final var view = (View) ReflectUtils.getObjectField(b, "com.baidu.tbadk.widget.richText.TbRichTextView");
view.setBackground(createSubPbBackground(DisplayUtils.dipToPx(getContext(), 5F)));
}
});
} catch (final NoSuchMethodException e) {
XposedBridge.log(e);
}
// 查看全部回复
XposedHelpers.findAndHookConstructor(subPbLayoutClass, Context.class, AttributeSet.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(final MethodHookParam param) throws Throwable {
final var view = ReflectUtils.getObjectField(param.thisObject, RelativeLayout.class);
view.setBackground(createSubPbBackground(DisplayUtils.dipToPx(getContext(), 3.5F)));
}
});
}

private StateListDrawable createSubPbBackground(int bottomInset) {
final StateListDrawable sld = new StateListDrawable();

PaintDrawable bg = new PaintDrawable(Color.argb(192,
Color.red(ReflectUtils.getColor("CAM_X0201")),
Color.green(ReflectUtils.getColor("CAM_X0201")),
Color.blue(ReflectUtils.getColor("CAM_X0201"))
));
bg.setCornerRadius(DisplayUtils.dipToPx(getContext(), 2F));

LayerDrawable layerBg = new LayerDrawable(new Drawable[]{bg});
layerBg.setLayerInset(0, 0, 0, 0, bottomInset);

sld.addState(new int[]{android.R.attr.state_pressed}, layerBg);
return sld;
}
}

0 comments on commit 5735970

Please sign in to comment.