diff --git a/app/ui/src/main/java/de/mm20/launcher2/ui/base/AppWidgetHost.kt b/app/ui/src/main/java/de/mm20/launcher2/ui/base/AppWidgetHost.kt index f2648693..189dafff 100644 --- a/app/ui/src/main/java/de/mm20/launcher2/ui/base/AppWidgetHost.kt +++ b/app/ui/src/main/java/de/mm20/launcher2/ui/base/AppWidgetHost.kt @@ -7,8 +7,8 @@ import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.remember import androidx.compose.runtime.staticCompositionLocalOf import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.platform.LocalLifecycleOwner import androidx.lifecycle.Lifecycle +import androidx.lifecycle.compose.LocalLifecycleOwner import androidx.lifecycle.repeatOnLifecycle import de.mm20.launcher2.crashreporter.CrashReporter import kotlinx.coroutines.awaitCancellation @@ -24,7 +24,7 @@ fun ProvideAppWidgetHost( val context = LocalContext.current val widgetHost = remember { AppWidgetHost(context.applicationContext, 44203) } LaunchedEffect(null) { - lifecycleOwner.lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) { + lifecycleOwner.lifecycle.repeatOnLifecycle(Lifecycle.State.RESUMED) { widgetHost.startListening() try { awaitCancellation() diff --git a/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/SharedLauncherActivity.kt b/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/SharedLauncherActivity.kt index 9b324033..3cb3cf48 100644 --- a/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/SharedLauncherActivity.kt +++ b/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/SharedLauncherActivity.kt @@ -77,7 +77,6 @@ import de.mm20.launcher2.ui.locals.LocalWindowSize import de.mm20.launcher2.ui.overlays.OverlayHost import de.mm20.launcher2.ui.theme.LauncherTheme import de.mm20.launcher2.ui.theme.wallpaperColorsAsState -import kotlin.math.pow abstract class SharedLauncherActivity( @@ -195,7 +194,10 @@ abstract class SharedLauncherActivity( if (it != null) { enterTransitionProgress.value = 0f enterTransition = it - enterTransitionProgress.animateTo(100f, animationSpec = animMotionSpec) + enterTransitionProgress.animateTo( + 100f, + animationSpec = animMotionSpec + ) enterTransition = null } } @@ -275,10 +277,15 @@ abstract class SharedLauncherActivity( }, ) - is GestureAction.Widgets -> ScaffoldGesture( - component = widgetComponent, - animation = if (gesture.orientation == null) ScaffoldAnimation.ZoomIn else ScaffoldAnimation.Push, - ) + is GestureAction.Widgets -> + if (widgetsOnHomeScreen == true) { + null + } else { + ScaffoldGesture( + component = widgetComponent, + animation = if (gesture.orientation == null) ScaffoldAnimation.ZoomIn else ScaffoldAnimation.Push, + ) + } is GestureAction.Notifications -> ScaffoldGesture( component = NotificationsComponent, diff --git a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/gestures/GestureSettingsScreen.kt b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/gestures/GestureSettingsScreen.kt index 73066d09..7a3ff0be 100644 --- a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/gestures/GestureSettingsScreen.kt +++ b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/gestures/GestureSettingsScreen.kt @@ -52,6 +52,7 @@ fun GestureSettingsScreen() { val viewModel: GestureSettingsScreenVM = viewModel() val hasPermission by viewModel.hasPermission.collectAsStateWithLifecycle(null) + val allowWidgetGesture by viewModel.allowWidgetGesture.collectAsStateWithLifecycle(null) val options = buildList { 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_power_menu) to GestureAction.PowerMenu) 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)) } @@ -265,7 +266,7 @@ fun GesturePreference( icon = icon, items = options, 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) } ) } diff --git a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/gestures/GestureSettingsScreenVM.kt b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/gestures/GestureSettingsScreenVM.kt index 1471af46..1f2fc989 100644 --- a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/gestures/GestureSettingsScreenVM.kt +++ b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/gestures/GestureSettingsScreenVM.kt @@ -34,6 +34,9 @@ class GestureSettingsScreenVM : ViewModel(), KoinComponent { val hasPermission = permissionsManager.hasPermission(PermissionGroup.Accessibility) .stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null) + val allowWidgetGesture = uiSettings.homeScreenWidgets.map { it == false } + .stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null) + val swipeDown = gestureSettings.swipeDown .stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null) val swipeLeft = gestureSettings.swipeLeft diff --git a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/homescreen/HomescreenSettingsScreenVM.kt b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/homescreen/HomescreenSettingsScreenVM.kt index 7867b26f..fec61653 100644 --- a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/homescreen/HomescreenSettingsScreenVM.kt +++ b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/homescreen/HomescreenSettingsScreenVM.kt @@ -157,38 +157,6 @@ class HomescreenSettingsScreenVM( fun setWidgetsOnHomeScreen(widgetsOnHomeScreen: Boolean) { 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 {