From e1a12f4c77661a392b33efd988af6a947fd8d256 Mon Sep 17 00:00:00 2001 From: onurays Date: Mon, 15 Jun 2020 00:21:49 +0300 Subject: [PATCH] Show current history readability. --- .../settings/RoomSettingsController.kt | 29 +++++++++++++++++++ .../settings/RoomSettingsFragment.kt | 4 +++ .../settings/RoomSettingsViewModel.kt | 2 ++ .../settings/RoomSettingsViewState.kt | 2 ++ 4 files changed, 37 insertions(+) diff --git a/vector/src/main/java/im/vector/riotx/features/roomprofile/settings/RoomSettingsController.kt b/vector/src/main/java/im/vector/riotx/features/roomprofile/settings/RoomSettingsController.kt index bb87c256e8..41fff7e988 100644 --- a/vector/src/main/java/im/vector/riotx/features/roomprofile/settings/RoomSettingsController.kt +++ b/vector/src/main/java/im/vector/riotx/features/roomprofile/settings/RoomSettingsController.kt @@ -17,6 +17,10 @@ package im.vector.riotx.features.roomprofile.settings import com.airbnb.epoxy.TypedEpoxyController +import im.vector.matrix.android.api.session.events.model.Event +import im.vector.matrix.android.api.session.events.model.toModel +import im.vector.matrix.android.api.session.room.model.RoomHistoryVisibility +import im.vector.matrix.android.api.session.room.model.RoomHistoryVisibilityContent import im.vector.matrix.android.api.util.toMatrixItem import im.vector.riotx.R import im.vector.riotx.core.epoxy.profiles.buildProfileAction @@ -39,6 +43,7 @@ class RoomSettingsController @Inject constructor( fun onNameChanged(name: String) fun onTopicChanged(topic: String) fun onPhotoClicked() + fun onHistoryVisibilityClicked() } private val dividerColor = colorProvider.getColorFromAttribute(R.attr.vctr_list_divider_color) @@ -52,6 +57,8 @@ class RoomSettingsController @Inject constructor( override fun buildModels(data: RoomSettingsViewState?) { val roomSummary = data?.roomSummary?.invoke() ?: return + val historyVisibility = data.historyVisibilityEvent?.let { formatRoomHistoryVisibilityEvent(it) } ?: "" + buildProfileSection( stringProvider.getString(R.string.settings) ) @@ -78,6 +85,16 @@ class RoomSettingsController @Inject constructor( } } + buildProfileAction( + id = "historyReadability", + title = stringProvider.getString(R.string.room_settings_room_read_history_rules_pref_title), + subtitle = historyVisibility.toString(), + dividerColor = dividerColor, + divider = false, + editable = true, + action = { callback?.onHistoryVisibilityClicked() } + ) + buildProfileAction( id = "photo", title = stringProvider.getString(R.string.room_settings_room_photo), @@ -110,4 +127,16 @@ class RoomSettingsController @Inject constructor( ) } } + + private fun formatRoomHistoryVisibilityEvent(event: Event): String? { + val historyVisibility = event.getClearContent().toModel()?.historyVisibility ?: return null + + val formattedVisibility = when (historyVisibility) { + RoomHistoryVisibility.SHARED -> stringProvider.getString(R.string.notice_room_visibility_shared) + RoomHistoryVisibility.INVITED -> stringProvider.getString(R.string.notice_room_visibility_invited) + RoomHistoryVisibility.JOINED -> stringProvider.getString(R.string.notice_room_visibility_joined) + RoomHistoryVisibility.WORLD_READABLE -> stringProvider.getString(R.string.notice_room_visibility_world_readable) + } + return formattedVisibility + } } diff --git a/vector/src/main/java/im/vector/riotx/features/roomprofile/settings/RoomSettingsFragment.kt b/vector/src/main/java/im/vector/riotx/features/roomprofile/settings/RoomSettingsFragment.kt index 3733b311ac..c75a4bda71 100644 --- a/vector/src/main/java/im/vector/riotx/features/roomprofile/settings/RoomSettingsFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/roomprofile/settings/RoomSettingsFragment.kt @@ -152,4 +152,8 @@ class RoomSettingsFragment @Inject constructor( } super.onActivityResult(requestCode, resultCode, data) } + + override fun onHistoryVisibilityClicked() { + + } } diff --git a/vector/src/main/java/im/vector/riotx/features/roomprofile/settings/RoomSettingsViewModel.kt b/vector/src/main/java/im/vector/riotx/features/roomprofile/settings/RoomSettingsViewModel.kt index 1b0d2da749..db46b6f9d7 100644 --- a/vector/src/main/java/im/vector/riotx/features/roomprofile/settings/RoomSettingsViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/roomprofile/settings/RoomSettingsViewModel.kt @@ -23,6 +23,7 @@ import com.squareup.inject.assisted.Assisted import com.squareup.inject.assisted.AssistedInject import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.session.Session +import im.vector.matrix.android.api.session.events.model.EventType import im.vector.matrix.rx.rx import im.vector.matrix.rx.unwrap import im.vector.riotx.core.platform.VectorViewModel @@ -60,6 +61,7 @@ class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState: .execute { async -> val roomSummary = async.invoke() copy( + historyVisibilityEvent = room.getStateEvent(EventType.STATE_ROOM_HISTORY_VISIBILITY), roomSummary = async, newName = roomSummary?.displayName, newTopic = roomSummary?.topic diff --git a/vector/src/main/java/im/vector/riotx/features/roomprofile/settings/RoomSettingsViewState.kt b/vector/src/main/java/im/vector/riotx/features/roomprofile/settings/RoomSettingsViewState.kt index 4ac870028c..3a953f2d18 100644 --- a/vector/src/main/java/im/vector/riotx/features/roomprofile/settings/RoomSettingsViewState.kt +++ b/vector/src/main/java/im/vector/riotx/features/roomprofile/settings/RoomSettingsViewState.kt @@ -19,12 +19,14 @@ package im.vector.riotx.features.roomprofile.settings import com.airbnb.mvrx.Async import com.airbnb.mvrx.MvRxState import com.airbnb.mvrx.Uninitialized +import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.room.model.RoomSummary import im.vector.riotx.features.roomprofile.RoomProfileArgs import im.vector.riotx.multipicker.entity.MultiPickerImageType data class RoomSettingsViewState( val roomId: String, + val historyVisibilityEvent: Event? = null, val roomSummary: Async = Uninitialized, val isLoading: Boolean = false, val newName: String? = null,