Skip to content

Commit 109bab7

Browse files
retain long press actions
1 parent cf5ba27 commit 109bab7

File tree

1 file changed

+35
-25
lines changed

1 file changed

+35
-25
lines changed

patches/src/main/kotlin/app/revanced/patches/shared/layout/branding/BaseCustomBrandingPatch.kt

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ import app.revanced.patches.shared.misc.settings.preference.ListPreference
1717
import app.revanced.util.ResourceGroup
1818
import app.revanced.util.Utils.trimIndentMultiline
1919
import app.revanced.util.copyResources
20+
import app.revanced.util.findElementByAttributeValue
2021
import app.revanced.util.findElementByAttributeValueOrThrow
2122
import app.revanced.util.returnEarly
2223
import org.w3c.dom.Element
24+
import org.w3c.dom.NodeList
2325
import java.io.File
2426
import java.util.logging.Logger
2527

@@ -264,25 +266,15 @@ internal fun baseCustomBrandingPatch(
264266
}
265267
}
266268

267-
// Create launch aliases that can be programmatically selected in app.
268269
document("AndroidManifest.xml").use { document ->
269-
// Remove the intent from the main activity since an alias will be used instead.
270-
document.childNodes.findElementByAttributeValueOrThrow(
271-
"android:name",
272-
activityAliasNameWithIntentToRemove
273-
).childNodes.findElementByAttributeValueOrThrow(
274-
"android:name",
275-
"android.intent.action.MAIN"
276-
).let { intent ->
277-
intent.parentNode.removeChild(intent)
278-
}
279-
270+
// Create launch aliases that can be programmatically selected in app.
280271
fun createAlias(
281272
aliasName: String,
282273
iconMipmapName: String,
283274
appNameIndex: Int,
284275
useCustomName: Boolean,
285-
enabled: Boolean
276+
enabled: Boolean,
277+
intents: NodeList
286278
): Element {
287279
val label = if (useCustomName) {
288280
if (customName == null) {
@@ -304,19 +296,34 @@ internal fun baseCustomBrandingPatch(
304296
alias.setAttribute("android:label", label)
305297
alias.setAttribute("android:targetActivity", mainActivityName)
306298

307-
val intentFilter = document.createElement("intent-filter")
308-
val action = document.createElement("action")
309-
action.setAttribute("android:name", "android.intent.action.MAIN")
310-
val category = document.createElement("category")
311-
category.setAttribute("android:name", "android.intent.category.LAUNCHER")
312-
313-
intentFilter.appendChild(action)
314-
intentFilter.appendChild(category)
315-
alias.appendChild(intentFilter)
299+
// Copy all intents from the original alias so long press actions still work.
300+
for (i in 0 until intents.length) {
301+
alias.appendChild(
302+
intents.item(i).cloneNode(true)
303+
)
304+
}
316305

317306
return alias
318307
}
319308

309+
// Remove the original main alias.
310+
val originalIntent = document.childNodes.findElementByAttributeValueOrThrow(
311+
"android:name",
312+
activityAliasNameWithIntentToRemove
313+
)
314+
originalIntent.parentNode.removeChild(originalIntent)
315+
316+
val intentFilters = originalIntent.childNodes
317+
for (i in 0 until intentFilters.length) {
318+
// Remove the default element from all intents.
319+
intentFilters.item(i).childNodes.findElementByAttributeValue(
320+
"android:name",
321+
"android.intent.category.DEFAULT"
322+
)?.let { intent ->
323+
intent.parentNode.removeChild(intent)
324+
}
325+
}
326+
320327
val namePrefix = ".revanced_"
321328
val iconResourcePrefix = "revanced_launcher_"
322329
val application = document.getElementsByTagName("application")
@@ -334,7 +341,8 @@ internal fun baseCustomBrandingPatch(
334341
iconMipmapName = originalLauncherIconName,
335342
appNameIndex = appNameIndex,
336343
useCustomName = useCustomNameLabel,
337-
enabled = (appNameIndex == 1)
344+
enabled = (appNameIndex == 1),
345+
intentFilters
338346
)
339347
)
340348

@@ -345,7 +353,8 @@ internal fun baseCustomBrandingPatch(
345353
iconMipmapName = iconResourcePrefix + style,
346354
appNameIndex = appNameIndex,
347355
useCustomName = useCustomNameLabel,
348-
enabled = false
356+
enabled = false,
357+
intentFilters
349358
)
350359
)
351360
}
@@ -362,7 +371,8 @@ internal fun baseCustomBrandingPatch(
362371
iconMipmapName = iconResourcePrefix + CUSTOM_USER_ICON_STYLE_NAME,
363372
appNameIndex = appNameIndex,
364373
useCustomName = useCustomNameLabel,
365-
enabled = false
374+
enabled = false,
375+
intentFilters
366376
)
367377
)
368378
}

0 commit comments

Comments
 (0)