Skip to content

Commit

Permalink
Update labs visibility (#1019)
Browse files Browse the repository at this point in the history
  • Loading branch information
yostyle authored Mar 14, 2024
1 parent e882817 commit c433cfe
Show file tree
Hide file tree
Showing 17 changed files with 51 additions and 18 deletions.
1 change: 1 addition & 0 deletions changelog.d/1019.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update labs visibility.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import androidx.test.platform.app.InstrumentationRegistry
import com.adevinta.android.barista.interaction.BaristaClickInteractions.clickOn
import im.vector.app.R
import im.vector.app.core.resources.BooleanProvider
import im.vector.app.core.resources.DefaultAppNameProvider
import im.vector.app.core.resources.StringArrayProvider
import im.vector.app.espresso.tools.waitUntilViewVisible
import im.vector.app.features.DefaultVectorFeatures
Expand All @@ -33,7 +34,8 @@ class NewRoomRobot(
private val labsPreferences: LabFeaturesPreferences
) {
private val context = InstrumentationRegistry.getInstrumentation().targetContext
private val features: VectorFeatures = DefaultVectorFeatures(StringArrayProvider(context.resources), BooleanProvider(context.resources))
private val features: VectorFeatures =
DefaultVectorFeatures(DefaultAppNameProvider(context), StringArrayProvider(context.resources), BooleanProvider(context.resources))

fun createNewRoom(block: CreateNewRoomRobot.() -> Unit) {
clickOn(R.string.create_new_room)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.adevinta.android.barista.interaction.BaristaClickInteractions.clickOn
import com.adevinta.android.barista.interaction.BaristaEditTextInteractions.writeTo
import im.vector.app.R
import im.vector.app.core.resources.BooleanProvider
import im.vector.app.core.resources.DefaultAppNameProvider
import im.vector.app.core.resources.StringArrayProvider
import im.vector.app.espresso.tools.waitUntilViewVisible
import im.vector.app.features.DefaultVectorFeatures
Expand All @@ -42,7 +43,10 @@ class OnboardingRobot {
// Tchap: Override default feature values for tests
private val context = InstrumentationRegistry.getInstrumentation().targetContext
private val defaultVectorFeatures =
DebugVectorFeatures(context, DefaultVectorFeatures(StringArrayProvider(context.resources), BooleanProvider(context.resources))).apply {
DebugVectorFeatures(
context,
DefaultVectorFeatures(DefaultAppNameProvider(context), StringArrayProvider(context.resources), BooleanProvider(context.resources))
).apply {
override(true, DebugFeatureKeys.tchapIsKeyBackupEnabled)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.adevinta.android.barista.interaction.BaristaDrawerInteractions.openDr
import com.adevinta.android.barista.internal.viewaction.ClickChildAction
import im.vector.app.R
import im.vector.app.core.resources.BooleanProvider
import im.vector.app.core.resources.DefaultAppNameProvider
import im.vector.app.core.resources.StringArrayProvider
import im.vector.app.espresso.tools.waitUntilDialogVisible
import im.vector.app.espresso.tools.waitUntilViewVisible
Expand All @@ -38,7 +39,8 @@ import org.hamcrest.Matchers

class SpaceRobot(private val labsPreferences: LabFeaturesPreferences) {
private val context = InstrumentationRegistry.getInstrumentation().targetContext
private val features: VectorFeatures = DefaultVectorFeatures(StringArrayProvider(context.resources), BooleanProvider(context.resources))
private val features: VectorFeatures =
DefaultVectorFeatures(DefaultAppNameProvider(context), StringArrayProvider(context.resources), BooleanProvider(context.resources))

fun createSpace(isFirstSpace: Boolean, block: SpaceCreateRobot.() -> Unit) {
if (labsPreferences.isNewAppLayoutEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import im.vector.app.core.resources.AppNameProvider
import im.vector.app.core.resources.BooleanProvider
import im.vector.app.core.resources.StringArrayProvider
import im.vector.app.features.DefaultVectorFeatures
Expand All @@ -44,8 +45,8 @@ interface FeaturesModule {
companion object {

@Provides
fun providesDefaultVectorFeatures(stringArrayProvider: StringArrayProvider, booleanProvider: BooleanProvider): DefaultVectorFeatures {
return DefaultVectorFeatures(stringArrayProvider, booleanProvider)
fun providesDefaultVectorFeatures(appNameProvider: AppNameProvider, stringArrayProvider: StringArrayProvider, booleanProvider: BooleanProvider): DefaultVectorFeatures {
return DefaultVectorFeatures(appNameProvider, stringArrayProvider, booleanProvider)
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class DebugVectorFeatures(

override fun tchapIsThreadEnabled() = vectorFeatures.tchapIsThreadEnabled()

override fun tchapIsLabsVisible(domain: String) = vectorFeatures.tchapIsLabsVisible(domain)

override fun onboardingVariant(): OnboardingVariant {
return readPreferences().getEnum<OnboardingVariant>() ?: vectorFeatures.onboardingVariant()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import im.vector.app.core.resources.AppNameProvider
import im.vector.app.core.resources.BooleanProvider
import im.vector.app.core.resources.StringArrayProvider
import im.vector.app.features.DefaultVectorFeatures
Expand All @@ -32,8 +33,8 @@ import im.vector.app.features.VectorOverrides
object FeaturesModule {

@Provides
fun providesFeatures(stringArrayProvider: StringArrayProvider, booleanProvider: BooleanProvider): VectorFeatures {
return DefaultVectorFeatures(stringArrayProvider, booleanProvider)
fun providesFeatures(appNameProvider: AppNameProvider, stringArrayProvider: StringArrayProvider, booleanProvider: BooleanProvider): VectorFeatures {
return DefaultVectorFeatures(appNameProvider, stringArrayProvider, booleanProvider)
}

@Provides
Expand Down
3 changes: 2 additions & 1 deletion vector-config/src/btchap/res/values/config-settings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="tchap_settings_root_labs_visible">true</bool>
<!-- Level 0: Root -->
<bool name="settings_root_labs_visible">true</bool>
</resources>
3 changes: 3 additions & 0 deletions vector-config/src/debug/res/values/config-settings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<!-- Level 0: Root -->
<bool name="settings_root_labs_visible">true</bool>

<!-- Level 1: Advanced settings -->
<bool name="tchap_settings_advanced_developer_mode_visible">true</bool> <!-- Tchap: Show developer mode in debug -->

Expand Down
3 changes: 2 additions & 1 deletion vector-config/src/devTchap/res/values/config-settings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="tchap_settings_root_labs_visible">true</bool>
<!-- Level 0: Root -->
<bool name="settings_root_labs_visible">true</bool>
</resources>
3 changes: 1 addition & 2 deletions vector-config/src/main/res/values/config-settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
<!-- <bool name="settings_root_voice_video_visible">true</bool>-->

<bool name="settings_root_security_privacy_visible">true</bool>
<!-- Tchap: use gradle config -->
<!-- <bool name="settings_root_labs_visible">true</bool>-->
<bool name="settings_root_labs_visible">false</bool>
<bool name="settings_root_advanced_visible">true</bool>
<bool name="settings_root_help_about_visible">true</bool>
<bool name="settings_root_legals_visible">true</bool>
Expand Down
4 changes: 0 additions & 4 deletions vector-config/src/tchap/res/values/config-settings.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import android.os.Build
import androidx.test.platform.app.InstrumentationRegistry
import im.vector.app.TestBuildVersionSdkIntProvider
import im.vector.app.core.resources.BooleanProvider
import im.vector.app.core.resources.DefaultAppNameProvider
import im.vector.app.core.resources.StringArrayProvider
import im.vector.app.features.DefaultVectorFeatures
import io.mockk.every
Expand All @@ -34,7 +35,7 @@ class VoiceRecorderProviderTests {
private val provider = spyk(
VoiceRecorderProvider(
context,
DefaultVectorFeatures(StringArrayProvider(context.resources), BooleanProvider(context.resources)),
DefaultVectorFeatures(DefaultAppNameProvider(context), StringArrayProvider(context.resources), BooleanProvider(context.resources)),
buildVersionSdkIntProvider
)
)
Expand Down
5 changes: 5 additions & 0 deletions vector/src/main/java/im/vector/app/features/VectorFeatures.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package im.vector.app.features
import im.vector.app.R
import im.vector.app.config.Config
import im.vector.app.config.OnboardingVariant
import im.vector.app.core.resources.AppNameProvider
import im.vector.app.core.resources.BooleanProvider
import im.vector.app.core.resources.StringArrayProvider
import im.vector.app.features.settings.VectorPreferences
Expand All @@ -30,6 +31,7 @@ interface VectorFeatures {
fun tchapIsCrossSigningEnabled(): Boolean
fun tchapIsKeyBackupEnabled(): Boolean
fun tchapIsThreadEnabled(): Boolean
fun tchapIsLabsVisible(domain: String): Boolean
fun onboardingVariant(): OnboardingVariant
fun isOnboardingAlreadyHaveAccountSplashEnabled(): Boolean
fun isOnboardingSplashCarouselEnabled(): Boolean
Expand All @@ -56,6 +58,7 @@ interface VectorFeatures {
}

class DefaultVectorFeatures @Inject constructor(
private val appNameProvider: AppNameProvider,
private val stringArrayProvider: StringArrayProvider,
private val booleanProvider: BooleanProvider
) : VectorFeatures {
Expand All @@ -66,6 +69,8 @@ class DefaultVectorFeatures @Inject constructor(
override fun tchapIsCrossSigningEnabled() = booleanProvider.getBoolean(R.bool.tchap_is_cross_signing_enabled)
override fun tchapIsKeyBackupEnabled() = booleanProvider.getBoolean(R.bool.tchap_is_key_backup_enabled)
override fun tchapIsThreadEnabled() = booleanProvider.getBoolean(R.bool.tchap_is_thread_enabled)
override fun tchapIsLabsVisible(domain: String) = booleanProvider.getBoolean(R.bool.settings_root_labs_visible) ||
domain == appNameProvider.getAppName()
override fun onboardingVariant() = Config.ONBOARDING_VARIANT
override fun isOnboardingAlreadyHaveAccountSplashEnabled() = true
override fun isOnboardingSplashCarouselEnabled() = false // Tchap: no carousel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,24 @@ package im.vector.app.features.settings
import android.os.Bundle
import androidx.preference.Preference
import dagger.hilt.android.AndroidEntryPoint
import fr.gouv.tchap.core.utils.TchapUtils
import im.vector.app.R
import im.vector.app.core.preference.VectorPreference
import im.vector.app.core.utils.FirstThrottler
import im.vector.app.core.utils.openUrlInChromeCustomTab
import im.vector.app.features.VectorFeatures
import im.vector.app.features.analytics.plan.MobileScreen
import im.vector.app.features.displayname.getBestName
import org.matrix.android.sdk.api.session.getUserOrDefault
import org.matrix.android.sdk.api.util.toMatrixItem
import javax.inject.Inject

@AndroidEntryPoint
class VectorSettingsRootFragment :
VectorSettingsBaseFragment() {

@Inject lateinit var vectorFeatures: VectorFeatures

override var titleRes: Int = R.string.title_activity_settings
override val preferenceXmlRes = R.xml.vector_settings_root

Expand All @@ -50,6 +58,11 @@ class VectorSettingsRootFragment :
}
false
}

// Tchap: Manage labs entry.
val myUserDisplayName = session.getUserOrDefault(session.myUserId).toMatrixItem().getBestName()
findPreference<VectorPreference>(VectorPreferences.SETTINGS_LABS_PREFERENCE_KEY)!!
.isVisible = vectorFeatures.tchapIsLabsVisible(TchapUtils.getDomainFromDisplayName(myUserDisplayName))
}

private fun tintIcons() {
Expand Down
3 changes: 2 additions & 1 deletion vector/src/main/res/xml/vector_settings_root.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@

<im.vector.app.core.preference.VectorPreference
android:icon="@drawable/ic_settings_root_labs"
android:key="SETTINGS_LABS_PREFERENCE_KEY"
android:title="@string/room_settings_labs_pref_title"
app:fragment="im.vector.app.features.settings.labs.VectorSettingsLabsFragment"
app:isPreferenceVisible="@bool/tchap_settings_root_labs_visible" />
app:isPreferenceVisible="@bool/settings_root_labs_visible" />

<im.vector.app.core.preference.VectorPreference
android:icon="@drawable/ic_settings_root_advanced"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import io.mockk.every
import io.mockk.mockk
import io.mockk.spyk

class FakeVectorFeatures : VectorFeatures by spyk(DefaultVectorFeatures(mockk(), mockk())) {
class FakeVectorFeatures : VectorFeatures by spyk(DefaultVectorFeatures(mockk(), mockk(), mockk())) {

fun givenPersonalisationEnabled() {
every { isOnboardingPersonalizeEnabled() } returns true
Expand Down

0 comments on commit c433cfe

Please sign in to comment.