-
Notifications
You must be signed in to change notification settings - Fork 732
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
FTUE - Capability based personalisation flow #5375
Changes from all commits
4a1bf11
074cde4
1c80914
232524d
567fd9a
6c4381f
0685b57
7ded900
10e4fd1
50740b1
3df4f1e
537c2f5
a033243
46be481
716928d
b5778bd
4b9b177
ab9e440
7e79d7e
bdedffb
edee6ab
d89cc71
c2fe669
c84ce5a
c06d3ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Dynamically showing/hiding onboarding personalisation screens based on the users homeserver capabilities |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,9 @@ package im.vector.app.features.debug.settings | |
|
||
import im.vector.app.core.platform.VectorViewModelAction | ||
|
||
sealed class DebugPrivateSettingsViewActions : VectorViewModelAction { | ||
data class SetDialPadVisibility(val force: Boolean) : DebugPrivateSettingsViewActions() | ||
data class SetForceLoginFallbackEnabled(val force: Boolean) : DebugPrivateSettingsViewActions() | ||
sealed interface DebugPrivateSettingsViewActions : VectorViewModelAction { | ||
data class SetDialPadVisibility(val force: Boolean) : DebugPrivateSettingsViewActions | ||
data class SetForceLoginFallbackEnabled(val force: Boolean) : DebugPrivateSettingsViewActions | ||
data class SetDisplayNameCapabilityOverride(val option: BooleanHomeserverCapabilitiesOverride?) : DebugPrivateSettingsViewActions | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am just wondering why is the option There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay it makes sense. I forgot it is an override setting. |
||
data class SetAvatarCapabilityOverride(val option: BooleanHomeserverCapabilitiesOverride?) : DebugPrivateSettingsViewActions | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* 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.features.debug.settings | ||
|
||
import android.content.Context | ||
import android.util.AttributeSet | ||
import android.view.Gravity | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.widget.AdapterView | ||
import android.widget.ArrayAdapter | ||
import android.widget.LinearLayout | ||
import im.vector.app.R | ||
import im.vector.app.databinding.ViewBooleanDropdownBinding | ||
|
||
class OverrideDropdownView @JvmOverloads constructor( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a reusable dropdown view for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! 👍 I am a big fan of custom views! |
||
context: Context, | ||
attrs: AttributeSet? = null | ||
) : LinearLayout(context, attrs) { | ||
|
||
private val binding = ViewBooleanDropdownBinding.inflate( | ||
LayoutInflater.from(context), | ||
this | ||
) | ||
|
||
init { | ||
orientation = HORIZONTAL | ||
gravity = Gravity.CENTER_VERTICAL | ||
} | ||
|
||
fun <T : OverrideOption> bind(feature: OverrideDropdown<T>, listener: Listener<T>) { | ||
binding.overrideLabel.text = feature.label | ||
|
||
binding.overrideOptions.apply { | ||
val arrayAdapter = ArrayAdapter<String>(context, android.R.layout.simple_spinner_dropdown_item) | ||
val options = listOf("Inactive") + feature.options.map { it.label } | ||
arrayAdapter.addAll(options) | ||
adapter = arrayAdapter | ||
|
||
feature.activeOption?.let { | ||
setSelection(options.indexOf(it.label), false) | ||
} | ||
|
||
onItemSelectedListener = object : AdapterView.OnItemSelectedListener { | ||
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { | ||
when (position) { | ||
0 -> listener.onOverrideSelected(option = null) | ||
else -> listener.onOverrideSelected(feature.options[position - 1]) | ||
} | ||
} | ||
|
||
override fun onNothingSelected(parent: AdapterView<*>?) { | ||
// do nothing | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun interface Listener<T> { | ||
fun onOverrideSelected(option: T?) | ||
} | ||
|
||
data class OverrideDropdown<T : OverrideOption>( | ||
val label: String, | ||
val options: List<T>, | ||
val activeOption: T?, | ||
) | ||
} | ||
|
||
interface OverrideOption { | ||
val label: String | ||
} |
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.features.debug.settings | ||
|
||
sealed interface BooleanHomeserverCapabilitiesOverride : OverrideOption { | ||
|
||
companion object { | ||
fun from(value: Boolean?) = when (value) { | ||
null -> null | ||
true -> ForceEnabled | ||
false -> ForceDisabled | ||
} | ||
} | ||
|
||
object ForceEnabled : BooleanHomeserverCapabilitiesOverride { | ||
override val label = "Force enabled" | ||
} | ||
|
||
object ForceDisabled : BooleanHomeserverCapabilitiesOverride { | ||
override val label = "Force disabled" | ||
} | ||
} | ||
|
||
fun BooleanHomeserverCapabilitiesOverride?.toBoolean() = when (this) { | ||
null -> null | ||
BooleanHomeserverCapabilitiesOverride.ForceDisabled -> false | ||
BooleanHomeserverCapabilitiesOverride.ForceEnabled -> true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<merge xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:parentTag="android.widget.LinearLayout"> | ||
|
||
<TextView | ||
android:id="@+id/overrideLabel" | ||
style="@style/Widget.Vector.TextView.Subtitle" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_marginStart="8dp" | ||
android:layout_weight="1" | ||
android:gravity="center" | ||
android:textColor="?vctr_content_primary" | ||
tools:text="Login version" /> | ||
|
||
<androidx.appcompat.widget.AppCompatSpinner | ||
android:id="@+id/overrideOptions" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_weight="1" /> | ||
|
||
</merge> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,9 +22,16 @@ import kotlinx.coroutines.flow.flowOf | |
interface VectorOverrides { | ||
val forceDialPad: Flow<Boolean> | ||
val forceLoginFallback: Flow<Boolean> | ||
val forceHomeserverCapabilities: Flow<HomeserverCapabilitiesOverride>? | ||
} | ||
|
||
data class HomeserverCapabilitiesOverride( | ||
val canChangeDisplayName: Boolean?, | ||
val canChangeAvatar: Boolean? | ||
) | ||
|
||
class DefaultVectorOverrides : VectorOverrides { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am a little confused about the purpose of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the missing piece of the puzzle here is that the default implementations are injected by the release variant of the app release module whereas the debug module allows for providing the runtime overridable version There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay thanks for explaining. |
||
override val forceDialPad = flowOf(false) | ||
override val forceLoginFallback = flowOf(false) | ||
override val forceHomeserverCapabilities: Flow<HomeserverCapabilitiesOverride>? = null | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have never used
DataStore
API but I see this so much cleaner than theSharedPreferences
API. 😄There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the main "downside" is that the api forces us to use suspend functions or flows (maybe a good thing from a performance standpoint 😄 )