|
| 1 | +/* |
| 2 | + * Copyright (c) 2021 New Vector Ltd |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package im.vector.app.features.ftue |
| 18 | + |
| 19 | +import android.content.Context |
| 20 | +import android.content.Intent |
| 21 | +import android.net.Uri |
| 22 | +import com.google.android.material.appbar.MaterialToolbar |
| 23 | +import dagger.hilt.android.AndroidEntryPoint |
| 24 | +import im.vector.app.core.extensions.lazyViewModel |
| 25 | +import im.vector.app.core.platform.ToolbarConfigurable |
| 26 | +import im.vector.app.core.platform.VectorBaseActivity |
| 27 | +import im.vector.app.core.platform.lifecycleAwareLazy |
| 28 | +import im.vector.app.databinding.ActivityLoginBinding |
| 29 | +import im.vector.app.features.login.LoginConfig |
| 30 | +import im.vector.app.features.pin.UnlockedActivity |
| 31 | +import javax.inject.Inject |
| 32 | + |
| 33 | +@AndroidEntryPoint |
| 34 | +class FTUEActivity : VectorBaseActivity<ActivityLoginBinding>(), ToolbarConfigurable, UnlockedActivity { |
| 35 | + |
| 36 | + private val ftueVariant by lifecycleAwareLazy { |
| 37 | + ftueVariantFactory.create(this, loginViewModel = lazyViewModel(), loginViewModel2 = lazyViewModel()) |
| 38 | + } |
| 39 | + |
| 40 | + @Inject lateinit var ftueVariantFactory: FTUEVariantFactory |
| 41 | + |
| 42 | + override fun getBinding() = ActivityLoginBinding.inflate(layoutInflater) |
| 43 | + |
| 44 | + override fun getCoordinatorLayout() = views.coordinatorLayout |
| 45 | + |
| 46 | + override fun configure(toolbar: MaterialToolbar) { |
| 47 | + configureToolbar(toolbar) |
| 48 | + } |
| 49 | + |
| 50 | + override fun onNewIntent(intent: Intent?) { |
| 51 | + super.onNewIntent(intent) |
| 52 | + ftueVariant.onNewIntent(intent) |
| 53 | + } |
| 54 | + |
| 55 | + override fun initUiAndData() { |
| 56 | + ftueVariant.initUiAndData(isFirstCreation()) |
| 57 | + } |
| 58 | + |
| 59 | + // Hack for AccountCreatedFragment |
| 60 | + fun setIsLoading(isLoading: Boolean) { |
| 61 | + ftueVariant.setIsLoading(isLoading) |
| 62 | + } |
| 63 | + |
| 64 | + companion object { |
| 65 | + const val EXTRA_CONFIG = "EXTRA_CONFIG" |
| 66 | + |
| 67 | + fun newIntent(context: Context, loginConfig: LoginConfig?): Intent { |
| 68 | + return Intent(context, FTUEActivity::class.java).apply { |
| 69 | + putExtra(EXTRA_CONFIG, loginConfig) |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + fun redirectIntent(context: Context, data: Uri?): Intent { |
| 74 | + return Intent(context, FTUEActivity::class.java).apply { |
| 75 | + setData(data) |
| 76 | + } |
| 77 | + } |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +interface FTUEVariant { |
| 82 | + fun onNewIntent(intent: Intent?) |
| 83 | + fun initUiAndData(isFirstCreation: Boolean) |
| 84 | + fun setIsLoading(isLoading: Boolean) |
| 85 | +} |
0 commit comments