mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-05-24 02:22:11 +02:00
fix(core): snap score changes
Signed-off-by: rhunk <101876869+rhunk@users.noreply.github.com>
This commit is contained in:
parent
952d43b5e2
commit
b6aa4857d2
@ -42,25 +42,28 @@ class SnapScoreChanges: Feature("Snap Score Changes") {
|
|||||||
|
|
||||||
if (event.viewClassName.endsWith("ProfileFlatlandFriendSnapScoreIdentityPillDialogView")) {
|
if (event.viewClassName.endsWith("ProfileFlatlandFriendSnapScoreIdentityPillDialogView")) {
|
||||||
event.view.post {
|
event.view.post {
|
||||||
val composerViewNode = event.view.getComposerViewNode() ?: return@post
|
event.view.getComposerContext()!!.enqueueNextRenderCallback {
|
||||||
val surface = composerViewNode.getChildren().getOrNull(1) ?: return@post
|
val composerViewNode = event.view.getComposerViewNode() ?: return@enqueueNextRenderCallback
|
||||||
|
val surface = composerViewNode.getChildren().getOrNull(1) ?: return@enqueueNextRenderCallback
|
||||||
|
|
||||||
val snapTextView = surface.getChildren().lastOrNull {
|
val snapTextView = surface.getChildren().lastOrNull {
|
||||||
it.getClassName() == "com.snap.composer.views.ComposerSnapTextView"
|
it.getClassName() == "com.snap.composer.views.ComposerSnapTextView"
|
||||||
} ?: return@post
|
} ?: return@enqueueNextRenderCallback
|
||||||
|
|
||||||
|
|
||||||
val currentFriendScore = scores[lastViewedUserId] ?: (event.view.getComposerContext()?.viewModel?.getObjectField("_friendSnapScore") as? Double)?.toLong() ?: return@post
|
val currentFriendScore = scores[lastViewedUserId] ?: (event.view.getComposerContext()?.viewModel?.getObjectField("_friendSnapScore") as? Double)?.toLong() ?: return@enqueueNextRenderCallback
|
||||||
|
|
||||||
val oldSnapScore = context.bridgeClient.getTracker().updateFriendScore(
|
val oldSnapScore = context.bridgeClient.getTracker().updateFriendScore(
|
||||||
lastViewedUserId ?: return@post,
|
lastViewedUserId ?: return@enqueueNextRenderCallback,
|
||||||
currentFriendScore
|
currentFriendScore
|
||||||
)
|
)
|
||||||
|
|
||||||
val diff = currentFriendScore - oldSnapScore
|
val diff = currentFriendScore - oldSnapScore
|
||||||
|
|
||||||
snapTextView.setAttribute("value", "${if (oldSnapScore != -1L && diff > 0) "\uD83D\uDCC8 +$diff !\n\n" else ""}Last Checked Score: ${oldSnapScore.takeIf { it != -1L } ?: "N/A"}")
|
snapTextView.setAttribute("value", "${if (oldSnapScore != -1L && diff > 0) "\uD83D\uDCC8 +$diff !\n\n" else ""}Last Checked Score: ${oldSnapScore.takeIf { it != -1L } ?: "N/A"}")
|
||||||
event.view.invalidate()
|
event.view.postInvalidate()
|
||||||
|
}
|
||||||
|
event.view.postInvalidate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,23 @@ package me.rhunk.snapenhance.core.wrapper.impl.composer
|
|||||||
|
|
||||||
import me.rhunk.snapenhance.core.wrapper.AbstractWrapper
|
import me.rhunk.snapenhance.core.wrapper.AbstractWrapper
|
||||||
import java.lang.ref.WeakReference
|
import java.lang.ref.WeakReference
|
||||||
|
import java.lang.reflect.Proxy
|
||||||
|
|
||||||
class ComposerContext(obj: Any): AbstractWrapper(obj) {
|
class ComposerContext(obj: Any): AbstractWrapper(obj) {
|
||||||
val componentPath by field<String>("componentPath")
|
val componentPath by field<String>("componentPath")
|
||||||
val viewModel by field<Any?>("innerViewModel")
|
val viewModel by field<Any?>("innerViewModel")
|
||||||
val moduleName by field<String>("moduleName")
|
val moduleName by field<String>("moduleName")
|
||||||
val componentContext by field<WeakReference<Any?>>("componentContext")
|
val componentContext by field<WeakReference<Any?>>("componentContext")
|
||||||
|
|
||||||
|
fun enqueueNextRenderCallback(callback: () -> Unit) {
|
||||||
|
val method = instanceNonNull()::class.java.methods.firstOrNull {
|
||||||
|
it.name == "onNextLayout"
|
||||||
|
}
|
||||||
|
method?.invoke(instanceNonNull(), Proxy.newProxyInstance(
|
||||||
|
instanceNonNull()::class.java.classLoader,
|
||||||
|
arrayOf(method.parameterTypes[0])
|
||||||
|
) { _, _, _ ->
|
||||||
|
callback()
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user