|
| 1 | +package app.revanced.patches.viber.misc.navbar |
| 2 | + |
| 3 | +import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels |
| 4 | +import app.revanced.patcher.patch.booleanOption |
| 5 | +import app.revanced.patcher.patch.bytecodePatch |
| 6 | +import java.util.logging.Logger |
| 7 | +import kotlin.collections.joinToString |
| 8 | + |
| 9 | + |
| 10 | +private const val instructionsFooter = """ |
| 11 | + # If we reach this, it means that this tab has been disabled by user |
| 12 | + const/4 v0, 0 |
| 13 | + return v0 # return false as "This tab is not enabled" |
| 14 | + |
| 15 | + # Proceed with default execution |
| 16 | + :continue |
| 17 | + nop |
| 18 | +""" |
| 19 | + |
| 20 | +@Suppress("unused") |
| 21 | +val hideNavigationButtonsPatch = bytecodePatch( |
| 22 | + name = "Hide navigation buttons", |
| 23 | + description = "Permanently hides navigation bar buttons, such as Explore and Marketplace.", |
| 24 | + use = false |
| 25 | +) { |
| 26 | + compatibleWith("com.viber.voip") |
| 27 | + |
| 28 | + val hideOptions = AllowedNavigationItems.entries.associateWith { |
| 29 | + booleanOption( |
| 30 | + key = it.key, |
| 31 | + default = it.defaultHideOption, |
| 32 | + title = it.title, |
| 33 | + description = it.description, |
| 34 | + ) |
| 35 | + } |
| 36 | + |
| 37 | + execute { |
| 38 | + // Items that won't be forcefully hidden. |
| 39 | + val allowedItems = hideOptions.filter { (option, enabled) -> enabled.value != true } |
| 40 | + |
| 41 | + if (allowedItems.size == AllowedNavigationItems.entries.size) { |
| 42 | + return@execute Logger.getLogger(this::class.java.name).warning( |
| 43 | + "No hide navigation buttons options are enabled. No changes made." |
| 44 | + ) |
| 45 | + } |
| 46 | + |
| 47 | + val injectionInstructions = allowedItems |
| 48 | + .map { it.key.buildAllowInstruction() } |
| 49 | + .joinToString("\n") + instructionsFooter |
| 50 | + |
| 51 | + shouldShowTabIdMethodFingerprint |
| 52 | + .method |
| 53 | + .addInstructionsWithLabels(0, injectionInstructions) |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +/** |
| 58 | + * Navigation items taken from source code. |
| 59 | + * They appear in code like new NavigationItem(0, R.string.bottom_tab_chats, R.drawable.ic_tab_chats). |
| 60 | + */ |
| 61 | +private enum class AllowedNavigationItems( |
| 62 | + val defaultHideOption: Boolean, |
| 63 | + private val itemName: String, |
| 64 | + private vararg val ids: Int |
| 65 | +) { |
| 66 | + CHATS(false, "Chats", 0), |
| 67 | + CALLS(false, "Calls", 1, 7), |
| 68 | + EXPLORE(true, "Explore", 2), |
| 69 | + MORE(false, "More", 3), |
| 70 | + PAY(true, "Pay", 5), |
| 71 | + CAMERA(true, "Camera", 6), |
| 72 | + MARKETPLACE(true, "Marketplace", 8); |
| 73 | + |
| 74 | + val key = "hide$itemName" |
| 75 | + val title = "Hide $itemName" |
| 76 | + val description = "Permanently hides the $itemName button." |
| 77 | + |
| 78 | + fun buildAllowInstruction(): String = |
| 79 | + ids.joinToString("\n") { id -> |
| 80 | + """ |
| 81 | + const/4 v0, $id # If tabId == $id ($itemName), don't hide it |
| 82 | + if-eq p1, v0, :continue |
| 83 | + """ |
| 84 | + } |
| 85 | +} |
0 commit comments