Skip to content

Commit 0dc4d38

Browse files
committed
porting the LoginActivty2 to a dynamic FTUE activity
- supports switching between a copied legacy flow (DefaultFTUE) and the WIP variant - this will allow us to make iterative changes to the default ftue flow without affecting the legacy flow/forks
1 parent b28a767 commit 0dc4d38

File tree

9 files changed

+589
-107
lines changed

9 files changed

+589
-107
lines changed

vector/src/main/AndroidManifest.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
android:windowSoftInputMode="adjustResize" />
138138

139139
<activity
140-
android:name=".features.login2.LoginActivity2"
140+
android:name=".features.ftue.FTUEActivity"
141141
android:launchMode="singleTask"
142142
android:windowSoftInputMode="adjustResize" />
143143

vector/src/main/java/im/vector/app/core/platform/VectorBaseActivity.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ abstract class VectorBaseActivity<VB : ViewBinding> : AppCompatActivity(), Maver
105105
protected val viewModelProvider
106106
get() = ViewModelProvider(this, viewModelFactory)
107107

108-
protected fun <T : VectorViewEvents> VectorViewModel<*, *, T>.observeViewEvents(observer: (T) -> Unit) {
108+
fun <T : VectorViewEvents> VectorViewModel<*, *, T>.observeViewEvents(observer: (T) -> Unit) {
109109
viewEvents
110110
.stream()
111111
.onEach {

vector/src/main/java/im/vector/app/features/VectorFeatures.kt

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ interface VectorFeatures {
2424

2525
enum class LoginVariant {
2626
LEGACY,
27+
FTUE,
2728
FTUE_WIP
2829
}
2930

vector/src/main/java/im/vector/app/features/ftue/DefaultFTUEVariant.kt

+367
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 im.vector.app.features.VectorFeatures
20+
import im.vector.app.features.login.LoginViewModel
21+
import im.vector.app.features.login2.LoginViewModel2
22+
import javax.inject.Inject
23+
24+
class FTUEVariantFactory @Inject constructor(
25+
private val vectorFeatures: VectorFeatures,
26+
) {
27+
28+
fun create(activity: FTUEActivity, loginViewModel: Lazy<LoginViewModel>, loginViewModel2: Lazy<LoginViewModel2>) = when (vectorFeatures.loginVariant()) {
29+
VectorFeatures.LoginVariant.LEGACY -> error("Legacy is not supported by the FTUE")
30+
VectorFeatures.LoginVariant.FTUE -> DefaultFTUEVariant(
31+
views = activity.getBinding(),
32+
loginViewModel = loginViewModel.value,
33+
activity = activity,
34+
supportFragmentManager = activity.supportFragmentManager
35+
)
36+
VectorFeatures.LoginVariant.FTUE_WIP -> FTUEWipVariant(
37+
views = activity.getBinding(),
38+
loginViewModel = loginViewModel2.value,
39+
activity = activity,
40+
supportFragmentManager = activity.supportFragmentManager
41+
)
42+
}
43+
}

0 commit comments

Comments
 (0)