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

Locking phones to portrait during FTUE onboarding #4918

Merged
merged 2 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions library/ui-styles/src/main/res/values-sw600dp/tablet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<resources>

<dimen name="width_percent">0.6</dimen>
<bool name="is_tablet">true</bool>

</resources>
1 change: 1 addition & 0 deletions library/ui-styles/src/main/res/values/tablet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<resources>

<dimen name="width_percent">1</dimen>
<bool name="is_tablet">false</bool>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird to see that in a file (that I) named tablet.xml :)


</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package im.vector.app.core.platform

import android.annotation.SuppressLint
import android.content.pm.ActivityInfo
import android.content.res.Resources
import androidx.appcompat.app.AppCompatActivity
import im.vector.app.R
import javax.inject.Inject

class ScreenOrientationLocker @Inject constructor(
private val resources: Resources
) {

// Some screens do not provide enough value for us to provide phone landscape experiences
@SuppressLint("SourceLockedOrientationActivity")
fun lockPhonesToPortrait(activity: AppCompatActivity) {
when (resources.getBoolean(R.bool.is_tablet)) {
true -> {
// do nothing
}
false -> {
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package im.vector.app.features.onboarding

import im.vector.app.core.platform.ScreenOrientationLocker
import im.vector.app.databinding.ActivityLoginBinding
import im.vector.app.features.VectorFeatures
import im.vector.app.features.login2.LoginViewModel2
Expand All @@ -24,6 +25,7 @@ import javax.inject.Inject

class OnboardingVariantFactory @Inject constructor(
private val vectorFeatures: VectorFeatures,
private val orientationLocker: ScreenOrientationLocker,
) {

fun create(activity: OnboardingActivity,
Expand All @@ -37,7 +39,8 @@ class OnboardingVariantFactory @Inject constructor(
onboardingViewModel = onboardingViewModel.value,
activity = activity,
supportFragmentManager = activity.supportFragmentManager,
vectorFeatures = vectorFeatures
vectorFeatures = vectorFeatures,
orientationLocker = orientationLocker
)
VectorFeatures.OnboardingVariant.LOGIN_2 -> Login2Variant(
views = views,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

package im.vector.app.features.onboarding.ftueauth

import android.content.Intent
import android.view.View
import android.view.ViewGroup
Expand All @@ -31,6 +32,7 @@ import im.vector.app.core.extensions.POP_BACK_STACK_EXCLUSIVE
import im.vector.app.core.extensions.addFragment
import im.vector.app.core.extensions.addFragmentToBackstack
import im.vector.app.core.extensions.exhaustive
import im.vector.app.core.platform.ScreenOrientationLocker
import im.vector.app.core.platform.VectorBaseActivity
import im.vector.app.databinding.ActivityLoginBinding
import im.vector.app.features.VectorFeatures
Expand Down Expand Up @@ -62,7 +64,8 @@ class FtueAuthVariant(
private val onboardingViewModel: OnboardingViewModel,
private val activity: VectorBaseActivity<ActivityLoginBinding>,
private val supportFragmentManager: FragmentManager,
private val vectorFeatures: VectorFeatures
private val vectorFeatures: VectorFeatures,
private val orientationLocker: ScreenOrientationLocker,
) : OnboardingVariant {

private val enterAnim = R.anim.enter_fade_in
Expand Down Expand Up @@ -91,6 +94,7 @@ class FtueAuthVariant(
}

with(activity) {
orientationLocker.lockPhonesToPortrait(this)
onboardingViewModel.onEach {
updateWithState(it)
}
Expand Down