From 2c6993af44b08df76b0d461ec083a9bb397f2431 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 22 Nov 2021 10:37:04 +0100 Subject: [PATCH 01/10] Add missing changelog for #4526 --- changelog.d/4520.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/4520.bugfix diff --git a/changelog.d/4520.bugfix b/changelog.d/4520.bugfix new file mode 100644 index 0000000000..58314025f1 --- /dev/null +++ b/changelog.d/4520.bugfix @@ -0,0 +1 @@ +Fix a crash when displaying the bootstrap bottom sheet \ No newline at end of file From e520a374e4c39b3624190ad815a19e82db5cf57b Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 22 Nov 2021 10:45:45 +0100 Subject: [PATCH 02/10] Format code --- .../app/features/home/HomeDetailViewModel.kt | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/HomeDetailViewModel.kt b/vector/src/main/java/im/vector/app/features/home/HomeDetailViewModel.kt index 1c1d012cc8..af7eea205f 100644 --- a/vector/src/main/java/im/vector/app/features/home/HomeDetailViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/HomeDetailViewModel.kt @@ -60,15 +60,16 @@ import timber.log.Timber * View model used to update the home bottom bar notification counts, observe the sync state and * change the selected room list view */ -class HomeDetailViewModel @AssistedInject constructor(@Assisted initialState: HomeDetailViewState, - private val session: Session, - private val uiStateRepository: UiStateRepository, - private val vectorDataStore: VectorDataStore, - private val callManager: WebRtcCallManager, - private val directRoomHelper: DirectRoomHelper, - private val appStateHandler: AppStateHandler, - private val autoAcceptInvites: AutoAcceptInvites) : - VectorViewModel(initialState), +class HomeDetailViewModel @AssistedInject constructor( + @Assisted initialState: HomeDetailViewState, + private val session: Session, + private val uiStateRepository: UiStateRepository, + private val vectorDataStore: VectorDataStore, + private val callManager: WebRtcCallManager, + private val directRoomHelper: DirectRoomHelper, + private val appStateHandler: AppStateHandler, + private val autoAcceptInvites: AutoAcceptInvites +) : VectorViewModel(initialState), CallProtocolsChecker.Listener { @AssistedFactory From 2586b376f5b0a4248ef12774f49eb091c88f00f0 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 22 Nov 2021 11:36:18 +0100 Subject: [PATCH 03/10] Add a debug screen to display private settings, and use it to force display of Dialpad Tab --- vector/src/debug/AndroidManifest.xml | 1 + .../app/features/debug/DebugMenuActivity.kt | 6 ++ .../settings/DebugPrivateSettingsActivity.kt | 41 +++++++++++ .../DebugPrivateSettingsViewActions.kt | 23 +++++++ .../settings/DebugPrivateSettingsViewModel.kt | 68 +++++++++++++++++++ .../settings/DebugPrivateSettingsViewState.kt | 23 +++++++ .../debug/res/layout/activity_debug_menu.xml | 6 ++ .../activity_debug_private_settings.xml | 32 +++++++++ .../app/features/home/HomeDetailViewModel.kt | 8 ++- .../app/features/settings/VectorDataStore.kt | 15 ++++ 10 files changed, 222 insertions(+), 1 deletion(-) create mode 100644 vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsActivity.kt create mode 100644 vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsViewActions.kt create mode 100644 vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsViewModel.kt create mode 100644 vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsViewState.kt create mode 100644 vector/src/debug/res/layout/activity_debug_private_settings.xml diff --git a/vector/src/debug/AndroidManifest.xml b/vector/src/debug/AndroidManifest.xml index 8ffcec6bc1..dba8440602 100644 --- a/vector/src/debug/AndroidManifest.xml +++ b/vector/src/debug/AndroidManifest.xml @@ -5,6 +5,7 @@ + diff --git a/vector/src/debug/java/im/vector/app/features/debug/DebugMenuActivity.kt b/vector/src/debug/java/im/vector/app/features/debug/DebugMenuActivity.kt index 960994b169..64de648a23 100644 --- a/vector/src/debug/java/im/vector/app/features/debug/DebugMenuActivity.kt +++ b/vector/src/debug/java/im/vector/app/features/debug/DebugMenuActivity.kt @@ -35,6 +35,7 @@ import im.vector.app.core.utils.registerForPermissionsResult import im.vector.app.core.utils.toast import im.vector.app.databinding.ActivityDebugMenuBinding import im.vector.app.features.debug.sas.DebugSasEmojiActivity +import im.vector.app.features.debug.settings.DebugPrivateSettingsActivity import im.vector.app.features.qrcode.QrCodeScannerActivity import im.vector.lib.ui.styles.debug.DebugMaterialThemeDarkDefaultActivity import im.vector.lib.ui.styles.debug.DebugMaterialThemeDarkTestActivity @@ -75,6 +76,7 @@ class DebugMenuActivity : VectorBaseActivity() { } private fun setupViews() { + views.debugPrivateSetting.setOnClickListener { openPrivateSettings() } views.debugTestTextViewLink.setOnClickListener { testTextViewLink() } views.debugOpenButtonStylesLight.setOnClickListener { startActivity(Intent(this, DebugVectorButtonStylesLightActivity::class.java)) @@ -115,6 +117,10 @@ class DebugMenuActivity : VectorBaseActivity() { } } + private fun openPrivateSettings() { + startActivity(Intent(this, DebugPrivateSettingsActivity::class.java)) + } + private fun renderQrCode(text: String) { views.debugQrCode.setData(text) } diff --git a/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsActivity.kt b/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsActivity.kt new file mode 100644 index 0000000000..ad2ac70646 --- /dev/null +++ b/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsActivity.kt @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2021 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 com.airbnb.mvrx.viewModel +import com.airbnb.mvrx.withState +import dagger.hilt.android.AndroidEntryPoint +import im.vector.app.core.platform.VectorBaseActivity +import im.vector.app.databinding.ActivityDebugPrivateSettingsBinding + +@AndroidEntryPoint +class DebugPrivateSettingsActivity : VectorBaseActivity() { + + private val viewModel: DebugPrivateSettingsViewModel by viewModel() + + override fun getBinding() = ActivityDebugPrivateSettingsBinding.inflate(layoutInflater) + + override fun initUiAndData() { + views.forceDialPadTabDisplay.setOnCheckedChangeListener { _, isChecked -> + viewModel.handle(DebugPrivateSettingsViewActions.SetDialPadVisibility(isChecked)) + } + } + + override fun invalidate() = withState(viewModel) { + views.forceDialPadTabDisplay.isChecked = it.dialPadVisible + } +} diff --git a/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsViewActions.kt b/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsViewActions.kt new file mode 100644 index 0000000000..ecbb241387 --- /dev/null +++ b/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsViewActions.kt @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2021 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 im.vector.app.core.platform.VectorViewModelAction + +sealed class DebugPrivateSettingsViewActions : VectorViewModelAction { + data class SetDialPadVisibility(val force: Boolean) : DebugPrivateSettingsViewActions() +} diff --git a/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsViewModel.kt b/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsViewModel.kt new file mode 100644 index 0000000000..f4ff4da163 --- /dev/null +++ b/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsViewModel.kt @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2021 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 com.airbnb.mvrx.MavericksViewModelFactory +import dagger.assisted.Assisted +import dagger.assisted.AssistedFactory +import dagger.assisted.AssistedInject +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 kotlinx.coroutines.flow.onEach +import kotlinx.coroutines.launch + +class DebugPrivateSettingsViewModel @AssistedInject constructor( + @Assisted initialState: DebugPrivateSettingsViewState, + private val vectorDataStore: VectorDataStore +) : VectorViewModel(initialState) { + + @AssistedFactory + interface Factory : MavericksAssistedViewModelFactory { + override fun create(initialState: DebugPrivateSettingsViewState): DebugPrivateSettingsViewModel + } + + companion object : MavericksViewModelFactory by hiltMavericksViewModelFactory() + + init { + observeVectorDataStore() + } + + private fun observeVectorDataStore() { + vectorDataStore.forceDialPadDisplayFlow.onEach { + setState { + copy( + dialPadVisible = it + ) + } + } + } + + override fun handle(action: DebugPrivateSettingsViewActions) { + when (action) { + is DebugPrivateSettingsViewActions.SetDialPadVisibility -> handleSetDialPadVisibility(action) + } + } + + private fun handleSetDialPadVisibility(action: DebugPrivateSettingsViewActions.SetDialPadVisibility) { + viewModelScope.launch { + vectorDataStore.setForceDialPadDisplay(action.force) + } + } +} diff --git a/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsViewState.kt b/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsViewState.kt new file mode 100644 index 0000000000..0ad4b185ec --- /dev/null +++ b/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsViewState.kt @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2021 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 com.airbnb.mvrx.MavericksState + +data class DebugPrivateSettingsViewState( + val dialPadVisible: Boolean = false +) : MavericksState diff --git a/vector/src/debug/res/layout/activity_debug_menu.xml b/vector/src/debug/res/layout/activity_debug_menu.xml index fadffecf83..ac70e4ef0e 100644 --- a/vector/src/debug/res/layout/activity_debug_menu.xml +++ b/vector/src/debug/res/layout/activity_debug_menu.xml @@ -20,6 +20,12 @@ android:padding="@dimen/layout_horizontal_margin" android:showDividers="middle"> +