mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
Deleting/Updating the client Info when changing the lab flag
This commit is contained in:
parent
89e14c915d
commit
f753e475d8
@ -100,6 +100,7 @@ import im.vector.app.features.settings.devtools.KeyRequestViewModel
|
||||
import im.vector.app.features.settings.font.FontScaleSettingViewModel
|
||||
import im.vector.app.features.settings.homeserver.HomeserverSettingsViewModel
|
||||
import im.vector.app.features.settings.ignored.IgnoredUsersViewModel
|
||||
import im.vector.app.features.settings.labs.VectorSettingsLabsViewModel
|
||||
import im.vector.app.features.settings.legals.LegalsViewModel
|
||||
import im.vector.app.features.settings.locale.LocalePickerViewModel
|
||||
import im.vector.app.features.settings.push.PushGatewaysViewModel
|
||||
@ -665,4 +666,9 @@ interface MavericksViewModelModule {
|
||||
@IntoMap
|
||||
@MavericksViewModelKey(SessionLearnMoreViewModel::class)
|
||||
fun sessionLearnMoreViewModelFactory(factory: SessionLearnMoreViewModel.Factory): MavericksAssistedViewModelFactory<*, *>
|
||||
|
||||
@Binds
|
||||
@IntoMap
|
||||
@MavericksViewModelKey(VectorSettingsLabsViewModel::class)
|
||||
fun vectorSettingsLabsViewModelFactory(factory: VectorSettingsLabsViewModel.Factory): MavericksAssistedViewModelFactory<*, *>
|
||||
}
|
||||
|
@ -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.core.session.clientinfo
|
||||
|
||||
import im.vector.app.core.di.ActiveSessionHolder
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* This use case delete the account data event containing extended client info.
|
||||
*/
|
||||
class DeleteMatrixClientInfoUseCase @Inject constructor(
|
||||
private val activeSessionHolder: ActiveSessionHolder,
|
||||
private val setMatrixClientInfoUseCase: SetMatrixClientInfoUseCase,
|
||||
) {
|
||||
|
||||
// TODO add unit tests
|
||||
suspend fun execute(): Result<Unit> = runCatching {
|
||||
Timber.d("deleting recorded client info")
|
||||
val session = activeSessionHolder.getActiveSession()
|
||||
val emptyClientInfo = MatrixClientInfoContent(
|
||||
name = "",
|
||||
version = "",
|
||||
url = "",
|
||||
)
|
||||
setMatrixClientInfoUseCase.execute(session, emptyClientInfo)
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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.settings.labs
|
||||
|
||||
import im.vector.app.core.platform.VectorViewModelAction
|
||||
|
||||
sealed class VectorSettingsLabsAction : VectorViewModelAction {
|
||||
object UpdateClientInfo : VectorSettingsLabsAction()
|
||||
object DeleteRecordedClientInfo : VectorSettingsLabsAction()
|
||||
}
|
@ -20,7 +20,9 @@ import android.os.Bundle
|
||||
import android.text.method.LinkMovementMethod
|
||||
import android.widget.TextView
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.Preference.OnPreferenceChangeListener
|
||||
import androidx.preference.SwitchPreference
|
||||
import com.airbnb.mvrx.fragmentViewModel
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import im.vector.app.R
|
||||
@ -39,6 +41,8 @@ import javax.inject.Inject
|
||||
class VectorSettingsLabsFragment :
|
||||
VectorSettingsBaseFragment() {
|
||||
|
||||
private val viewModel: VectorSettingsLabsViewModel by fragmentViewModel()
|
||||
|
||||
@Inject lateinit var vectorPreferences: VectorPreferences
|
||||
@Inject lateinit var lightweightSettingsStorage: LightweightSettingsStorage
|
||||
@Inject lateinit var threadsManager: ThreadsManager
|
||||
@ -87,6 +91,7 @@ class VectorSettingsLabsFragment :
|
||||
}
|
||||
|
||||
configureUnreadNotificationsAsTabPreference()
|
||||
configureEnableClientInfoRecordingPreference()
|
||||
}
|
||||
|
||||
private fun configureUnreadNotificationsAsTabPreference() {
|
||||
@ -142,4 +147,16 @@ class VectorSettingsLabsFragment :
|
||||
private fun onNewLayoutPreferenceClicked() {
|
||||
configureUnreadNotificationsAsTabPreference()
|
||||
}
|
||||
|
||||
private fun configureEnableClientInfoRecordingPreference() {
|
||||
findPreference<VectorSwitchPreference>(VectorPreferences.SETTINGS_LABS_CLIENT_INFO_RECORDING_KEY)?.onPreferenceChangeListener =
|
||||
OnPreferenceChangeListener { _, newValue ->
|
||||
when {
|
||||
(newValue as? Boolean) == false -> viewModel.handle(VectorSettingsLabsAction.DeleteRecordedClientInfo)
|
||||
(newValue as? Boolean) == true -> viewModel.handle(VectorSettingsLabsAction.UpdateClientInfo)
|
||||
else -> Unit
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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.settings.labs
|
||||
|
||||
import com.airbnb.mvrx.MavericksViewModelFactory
|
||||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedFactory
|
||||
import dagger.assisted.AssistedInject
|
||||
import im.vector.app.core.di.ActiveSessionHolder
|
||||
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.core.session.clientinfo.DeleteMatrixClientInfoUseCase
|
||||
import im.vector.app.core.session.clientinfo.UpdateMatrixClientInfoUseCase
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class VectorSettingsLabsViewModel @AssistedInject constructor(
|
||||
@Assisted initialState: VectorSettingsLabsViewState,
|
||||
private val activeSessionHolder: ActiveSessionHolder,
|
||||
private val updateMatrixClientInfoUseCase: UpdateMatrixClientInfoUseCase,
|
||||
private val deleteMatrixClientInfoUseCase: DeleteMatrixClientInfoUseCase,
|
||||
) : VectorViewModel<VectorSettingsLabsViewState, VectorSettingsLabsAction, EmptyViewEvents>(initialState) {
|
||||
|
||||
@AssistedFactory
|
||||
interface Factory : MavericksAssistedViewModelFactory<VectorSettingsLabsViewModel, VectorSettingsLabsViewState> {
|
||||
override fun create(initialState: VectorSettingsLabsViewState): VectorSettingsLabsViewModel
|
||||
}
|
||||
|
||||
companion object : MavericksViewModelFactory<VectorSettingsLabsViewModel, VectorSettingsLabsViewState> by hiltMavericksViewModelFactory()
|
||||
|
||||
// TODO add unit tests
|
||||
override fun handle(action: VectorSettingsLabsAction) {
|
||||
when (action) {
|
||||
VectorSettingsLabsAction.UpdateClientInfo -> handleUpdateClientInfo()
|
||||
VectorSettingsLabsAction.DeleteRecordedClientInfo -> handleDeleteRecordedClientInfo()
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleUpdateClientInfo() {
|
||||
viewModelScope.launch {
|
||||
activeSessionHolder.getSafeActiveSession()
|
||||
?.let { session ->
|
||||
updateMatrixClientInfoUseCase.execute(session)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleDeleteRecordedClientInfo() {
|
||||
viewModelScope.launch {
|
||||
deleteMatrixClientInfoUseCase.execute()
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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.settings.labs
|
||||
|
||||
import com.airbnb.mvrx.MavericksState
|
||||
|
||||
class VectorSettingsLabsViewState : MavericksState
|
Loading…
Reference in New Issue
Block a user