From fe800a56e21ba7330af86ada7669188fae239957 Mon Sep 17 00:00:00 2001 From: David Langley Date: Tue, 24 Aug 2021 12:12:39 +0100 Subject: [PATCH] Address comments. --- .../roomprofile/RoomProfileActivity.kt | 4 +-- .../roomprofile/RoomProfileFragment.kt | 2 +- .../roomprofile/RoomProfileSharedAction.kt | 2 +- .../RoomNotificationSettingsController.kt | 2 +- .../RoomNotificationSettingsFragment.kt | 11 ++++++- .../RoomNotificationSettingsViewModel.kt | 24 +++++++------- .../RoomNotificationSettingsViewState.kt | 10 ++---- .../res/layout/item_notifications_footer.xml | 30 ++++++------------ .../src/main/res/layout/item_text_header.xml | 31 ++++++------------- 9 files changed, 49 insertions(+), 67 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileActivity.kt b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileActivity.kt index d8e080f6a4..d28878283f 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileActivity.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileActivity.kt @@ -113,8 +113,8 @@ class RoomProfileActivity : RoomProfileSharedAction.OpenRoomAliasesSettings -> openRoomAlias() RoomProfileSharedAction.OpenRoomPermissionsSettings -> openRoomPermissions() RoomProfileSharedAction.OpenRoomUploads -> openRoomUploads() - RoomProfileSharedAction.OpenBannedRoomMembers -> openBannedRoomMembers() - RoomProfileSharedAction.OpenRoomNotificaitonSettings -> openRoomNotificationSettings() + RoomProfileSharedAction.OpenBannedRoomMembers -> openBannedRoomMembers() + RoomProfileSharedAction.OpenRoomNotificationSettings -> openRoomNotificationSettings() }.exhaustive } .disposeOnDestroy() diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileFragment.kt b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileFragment.kt index ea5bbd2e84..4b37d038b5 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileFragment.kt @@ -255,7 +255,7 @@ class RoomProfileFragment @Inject constructor( override fun onNotificationsClicked() { if (BuildConfig.USE_NOTIFICATION_SETTINGS_V2) { - roomProfileSharedActionViewModel.post(RoomProfileSharedAction.OpenRoomNotificaitonSettings) + roomProfileSharedActionViewModel.post(RoomProfileSharedAction.OpenRoomNotificationSettings) } else { RoomListQuickActionsBottomSheet .newInstance(roomProfileArgs.roomId, RoomListActionsArgs.Mode.NOTIFICATIONS) diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileSharedAction.kt b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileSharedAction.kt index 6a9533a2eb..eb4ab56634 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileSharedAction.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileSharedAction.kt @@ -28,5 +28,5 @@ sealed class RoomProfileSharedAction : VectorSharedAction { object OpenRoomUploads : RoomProfileSharedAction() object OpenRoomMembers : RoomProfileSharedAction() object OpenBannedRoomMembers : RoomProfileSharedAction() - object OpenRoomNotificaitonSettings : RoomProfileSharedAction() + object OpenRoomNotificationSettings : RoomProfileSharedAction() } diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/notifications/RoomNotificationSettingsController.kt b/vector/src/main/java/im/vector/app/features/roomprofile/notifications/RoomNotificationSettingsController.kt index 654400e790..9a2085a7e8 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/notifications/RoomNotificationSettingsController.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/notifications/RoomNotificationSettingsController.kt @@ -59,7 +59,7 @@ class RoomNotificationSettingsController @Inject constructor() : TypedEpoxyContr } notificationSettingsFooterItem { id("roomNotificationSettingsFooter") - encrypted(data.roomEncrypted) + encrypted(data.roomSummary()?.isEncrypted == true) clickListener { host.callback?.didSelectAccountSettingsLink() } diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/notifications/RoomNotificationSettingsFragment.kt b/vector/src/main/java/im/vector/app/features/roomprofile/notifications/RoomNotificationSettingsFragment.kt index 8baef5d10c..ce0fde32c6 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/notifications/RoomNotificationSettingsFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/notifications/RoomNotificationSettingsFragment.kt @@ -24,10 +24,12 @@ import androidx.core.view.isVisible import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.withState import im.vector.app.R +import im.vector.app.core.extensions.cleanup import im.vector.app.core.extensions.configureWith import im.vector.app.core.platform.VectorBaseFragment import im.vector.app.databinding.FragmentRoomSettingGenericBinding import im.vector.app.features.home.AvatarRenderer +import im.vector.app.features.settings.VectorSettingsActivity import org.matrix.android.sdk.api.session.room.notification.RoomNotificationState import org.matrix.android.sdk.api.util.toMatrixItem import javax.inject.Inject @@ -53,6 +55,13 @@ class RoomNotificationSettingsFragment @Inject constructor( setupWaitingView() observeViewEvents() } + + override fun onDestroyView() { + views.roomSettingsRecyclerView.cleanup() + roomNotificationSettingsController.callback = null + super.onDestroyView() + } + private fun setupWaitingView() { views.waitingView.waitingStatusText.setText(R.string.please_wait) views.waitingView.waitingStatusText.isVisible = true @@ -77,7 +86,7 @@ class RoomNotificationSettingsFragment @Inject constructor( } override fun didSelectAccountSettingsLink() { - navigator.openSettings(requireContext()) + navigator.openSettings(requireContext(), VectorSettingsActivity.EXTRA_DIRECT_ACCESS_NOTIFICATIONS) } private fun renderRoomSummary(state: RoomNotificationSettingsViewState) { diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/notifications/RoomNotificationSettingsViewModel.kt b/vector/src/main/java/im/vector/app/features/roomprofile/notifications/RoomNotificationSettingsViewModel.kt index 5d23931d88..dd0535f51b 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/notifications/RoomNotificationSettingsViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/notifications/RoomNotificationSettingsViewModel.kt @@ -59,17 +59,10 @@ class RoomNotificationSettingsViewModel @AssistedInject constructor( private val room = session.getRoom(initialState.roomId)!! init { - initEncrypted() observeSummary() observeNotificationState() } - private fun initEncrypted() { - setState { - copy(roomEncrypted = room.isEncrypted()) - } - } - private fun observeSummary() { room.rx().liveRoomSummary() .unwrap() @@ -96,10 +89,19 @@ class RoomNotificationSettingsViewModel @AssistedInject constructor( setState { copy(isLoading = true) } viewModelScope.launch { runCatching { room.setRoomNotificationState(action.notificationState) } - .onFailure { _viewEvents.post(RoomNotificationSettingsViewEvents.Failure(it)) } - setState { - copy(isLoading = false, notificationState = Success(action.notificationState)) - } + .fold( + { + setState { + copy(isLoading = false, notificationState = Success(action.notificationState)) + } + }, + { + setState { + copy(isLoading = false) + } + _viewEvents.post(RoomNotificationSettingsViewEvents.Failure(it)) + } + ) } } } diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/notifications/RoomNotificationSettingsViewState.kt b/vector/src/main/java/im/vector/app/features/roomprofile/notifications/RoomNotificationSettingsViewState.kt index 30fde5ddea..54e2ef9550 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/notifications/RoomNotificationSettingsViewState.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/notifications/RoomNotificationSettingsViewState.kt @@ -29,24 +29,18 @@ data class RoomNotificationSettingsViewState( val roomId: String, val roomSummary: Async = Uninitialized, val isLoading: Boolean = false, - val roomEncrypted: Boolean = false, val notificationState: Async = Uninitialized ) : MvRxState { constructor(args: RoomProfileArgs) : this(roomId = args.roomId) constructor(args: RoomListActionsArgs) : this(roomId = args.roomId) } -data class AvatarData( - val displayName: String, - val avatarUrl: String -) - /** * Used to map this old room notification settings to the new options in v2. */ val RoomNotificationSettingsViewState.notificationStateMapped: Async get() { - if ((roomEncrypted && notificationState() == RoomNotificationState.MENTIONS_ONLY) || notificationState() == RoomNotificationState.ALL_MESSAGES) { + if ((roomSummary()?.isEncrypted == true && notificationState() == RoomNotificationState.MENTIONS_ONLY) || notificationState() == RoomNotificationState.ALL_MESSAGES) { /** if in an encrypted room, mentions notifications are not supported so show "All Messages" as selected. * Also in the new settings there is no notion of notifications without sound so it maps to noisy also */ @@ -59,7 +53,7 @@ val RoomNotificationSettingsViewState.notificationStateMapped: Async get() { - return if (roomEncrypted) { + return if (roomSummary()?.isEncrypted == true) { listOf(RoomNotificationState.ALL_MESSAGES_NOISY, RoomNotificationState.MUTE) } else { listOf(RoomNotificationState.ALL_MESSAGES_NOISY, RoomNotificationState.MENTIONS_ONLY, RoomNotificationState.MUTE) diff --git a/vector/src/main/res/layout/item_notifications_footer.xml b/vector/src/main/res/layout/item_notifications_footer.xml index 8338358048..36db166e8f 100644 --- a/vector/src/main/res/layout/item_notifications_footer.xml +++ b/vector/src/main/res/layout/item_notifications_footer.xml @@ -1,25 +1,13 @@ - - - - - \ No newline at end of file + android:paddingStart="@dimen/layout_horizontal_margin" + android:paddingTop="@dimen/layout_vertical_margin" + android:paddingEnd="@dimen/layout_horizontal_margin" + android:paddingBottom="@dimen/layout_vertical_margin" + android:textColor="?vctr_content_secondary" + tools:text="@string/room_settings_room_notifications_encryption_notice" /> diff --git a/vector/src/main/res/layout/item_text_header.xml b/vector/src/main/res/layout/item_text_header.xml index 15848f585e..3f876e5ece 100644 --- a/vector/src/main/res/layout/item_text_header.xml +++ b/vector/src/main/res/layout/item_text_header.xml @@ -1,25 +1,14 @@ - - - - - \ No newline at end of file + android:paddingStart="@dimen/layout_horizontal_margin" + android:paddingTop="@dimen/layout_vertical_margin" + android:paddingEnd="@dimen/layout_horizontal_margin" + android:paddingBottom="@dimen/layout_vertical_margin" + android:textColor="?vctr_content_secondary" + android:textStyle="bold" + tools:text="@string/room_settings_room_notifications_notify_me" /> \ No newline at end of file