Skip to content

Commit

Permalink
GrindrPlus Fix taps scroll
Browse files Browse the repository at this point in the history
* Fix scroll mechanism upon clicking tap notifications

* From #48
  • Loading branch information
TebbeUbben authored Jan 10, 2025
1 parent f49bb50 commit a620bfd
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions app/src/main/java/com/grindrplus/hooks/ReverseRadarTabs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ import com.grindrplus.utils.HookStage
import com.grindrplus.utils.hook
import com.grindrplus.utils.hookConstructor
import de.robv.android.xposed.XposedHelpers
import de.robv.android.xposed.XposedHelpers.*
import java.lang.Thread.sleep
import java.util.ArrayList
import java.util.Arrays
import java.util.Collections
import kotlin.concurrent.thread

class ReverseRadarTabs : Hook(
"Reverse radar tabs",
Expand Down Expand Up @@ -45,7 +48,7 @@ class ReverseRadarTabs : Hook(
//viewPagerClass.getMethod("setCurrentItem", Int::class.java).invoke(viewPager, 1)
}*/

val radarTabs = XposedHelpers.callStaticMethod(findClass(radarTabs), "values") as Array<*>
val radarTabs = callStaticMethod(findClass(radarTabs), "values") as Array<*>

findClass("$radarFragment\$a")
.hookConstructor(HookStage.BEFORE) { param ->
Expand All @@ -57,14 +60,36 @@ class ReverseRadarTabs : Hook(
}


//Unfortunately, some methods in RadarFragment use the ordinal of the RadarTab enum to determine the position in the TabLayout
//Unfortunately, some methods in RadarFragment use the ordinal of the RadarTab enum to determine the position in the TabLayout,
//which no longer reflects the actual position in the ViewPager
findClass("com.google.android.material.tabs.TabLayout")
.hook("getTabAt", HookStage.BEFORE) { param ->
if (!Thread.currentThread().stackTrace.any {
it.className.contains(radarFragment)
}) return@hook
param.setArg(0, radarTabs.size - 1 - param.arg<Int>(0))
}

//This LiveData observer consumes the integer values from a flow and makes the ViewPager scroll to that position
//This is used to make the ViewPager scroll to the taps page upon clicking such notification.
//However, this is based on the ordinal values again, so we have to reverse the values, too.
findClass("K9.H0")
.hook("onChanged", HookStage.BEFORE) { param ->
//Check whether this observer is responsible for handling the ViewPager position
if (getIntField(param.thisObject(), "b") != 1) return@hook
val position = param.arg<Number>(0).toInt()
param.setArg(0, Integer.valueOf(radarTabs.size - 1 - position))
}

//The modified LiveData observer will no longer scroll to the first position when receiving a value 0.
//In order to still show the new first tab (TapsFragment) by default, we need to set the initial value to the last index,
//so that the LiveData observer reverts it back to 0.
findClass("ma.t0")
.hookConstructor(HookStage.AFTER) { param ->
val stateFlow = getObjectField(param.thisObject(), "I0")
//Set initial position to the last page, so that the onChanged hook of the LiveData observer reverts it to the new first page
callMethod(stateFlow, "setValue", Integer.valueOf(radarTabs.size - 1))
}
}

}

0 comments on commit a620bfd

Please sign in to comment.