diff --git a/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/LauncherScaffoldVM.kt b/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/LauncherScaffoldVM.kt index cd28cb61..78571a76 100644 --- a/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/LauncherScaffoldVM.kt +++ b/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/LauncherScaffoldVM.kt @@ -67,6 +67,7 @@ class LauncherScaffoldVM : ViewModel(), KoinComponent { val bottomSearchBar = dataStore.data.map { it.layout.bottomSearchBar }.asLiveData() val reverseSearchResults = dataStore.data.map { it.layout.reverseSearchResults }.asLiveData() val fixedSearchBar = dataStore.data.map { it.layout.fixedSearchBar }.asLiveData() + val fixedRotation = dataStore.data.map { it.layout.fixedRotation }.asLiveData() val isSearchOpen = MutableLiveData(false) val isWidgetEditMode = MutableLiveData(false) 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 4b6ba46c..39c987f2 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 @@ -1,6 +1,7 @@ package de.mm20.launcher2.ui.launcher import android.app.WallpaperManager +import android.content.pm.ActivityInfo import android.content.res.Configuration import android.content.res.Resources import android.os.Bundle @@ -35,6 +36,7 @@ import androidx.compose.ui.unit.dp import androidx.core.view.WindowCompat import androidx.core.view.WindowInsetsControllerCompat import androidx.lifecycle.Lifecycle +import androidx.lifecycle.Observer import androidx.lifecycle.flowWithLifecycle import com.google.accompanist.systemuicontroller.rememberSystemUiController import de.mm20.launcher2.globalactions.GlobalActionsService @@ -132,6 +134,15 @@ abstract class SharedLauncherActivity( val reverseSearchResults by viewModel.reverseSearchResults.observeAsState(false) val fixedSearchBar by viewModel.fixedSearchBar.observeAsState(false) + viewModel.fixedRotation.observe(this) { fixedRotation -> + requestedOrientation = if (fixedRotation) { + ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + } else { + ActivityInfo.SCREEN_ORIENTATION_USER + } + } + + val systemUiController = rememberSystemUiController() val enterTransitionProgress = remember { mutableStateOf(1f) } diff --git a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/layout/LayoutSettingsScreen.kt b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/layout/LayoutSettingsScreen.kt index 6bc64c1b..d53d034d 100644 --- a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/layout/LayoutSettingsScreen.kt +++ b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/layout/LayoutSettingsScreen.kt @@ -64,6 +64,15 @@ fun LayoutSettingsScreen() { if (it != null) viewModel.setReverseSearchResults(it) }, ) + val fixedRotation by viewModel.fixedRotation.observeAsState() + SwitchPreference( + title = stringResource(R.string.preference_layout_fixed_rotation), + summary = stringResource(R.string.preference_layout_fixed_rotation_summary), + value = fixedRotation == true, + onValueChanged = { + viewModel.setFixedRotation(it) + }, + ) } } } diff --git a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/layout/LayoutSettingsScreenVM.kt b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/layout/LayoutSettingsScreenVM.kt index d6d7b1fc..bf7fe33f 100644 --- a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/layout/LayoutSettingsScreenVM.kt +++ b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/layout/LayoutSettingsScreenVM.kt @@ -57,4 +57,15 @@ class LayoutSettingsScreenVM: ViewModel(), KoinComponent { } } } + + val fixedRotation = dataStore.data.map { it.layout.fixedRotation }.asLiveData() + fun setFixedRotation(fixedRotation: Boolean) { + viewModelScope.launch { + dataStore.updateData { + it.toBuilder() + .setLayout(it.layout.toBuilder().setFixedRotation(fixedRotation)) + .build() + } + } + } } \ No newline at end of file diff --git a/core/i18n/src/main/res/values-de/strings.xml b/core/i18n/src/main/res/values-de/strings.xml index c3d7e872..68feccc8 100644 --- a/core/i18n/src/main/res/values-de/strings.xml +++ b/core/i18n/src/main/res/values-de/strings.xml @@ -567,4 +567,6 @@ Sie haben eine „%1$s“-Geste ausgeführt. Diese Geste ist momentan konfiguriert, eine „%2$s“-Aktion auszulösen. Diese Aktion konnte aus dem folgenden Grund nicht durchgeführt werden: Angeheftete Suchleiste Suchleiste nicht aus dem Sichtbereich herausscrollen + Fixierte Bildschirmausrichtung + Erzwingt Porträtmodus des Launchers \ No newline at end of file diff --git a/core/i18n/src/main/res/values/strings.xml b/core/i18n/src/main/res/values/strings.xml index 5fdf1f4d..7f29bc19 100644 --- a/core/i18n/src/main/res/values/strings.xml +++ b/core/i18n/src/main/res/values/strings.xml @@ -733,6 +733,8 @@ Bottom-up Fixed search bar Don\'t scroll the search bar out of view + Fixed screen rotation + Lock screen rotation to portrait mode Gestures Gestures and gesture actions Swipe down diff --git a/core/preferences/src/main/java/de/mm20/launcher2/preferences/Defaults.kt b/core/preferences/src/main/java/de/mm20/launcher2/preferences/Defaults.kt index 31c54df8..b4287358 100644 --- a/core/preferences/src/main/java/de/mm20/launcher2/preferences/Defaults.kt +++ b/core/preferences/src/main/java/de/mm20/launcher2/preferences/Defaults.kt @@ -168,6 +168,7 @@ fun createFactorySettings(context: Context): Settings { .setBaseLayout(Settings.LayoutSettings.Layout.PullDown) .setBottomSearchBar(false) .setReverseSearchResults(false) + .setFixedRotation(false) ) .setGestures( Settings.GestureSettings.newBuilder() diff --git a/core/preferences/src/main/proto/settings.proto b/core/preferences/src/main/proto/settings.proto index afb2a63d..a8503cee 100644 --- a/core/preferences/src/main/proto/settings.proto +++ b/core/preferences/src/main/proto/settings.proto @@ -298,6 +298,7 @@ message Settings { bool bottom_search_bar = 2; bool reverse_search_results = 3; bool fixed_search_bar = 4; + bool fixed_rotation = 5; } LayoutSettings layout = 27;