Render canonical alias
This commit is contained in:
parent
f5ae95d7f1
commit
2d4cbde72c
|
@ -51,7 +51,7 @@ class RoomAliasController @Inject constructor(
|
||||||
fun toggleLocalAliasForm()
|
fun toggleLocalAliasForm()
|
||||||
fun setNewLocalAliasLocalPart(value: String)
|
fun setNewLocalAliasLocalPart(value: String)
|
||||||
fun addLocalAlias()
|
fun addLocalAlias()
|
||||||
fun openAlias(alias: String, isPublished: Boolean)
|
fun openAliasDetail(alias: String, isPublished: Boolean)
|
||||||
}
|
}
|
||||||
|
|
||||||
var callback: Callback? = null
|
var callback: Callback? = null
|
||||||
|
@ -78,7 +78,17 @@ class RoomAliasController @Inject constructor(
|
||||||
helperTextResId(R.string.room_alias_published_alias_subtitle)
|
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()) {
|
if (data.alternativeAliases.isEmpty()) {
|
||||||
settingsInfoItem {
|
settingsInfoItem {
|
||||||
|
@ -98,7 +108,7 @@ class RoomAliasController @Inject constructor(
|
||||||
profileActionItem {
|
profileActionItem {
|
||||||
id("alt_$idx")
|
id("alt_$idx")
|
||||||
title(altAlias)
|
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) {
|
private fun buildPublishManuallyForm(data: RoomAliasViewState) {
|
||||||
when (data.publishManuallyState) {
|
when (data.publishManuallyState) {
|
||||||
RoomAliasViewState.AddAliasState.Hidden -> Unit
|
RoomAliasViewState.AddAliasState.Hidden -> Unit
|
||||||
RoomAliasViewState.AddAliasState.Closed -> {
|
RoomAliasViewState.AddAliasState.Closed -> {
|
||||||
settingsButtonItem {
|
settingsButtonItem {
|
||||||
id("publishManually")
|
id("publishManually")
|
||||||
colorProvider(colorProvider)
|
colorProvider(colorProvider)
|
||||||
|
@ -154,16 +164,16 @@ class RoomAliasController @Inject constructor(
|
||||||
id("loadingAliases")
|
id("loadingAliases")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is Success -> {
|
is Success -> {
|
||||||
localAliases().forEachIndexed { idx, localAlias ->
|
localAliases().forEachIndexed { idx, localAlias ->
|
||||||
profileActionItem {
|
profileActionItem {
|
||||||
id("loc_$idx")
|
id("loc_$idx")
|
||||||
title(localAlias)
|
title(localAlias)
|
||||||
listener { callback?.openAlias(localAlias, false) }
|
listener { callback?.openAliasDetail(localAlias, false) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is Fail -> {
|
is Fail -> {
|
||||||
errorWithRetryItem {
|
errorWithRetryItem {
|
||||||
id("alt_error")
|
id("alt_error")
|
||||||
text(errorFormatter.toHumanReadable(localAliases.error))
|
text(errorFormatter.toHumanReadable(localAliases.error))
|
||||||
|
@ -177,8 +187,8 @@ class RoomAliasController @Inject constructor(
|
||||||
|
|
||||||
private fun buildAddLocalAlias(data: RoomAliasViewState) {
|
private fun buildAddLocalAlias(data: RoomAliasViewState) {
|
||||||
when (data.newLocalAliasState) {
|
when (data.newLocalAliasState) {
|
||||||
RoomAliasViewState.AddAliasState.Hidden -> Unit
|
RoomAliasViewState.AddAliasState.Hidden -> Unit
|
||||||
RoomAliasViewState.AddAliasState.Closed -> {
|
RoomAliasViewState.AddAliasState.Closed -> {
|
||||||
settingsButtonItem {
|
settingsButtonItem {
|
||||||
id("newLocalAliasButton")
|
id("newLocalAliasButton")
|
||||||
colorProvider(colorProvider)
|
colorProvider(colorProvider)
|
||||||
|
|
|
@ -113,29 +113,26 @@ class RoomAliasFragment @Inject constructor(
|
||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun invalidate() = withState(viewModel) { viewState ->
|
override fun invalidate() = withState(viewModel) { state ->
|
||||||
controller.setData(viewState)
|
waiting_view.isVisible = state.isLoading
|
||||||
renderRoomSummary(viewState)
|
controller.setData(state)
|
||||||
|
renderRoomSummary(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun renderRoomSummary(state: RoomAliasViewState) {
|
private fun renderRoomSummary(state: RoomAliasViewState) {
|
||||||
waiting_view.isVisible = state.isLoading
|
|
||||||
|
|
||||||
state.roomSummary()?.let {
|
state.roomSummary()?.let {
|
||||||
roomSettingsToolbarTitleView.text = it.displayName
|
roomSettingsToolbarTitleView.text = it.displayName
|
||||||
avatarRenderer.render(it.toMatrixItem(), roomSettingsToolbarAvatarImageView)
|
avatarRenderer.render(it.toMatrixItem(), roomSettingsToolbarAvatarImageView)
|
||||||
}
|
}
|
||||||
|
|
||||||
invalidateOptionsMenu()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun unpublishAlias(altAlias: String) {
|
private fun unpublishAlias(alias: String) {
|
||||||
AlertDialog.Builder(requireContext())
|
AlertDialog.Builder(requireContext())
|
||||||
.setTitle(R.string.dialog_title_confirmation)
|
.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)
|
.setNegativeButton(R.string.cancel, null)
|
||||||
.setPositiveButton(R.string.delete) { _, _ ->
|
.setPositiveButton(R.string.action_unpublish) { _, _ ->
|
||||||
viewModel.handle(RoomAliasAction.UnpublishAlias(altAlias))
|
viewModel.handle(RoomAliasAction.UnpublishAlias(alias))
|
||||||
}
|
}
|
||||||
.show()
|
.show()
|
||||||
.withColoredButton(DialogInterface.BUTTON_POSITIVE)
|
.withColoredButton(DialogInterface.BUTTON_POSITIVE)
|
||||||
|
@ -165,7 +162,7 @@ class RoomAliasFragment @Inject constructor(
|
||||||
viewModel.handle(RoomAliasAction.AddLocalAlias)
|
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
|
RoomAliasBottomSheet
|
||||||
.newInstance(
|
.newInstance(
|
||||||
alias = alias,
|
alias = alias,
|
||||||
|
|
|
@ -157,8 +157,8 @@ class RoomAliasViewModel @AssistedInject constructor(@Assisted initialState: Roo
|
||||||
when (action) {
|
when (action) {
|
||||||
RoomAliasAction.ToggleManualPublishForm -> handleToggleManualPublishForm()
|
RoomAliasAction.ToggleManualPublishForm -> handleToggleManualPublishForm()
|
||||||
is RoomAliasAction.SetNewAlias -> handleSetNewAlias(action)
|
is RoomAliasAction.SetNewAlias -> handleSetNewAlias(action)
|
||||||
is RoomAliasAction.ManualPublishAlias -> handleAddAlias()
|
is RoomAliasAction.ManualPublishAlias -> handleManualPublishAlias()
|
||||||
is RoomAliasAction.UnpublishAlias -> handleRemoveAlias(action)
|
is RoomAliasAction.UnpublishAlias -> handleUnpublishAlias(action)
|
||||||
is RoomAliasAction.SetCanonicalAlias -> handleSetCanonicalAlias(action)
|
is RoomAliasAction.SetCanonicalAlias -> handleSetCanonicalAlias(action)
|
||||||
RoomAliasAction.ToggleAddLocalAliasForm -> handleToggleAddLocalAliasForm()
|
RoomAliasAction.ToggleAddLocalAliasForm -> handleToggleAddLocalAliasForm()
|
||||||
is RoomAliasAction.SetNewLocalAliasLocalPart -> handleSetNewLocalAliasLocalPart(action)
|
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
|
val newAlias = (state.publishManuallyState as? RoomAliasViewState.AddAliasState.Editing)?.value ?: return@withState
|
||||||
updateCanonicalAlias(
|
updateCanonicalAlias(
|
||||||
canonicalAlias = state.canonicalAlias,
|
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(
|
updateCanonicalAlias(
|
||||||
canonicalAlias = state.canonicalAlias,
|
canonicalAlias = state.canonicalAlias,
|
||||||
alternativeAliases = state.alternativeAliases - action.alias,
|
alternativeAliases = state.alternativeAliases - action.alias,
|
||||||
|
@ -235,7 +235,8 @@ class RoomAliasViewModel @AssistedInject constructor(@Assisted initialState: Roo
|
||||||
private fun handleSetCanonicalAlias(action: RoomAliasAction.SetCanonicalAlias) = withState { state ->
|
private fun handleSetCanonicalAlias(action: RoomAliasAction.SetCanonicalAlias) = withState { state ->
|
||||||
updateCanonicalAlias(
|
updateCanonicalAlias(
|
||||||
canonicalAlias = action.canonicalAlias,
|
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
|
closeForm = false
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -247,10 +248,7 @@ class RoomAliasViewModel @AssistedInject constructor(@Assisted initialState: Roo
|
||||||
setState {
|
setState {
|
||||||
copy(
|
copy(
|
||||||
isLoading = false,
|
isLoading = false,
|
||||||
publishManuallyState = if (closeForm) RoomAliasViewState.AddAliasState.Closed else publishManuallyState,
|
publishManuallyState = if (closeForm) RoomAliasViewState.AddAliasState.Closed else publishManuallyState
|
||||||
// Local echo
|
|
||||||
canonicalAlias = canonicalAlias,
|
|
||||||
alternativeAliases = alternativeAliases
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ class RoomAliasBottomSheetController @Inject constructor() : TypedEpoxyControlle
|
||||||
id("alias")
|
id("alias")
|
||||||
title(state.alias)
|
title(state.alias)
|
||||||
subtitle(state.matrixToLink)
|
subtitle(state.matrixToLink)
|
||||||
|
editable(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notifications
|
// Notifications
|
||||||
|
|
|
@ -138,6 +138,7 @@
|
||||||
<string name="action_close">Close</string>
|
<string name="action_close">Close</string>
|
||||||
<string name="action_copy">Copy</string>
|
<string name="action_copy">Copy</string>
|
||||||
<string name="action_add">Add</string>
|
<string name="action_add">Add</string>
|
||||||
|
<string name="action_unpublish">Unpublish</string>
|
||||||
<string name="copied_to_clipboard">Copied to clipboard</string>
|
<string name="copied_to_clipboard">Copied to clipboard</string>
|
||||||
<string name="disable">Disable</string>
|
<string name="disable">Disable</string>
|
||||||
|
|
||||||
|
@ -1030,10 +1031,12 @@
|
||||||
<string name="room_alias_title">Room Addresses</string>
|
<string name="room_alias_title">Room Addresses</string>
|
||||||
<string name="room_alias_published_alias_title">Published 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_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_main_address_hint">Main address</string>
|
||||||
<string name="room_alias_published_other">Other published addresses:</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">Published a new address manually</string>
|
||||||
<string name="room_alias_published_alias_add_manually_submit">Publish</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>
|
<string name="room_alias_delete_confirmation">Delete the address \"%1$s\"?</string>
|
||||||
<!-- Parameter will be the url of the homeserver, ex: matrix.org -->
|
<!-- 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>
|
<string name="room_alias_publish">Publish this room to the public in %1$s\'s room directory?</string>
|
||||||
|
|
Loading…
Reference in New Issue