From 0e400dca24a69636059bf23b03068cfe40197709 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Radics?= Date: Wed, 3 Feb 2021 20:04:24 +0100 Subject: [PATCH] [issue-2610] Add Override Color menu item under More... --- gradle/wrapper/gradle-wrapper.properties | 2 +- .../RoomMemberProfileController.kt | 13 +++++++++++-- .../RoomMemberProfileFragment.kt | 15 ++++++++------- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 247e2b90ad..73f88221b1 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,7 @@ #Fri Jan 15 11:30:47 CET 2021 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionSha256Sum=a7ca23b3ccf265680f2bfd35f1f00b1424f4466292c7337c85d46c9641b3f053 +#distributionSha256Sum=a7ca23b3ccf265680f2bfd35f1f00b1424f4466292c7337c85d46c9641b3f053 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-all.zip diff --git a/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileController.kt b/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileController.kt index e29c197ab8..9c2d2ded70 100644 --- a/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileController.kt +++ b/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileController.kt @@ -46,6 +46,7 @@ class RoomMemberProfileController @Inject constructor( fun onShowDeviceList() fun onShowDeviceListNoCrossSigning() fun onOpenDmClicked() + fun onOverrideColorClicked() fun onJumpToReadReceiptClicked() fun onMentionClicked() fun onEditPowerLevel(currentRole: Role) @@ -180,11 +181,19 @@ class RoomMemberProfileController @Inject constructor( private fun buildMoreSection(state: RoomMemberProfileViewState) { // More + buildProfileSection(stringProvider.getString(R.string.room_profile_section_more)) + + buildProfileAction( + id = "overrideColor", + editable = false, + title = stringProvider.getString(R.string.room_member_override_color), + dividerColor = dividerColor, + action = { callback?.onOverrideColorClicked() } + ) + if (!state.isMine) { val membership = state.asyncMembership() ?: return - buildProfileSection(stringProvider.getString(R.string.room_profile_section_more)) - buildProfileAction( id = "direct", editable = false, diff --git a/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileFragment.kt b/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileFragment.kt index 92cdf305fe..2099b706eb 100644 --- a/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileFragment.kt @@ -243,7 +243,7 @@ class RoomMemberProfileFragment @Inject constructor( onAvatarClicked(view, userMatrixItem) } headerViews.memberProfileNameView.setOnClickListener { _ -> - onProfileNameClicked(userMatrixItem) + onOverrideColorClicked() } views.matrixProfileToolbarAvatarImageView.setOnClickListener { view -> onAvatarClicked(view, userMatrixItem) @@ -331,14 +331,15 @@ class RoomMemberProfileFragment @Inject constructor( navigator.openBigImageViewer(requireActivity(), view, userMatrixItem) } - private fun onProfileNameClicked(userMatrixItem: MatrixItem) { + override fun onOverrideColorClicked(): Unit = withState(viewModel) { state -> val inflater = requireActivity().layoutInflater val layout = inflater.inflate(R.layout.dialog_base_edit_text, null) val views = DialogBaseEditTextBinding.bind(layout) val session = injector().activeSessionHolder().getActiveSession() val overrideColorsSetting = session.getAccountDataEvent(UserAccountDataTypes.TYPE_OVERRIDE_COLORS) val overrideColorSpecs = overrideColorsSetting?.content?.toMap().orEmpty() - val overrideColorSpec = overrideColorSpecs[userMatrixItem.id]?.toString() + val userId = state.userId; + val overrideColorSpec = overrideColorSpecs[userId]?.toString() views.editText.setText(overrideColorSpec) views.editText.hint = "#000000" @@ -349,16 +350,16 @@ class RoomMemberProfileFragment @Inject constructor( val newOverrideColorSpec = views.editText.text.toString() if (newOverrideColorSpec != overrideColorSpec) { val newOverrideColorSpecs = overrideColorSpecs.toMutableMap() - if (matrixItemColorProvider.setOverrideColor(userMatrixItem.id, newOverrideColorSpec)) { - newOverrideColorSpecs[userMatrixItem.id] = newOverrideColorSpec + if (matrixItemColorProvider.setOverrideColor(userId, newOverrideColorSpec)) { + newOverrideColorSpecs[userId] = newOverrideColorSpec } else { - newOverrideColorSpecs.remove(userMatrixItem.id) + newOverrideColorSpecs.remove(userId) } session.updateAccountData( type = UserAccountDataTypes.TYPE_OVERRIDE_COLORS, content = newOverrideColorSpecs ) - headerViews.memberProfileNameView.setTextColor(matrixItemColorProvider.getColor(userMatrixItem)) + invalidate() } } .setNegativeButton(R.string.cancel, null)