Disallow extra widget page if widgets on home screen is enabled

Close #1569
This commit is contained in:
MM20 2025-07-27 16:47:24 +02:00
parent f0374a08c7
commit 341259d09f
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
5 changed files with 21 additions and 42 deletions

View File

@ -7,8 +7,8 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.staticCompositionLocalOf import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.lifecycle.Lifecycle import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.LocalLifecycleOwner
import androidx.lifecycle.repeatOnLifecycle import androidx.lifecycle.repeatOnLifecycle
import de.mm20.launcher2.crashreporter.CrashReporter import de.mm20.launcher2.crashreporter.CrashReporter
import kotlinx.coroutines.awaitCancellation import kotlinx.coroutines.awaitCancellation
@ -24,7 +24,7 @@ fun ProvideAppWidgetHost(
val context = LocalContext.current val context = LocalContext.current
val widgetHost = remember { AppWidgetHost(context.applicationContext, 44203) } val widgetHost = remember { AppWidgetHost(context.applicationContext, 44203) }
LaunchedEffect(null) { LaunchedEffect(null) {
lifecycleOwner.lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) { lifecycleOwner.lifecycle.repeatOnLifecycle(Lifecycle.State.RESUMED) {
widgetHost.startListening() widgetHost.startListening()
try { try {
awaitCancellation() awaitCancellation()

View File

@ -77,7 +77,6 @@ import de.mm20.launcher2.ui.locals.LocalWindowSize
import de.mm20.launcher2.ui.overlays.OverlayHost import de.mm20.launcher2.ui.overlays.OverlayHost
import de.mm20.launcher2.ui.theme.LauncherTheme import de.mm20.launcher2.ui.theme.LauncherTheme
import de.mm20.launcher2.ui.theme.wallpaperColorsAsState import de.mm20.launcher2.ui.theme.wallpaperColorsAsState
import kotlin.math.pow
abstract class SharedLauncherActivity( abstract class SharedLauncherActivity(
@ -195,7 +194,10 @@ abstract class SharedLauncherActivity(
if (it != null) { if (it != null) {
enterTransitionProgress.value = 0f enterTransitionProgress.value = 0f
enterTransition = it enterTransition = it
enterTransitionProgress.animateTo(100f, animationSpec = animMotionSpec) enterTransitionProgress.animateTo(
100f,
animationSpec = animMotionSpec
)
enterTransition = null enterTransition = null
} }
} }
@ -275,10 +277,15 @@ abstract class SharedLauncherActivity(
}, },
) )
is GestureAction.Widgets -> ScaffoldGesture( is GestureAction.Widgets ->
component = widgetComponent, if (widgetsOnHomeScreen == true) {
animation = if (gesture.orientation == null) ScaffoldAnimation.ZoomIn else ScaffoldAnimation.Push, null
) } else {
ScaffoldGesture(
component = widgetComponent,
animation = if (gesture.orientation == null) ScaffoldAnimation.ZoomIn else ScaffoldAnimation.Push,
)
}
is GestureAction.Notifications -> ScaffoldGesture( is GestureAction.Notifications -> ScaffoldGesture(
component = NotificationsComponent, component = NotificationsComponent,

View File

@ -52,6 +52,7 @@ fun GestureSettingsScreen() {
val viewModel: GestureSettingsScreenVM = viewModel() val viewModel: GestureSettingsScreenVM = viewModel()
val hasPermission by viewModel.hasPermission.collectAsStateWithLifecycle(null) val hasPermission by viewModel.hasPermission.collectAsStateWithLifecycle(null)
val allowWidgetGesture by viewModel.allowWidgetGesture.collectAsStateWithLifecycle(null)
val options = buildList { val options = buildList {
add(stringResource(R.string.gesture_action_none) to GestureAction.NoAction) add(stringResource(R.string.gesture_action_none) to GestureAction.NoAction)
@ -61,7 +62,7 @@ fun GestureSettingsScreen() {
add(stringResource(R.string.gesture_action_recents) to GestureAction.Recents) add(stringResource(R.string.gesture_action_recents) to GestureAction.Recents)
add(stringResource(R.string.gesture_action_power_menu) to GestureAction.PowerMenu) add(stringResource(R.string.gesture_action_power_menu) to GestureAction.PowerMenu)
add(stringResource(R.string.gesture_action_open_search) to GestureAction.Search) add(stringResource(R.string.gesture_action_open_search) to GestureAction.Search)
add(stringResource(R.string.gesture_action_widgets) to GestureAction.Widgets) if (allowWidgetGesture == true) add(stringResource(R.string.gesture_action_widgets) to GestureAction.Widgets)
add(stringResource(R.string.gesture_action_launch_app) to GestureAction.Launch(null)) add(stringResource(R.string.gesture_action_launch_app) to GestureAction.Launch(null))
} }
@ -265,7 +266,7 @@ fun GesturePreference(
icon = icon, icon = icon,
items = options, items = options,
value = value, value = value,
summary = options.find { value?.javaClass == it.second.javaClass }?.first, summary = options.find { value?.javaClass == it.second.javaClass }?.first ?: stringResource(R.string.gesture_action_none),
onValueChanged = { if (it != null) onValueChanged(it) } onValueChanged = { if (it != null) onValueChanged(it) }
) )
} }

View File

@ -34,6 +34,9 @@ class GestureSettingsScreenVM : ViewModel(), KoinComponent {
val hasPermission = permissionsManager.hasPermission(PermissionGroup.Accessibility) val hasPermission = permissionsManager.hasPermission(PermissionGroup.Accessibility)
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null) .stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null)
val allowWidgetGesture = uiSettings.homeScreenWidgets.map { it == false }
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null)
val swipeDown = gestureSettings.swipeDown val swipeDown = gestureSettings.swipeDown
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null) .stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null)
val swipeLeft = gestureSettings.swipeLeft val swipeLeft = gestureSettings.swipeLeft

View File

@ -157,38 +157,6 @@ class HomescreenSettingsScreenVM(
fun setWidgetsOnHomeScreen(widgetsOnHomeScreen: Boolean) { fun setWidgetsOnHomeScreen(widgetsOnHomeScreen: Boolean) {
uiSettings.setHomeScreenWidgets(widgetsOnHomeScreen) uiSettings.setHomeScreenWidgets(widgetsOnHomeScreen)
viewModelScope.launch {
val gestures = gestureSettings.first()
if (widgetsOnHomeScreen) {
if (gestures.swipeUp is GestureAction.Widgets) {
gestureSettings.setSwipeUp(GestureAction.NoAction)
} else if (gestures.swipeRight is GestureAction.Widgets) {
gestureSettings.setSwipeUp(GestureAction.NoAction)
} else if (gestures.swipeLeft is GestureAction.Widgets) {
gestureSettings.setSwipeUp(GestureAction.NoAction)
} else if (gestures.swipeDown is GestureAction.Widgets) {
gestureSettings.setSwipeUp(GestureAction.NoAction)
} else if (gestures.longPress is GestureAction.Widgets) {
gestureSettings.setLongPress(GestureAction.NoAction)
} else if (gestures.doubleTap is GestureAction.Widgets) {
gestureSettings.setDoubleTap(GestureAction.NoAction)
}
} else {
if (gestures.swipeUp is GestureAction.NoAction || gestures.swipeUp is GestureAction.Widgets) {
gestureSettings.setSwipeUp(GestureAction.Widgets)
} else if (gestures.swipeRight is GestureAction.NoAction || gestures.swipeRight is GestureAction.Widgets) {
gestureSettings.setSwipeRight(GestureAction.Widgets)
} else if (gestures.swipeLeft is GestureAction.NoAction || gestures.swipeLeft is GestureAction.Widgets) {
gestureSettings.setSwipeLeft(GestureAction.Widgets)
} else if (gestures.swipeDown is GestureAction.NoAction || gestures.swipeDown is GestureAction.Widgets) {
gestureSettings.setSwipeDown(GestureAction.Widgets)
} else if (gestures.longPress is GestureAction.NoAction || gestures.longPress is GestureAction.Widgets) {
gestureSettings.setLongPress(GestureAction.Widgets)
} else if (gestures.doubleTap is GestureAction.NoAction || gestures.doubleTap is GestureAction.Widgets) {
gestureSettings.setDoubleTap(GestureAction.Widgets)
}
}
}
} }
companion object : KoinComponent { companion object : KoinComponent {