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

Commit

Permalink
More logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
ppawel committed Mar 31, 2021
1 parent 6e58730 commit dc74b49
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 12 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand All @@ -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'
Expand All @@ -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'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
38 changes: 33 additions & 5 deletions app/src/main/java/com/acme/twitteradeater/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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--") }
}
}

Expand Down

0 comments on commit dc74b49

Please # to comment.