[issue-2610] Add Override Color menu item under More...

This commit is contained in:
Péter Radics 2021-02-03 20:04:24 +01:00
parent 0aee15fd04
commit 0e400dca24
3 changed files with 20 additions and 10 deletions

View file

@ -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

View file

@ -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,

View file

@ -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)