Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: lock app into portrait mode #319

Merged
merged 6 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) }
Expand All @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 ->
Expand Down
Original file line number Diff line number Diff line change
@@ -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.*
Expand All @@ -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
Expand Down Expand Up @@ -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("") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -65,6 +67,14 @@ fun FeedScreen(
initialNearbyPosts: List<Post>? = 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")
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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.*
Expand Down Expand Up @@ -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) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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) }
Expand Down
Loading
Loading