diff --git a/app/build.gradle b/app/build.gradle index 44543bf..0695858 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,7 +6,7 @@ android { defaultConfig { applicationId "moe.reimu.weiboxposed" - minSdkVersion 19 + minSdkVersion 21 targetSdkVersion 23 versionCode 2 versionName "1.0.1" @@ -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' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 84b6b10..42ba5f8 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,20 +1,32 @@ - + + android:label="@string/app_name" + android:theme="@android:style/Theme.Material.Light"> + android:value="true"/> + android:value="@string/module_desc"/> + android:value="30"/> + + + + + + + + - + \ No newline at end of file diff --git a/app/src/main/java/moe/reimu/weiboxposed/Module.java b/app/src/main/java/moe/reimu/weiboxposed/Module.java index 1d6ae9a..0b84f96 100644 --- a/app/src/main/java/moe/reimu/weiboxposed/Module.java +++ b/app/src/main/java/moe/reimu/weiboxposed/Module.java @@ -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; @@ -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")) @@ -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 { @@ -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 origResult = (ArrayList)param.getResult(); @@ -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); + } /** @@ -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."); + } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2f841ca..8201b45 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,4 +1,14 @@ WeiboXposed 微博修改 by 加大号的猫 + 设置 + + + + 使用实验性移除方式 + 将采用新的微博移除方式,会留下较为明显的空白。如果您不需要查看分组微博,可禁用此功能 + + 将采用基于数据的移除方式,可能影响分组微博,导致无法正常刷新。 + + 配置已保存,强行停止微博或重启设备后生效