locking phones to portait during the ftue auth onboarding flow

- uses a resource bucket flag for determining if the device is big enough to be considered a tablet and in turn, enable a landscape experience
This commit is contained in:
Adam Brown 2022-01-11 17:28:29 +00:00
parent 67bdf4b226
commit ce7a93bcae
5 changed files with 53 additions and 2 deletions

View File

@ -2,5 +2,6 @@
<resources> <resources>
<dimen name="width_percent">0.6</dimen> <dimen name="width_percent">0.6</dimen>
<bool name="is_tablet">true</bool>
</resources> </resources>

View File

@ -2,5 +2,6 @@
<resources> <resources>
<dimen name="width_percent">1</dimen> <dimen name="width_percent">1</dimen>
<bool name="is_tablet">false</bool>
</resources> </resources>

View File

@ -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
}
}
}
}

View File

@ -16,6 +16,7 @@
package im.vector.app.features.onboarding package im.vector.app.features.onboarding
import im.vector.app.core.platform.ScreenOrientationLocker
import im.vector.app.databinding.ActivityLoginBinding import im.vector.app.databinding.ActivityLoginBinding
import im.vector.app.features.VectorFeatures import im.vector.app.features.VectorFeatures
import im.vector.app.features.login2.LoginViewModel2 import im.vector.app.features.login2.LoginViewModel2
@ -24,6 +25,7 @@ import javax.inject.Inject
class OnboardingVariantFactory @Inject constructor( class OnboardingVariantFactory @Inject constructor(
private val vectorFeatures: VectorFeatures, private val vectorFeatures: VectorFeatures,
private val orientationLocker: ScreenOrientationLocker,
) { ) {
fun create(activity: OnboardingActivity, fun create(activity: OnboardingActivity,
@ -37,7 +39,8 @@ class OnboardingVariantFactory @Inject constructor(
onboardingViewModel = onboardingViewModel.value, onboardingViewModel = onboardingViewModel.value,
activity = activity, activity = activity,
supportFragmentManager = activity.supportFragmentManager, supportFragmentManager = activity.supportFragmentManager,
vectorFeatures = vectorFeatures vectorFeatures = vectorFeatures,
orientationLocker = orientationLocker
) )
VectorFeatures.OnboardingVariant.LOGIN_2 -> Login2Variant( VectorFeatures.OnboardingVariant.LOGIN_2 -> Login2Variant(
views = views, views = views,

View File

@ -15,6 +15,7 @@
*/ */
package im.vector.app.features.onboarding.ftueauth package im.vector.app.features.onboarding.ftueauth
import android.content.Intent import android.content.Intent
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
@ -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.addFragment
import im.vector.app.core.extensions.addFragmentToBackstack import im.vector.app.core.extensions.addFragmentToBackstack
import im.vector.app.core.extensions.exhaustive 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.core.platform.VectorBaseActivity
import im.vector.app.databinding.ActivityLoginBinding import im.vector.app.databinding.ActivityLoginBinding
import im.vector.app.features.VectorFeatures import im.vector.app.features.VectorFeatures
@ -62,7 +64,8 @@ class FtueAuthVariant(
private val onboardingViewModel: OnboardingViewModel, private val onboardingViewModel: OnboardingViewModel,
private val activity: VectorBaseActivity<ActivityLoginBinding>, private val activity: VectorBaseActivity<ActivityLoginBinding>,
private val supportFragmentManager: FragmentManager, private val supportFragmentManager: FragmentManager,
private val vectorFeatures: VectorFeatures private val vectorFeatures: VectorFeatures,
private val orientationLocker: ScreenOrientationLocker,
) : OnboardingVariant { ) : OnboardingVariant {
private val enterAnim = R.anim.enter_fade_in private val enterAnim = R.anim.enter_fade_in
@ -91,6 +94,7 @@ class FtueAuthVariant(
} }
with(activity) { with(activity) {
orientationLocker.lockPhonesToPortrait(this)
onboardingViewModel.onEach { onboardingViewModel.onEach {
updateWithState(it) updateWithState(it)
} }