Skip to content

Commit

Permalink
No more deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
shatyuka committed Mar 17, 2024
1 parent 03353f4 commit 8d41db3
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 8 deletions.
6 changes: 6 additions & 0 deletions app/src/main/java/com/shatyuka/zhiliao/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class Helper {
public static SharedPreferences prefs;
public static Resources modRes;
public static PackageInfo packageInfo;
public static int versionCode;

public static Object settingsView;

Expand All @@ -55,12 +56,15 @@ public class Helper {
public final static String hookPackage = "com.zhihu.android";
private final static byte[] signature = new byte[]{(byte) 0xB6, (byte) 0xF9, (byte) 0x97, (byte) 0xE3, (byte) 0x82, 0x7B, (byte) 0xE1, 0x1A, (byte) 0xF2, (byte) 0xFA, 0x4A, 0x15, 0x3F, (byte) 0xEA, 0x3F, (byte) 0xE6, 0x27, 0x68, 0x66, 0x02};

/** @noinspection RedundantSuppression*/
@SuppressWarnings("deprecation")
static boolean init(ClassLoader classLoader) {
try {
init_class(classLoader);

prefs = context.getSharedPreferences("zhiliao_preferences", Context.MODE_PRIVATE);
packageInfo = context.getPackageManager().getPackageInfo("com.zhihu.android", 0);
versionCode = packageInfo.versionCode;

regex_title = compileRegex(prefs.getString("edit_title", ""));
regex_author = compileRegex(prefs.getString("edit_author", ""));
Expand Down Expand Up @@ -265,6 +269,8 @@ public static Field findFieldByType(Class<?> clazz, Class<?> type) {
return field;
}

/** @noinspection RedundantSuppression*/
@SuppressWarnings("deprecation")
private static Signature[] getSignatures(Context context) throws PackageManager.NameNotFoundException {
PackageManager pm = context.getPackageManager();
Signature[] sig;
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/shatyuka/zhiliao/hooks/Article.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public String getName() {

@Override
public void init(ClassLoader classLoader) throws Throwable {
if (Helper.packageInfo.versionCode > 2614) {
if (Helper.versionCode > 2614) {
try {
ContentMixAdapter = classLoader.loadClass("com.zhihu.android.mix.a.a");
getItemCount = ContentMixAdapter.getMethod("getItemCount");
Expand Down Expand Up @@ -72,7 +72,7 @@ public void init(ClassLoader classLoader) throws Throwable {

@Override
public void hook() throws Throwable {
if (Helper.packageInfo.versionCode > 2614) { // after 6.61.0
if (Helper.versionCode > 2614) { // after 6.61.0
if (Helper.prefs.getBoolean("switch_mainswitch", false) && Helper.prefs.getBoolean("switch_article", false)) {
XposedBridge.hookMethod(getItemCount, new XC_MethodHook() {
@Override
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/shatyuka/zhiliao/hooks/Horizontal.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void init(ClassLoader classLoader) throws Throwable {
ActionSheetLayout_callbackList = ActionSheetLayout.getDeclaredField("z");
ActionSheetLayout_callbackList.setAccessible(true);

if (Helper.packageInfo.versionCode > 2614) {
if (Helper.versionCode > 2614) {
MixPagerContainer = classLoader.loadClass("com.zhihu.android.mix.widget.MixPagerContainer");
Class<?> VerticalPagerContainer = classLoader.loadClass("com.zhihu.android.bootstrap.vertical_pager.VerticalPagerContainer");
Helper.findClass(classLoader, "com.zhihu.android.bootstrap.vertical_pager.",
Expand Down Expand Up @@ -200,7 +200,7 @@ protected void beforeHookedMethod(MethodHookParam param) {
}
});

if (Helper.packageInfo.versionCode > 2614) {
if (Helper.versionCode > 2614) {
XposedBridge.hookMethod(Helper.getMethodByParameterTypes(ContentMixPagerFragment, MotionEvent.class), new XC_MethodHook() {
float old_x = 0;
float old_y = 0;
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/shatyuka/zhiliao/hooks/NextAnswer.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public String getName() {

@Override
public void init(ClassLoader classLoader) throws Throwable {
if (Helper.packageInfo.versionCode > 2614) {
if (Helper.versionCode > 2614) {
NextContentAnimationView = classLoader.loadClass("com.zhihu.android.mix.widget.NextContentAnimationView");
try {
NextContentAnimationView_short = classLoader.loadClass("com.zhihu.android.mixshortcontainer.function.next.NextContentAnimationView");
Expand Down Expand Up @@ -82,7 +82,7 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
});
}

if (Helper.packageInfo.versionCode > 2614) {
if (Helper.versionCode > 2614) {
XposedHelpers.findAndHookMethod(ViewGroup.class, "addView", View.class, ViewGroup.LayoutParams.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ allprojects {
}

tasks.register('clean', Delete) {
delete rootProject.buildDir
delete rootProject.layout.buildDirectory
}
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ android.enableAppCompileTimeRClass=true
android.enableR8.fullMode=true
android.experimental.enableNewResourceShrinker=true
android.experimental.enableNewResourceShrinker.preciseShrinking=true
android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
Expand Down

0 comments on commit 8d41db3

Please sign in to comment.