Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
New Removing Method
Browse files Browse the repository at this point in the history
  • Loading branch information
kmod-midori committed Aug 1, 2016
1 parent 241a2d9 commit b9a7a24
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 13 deletions.
4 changes: 3 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ android {

defaultConfig {
applicationId "moe.reimu.weiboxposed"
minSdkVersion 19
minSdkVersion 21
targetSdkVersion 23
versionCode 2
versionName "1.0.1"
Expand All @@ -21,4 +21,6 @@ android {

dependencies {
provided 'de.robv.android.xposed:api:82'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:design:23.4.0'
}
26 changes: 19 additions & 7 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="moe.reimu.weiboxposed" >
<manifest package="moe.reimu.weiboxposed"
xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" >
android:label="@string/app_name"
android:theme="@android:style/Theme.Material.Light">
<meta-data
android:name="xposedmodule"
android:value="true" />
android:value="true"/>
<meta-data
android:name="xposeddescription"
android:value="@string/module_desc" />
android:value="@string/module_desc"/>
<meta-data
android:name="xposedminversion"
android:value="30" />
android:value="30"/>

<activity
android:name=".SettingsActivity"
android:label="@string/title_activity_settings"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="de.robv.android.xposed.category.MODULE_SETTINGS" />
</intent-filter>
</activity>
</application>

</manifest>
</manifest>
64 changes: 59 additions & 5 deletions app/src/main/java/moe/reimu/weiboxposed/Module.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package moe.reimu.weiboxposed;

import android.app.AndroidAppHelper;
import android.content.res.XResources;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import org.json.JSONArray;
import org.json.JSONObject;
Expand All @@ -14,15 +16,18 @@

import de.robv.android.xposed.IXposedHookInitPackageResources;
import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.IXposedHookZygoteInit;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XSharedPreferences;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.callbacks.XC_InitPackageResources.InitPackageResourcesParam;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;
import static de.robv.android.xposed.XposedHelpers.getObjectField;

public class Module implements IXposedHookInitPackageResources, IXposedHookLoadPackage {

public class Module implements IXposedHookInitPackageResources, IXposedHookLoadPackage, IXposedHookZygoteInit {
public XSharedPreferences prefs;
@Override
public void handleInitPackageResources(InitPackageResourcesParam resparam) throws Throwable {
if (!resparam.packageName.equals("com.sina.weibo"))
Expand All @@ -37,6 +42,11 @@ public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam lpparam) thr
if (!lpparam.packageName.equals("com.sina.weibo"))
return;

prefs.reload();
boolean useExpMethod = prefs.getBoolean("switch_remove_mode", false);
XposedBridge.log("[WeiboXposed] App Weibo Loaded");
XposedBridge.log("[WeiboXposed] Remove Mode: " + useExpMethod);

XC_MethodHook callbackCancel = new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
Expand All @@ -57,7 +67,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
});
findAndHookMethod(LIST_BASE, lpparam.classLoader, "insetTrend", callbackCancel);

XC_MethodHook removeAD = new XC_MethodHook() {
XC_MethodHook removeAD_Old = new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
ArrayList<Object> origResult = (ArrayList<Object>)param.getResult();
Expand All @@ -80,9 +90,45 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
}
};

findAndHookMethod(LIST_BASE, lpparam.classLoader, "getStatuses", removeAD);
findAndHookMethod(LIST_BASE, lpparam.classLoader, "getStatusesCopy", removeAD);
XC_MethodHook removeAD_New = new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
/*
.param p1, "position" # I
.param p2, "convertView" # Landroid/view/View;
.param p3, "parent" # Landroid/view/ViewGroup;
*/
Object view = param.getResult();

Object status;
Object promotion;
try {
status = getObjectField(view, "d");
promotion = getObjectField(status, "promotion");
} catch (NoSuchFieldError e) {
return;
}

if (promotion != null) {
String adType = (String)getObjectField(promotion, "adtype");

// Exclude "热门"
if ("8".equals(adType)) return;

XposedBridge.log("[WeiboXposed] Removing #" + getObjectField(status, "id") + " with adtype=" + adType + ":" + getObjectField(promotion, "recommend"));
TextView tv = new TextView(AndroidAppHelper.currentApplication()); // Empty view
param.setResult(tv);
}
}
};

if (useExpMethod) {
findAndHookMethod("com.sina.weibo.feed.HomeListActivity$o", lpparam.classLoader, "getView",
int.class, android.view.View.class, android.view.ViewGroup.class, removeAD_New);
} else {
findAndHookMethod(LIST_BASE, lpparam.classLoader, "getStatuses", removeAD_Old);
findAndHookMethod(LIST_BASE, lpparam.classLoader, "getStatusesCopy", removeAD_Old);
}


/**
Expand Down Expand Up @@ -111,4 +157,12 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
}
});
}

@Override
public void initZygote(StartupParam startupParam) throws Throwable {
prefs = new XSharedPreferences(Module.class.getPackage().getName(), SettingsActivity.PREF_NAME);
prefs.makeWorldReadable();

XposedBridge.log("[WeiboXposed] Pref Init.");
}
}
10 changes: 10 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
<resources>
<string name="app_name">WeiboXposed</string>
<string name="module_desc">微博修改 by 加大号的猫</string>
<string name="title_activity_settings">设置</string>

<!-- Strings related to Settings -->

<string name="pref_title_switch_remove_mode">使用实验性移除方式</string>
<string name="pref_description_switch_remove_mode_on">将采用新的微博移除方式,会留下较为明显的空白。如果您不需要查看分组微博,可禁用此功能
</string>
<string name="pref_description_switch_remove_mode_off">将采用基于数据的移除方式,可能影响分组微博,导致无法正常刷新。
</string>
<string name="restart_weibo">配置已保存,强行停止微博或重启设备后生效</string>
</resources>

0 comments on commit b9a7a24

Please sign in to comment.