-
Notifications
You must be signed in to change notification settings - Fork 781
Lifting debug overrides to their own abstraction #5361
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
Changes from all commits
d600597
f6735b6
ce719b3
7637ee4
350aceb
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 @@ | ||
Creates dedicated VectorOverrides for forcing behaviour for local testing/development |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* 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.features | ||
|
||
import android.content.Context | ||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.core.booleanPreferencesKey | ||
import androidx.datastore.preferences.core.edit | ||
import androidx.datastore.preferences.preferencesDataStore | ||
import im.vector.app.features.VectorOverrides | ||
import kotlinx.coroutines.flow.map | ||
import org.matrix.android.sdk.api.extensions.orFalse | ||
|
||
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "vector_overrides") | ||
private val keyForceDialPadDisplay = booleanPreferencesKey("force_dial_pad_display") | ||
private val keyForceLoginFallback = booleanPreferencesKey("force_login_fallback") | ||
|
||
class DebugVectorOverrides(private val context: Context) : VectorOverrides { | ||
|
||
override val forceDialPad = context.dataStore.data.map { preferences -> | ||
preferences[keyForceDialPadDisplay].orFalse() | ||
} | ||
|
||
override val forceLoginFallback = context.dataStore.data.map { preferences -> | ||
preferences[keyForceLoginFallback].orFalse() | ||
} | ||
|
||
suspend fun setForceDialPadDisplay(force: Boolean) { | ||
context.dataStore.edit { settings -> | ||
settings[keyForceDialPadDisplay] = force | ||
} | ||
} | ||
|
||
suspend fun setForceLoginFallback(force: Boolean) { | ||
context.dataStore.edit { settings -> | ||
settings[keyForceLoginFallback] = force | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,12 +24,12 @@ import im.vector.app.core.di.MavericksAssistedViewModelFactory | |
import im.vector.app.core.di.hiltMavericksViewModelFactory | ||
import im.vector.app.core.platform.EmptyViewEvents | ||
import im.vector.app.core.platform.VectorViewModel | ||
import im.vector.app.features.settings.VectorDataStore | ||
import im.vector.app.features.debug.features.DebugVectorOverrides | ||
import kotlinx.coroutines.launch | ||
|
||
class DebugPrivateSettingsViewModel @AssistedInject constructor( | ||
@Assisted initialState: DebugPrivateSettingsViewState, | ||
private val vectorDataStore: VectorDataStore | ||
private val debugVectorOverrides: DebugVectorOverrides | ||
) : VectorViewModel<DebugPrivateSettingsViewState, DebugPrivateSettingsViewActions, EmptyViewEvents>(initialState) { | ||
|
||
@AssistedFactory | ||
|
@@ -44,11 +44,12 @@ class DebugPrivateSettingsViewModel @AssistedInject constructor( | |
} | ||
|
||
private fun observeVectorDataStore() { | ||
vectorDataStore.forceDialPadDisplayFlow.setOnEach { | ||
copy(dialPadVisible = it) | ||
debugVectorOverrides.forceDialPad.setOnEach { | ||
copy( | ||
dialPadVisible = it | ||
) | ||
Comment on lines
+48
to
+50
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. Not something to action as this is more of a personal preference thing but I never understood opting for this format rather than a single line 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. Yes, when there is only one line it's OK. I think, it's for future hypothetical code to split into 3 lines, so if for instance in the future we have: copy(
dialPadVisible = it,
other = blah
) But this is definitely not a strong constraint. 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 don't have any strong feelings for either, I chose to stick with the consistency of the file, happy to change! |
||
} | ||
|
||
vectorDataStore.forceLoginFallbackFlow.setOnEach { | ||
debugVectorOverrides.forceLoginFallback.setOnEach { | ||
copy(forceLoginFallback = it) | ||
} | ||
} | ||
|
@@ -62,13 +63,13 @@ class DebugPrivateSettingsViewModel @AssistedInject constructor( | |
|
||
private fun handleSetDialPadVisibility(action: DebugPrivateSettingsViewActions.SetDialPadVisibility) { | ||
viewModelScope.launch { | ||
vectorDataStore.setForceDialPadDisplay(action.force) | ||
debugVectorOverrides.setForceDialPadDisplay(action.force) | ||
} | ||
} | ||
|
||
private fun handleSetForceLoginFallbackEnabled(action: DebugPrivateSettingsViewActions.SetForceLoginFallbackEnabled) { | ||
viewModelScope.launch { | ||
vectorDataStore.setForceLoginFallbackFlow(action.force) | ||
debugVectorOverrides.setForceLoginFallback(action.force) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* 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 | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flowOf | ||
|
||
interface VectorOverrides { | ||
val forceDialPad: Flow<Boolean> | ||
val forceLoginFallback: Flow<Boolean> | ||
} | ||
|
||
class DefaultVectorOverrides : VectorOverrides { | ||
override val forceDialPad = flowOf(false) | ||
override val forceLoginFallback = flowOf(false) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,9 @@ import dagger.Provides | |
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import im.vector.app.features.DefaultVectorFeatures | ||
import im.vector.app.features.DefaultVectorOverrides | ||
import im.vector.app.features.VectorFeatures | ||
import im.vector.app.features.VectorOverrides | ||
|
||
@InstallIn(SingletonComponent::class) | ||
@Module | ||
|
@@ -31,4 +33,9 @@ object FeaturesModule { | |
fun providesFeatures(): VectorFeatures { | ||
return DefaultVectorFeatures() | ||
} | ||
|
||
@Provides | ||
fun providesOverrides(): VectorOverrides { | ||
return DefaultVectorOverrides() | ||
} | ||
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. Same with the above DI comment. Unfortunately I can't run builds on my machine so I can't confirm this myself but it's worth taking a look imo |
||
} |
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.
Optional: We can remove this entire companion inject if we add
@Inject constructor
on each of thse classesIt would be nice cleanup that falls well into the scope of this task, but consider it optional though, since I can see we already had this pattern in place
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.
It's maybe because of
@InstallIn(SingletonComponent::class)
anotation of the interfaceFeaturesModule
but I am not a big specialist of the DI.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.
there's two parts to this
VectorFeatures
*Both debug and release need to provide the interface VectorFeatures
hopefully that makes sense (and wasn't me rambling 😅 )
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 see, this does shine some light on it, thanks!