Merge pull request #4918 from vector-im/feature/adm/lock-ftue-onboarding-to-portrait

Locking phones to portrait during FTUE onboarding
This commit is contained in:
Adam Brown 2022-01-13 12:42:59 +00:00 committed by GitHub
commit 18207da94e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 58 additions and 2 deletions

View File

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

View File

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

@ -20,8 +20,10 @@ import com.airbnb.mvrx.viewModel
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.core.extensions.addFragment
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.ActivitySimpleBinding
import javax.inject.Inject
/**
* Simple container for AnalyticsOptInFragment
@ -29,6 +31,8 @@ import im.vector.app.databinding.ActivitySimpleBinding
@AndroidEntryPoint
class AnalyticsOptInActivity : VectorBaseActivity<ActivitySimpleBinding>() {
@Inject lateinit var orientationLocker: ScreenOrientationLocker
private val viewModel: AnalyticsConsentViewModel by viewModel()
override fun getBinding() = ActivitySimpleBinding.inflate(layoutInflater)
@ -36,6 +40,7 @@ class AnalyticsOptInActivity : VectorBaseActivity<ActivitySimpleBinding>() {
override fun getCoordinatorLayout() = views.coordinatorLayout
override fun initUiAndData() {
orientationLocker.lockPhonesToPortrait(this)
if (isFirstCreation()) {
addFragment(views.simpleFragmentContainer, AnalyticsOptInFragment::class.java)
}

View File

@ -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
@ -24,6 +25,7 @@ import javax.inject.Inject
class OnboardingVariantFactory @Inject constructor(
private val vectorFeatures: VectorFeatures,
private val orientationLocker: ScreenOrientationLocker,
) {
fun create(activity: OnboardingActivity,
@ -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,

View File

@ -15,6 +15,7 @@
*/
package im.vector.app.features.onboarding.ftueauth
import android.content.Intent
import android.view.View
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.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
@ -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
@ -91,6 +94,7 @@ class FtueAuthVariant(
}
with(activity) {
orientationLocker.lockPhonesToPortrait(this)
onboardingViewModel.onEach {
updateWithState(it)
}