From dc74b4932725a1c441093b77c1bdee30e0bd0738 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Paprota?= Date: Wed, 31 Mar 2021 21:24:55 +0200 Subject: [PATCH] More logging. --- app/build.gradle | 8 ++-- .../twitteradeater/TwitterAdEaterModule.kt | 12 ++++-- .../java/com/acme/twitteradeater/Utils.kt | 38 ++++++++++++++++--- 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index dd2cb47..db6f65f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -11,8 +11,8 @@ android { applicationId "com.acme.twitteradeater" minSdkVersion 29 targetSdkVersion 30 - versionCode 1 - versionName "1.0" + versionCode 12 + versionName "1.2" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } @@ -27,13 +27,13 @@ android { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } + kotlinOptions { jvmTarget = '1.8' } } dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" implementation 'androidx.core:core-ktx:1.2.0' implementation 'androidx.appcompat:appcompat:1.1.0' @@ -44,4 +44,4 @@ dependencies { testImplementation 'junit:junit:4.+' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' -} \ No newline at end of file +} diff --git a/app/src/main/java/com/acme/twitteradeater/TwitterAdEaterModule.kt b/app/src/main/java/com/acme/twitteradeater/TwitterAdEaterModule.kt index 59b65b8..cfbcbd7 100644 --- a/app/src/main/java/com/acme/twitteradeater/TwitterAdEaterModule.kt +++ b/app/src/main/java/com/acme/twitteradeater/TwitterAdEaterModule.kt @@ -49,15 +49,21 @@ class TwitterAdEaterModule : IXposedHookLoadPackage { // Need to use the event loop, otherwise we don't have the correct visibility of the promoted parts v.postDelayed( { - v.visibility = if (isPromoted(v)) View.GONE else View.VISIBLE + if (isPromoted(v)) { + v.visibility = View.GONE + logcat("Removing ad: view = %s", v) + logView(v.parent as View) + } else { + v.visibility = View.VISIBLE + } }, 1 ) } private fun isPromoted(v: View): Boolean { - if (v.toString().contains("tweet_promoted_badge_bottom") && v.visibility == View.VISIBLE) { - return v !is ViewStub + if (v.toString().contains("promoted") && v.visibility == View.VISIBLE) { + return true } if (v is ViewGroup) { return v.children.any { isPromoted(it) } diff --git a/app/src/main/java/com/acme/twitteradeater/Utils.kt b/app/src/main/java/com/acme/twitteradeater/Utils.kt index fa17902..2840fbb 100644 --- a/app/src/main/java/com/acme/twitteradeater/Utils.kt +++ b/app/src/main/java/com/acme/twitteradeater/Utils.kt @@ -6,7 +6,7 @@ import android.view.ViewGroup import androidx.core.view.children import de.robv.android.xposed.XposedBridge -private val TAG: String = "TwitterAdEater" +private const val TAG: String = "TwitterAdEater" fun log(message: String, vararg va: Any?) { XposedBridge.log(String.format(message, *va)) @@ -16,11 +16,39 @@ fun logcat(message: String, vararg va: Any?) { Log.i(TAG, String.format(message, *va)) } -fun logView(v: View, ind: String = "") { - logcat("%sView %s", ind, v.toString()) +fun logerr(message: String, vararg va: Any?) { + Log.e(TAG, String.format(message, *va)) +} + +fun logView(v: View, ind: String = "--") { + var desc = v.toString() + val cls = v.javaClass + + try { + when (cls.name) { + "androidx.appcompat.widget.AppCompatTextView" -> { + desc = cls.getMethod("getText").invoke(v).toString() + } + "com.twitter.ui.widget.TypefacesTextView" -> { + desc = cls.getMethod("getText").invoke(v).toString() + } + "com.twitter.ui.widget.TextLayoutView" -> { + desc = cls.getMethod("getText").invoke(v).toString() + } + "com.twitter.ui.widget.UnpaddedTextLayoutView" -> { + desc = cls.getMethod("getText").invoke(v).toString() + } + //"com.twitter.ui.user.UserLabelView" -> { + // desc = cls.getMethod("getText").invoke(v).toString() + //} + } + } catch (e: NoSuchMethodException) { + logerr("Failed to describe view %s", v) + } + + logcat("%sView [%s]: %s", ind, v.javaClass.name, desc) if (v is ViewGroup) { - //logcat(v.children.joinToString("\n") { it.toString() }) - v.children.forEach { logView(it, "$ind ") } + v.children.forEach { logView(it, "$ind--") } } }