Skip to content

Commit af76042

Browse files
committed
feat: add Left Swipe Discover Redirect functionality
- Implement LeftSwipeDiscoverRedirectHook to intercept left-swipe overlay and redirect to app drawer. - Add preferences for enabling/disabling the redirect and optional auto-focus on search input. - Update MainActivity and layout files to include toggle switches for the new feature. - Add corresponding string resources for the new preferences.
1 parent 8346b90 commit af76042

File tree

6 files changed

+117
-0
lines changed

6 files changed

+117
-0
lines changed

app/src/main/java/com/wizpizz/onepluspluslauncher/hook/HookEntry.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ object HookEntry : IYukiHookXposedInit {
2323
FuzzySearchHook.apply(this)
2424
GlobalSearchRedirectHook.apply(this)
2525
SwipeDownSearchRedirectHook.apply(this)
26+
LeftSwipeDiscoverRedirectHook.apply(this)
2627
}
2728
}
2829
}

app/src/main/java/com/wizpizz/onepluspluslauncher/hook/features/HookUtils.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ object HookUtils {
2323
const val PREF_ENTER_KEY_LAUNCH = "enter_key_launch"
2424
const val PREF_GLOBAL_SEARCH_REDIRECT = "global_search_redirect"
2525
const val PREF_SWIPE_DOWN_SEARCH_REDIRECT = "swipe_down_search_redirect"
26+
const val PREF_LEFT_SWIPE_DISCOVER_REDIRECT = "left_swipe_discover_redirect"
27+
const val PREF_AUTO_FOCUS_LEFT_SWIPE_REDIRECT = "auto_focus_left_swipe_redirect"
2628

2729
// Class names
2830
const val LAUNCHER_CLASS = "com.android.launcher3.Launcher"
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package com.wizpizz.onepluspluslauncher.hook.features
2+
3+
import android.util.Log
4+
import com.highcapable.yukihookapi.hook.param.PackageParam
5+
import com.highcapable.yukihookapi.hook.factory.current
6+
import com.highcapable.yukihookapi.hook.factory.field
7+
import com.highcapable.yukihookapi.hook.factory.method
8+
import com.wizpizz.onepluspluslauncher.hook.features.HookUtils.PREF_LEFT_SWIPE_DISCOVER_REDIRECT
9+
import com.wizpizz.onepluspluslauncher.hook.features.HookUtils.PREF_AUTO_FOCUS_LEFT_SWIPE_REDIRECT
10+
import com.wizpizz.onepluspluslauncher.hook.features.HookUtils.TAG
11+
12+
/**
13+
* Intercepts the left-swipe (Discover/Feed/News) overlay and opens the app drawer instead.
14+
* Hooks OplusLauncherOverlay.onScrollInteractionBegin().
15+
*
16+
* Features:
17+
* - Toggle to enable/disable the redirect
18+
* - Optional auto-focus on search input when redirecting
19+
*/
20+
object LeftSwipeDiscoverRedirectHook {
21+
private const val OPLUS_LAUNCHER_OVERLAY_CLASS = "com.android.overlay.OplusLauncherOverlay"
22+
23+
fun apply(packageParam: PackageParam) {
24+
packageParam.apply {
25+
OPLUS_LAUNCHER_OVERLAY_CLASS.toClassOrNull(appClassLoader)?.method {
26+
name = "onScrollInteractionBegin"
27+
paramCount = 0
28+
}?.hook {
29+
before {
30+
// Check if left-swipe redirect is enabled
31+
val leftSwipeRedirectEnabled = prefs.getBoolean(PREF_LEFT_SWIPE_DISCOVER_REDIRECT, true)
32+
if (!leftSwipeRedirectEnabled) {
33+
Log.d(TAG, "[LeftSwipe] Feature disabled, allowing original behavior")
34+
return@before
35+
}
36+
37+
Log.d(TAG, "[LeftSwipe] Intercepting left-swipe overlay, redirecting to app drawer")
38+
39+
// Mark that we're starting a redirect to prevent AutoFocusHook from triggering
40+
HookUtils.setRedirectInProgress(true)
41+
42+
// Get the Launcher instance from the overlay
43+
val launcher = instance.javaClass.field {
44+
name = "mLauncher"
45+
superClass(true)
46+
}.get(instance).any()
47+
48+
if (launcher != null) {
49+
try {
50+
// Try to call showAllAppsFromIntent(true) on the launcher
51+
launcher.current().method {
52+
name = "showAllAppsFromIntent"
53+
param(Boolean::class.java)
54+
}.call(true)
55+
Log.d(TAG, "[LeftSwipe] Successfully opened app drawer from left swipe")
56+
57+
// If redirect was successful and auto focus on redirect is enabled, focus search
58+
val autoFocusRedirectEnabled = prefs.getBoolean(PREF_AUTO_FOCUS_LEFT_SWIPE_REDIRECT, true)
59+
if (autoFocusRedirectEnabled) {
60+
Log.d(TAG, "[LeftSwipe] Auto focus enabled, focusing search input")
61+
appClassLoader?.let { HookUtils.focusSearchInput(launcher, it) }
62+
// Clear redirect flag after focusing
63+
HookUtils.setRedirectInProgress(false)
64+
} else {
65+
Log.d(TAG, "[LeftSwipe] Auto focus disabled, clearing redirect flag")
66+
// Clear redirect flag immediately if not focusing
67+
HookUtils.setRedirectInProgress(false)
68+
}
69+
70+
} catch (e: Throwable) {
71+
Log.e(TAG, "[LeftSwipe] Failed to open app drawer: ${e.message}")
72+
// Reset flag if redirect failed
73+
HookUtils.setRedirectInProgress(false)
74+
}
75+
} else {
76+
Log.e(TAG, "[LeftSwipe] Failed to get launcher instance from overlay")
77+
// Reset flag if we couldn't get launcher
78+
HookUtils.setRedirectInProgress(false)
79+
}
80+
81+
// Prevent the overlay from opening
82+
result = null
83+
return@before
84+
}
85+
} ?: Log.e(TAG, "[LeftSwipe] Failed to find OplusLauncherOverlay.onScrollInteractionBegin method")
86+
}
87+
}
88+
}

app/src/main/java/com/wizpizz/onepluspluslauncher/ui/activity/MainActivity.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import com.wizpizz.onepluspluslauncher.hook.features.HookUtils.PREF_AUTO_FOCUS_S
1515
import com.wizpizz.onepluspluslauncher.hook.features.HookUtils.PREF_ENTER_KEY_LAUNCH
1616
import com.wizpizz.onepluspluslauncher.hook.features.HookUtils.PREF_GLOBAL_SEARCH_REDIRECT
1717
import com.wizpizz.onepluspluslauncher.hook.features.HookUtils.PREF_SWIPE_DOWN_SEARCH_REDIRECT
18+
import com.wizpizz.onepluspluslauncher.hook.features.HookUtils.PREF_LEFT_SWIPE_DISCOVER_REDIRECT
19+
import com.wizpizz.onepluspluslauncher.hook.features.HookUtils.PREF_AUTO_FOCUS_LEFT_SWIPE_REDIRECT
1820
import com.wizpizz.onepluspluslauncher.hook.features.HookUtils.PREF_USE_FUZZY_SEARCH
1921

2022
class MainActivity : BaseActivity<ActivityMainBinding>() {
@@ -32,6 +34,8 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
3234
setupFeatureToggle(binding.enterKeyLaunchSwitch, PREF_ENTER_KEY_LAUNCH)
3335
setupFeatureToggle(binding.globalSearchRedirectSwitch, PREF_GLOBAL_SEARCH_REDIRECT)
3436
setupFeatureToggle(binding.swipeDownSearchRedirectSwitch, PREF_SWIPE_DOWN_SEARCH_REDIRECT)
37+
setupFeatureToggle(binding.leftSwipeDiscoverRedirectSwitch, PREF_LEFT_SWIPE_DISCOVER_REDIRECT)
38+
setupFeatureToggle(binding.autoFocusLeftSwipeRedirectSwitch, PREF_AUTO_FOCUS_LEFT_SWIPE_REDIRECT)
3539
setupFeatureToggle(binding.fuzzySearchSwitchNew, PREF_USE_FUZZY_SEARCH)
3640
}
3741

app/src/main/res/layout/activity_main.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,26 @@
329329
android:textColor="@color/colorTextGray"
330330
android:textSize="15sp" />
331331

332+
<com.wizpizz.onepluspluslauncher.ui.view.MaterialSwitch
333+
android:id="@+id/left_swipe_discover_redirect_switch"
334+
android:layout_width="match_parent"
335+
android:layout_height="wrap_content"
336+
android:layout_marginTop="8dp"
337+
android:text="@string/pref_left_swipe_discover_redirect_title"
338+
android:textAllCaps="false"
339+
android:textColor="@color/colorTextGray"
340+
android:textSize="15sp" />
341+
342+
<com.wizpizz.onepluspluslauncher.ui.view.MaterialSwitch
343+
android:id="@+id/auto_focus_left_swipe_redirect_switch"
344+
android:layout_width="match_parent"
345+
android:layout_height="wrap_content"
346+
android:layout_marginTop="8dp"
347+
android:text="@string/pref_auto_focus_left_swipe_redirect_title"
348+
android:textAllCaps="false"
349+
android:textColor="@color/colorTextGray"
350+
android:textSize="15sp" />
351+
332352
</LinearLayout>
333353

334354
<androidx.core.widget.NestedScrollView

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
<string name="pref_enter_key_launch_title">Launch App on Enter</string>
1414
<string name="pref_global_search_redirect_title">Redirect Global Search Button</string>
1515
<string name="pref_swipe_down_search_redirect_title">Redirect Swipe Down Search</string>
16+
<string name="pref_left_swipe_discover_redirect_title">Redirect Left Swipe (Google Discover)</string>
17+
<string name="pref_auto_focus_left_swipe_redirect_title">Auto Focus on Left Swipe Redirect</string>
1618
<string name="feature_settings">Feature settings</string>
1719
<string name="category_search_enhancement">Search Enhancement</string>
1820
<string name="category_auto_focus">Auto Focus (Show Keyboard)</string>

0 commit comments

Comments
 (0)