From 7a72faa85b9b1a7f8534fadc8a60c3381dd88fcc Mon Sep 17 00:00:00 2001 From: Ismaillat Date: Thu, 19 Dec 2024 23:46:47 +0100 Subject: [PATCH 1/6] feat: lock app into portrait mode --- app/src/main/AndroidManifest.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c6b158a45..9a85932ca 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -30,6 +30,7 @@ From def40316ad089d5ef3765077d409104d933f5210 Mon Sep 17 00:00:00 2001 From: Ismaillat Date: Fri, 20 Dec 2024 00:52:01 +0100 Subject: [PATCH 2/6] feat: lock screens directly in each screen. --- app/src/main/AndroidManifest.xml | 1 - .../lookup/ui/authentication/SignIn.kt | 8 ++++++++ .../lookupgroup27/lookup/ui/calendar/Calendar.kt | 11 +++++++++++ .../com/github/lookupgroup27/lookup/ui/feed/Feed.kt | 11 ++++++++++- .../lookup/ui/fullscreen/FullScreen.kt | 9 +++++++++ .../lookupgroup27/lookup/ui/googlemap/GoogleMap.kt | 10 ++++++++++ .../lookupgroup27/lookup/ui/image/EditImage.kt | 10 ++++++++++ .../lookupgroup27/lookup/ui/image/ImageReview.kt | 11 +++++++++++ .../lookupgroup27/lookup/ui/image/TakeImage.kt | 10 ++++++++++ .../github/lookupgroup27/lookup/ui/login/Login.kt | 11 +++++++++++ .../com/github/lookupgroup27/lookup/ui/map/Map.kt | 8 ++++++++ .../lookupgroup27/lookup/ui/overview/Landing.kt | 11 +++++++++++ .../github/lookupgroup27/lookup/ui/overview/Menu.kt | 10 ++++++++++ .../lookup/ui/passwordreset/PasswordReset.kt | 13 +++++++++++++ .../ui/planetselection/PlanetSelectionScreen.kt | 12 ++++++++++++ .../lookupgroup27/lookup/ui/profile/Collection.kt | 12 ++++++++++++ .../lookupgroup27/lookup/ui/profile/Profile.kt | 12 ++++++++++++ .../lookup/ui/profile/ProfileInformation.kt | 12 ++++++++++++ .../com/github/lookupgroup27/lookup/ui/quiz/Quiz.kt | 12 ++++++++++++ .../github/lookupgroup27/lookup/ui/quiz/QuizPlay.kt | 13 +++++++++++++ .../lookupgroup27/lookup/ui/register/Register.kt | 11 +++++++++++ 21 files changed, 216 insertions(+), 2 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9a85932ca..c6b158a45 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -30,7 +30,6 @@ diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/authentication/SignIn.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/authentication/SignIn.kt index b924cc852..25cafe7e8 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/authentication/SignIn.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/authentication/SignIn.kt @@ -1,9 +1,11 @@ package com.github.lookupgroup27.lookup.ui.authentication import android.content.Intent +import android.content.pm.ActivityInfo import android.content.res.Configuration import android.util.Log import android.widget.Toast +import androidx.activity.ComponentActivity import androidx.activity.compose.ManagedActivityResultLauncher import androidx.activity.compose.rememberLauncherForActivityResult import androidx.activity.result.ActivityResult @@ -57,6 +59,12 @@ import kotlinx.coroutines.tasks.await fun SignInScreen(navigationActions: NavigationActions) { val context = LocalContext.current + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } + val launcher = rememberFirebaseAuthLauncher( onAuthComplete = { result -> diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/calendar/Calendar.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/calendar/Calendar.kt index 34298e1b7..21ed17e80 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/calendar/Calendar.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/calendar/Calendar.kt @@ -1,5 +1,7 @@ package com.github.lookupgroup27.lookup.ui.calendar +import android.content.pm.ActivityInfo +import androidx.activity.ComponentActivity import androidx.compose.foundation.* import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.* @@ -9,6 +11,7 @@ import androidx.compose.material.icons.filled.Search import androidx.compose.material3.* import androidx.compose.runtime.* import androidx.compose.ui.* +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.testTag import androidx.compose.ui.unit.dp import androidx.lifecycle.viewmodel.compose.viewModel @@ -47,6 +50,14 @@ fun CalendarScreen( calendarViewModel: CalendarViewModel = viewModel(), navigationActions: NavigationActions ) { + val context = LocalContext.current + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } + // State variables for selected date, search query, and visibility of the search dialog. var selectedDate by remember { mutableStateOf(Date()) } var searchQuery by remember { mutableStateOf("") } diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/feed/Feed.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/feed/Feed.kt index 1278d9a7b..f382fe31e 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/feed/Feed.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/feed/Feed.kt @@ -2,9 +2,11 @@ package com.github.lookupgroup27.lookup.ui.feed import android.Manifest import android.annotation.SuppressLint +import android.content.pm.ActivityInfo import android.content.pm.PackageManager import android.util.Log import android.widget.Toast +import androidx.activity.ComponentActivity import androidx.activity.compose.rememberLauncherForActivityResult import androidx.activity.result.contract.ActivityResultContracts import androidx.compose.foundation.Image @@ -65,6 +67,14 @@ fun FeedScreen( initialNearbyPosts: List? = null, testNoLoca: Boolean = false ) { + val context = LocalContext.current + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } + // Fetch user profile LaunchedEffect(Unit) { Log.d("FeedScreen", "Fetching user profile") @@ -81,7 +91,6 @@ fun FeedScreen( val email by remember { mutableStateOf(userEmail) } // Location setup - val context = LocalContext.current val locationProvider = LocationProviderSingleton.getInstance(context) var locationPermissionGranted by remember { mutableStateOf( diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/fullscreen/FullScreen.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/fullscreen/FullScreen.kt index 2e0983890..f758679b9 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/fullscreen/FullScreen.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/fullscreen/FullScreen.kt @@ -1,6 +1,8 @@ package com.github.lookupgroup27.lookup.ui.fullscreen +import android.content.pm.ActivityInfo import android.widget.Toast +import androidx.activity.ComponentActivity import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.layout.* @@ -45,6 +47,13 @@ fun FullScreenImageScreen( ) { val context = LocalContext.current + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } + // State to track if a toast for empty imageUrl has been shown var hasShownEmptyToast by remember { mutableStateOf(false) } diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/googlemap/GoogleMap.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/googlemap/GoogleMap.kt index 124b1e08f..733e42f1c 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/googlemap/GoogleMap.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/googlemap/GoogleMap.kt @@ -2,8 +2,10 @@ package com.github.lookupgroup27.lookup.ui.googlemap import android.Manifest import android.annotation.SuppressLint +import android.content.pm.ActivityInfo import android.content.pm.PackageManager import android.widget.Toast +import androidx.activity.ComponentActivity import androidx.activity.compose.rememberLauncherForActivityResult import androidx.activity.result.contract.ActivityResultContracts import androidx.compose.foundation.Image @@ -57,6 +59,14 @@ fun GoogleMapScreen( testNoLoca: Boolean = false ) { val context = LocalContext.current + + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } + val locationProvider = LocationProviderSingleton.getInstance(context) var hasLocationPermission by remember { mutableStateOf( diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/image/EditImage.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/image/EditImage.kt index daf4d1b5b..7f3bb160b 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/image/EditImage.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/image/EditImage.kt @@ -1,6 +1,8 @@ package com.github.lookupgroup27.lookup.ui.image +import android.content.pm.ActivityInfo import android.widget.Toast +import androidx.activity.ComponentActivity import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.clickable @@ -15,6 +17,7 @@ import androidx.compose.material.icons.automirrored.filled.ArrowBack import androidx.compose.material.icons.filled.Person import androidx.compose.material3.* import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue @@ -75,6 +78,13 @@ fun EditImageScreen( val editImageState by editImageViewModel.editImageState.collectAsState() val context = LocalContext.current + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } + var description by remember { mutableStateOf(postDescription) } var isEditing by remember { mutableStateOf(false) } var showSaveDialog by remember { mutableStateOf(false) } diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/image/ImageReview.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/image/ImageReview.kt index 8e83dc899..10045380d 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/image/ImageReview.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/image/ImageReview.kt @@ -1,6 +1,8 @@ package com.github.lookupgroup27.lookup.ui.image +import android.content.pm.ActivityInfo import android.widget.Toast +import androidx.activity.ComponentActivity import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.clickable @@ -12,6 +14,7 @@ import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.verticalScroll import androidx.compose.material3.* import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue @@ -61,6 +64,14 @@ fun ImageReviewScreen( timestamp: Long? ) { val context = LocalContext.current + + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } + val locationProvider = LocationProviderSingleton.getInstance(context) val currentTimestamp = timestamp ?: System.currentTimeMillis() // Fallback to current time diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/image/TakeImage.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/image/TakeImage.kt index 167e38029..d9ab96cd0 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/image/TakeImage.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/image/TakeImage.kt @@ -1,9 +1,11 @@ package com.github.lookupgroup27.lookup.ui.image import android.Manifest +import android.content.pm.ActivityInfo import android.net.Uri import android.os.Environment import android.widget.Toast +import androidx.activity.ComponentActivity import androidx.activity.compose.rememberLauncherForActivityResult import androidx.activity.result.contract.ActivityResultContracts import androidx.camera.core.CameraSelector @@ -52,6 +54,14 @@ fun CameraCapture( navigationActions: NavigationActions, ) { val context = LocalContext.current + + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } + var imageCapture: ImageCapture? by remember { mutableStateOf(null) } var isCameraPermissionGranted by remember { mutableStateOf(false) } diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/login/Login.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/login/Login.kt index 14bcf45af..2aa83f447 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/login/Login.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/login/Login.kt @@ -1,9 +1,12 @@ package com.github.lookupgroup27.lookup.ui.login +import android.content.pm.ActivityInfo import android.widget.Toast +import androidx.activity.ComponentActivity import androidx.compose.foundation.layout.* import androidx.compose.material3.* import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment @@ -27,6 +30,14 @@ import com.github.lookupgroup27.lookup.ui.register.components.CustomOutlinedText @Composable fun LoginScreen(viewModel: LoginViewModel, navigationActions: NavigationActions) { val context = LocalContext.current + + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } + val uiState by viewModel.uiState.collectAsState() AuthScreen( diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/map/Map.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/map/Map.kt index fff781f29..574111de1 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/map/Map.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/map/Map.kt @@ -61,6 +61,14 @@ private const val LOCATION_PERMISSION_REQUEST_CODE: Int = 1001 fun MapScreen(navigationActions: NavigationActions, mapViewModel: MapViewModel) { val context = LocalContext.current + + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } + val user = FirebaseAuth.getInstance().currentUser val isUserLoggedIn = user != null val activity = diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/overview/Landing.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/overview/Landing.kt index 91165b6f1..e6ec9b832 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/overview/Landing.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/overview/Landing.kt @@ -1,6 +1,8 @@ package com.github.lookupgroup27.lookup.ui.overview import android.annotation.SuppressLint +import android.content.pm.ActivityInfo +import androidx.activity.ComponentActivity import androidx.compose.foundation.Image import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.* @@ -12,6 +14,7 @@ import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.Icon import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.ui.Alignment @@ -42,6 +45,14 @@ fun LandingScreen( ) { val context = LocalContext.current + + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } + val isOnline = remember { mutableStateOf(NetworkUtils.isNetworkAvailable(context)) } // Background container with clickable modifier to navigate to Map screen diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/overview/Menu.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/overview/Menu.kt index 0b3512beb..85550b7d4 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/overview/Menu.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/overview/Menu.kt @@ -1,6 +1,8 @@ package com.github.lookupgroup27.lookup.ui.overview import android.annotation.SuppressLint +import android.content.pm.ActivityInfo +import androidx.activity.ComponentActivity import androidx.compose.foundation.Image import androidx.compose.foundation.layout.* import androidx.compose.foundation.rememberScrollState @@ -39,6 +41,14 @@ fun MenuScreen( val userId = auth.currentUser?.uid.orEmpty() val context = LocalContext.current + + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } + val isOnline = remember { mutableStateOf(NetworkUtils.isNetworkAvailable(context)) } // Fetch the selected avatar for the logged-in user diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/passwordreset/PasswordReset.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/passwordreset/PasswordReset.kt index 65c1ea849..e31cbac76 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/passwordreset/PasswordReset.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/passwordreset/PasswordReset.kt @@ -1,5 +1,7 @@ package com.github.lookupgroup27.lookup.ui.passwordreset +import android.content.pm.ActivityInfo +import androidx.activity.ComponentActivity import androidx.compose.foundation.Image import androidx.compose.foundation.layout.* import androidx.compose.foundation.rememberScrollState @@ -9,12 +11,14 @@ import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.filled.ArrowBack import androidx.compose.material3.* import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.testTag import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.font.FontWeight @@ -38,6 +42,15 @@ import com.github.lookupgroup27.lookup.ui.navigation.Screen @OptIn(ExperimentalMaterial3Api::class) @Composable fun PasswordResetScreen(viewModel: PasswordResetViewModel, navigationActions: NavigationActions) { + val context = LocalContext.current + + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } + // Observes the UI state from the ViewModel val uiState by viewModel.uiState.collectAsState() diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/planetselection/PlanetSelectionScreen.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/planetselection/PlanetSelectionScreen.kt index 5c2320c9d..2f38b06bd 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/planetselection/PlanetSelectionScreen.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/planetselection/PlanetSelectionScreen.kt @@ -1,6 +1,8 @@ package com.github.lookupgroup27.lookup.ui.planetselection import android.annotation.SuppressLint +import android.content.pm.ActivityInfo +import androidx.activity.ComponentActivity import androidx.compose.foundation.background import androidx.compose.foundation.layout.* import androidx.compose.material.icons.Icons @@ -14,6 +16,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color.Companion.White +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.testTag import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp @@ -39,6 +42,15 @@ fun PlanetSelectionScreen( viewModel: PlanetSelectionViewModel = viewModel(), navigationActions: NavigationActions ) { + val context = LocalContext.current + + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } + val planets = viewModel.planets val selectedPlanet by viewModel.selectedPlanet.collectAsState() diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/profile/Collection.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/profile/Collection.kt index a0ea468bf..41b874cd2 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/profile/Collection.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/profile/Collection.kt @@ -1,5 +1,7 @@ package com.github.lookupgroup27.lookup.ui.profile +import android.content.pm.ActivityInfo +import androidx.activity.ComponentActivity import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.clickable @@ -15,6 +17,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.blur import androidx.compose.ui.graphics.Color import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.testTag import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.font.FontWeight @@ -45,6 +48,15 @@ fun CollectionScreen( viewModel: CollectionViewModel = androidx.lifecycle.viewmodel.compose.viewModel(factory = CollectionViewModel.Factory) ) { + val context = LocalContext.current + + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } + val myPosts by viewModel.myPosts.collectAsState() Box( diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/profile/Profile.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/profile/Profile.kt index b224bd601..7b3c06204 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/profile/Profile.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/profile/Profile.kt @@ -1,6 +1,8 @@ package com.github.lookupgroup27.lookup.ui.profile +import android.content.pm.ActivityInfo import android.content.res.Configuration +import androidx.activity.ComponentActivity import androidx.compose.foundation.layout.* import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll @@ -12,6 +14,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalConfiguration +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.testTag import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource @@ -32,6 +35,15 @@ import components.BackgroundImage @Composable fun ProfileScreen(navigationActions: NavigationActions, avatarViewModel: AvatarViewModel) { + val context = LocalContext.current + + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } + val configuration = LocalConfiguration.current val isLandscape = configuration.orientation == Configuration.ORIENTATION_LANDSCAPE val user = FirebaseAuth.getInstance().currentUser diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/profile/ProfileInformation.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/profile/ProfileInformation.kt index 16904f93e..cd3a6ecbb 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/profile/ProfileInformation.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/profile/ProfileInformation.kt @@ -1,6 +1,8 @@ package com.github.lookupgroup27.lookup.ui.profile import android.annotation.SuppressLint +import android.content.pm.ActivityInfo +import androidx.activity.ComponentActivity import androidx.compose.foundation.* import androidx.compose.foundation.layout.* import androidx.compose.foundation.shape.RoundedCornerShape @@ -10,6 +12,7 @@ import androidx.compose.material3.* import androidx.compose.runtime.* import androidx.compose.ui.* import androidx.compose.ui.graphics.Color +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.testTag import androidx.compose.ui.unit.dp import com.github.lookupgroup27.lookup.model.profile.* @@ -23,6 +26,15 @@ fun ProfileInformationScreen( navigationActions: NavigationActions ) { + val context = LocalContext.current + + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } + val scrollState = rememberScrollState() profileViewModel.fetchUserProfile() diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/quiz/Quiz.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/quiz/Quiz.kt index b3882a29f..d785301d5 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/quiz/Quiz.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/quiz/Quiz.kt @@ -1,6 +1,8 @@ package com.github.lookupgroup27.lookup.ui.quiz import android.annotation.SuppressLint +import android.content.pm.ActivityInfo +import androidx.activity.ComponentActivity import androidx.compose.foundation.layout.* import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll @@ -11,6 +13,7 @@ import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffect import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color @@ -39,6 +42,15 @@ import components.BackgroundImage fun QuizScreen(viewModel: QuizViewModel, navigationActions: NavigationActions) { val context = LocalContext.current + + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } + + val bestScores = viewModel.getAllBestScores() BoxWithConstraints(modifier = Modifier.fillMaxSize().testTag("quiz_screen")) { diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/quiz/QuizPlay.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/quiz/QuizPlay.kt index 9c481c65c..f689eae58 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/quiz/QuizPlay.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/quiz/QuizPlay.kt @@ -1,6 +1,8 @@ package com.github.lookupgroup27.lookup.ui.quiz import android.annotation.SuppressLint +import android.content.pm.ActivityInfo +import androidx.activity.ComponentActivity import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.layout.* @@ -8,6 +10,7 @@ import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment @@ -16,6 +19,7 @@ import androidx.compose.ui.draw.blur import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.testTag import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.font.FontWeight @@ -39,6 +43,15 @@ import com.github.lookupgroup27.lookup.ui.theme.DarkPurple @SuppressLint("UnusedBoxWithConstraintsScope") @Composable fun QuizPlayScreen(viewModel: QuizViewModel, navigationActions: NavigationActions) { + val context = LocalContext.current + + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } + val quizQuestions by viewModel.quizQuestions.collectAsState() val currentQuestionIndex by viewModel.currentQuestionIndex.collectAsState() val score by viewModel.score.collectAsState() diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/register/Register.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/register/Register.kt index 7b918780e..bdc85484c 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/register/Register.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/register/Register.kt @@ -1,6 +1,9 @@ package com.github.lookupgroup27.lookup.ui.register +import android.annotation.SuppressLint +import android.content.pm.ActivityInfo import android.widget.Toast +import androidx.activity.ComponentActivity import androidx.compose.foundation.background import androidx.compose.foundation.layout.* import androidx.compose.material3.* @@ -34,6 +37,14 @@ fun RegisterScreen( viewModel: RegisterViewModel = viewModel(factory = RegisterViewModel.Factory) ) { val context = LocalContext.current + + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } + val uiState by viewModel.uiState.collectAsState() Box(modifier = Modifier.fillMaxSize()) { From a64ff3e8df1fc828816a1764a2a5009baab6470e Mon Sep 17 00:00:00 2001 From: Ismaillat Date: Fri, 20 Dec 2024 00:54:05 +0100 Subject: [PATCH 3/6] style: ktfmt format code --- .../lookup/ui/authentication/SignIn.kt | 10 +++++----- .../lookupgroup27/lookup/ui/calendar/Calendar.kt | 14 +++++++------- .../github/lookupgroup27/lookup/ui/feed/Feed.kt | 14 +++++++------- .../lookup/ui/fullscreen/FullScreen.kt | 12 ++++++------ .../lookupgroup27/lookup/ui/googlemap/GoogleMap.kt | 12 ++++++------ .../lookupgroup27/lookup/ui/image/EditImage.kt | 12 ++++++------ .../lookupgroup27/lookup/ui/image/ImageReview.kt | 12 ++++++------ .../lookupgroup27/lookup/ui/image/TakeImage.kt | 12 ++++++------ .../github/lookupgroup27/lookup/ui/login/Login.kt | 12 ++++++------ .../com/github/lookupgroup27/lookup/ui/map/Map.kt | 12 ++++++------ .../lookupgroup27/lookup/ui/overview/Landing.kt | 12 ++++++------ .../lookupgroup27/lookup/ui/overview/Menu.kt | 12 ++++++------ .../lookup/ui/passwordreset/PasswordReset.kt | 14 +++++++------- .../ui/planetselection/PlanetSelectionScreen.kt | 14 +++++++------- .../lookupgroup27/lookup/ui/profile/Collection.kt | 14 +++++++------- .../lookupgroup27/lookup/ui/profile/Profile.kt | 14 +++++++------- .../lookup/ui/profile/ProfileInformation.kt | 14 +++++++------- .../github/lookupgroup27/lookup/ui/quiz/Quiz.kt | 13 ++++++------- .../lookupgroup27/lookup/ui/quiz/QuizPlay.kt | 14 +++++++------- .../lookupgroup27/lookup/ui/register/Register.kt | 13 ++++++------- 20 files changed, 127 insertions(+), 129 deletions(-) diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/authentication/SignIn.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/authentication/SignIn.kt index 25cafe7e8..bb5307818 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/authentication/SignIn.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/authentication/SignIn.kt @@ -59,11 +59,11 @@ import kotlinx.coroutines.tasks.await fun SignInScreen(navigationActions: NavigationActions) { val context = LocalContext.current - DisposableEffect(Unit) { - val activity = context as? ComponentActivity - activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT - onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } - } + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } val launcher = rememberFirebaseAuthLauncher( diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/calendar/Calendar.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/calendar/Calendar.kt index 21ed17e80..b6dd547fe 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/calendar/Calendar.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/calendar/Calendar.kt @@ -50,13 +50,13 @@ fun CalendarScreen( calendarViewModel: CalendarViewModel = viewModel(), navigationActions: NavigationActions ) { - val context = LocalContext.current - // Lock the screen orientation to portrait mode. - DisposableEffect(Unit) { - val activity = context as? ComponentActivity - activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT - onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } - } + val context = LocalContext.current + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } // State variables for selected date, search query, and visibility of the search dialog. var selectedDate by remember { mutableStateOf(Date()) } diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/feed/Feed.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/feed/Feed.kt index f382fe31e..d586f360e 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/feed/Feed.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/feed/Feed.kt @@ -67,13 +67,13 @@ fun FeedScreen( initialNearbyPosts: List? = null, testNoLoca: Boolean = false ) { - val context = LocalContext.current - // Lock the screen orientation to portrait mode. - DisposableEffect(Unit) { - val activity = context as? ComponentActivity - activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT - onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } - } + val context = LocalContext.current + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } // Fetch user profile LaunchedEffect(Unit) { diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/fullscreen/FullScreen.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/fullscreen/FullScreen.kt index f758679b9..09d003ff2 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/fullscreen/FullScreen.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/fullscreen/FullScreen.kt @@ -47,12 +47,12 @@ fun FullScreenImageScreen( ) { val context = LocalContext.current - // Lock the screen orientation to portrait mode. - DisposableEffect(Unit) { - val activity = context as? ComponentActivity - activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT - onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } - } + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } // State to track if a toast for empty imageUrl has been shown var hasShownEmptyToast by remember { mutableStateOf(false) } diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/googlemap/GoogleMap.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/googlemap/GoogleMap.kt index 733e42f1c..76246ddf2 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/googlemap/GoogleMap.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/googlemap/GoogleMap.kt @@ -60,12 +60,12 @@ fun GoogleMapScreen( ) { val context = LocalContext.current - // Lock the screen orientation to portrait mode. - DisposableEffect(Unit) { - val activity = context as? ComponentActivity - activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT - onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } - } + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } val locationProvider = LocationProviderSingleton.getInstance(context) var hasLocationPermission by remember { diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/image/EditImage.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/image/EditImage.kt index 7f3bb160b..55cdb1904 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/image/EditImage.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/image/EditImage.kt @@ -78,12 +78,12 @@ fun EditImageScreen( val editImageState by editImageViewModel.editImageState.collectAsState() val context = LocalContext.current - // Lock the screen orientation to portrait mode. - DisposableEffect(Unit) { - val activity = context as? ComponentActivity - activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT - onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } - } + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } var description by remember { mutableStateOf(postDescription) } var isEditing by remember { mutableStateOf(false) } diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/image/ImageReview.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/image/ImageReview.kt index 10045380d..cdff868a6 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/image/ImageReview.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/image/ImageReview.kt @@ -65,12 +65,12 @@ fun ImageReviewScreen( ) { val context = LocalContext.current - // Lock the screen orientation to portrait mode. - DisposableEffect(Unit) { - val activity = context as? ComponentActivity - activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT - onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } - } + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } val locationProvider = LocationProviderSingleton.getInstance(context) val currentTimestamp = timestamp ?: System.currentTimeMillis() // Fallback to current time diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/image/TakeImage.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/image/TakeImage.kt index d9ab96cd0..56bd4443e 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/image/TakeImage.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/image/TakeImage.kt @@ -55,12 +55,12 @@ fun CameraCapture( ) { val context = LocalContext.current - // Lock the screen orientation to portrait mode. - DisposableEffect(Unit) { - val activity = context as? ComponentActivity - activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT - onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } - } + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } var imageCapture: ImageCapture? by remember { mutableStateOf(null) } var isCameraPermissionGranted by remember { mutableStateOf(false) } diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/login/Login.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/login/Login.kt index 2aa83f447..9afbcfa89 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/login/Login.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/login/Login.kt @@ -31,12 +31,12 @@ import com.github.lookupgroup27.lookup.ui.register.components.CustomOutlinedText fun LoginScreen(viewModel: LoginViewModel, navigationActions: NavigationActions) { val context = LocalContext.current - // Lock the screen orientation to portrait mode. - DisposableEffect(Unit) { - val activity = context as? ComponentActivity - activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT - onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } - } + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } val uiState by viewModel.uiState.collectAsState() diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/map/Map.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/map/Map.kt index 574111de1..3edde2a87 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/map/Map.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/map/Map.kt @@ -62,12 +62,12 @@ fun MapScreen(navigationActions: NavigationActions, mapViewModel: MapViewModel) val context = LocalContext.current - // Lock the screen orientation to portrait mode. - DisposableEffect(Unit) { - val activity = context as? ComponentActivity - activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT - onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } - } + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } val user = FirebaseAuth.getInstance().currentUser val isUserLoggedIn = user != null diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/overview/Landing.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/overview/Landing.kt index e6ec9b832..8c53fbcfd 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/overview/Landing.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/overview/Landing.kt @@ -46,12 +46,12 @@ fun LandingScreen( val context = LocalContext.current - // Lock the screen orientation to portrait mode. - DisposableEffect(Unit) { - val activity = context as? ComponentActivity - activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT - onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } - } + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } val isOnline = remember { mutableStateOf(NetworkUtils.isNetworkAvailable(context)) } diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/overview/Menu.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/overview/Menu.kt index 85550b7d4..57a33cdd4 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/overview/Menu.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/overview/Menu.kt @@ -42,12 +42,12 @@ fun MenuScreen( val context = LocalContext.current - // Lock the screen orientation to portrait mode. - DisposableEffect(Unit) { - val activity = context as? ComponentActivity - activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT - onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } - } + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } val isOnline = remember { mutableStateOf(NetworkUtils.isNetworkAvailable(context)) } diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/passwordreset/PasswordReset.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/passwordreset/PasswordReset.kt index e31cbac76..8018c7344 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/passwordreset/PasswordReset.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/passwordreset/PasswordReset.kt @@ -42,14 +42,14 @@ import com.github.lookupgroup27.lookup.ui.navigation.Screen @OptIn(ExperimentalMaterial3Api::class) @Composable fun PasswordResetScreen(viewModel: PasswordResetViewModel, navigationActions: NavigationActions) { - val context = LocalContext.current + val context = LocalContext.current - // Lock the screen orientation to portrait mode. - DisposableEffect(Unit) { - val activity = context as? ComponentActivity - activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT - onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } - } + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } // Observes the UI state from the ViewModel val uiState by viewModel.uiState.collectAsState() diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/planetselection/PlanetSelectionScreen.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/planetselection/PlanetSelectionScreen.kt index 2f38b06bd..19f74d99f 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/planetselection/PlanetSelectionScreen.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/planetselection/PlanetSelectionScreen.kt @@ -42,14 +42,14 @@ fun PlanetSelectionScreen( viewModel: PlanetSelectionViewModel = viewModel(), navigationActions: NavigationActions ) { - val context = LocalContext.current + val context = LocalContext.current - // Lock the screen orientation to portrait mode. - DisposableEffect(Unit) { - val activity = context as? ComponentActivity - activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT - onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } - } + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } val planets = viewModel.planets val selectedPlanet by viewModel.selectedPlanet.collectAsState() diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/profile/Collection.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/profile/Collection.kt index 41b874cd2..221996517 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/profile/Collection.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/profile/Collection.kt @@ -48,14 +48,14 @@ fun CollectionScreen( viewModel: CollectionViewModel = androidx.lifecycle.viewmodel.compose.viewModel(factory = CollectionViewModel.Factory) ) { - val context = LocalContext.current + val context = LocalContext.current - // Lock the screen orientation to portrait mode. - DisposableEffect(Unit) { - val activity = context as? ComponentActivity - activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT - onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } - } + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } val myPosts by viewModel.myPosts.collectAsState() diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/profile/Profile.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/profile/Profile.kt index 7b3c06204..6b852bfaf 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/profile/Profile.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/profile/Profile.kt @@ -35,14 +35,14 @@ import components.BackgroundImage @Composable fun ProfileScreen(navigationActions: NavigationActions, avatarViewModel: AvatarViewModel) { - val context = LocalContext.current + val context = LocalContext.current - // Lock the screen orientation to portrait mode. - DisposableEffect(Unit) { - val activity = context as? ComponentActivity - activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT - onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } - } + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } val configuration = LocalConfiguration.current val isLandscape = configuration.orientation == Configuration.ORIENTATION_LANDSCAPE diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/profile/ProfileInformation.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/profile/ProfileInformation.kt index cd3a6ecbb..b6626ae46 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/profile/ProfileInformation.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/profile/ProfileInformation.kt @@ -26,14 +26,14 @@ fun ProfileInformationScreen( navigationActions: NavigationActions ) { - val context = LocalContext.current + val context = LocalContext.current - // Lock the screen orientation to portrait mode. - DisposableEffect(Unit) { - val activity = context as? ComponentActivity - activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT - onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } - } + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } val scrollState = rememberScrollState() diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/quiz/Quiz.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/quiz/Quiz.kt index d785301d5..2b414ea3b 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/quiz/Quiz.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/quiz/Quiz.kt @@ -43,13 +43,12 @@ fun QuizScreen(viewModel: QuizViewModel, navigationActions: NavigationActions) { val context = LocalContext.current - // Lock the screen orientation to portrait mode. - DisposableEffect(Unit) { - val activity = context as? ComponentActivity - activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT - onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } - } - + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } val bestScores = viewModel.getAllBestScores() diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/quiz/QuizPlay.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/quiz/QuizPlay.kt index f689eae58..11abb51e8 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/quiz/QuizPlay.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/quiz/QuizPlay.kt @@ -43,14 +43,14 @@ import com.github.lookupgroup27.lookup.ui.theme.DarkPurple @SuppressLint("UnusedBoxWithConstraintsScope") @Composable fun QuizPlayScreen(viewModel: QuizViewModel, navigationActions: NavigationActions) { - val context = LocalContext.current + val context = LocalContext.current - // Lock the screen orientation to portrait mode. - DisposableEffect(Unit) { - val activity = context as? ComponentActivity - activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT - onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } - } + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } val quizQuestions by viewModel.quizQuestions.collectAsState() val currentQuestionIndex by viewModel.currentQuestionIndex.collectAsState() diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/register/Register.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/register/Register.kt index bdc85484c..a3242a727 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/register/Register.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/register/Register.kt @@ -1,6 +1,5 @@ package com.github.lookupgroup27.lookup.ui.register -import android.annotation.SuppressLint import android.content.pm.ActivityInfo import android.widget.Toast import androidx.activity.ComponentActivity @@ -38,12 +37,12 @@ fun RegisterScreen( ) { val context = LocalContext.current - // Lock the screen orientation to portrait mode. - DisposableEffect(Unit) { - val activity = context as? ComponentActivity - activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT - onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } - } + // Lock the screen orientation to portrait mode. + DisposableEffect(Unit) { + val activity = context as? ComponentActivity + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } + } val uiState by viewModel.uiState.collectAsState() From 6e808781b7f9e63cb5469a02ef9c82a3a2ba3fe9 Mon Sep 17 00:00:00 2001 From: Ismaillat Date: Fri, 20 Dec 2024 01:48:22 +0100 Subject: [PATCH 4/6] fix: remove landscape tesst from signIn --- .../lookupgroup27/lookup/ui/authentication/SignInKtTest.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/androidTest/java/com/github/lookupgroup27/lookup/ui/authentication/SignInKtTest.kt b/app/src/androidTest/java/com/github/lookupgroup27/lookup/ui/authentication/SignInKtTest.kt index fe1172c57..61535caa8 100644 --- a/app/src/androidTest/java/com/github/lookupgroup27/lookup/ui/authentication/SignInKtTest.kt +++ b/app/src/androidTest/java/com/github/lookupgroup27/lookup/ui/authentication/SignInKtTest.kt @@ -80,7 +80,7 @@ class SignInKtTest : TestCase() { verify(mockNavigationActions).navigateTo(Screen.MENU) } - @Test + /*@Test fun testSignInScreenIsFullyVisibleInLandscape() { // Set device orientation to landscape setLandscapeOrientation() @@ -103,7 +103,7 @@ class SignInKtTest : TestCase() { // Reset orientation to portrait after the test resetOrientation() - } + }*/ @Test fun backArrowIsInTopLeftCorner() { From 6759e8f74c194f8838979bdf9891c7204688af6e Mon Sep 17 00:00:00 2001 From: Ismaillat Date: Fri, 20 Dec 2024 02:00:38 +0100 Subject: [PATCH 5/6] fix: remove landscape tests from Quiz, Landing and Signin tests --- .../lookup/ui/authentication/SignInKtTest.kt | 37 ------------------- .../lookup/ui/overview/LandingKtTest.kt | 37 ------------------- .../lookup/ui/quiz/QuizKtTest.kt | 37 ------------------- 3 files changed, 111 deletions(-) diff --git a/app/src/androidTest/java/com/github/lookupgroup27/lookup/ui/authentication/SignInKtTest.kt b/app/src/androidTest/java/com/github/lookupgroup27/lookup/ui/authentication/SignInKtTest.kt index 61535caa8..659d7c290 100644 --- a/app/src/androidTest/java/com/github/lookupgroup27/lookup/ui/authentication/SignInKtTest.kt +++ b/app/src/androidTest/java/com/github/lookupgroup27/lookup/ui/authentication/SignInKtTest.kt @@ -6,8 +6,6 @@ import androidx.test.espresso.intent.Intents import androidx.test.espresso.intent.Intents.intended import androidx.test.espresso.intent.matcher.IntentMatchers.toPackage import androidx.test.ext.junit.runners.AndroidJUnit4 -import androidx.test.platform.app.InstrumentationRegistry -import androidx.test.uiautomator.UiDevice import com.github.lookupgroup27.lookup.ui.navigation.NavigationActions import com.github.lookupgroup27.lookup.ui.navigation.Screen import com.kaspersky.kaspresso.testcases.api.testcase.TestCase @@ -80,31 +78,6 @@ class SignInKtTest : TestCase() { verify(mockNavigationActions).navigateTo(Screen.MENU) } - /*@Test - fun testSignInScreenIsFullyVisibleInLandscape() { - // Set device orientation to landscape - setLandscapeOrientation() - - // Launch the SignInScreen in landscape mode - composeTestRule.setContent { SignInScreen(mockNavigationActions) } - - // Scroll to each component and verify it is displayed - composeTestRule.onNodeWithTag("loginTitle").performScrollTo().assertIsDisplayed() - composeTestRule.onNodeWithTag("loginTitle").assertTextEquals("Welcome to the Cosmos") - composeTestRule - .onNodeWithTag("loginButton") - .performScrollTo() - .assertIsDisplayed() - .assertHasClickAction() - composeTestRule - .onNodeWithTag("go_back_button_signin") - .assertIsDisplayed() - .assertHasClickAction() - - // Reset orientation to portrait after the test - resetOrientation() - }*/ - @Test fun backArrowIsInTopLeftCorner() { composeTestRule.setContent { SignInScreen(mockNavigationActions) } @@ -118,14 +91,4 @@ class SignInKtTest : TestCase() { assert(backArrowBounds.left < screenWidth * 0.1f) assert(backArrowBounds.top < screenHeight * 0.1f) } - - private fun setLandscapeOrientation() { - val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) - device.setOrientationLeft() - } - - private fun resetOrientation() { - val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) - device.setOrientationNatural() - } } diff --git a/app/src/androidTest/java/com/github/lookupgroup27/lookup/ui/overview/LandingKtTest.kt b/app/src/androidTest/java/com/github/lookupgroup27/lookup/ui/overview/LandingKtTest.kt index 33e2e9636..15f71c8bb 100644 --- a/app/src/androidTest/java/com/github/lookupgroup27/lookup/ui/overview/LandingKtTest.kt +++ b/app/src/androidTest/java/com/github/lookupgroup27/lookup/ui/overview/LandingKtTest.kt @@ -10,8 +10,6 @@ import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performScrollTo import androidx.test.espresso.intent.Intents import androidx.test.ext.junit.runners.AndroidJUnit4 -import androidx.test.platform.app.InstrumentationRegistry -import androidx.test.uiautomator.UiDevice import com.github.lookupgroup27.lookup.ui.navigation.NavigationActions import com.github.lookupgroup27.lookup.ui.navigation.Screen import com.github.lookupgroup27.lookup.util.ToastHelper @@ -98,31 +96,6 @@ class LandingKtTest { composeTestRule.onNodeWithText("Click for full map view").assertIsDisplayed() } - @Test - fun testLandingScreenIsFullyVisibleInLandscape() { - // Set device orientation to landscape - setLandscapeOrientation() - - // Launch LandingScreen in landscape mode - composeTestRule.setContent { LandingScreen(mockNavigationActions) } - - // Ensure main UI elements are visible and accessible by scrolling if needed - composeTestRule.onNodeWithContentDescription("Look Up Logo").assertIsDisplayed() - composeTestRule - .onNodeWithContentDescription("Home Icon") - .performScrollTo() - .assertIsDisplayed() - .assertHasClickAction() - composeTestRule - .onNodeWithContentDescription("Background") - .assertIsDisplayed() - .assertHasClickAction() - composeTestRule.onNodeWithText("Click for full map view").assertIsDisplayed() - - // Reset orientation to portrait after the test - resetOrientation() - } - @Test fun testBackgroundClickDoesNotNavigateToMapWhenOffline() { // Simulate offline mode @@ -166,14 +139,4 @@ class LandingKtTest { // Verify no navigation occurred verify(mockNavigationActions, never()).navigateTo(Screen.SKY_MAP) } - - private fun setLandscapeOrientation() { - val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) - device.setOrientationLeft() - } - - private fun resetOrientation() { - val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) - device.setOrientationNatural() - } } diff --git a/app/src/androidTest/java/com/github/lookupgroup27/lookup/ui/quiz/QuizKtTest.kt b/app/src/androidTest/java/com/github/lookupgroup27/lookup/ui/quiz/QuizKtTest.kt index cd43c1e07..d263f2bc6 100644 --- a/app/src/androidTest/java/com/github/lookupgroup27/lookup/ui/quiz/QuizKtTest.kt +++ b/app/src/androidTest/java/com/github/lookupgroup27/lookup/ui/quiz/QuizKtTest.kt @@ -8,8 +8,6 @@ import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performScrollTo -import androidx.test.platform.app.InstrumentationRegistry -import androidx.test.uiautomator.UiDevice import com.github.lookupgroup27.lookup.model.quiz.QuizRepository import com.github.lookupgroup27.lookup.ui.navigation.NavigationActions import com.github.lookupgroup27.lookup.ui.navigation.Screen @@ -143,39 +141,4 @@ class QuizKtTest { // Verify no navigation actions are triggered verifyNoInteractions(mockNavigationActions) } - - @Test - fun quizScreen_displaysBottomElementsInLandscapeModeWithScroll() { - // Set device orientation to landscape - setLandscapeOrientation() - - // Load the QuizScreen in landscape orientation - composeTestRule.setContent { - QuizScreen(quizViewModel, navigationActions = mockNavigationActions) - } - - // In landscape mode, verify top elements are displayed - composeTestRule.onNodeWithTag("quiz_screen").assertIsDisplayed() - composeTestRule.onNodeWithTag("go_back_button_quiz").assertIsDisplayed() - composeTestRule.onNodeWithTag("background_test_tag").assertIsDisplayed() - composeTestRule.onNodeWithTag("quiz_title").assertIsDisplayed() - composeTestRule.onNodeWithText("Take a Quiz").assertIsDisplayed() - - // Scroll to and verify the visibility of bottom elements in the quiz screen - composeTestRule.onNodeWithTag("solar system_button").performScrollTo().assertIsDisplayed() - composeTestRule.onNodeWithTag("earth_button").performScrollTo().assertIsDisplayed() - - // Reset orientation to portrait after test - resetOrientation() - } - - private fun setLandscapeOrientation() { - val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) - device.setOrientationLeft() - } - - private fun resetOrientation() { - val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) - device.setOrientationNatural() - } } From fd50262b834c13b6c8ea9b1d1de878d4cafe1f1c Mon Sep 17 00:00:00 2001 From: Ismaillat Date: Fri, 20 Dec 2024 02:29:22 +0100 Subject: [PATCH 6/6] fix: remove landscape tests from profile tests --- .../lookup/ui/profile/ProfileKtTest.kt | 41 ------------------- 1 file changed, 41 deletions(-) diff --git a/app/src/androidTest/java/com/github/lookupgroup27/lookup/ui/profile/ProfileKtTest.kt b/app/src/androidTest/java/com/github/lookupgroup27/lookup/ui/profile/ProfileKtTest.kt index 80be8f682..d881e463c 100644 --- a/app/src/androidTest/java/com/github/lookupgroup27/lookup/ui/profile/ProfileKtTest.kt +++ b/app/src/androidTest/java/com/github/lookupgroup27/lookup/ui/profile/ProfileKtTest.kt @@ -4,10 +4,7 @@ import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithContentDescription import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick -import androidx.compose.ui.test.performScrollTo import androidx.test.ext.junit.runners.AndroidJUnit4 -import androidx.test.platform.app.InstrumentationRegistry -import androidx.test.uiautomator.UiDevice import com.github.lookupgroup27.lookup.R import com.github.lookupgroup27.lookup.model.profile.ProfileRepository import com.github.lookupgroup27.lookup.ui.navigation.LIST_TOP_LEVEL_DESTINATION @@ -182,42 +179,4 @@ class ProfileKtTest { // Verify that no further interactions (including `navigateTo()`) occurred Mockito.verifyNoMoreInteractions(mockNavigationActions) } - - @Test - fun testProfileScreenIsScrollableAndFullyVisibleInLandscape() { - // Set the device to landscape orientation - setLandscapeOrientation() - - // Launch the ProfileScreen in landscape mode - composeTestRule.setContent { - ProfileScreen( - navigationActions = mockNavigationActions, avatarViewModel = mockAvatarViewModel) - } - - // Check that main elements are displayed after scrolling in landscape mode - composeTestRule - .onNodeWithContentDescription(getResourceString(R.string.profile_profile_icon_description)) - .assertExists() - composeTestRule - .onNodeWithText(getResourceString(R.string.profile_personal_info_button)) - .performScrollTo() - .assertExists() - composeTestRule - .onNodeWithText(getResourceString(R.string.profile_collection_button)) - .performScrollTo() - .assertExists() - - // Reset orientation to portrait after the test - resetOrientation() - } - - private fun setLandscapeOrientation() { - val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) - device.setOrientationLeft() - } - - private fun resetOrientation() { - val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) - device.setOrientationNatural() - } }