Render canonical alias

This commit is contained in:
Benoit Marty 2020-11-24 08:56:56 +01:00 committed by Benoit Marty
parent f5ae95d7f1
commit 2d4cbde72c
5 changed files with 40 additions and 31 deletions

View file

@ -51,7 +51,7 @@ class RoomAliasController @Inject constructor(
fun toggleLocalAliasForm()
fun setNewLocalAliasLocalPart(value: String)
fun addLocalAlias()
fun openAlias(alias: String, isPublished: Boolean)
fun openAliasDetail(alias: String, isPublished: Boolean)
}
var callback: Callback? = null
@ -78,7 +78,17 @@ class RoomAliasController @Inject constructor(
helperTextResId(R.string.room_alias_published_alias_subtitle)
}
// TODO Set/Unset Canonical
data.canonicalAlias
?.takeIf { it.isNotEmpty() }
?.let { canonicalAlias ->
profileActionItem {
id("canonical")
title(data.canonicalAlias)
subtitle(stringProvider.getString(R.string.room_alias_published_alias_main))
listener { callback?.openAliasDetail(canonicalAlias, true) }
}
}
if (data.alternativeAliases.isEmpty()) {
settingsInfoItem {
@ -98,7 +108,7 @@ class RoomAliasController @Inject constructor(
profileActionItem {
id("alt_$idx")
title(altAlias)
listener { callback?.openAlias(altAlias, true) }
listener { callback?.openAliasDetail(altAlias, true) }
}
}
}
@ -110,8 +120,8 @@ class RoomAliasController @Inject constructor(
private fun buildPublishManuallyForm(data: RoomAliasViewState) {
when (data.publishManuallyState) {
RoomAliasViewState.AddAliasState.Hidden -> Unit
RoomAliasViewState.AddAliasState.Closed -> {
RoomAliasViewState.AddAliasState.Hidden -> Unit
RoomAliasViewState.AddAliasState.Closed -> {
settingsButtonItem {
id("publishManually")
colorProvider(colorProvider)
@ -154,16 +164,16 @@ class RoomAliasController @Inject constructor(
id("loadingAliases")
}
}
is Success -> {
is Success -> {
localAliases().forEachIndexed { idx, localAlias ->
profileActionItem {
id("loc_$idx")
title(localAlias)
listener { callback?.openAlias(localAlias, false) }
listener { callback?.openAliasDetail(localAlias, false) }
}
}
}
is Fail -> {
is Fail -> {
errorWithRetryItem {
id("alt_error")
text(errorFormatter.toHumanReadable(localAliases.error))
@ -177,8 +187,8 @@ class RoomAliasController @Inject constructor(
private fun buildAddLocalAlias(data: RoomAliasViewState) {
when (data.newLocalAliasState) {
RoomAliasViewState.AddAliasState.Hidden -> Unit
RoomAliasViewState.AddAliasState.Closed -> {
RoomAliasViewState.AddAliasState.Hidden -> Unit
RoomAliasViewState.AddAliasState.Closed -> {
settingsButtonItem {
id("newLocalAliasButton")
colorProvider(colorProvider)

View file

@ -113,29 +113,26 @@ class RoomAliasFragment @Inject constructor(
super.onDestroyView()
}
override fun invalidate() = withState(viewModel) { viewState ->
controller.setData(viewState)
renderRoomSummary(viewState)
override fun invalidate() = withState(viewModel) { state ->
waiting_view.isVisible = state.isLoading
controller.setData(state)
renderRoomSummary(state)
}
private fun renderRoomSummary(state: RoomAliasViewState) {
waiting_view.isVisible = state.isLoading
state.roomSummary()?.let {
roomSettingsToolbarTitleView.text = it.displayName
avatarRenderer.render(it.toMatrixItem(), roomSettingsToolbarAvatarImageView)
}
invalidateOptionsMenu()
}
private fun unpublishAlias(altAlias: String) {
private fun unpublishAlias(alias: String) {
AlertDialog.Builder(requireContext())
.setTitle(R.string.dialog_title_confirmation)
.setMessage(getString(R.string.room_alias_delete_confirmation, altAlias))
.setMessage(getString(R.string.room_alias_unpublish_confirmation, alias))
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(R.string.delete) { _, _ ->
viewModel.handle(RoomAliasAction.UnpublishAlias(altAlias))
.setPositiveButton(R.string.action_unpublish) { _, _ ->
viewModel.handle(RoomAliasAction.UnpublishAlias(alias))
}
.show()
.withColoredButton(DialogInterface.BUTTON_POSITIVE)
@ -165,7 +162,7 @@ class RoomAliasFragment @Inject constructor(
viewModel.handle(RoomAliasAction.AddLocalAlias)
}
override fun openAlias(alias: String, isPublished: Boolean) = withState(viewModel) { state ->
override fun openAliasDetail(alias: String, isPublished: Boolean) = withState(viewModel) { state ->
RoomAliasBottomSheet
.newInstance(
alias = alias,

View file

@ -157,8 +157,8 @@ class RoomAliasViewModel @AssistedInject constructor(@Assisted initialState: Roo
when (action) {
RoomAliasAction.ToggleManualPublishForm -> handleToggleManualPublishForm()
is RoomAliasAction.SetNewAlias -> handleSetNewAlias(action)
is RoomAliasAction.ManualPublishAlias -> handleAddAlias()
is RoomAliasAction.UnpublishAlias -> handleRemoveAlias(action)
is RoomAliasAction.ManualPublishAlias -> handleManualPublishAlias()
is RoomAliasAction.UnpublishAlias -> handleUnpublishAlias(action)
is RoomAliasAction.SetCanonicalAlias -> handleSetCanonicalAlias(action)
RoomAliasAction.ToggleAddLocalAliasForm -> handleToggleAddLocalAliasForm()
is RoomAliasAction.SetNewLocalAliasLocalPart -> handleSetNewLocalAliasLocalPart(action)
@ -208,7 +208,7 @@ class RoomAliasViewModel @AssistedInject constructor(@Assisted initialState: Roo
}
}
private fun handleAddAlias() = withState { state ->
private fun handleManualPublishAlias() = withState { state ->
val newAlias = (state.publishManuallyState as? RoomAliasViewState.AddAliasState.Editing)?.value ?: return@withState
updateCanonicalAlias(
canonicalAlias = state.canonicalAlias,
@ -225,7 +225,7 @@ class RoomAliasViewModel @AssistedInject constructor(@Assisted initialState: Roo
)
}
private fun handleRemoveAlias(action: RoomAliasAction.UnpublishAlias) = withState { state ->
private fun handleUnpublishAlias(action: RoomAliasAction.UnpublishAlias) = withState { state ->
updateCanonicalAlias(
canonicalAlias = state.canonicalAlias,
alternativeAliases = state.alternativeAliases - action.alias,
@ -235,7 +235,8 @@ class RoomAliasViewModel @AssistedInject constructor(@Assisted initialState: Roo
private fun handleSetCanonicalAlias(action: RoomAliasAction.SetCanonicalAlias) = withState { state ->
updateCanonicalAlias(
canonicalAlias = action.canonicalAlias,
alternativeAliases = state.alternativeAliases,
// Ensure the previous canonical alias is moved to the alt aliases
alternativeAliases = (state.alternativeAliases + listOfNotNull(state.canonicalAlias)).distinct(),
closeForm = false
)
}
@ -247,10 +248,7 @@ class RoomAliasViewModel @AssistedInject constructor(@Assisted initialState: Roo
setState {
copy(
isLoading = false,
publishManuallyState = if (closeForm) RoomAliasViewState.AddAliasState.Closed else publishManuallyState,
// Local echo
canonicalAlias = canonicalAlias,
alternativeAliases = alternativeAliases
publishManuallyState = if (closeForm) RoomAliasViewState.AddAliasState.Closed else publishManuallyState
)
}
}

View file

@ -34,6 +34,7 @@ class RoomAliasBottomSheetController @Inject constructor() : TypedEpoxyControlle
id("alias")
title(state.alias)
subtitle(state.matrixToLink)
editable(false)
}
// Notifications

View file

@ -138,6 +138,7 @@
<string name="action_close">Close</string>
<string name="action_copy">Copy</string>
<string name="action_add">Add</string>
<string name="action_unpublish">Unpublish</string>
<string name="copied_to_clipboard">Copied to clipboard</string>
<string name="disable">Disable</string>
@ -1030,10 +1031,12 @@
<string name="room_alias_title">Room Addresses</string>
<string name="room_alias_published_alias_title">Published Addresses</string>
<string name="room_alias_published_alias_subtitle">Published addresses can be used by anyone on any server to join your room. To publish an address, it needs to be set as a local address first.</string>
<string name="room_alias_published_alias_main">This is the main address</string>
<string name="room_alias_main_address_hint">Main address</string>
<string name="room_alias_published_other">Other published addresses:</string>
<string name="room_alias_published_alias_add_manually">Published a new address manually</string>
<string name="room_alias_published_alias_add_manually_submit">Publish</string>
<string name="room_alias_unpublish_confirmation">Unpublish the address \"%1$s\"?</string>
<string name="room_alias_delete_confirmation">Delete the address \"%1$s\"?</string>
<!-- Parameter will be the url of the homeserver, ex: matrix.org -->
<string name="room_alias_publish">Publish this room to the public in %1$s\'s room directory?</string>