Create RoomHistoryVisibilityFormatter
This commit is contained in:
parent
cca6d0e967
commit
ff0b92272a
|
@ -26,7 +26,6 @@ import im.vector.matrix.android.api.session.room.model.PowerLevelsContent
|
|||
import im.vector.matrix.android.api.session.room.model.RoomAliasesContent
|
||||
import im.vector.matrix.android.api.session.room.model.RoomCanonicalAliasContent
|
||||
import im.vector.matrix.android.api.session.room.model.RoomGuestAccessContent
|
||||
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.session.room.model.RoomJoinRules
|
||||
import im.vector.matrix.android.api.session.room.model.RoomJoinRulesContent
|
||||
|
@ -47,6 +46,7 @@ import timber.log.Timber
|
|||
import javax.inject.Inject
|
||||
|
||||
class NoticeEventFormatter @Inject constructor(private val sessionHolder: ActiveSessionHolder,
|
||||
private val roomHistoryVisibilityFormatter: RoomHistoryVisibilityFormatter,
|
||||
private val sp: StringProvider) {
|
||||
|
||||
private fun Event.isSentByCurrentUser() = senderId != null && senderId == sessionHolder.getSafeActiveSession()?.myUserId
|
||||
|
@ -223,12 +223,7 @@ class NoticeEventFormatter @Inject constructor(private val sessionHolder: Active
|
|||
private fun formatRoomHistoryVisibilityEvent(event: Event, senderName: String?): CharSequence? {
|
||||
val historyVisibility = event.getClearContent().toModel<RoomHistoryVisibilityContent>()?.historyVisibility ?: return null
|
||||
|
||||
val formattedVisibility = when (historyVisibility) {
|
||||
RoomHistoryVisibility.SHARED -> sp.getString(R.string.notice_room_visibility_shared)
|
||||
RoomHistoryVisibility.INVITED -> sp.getString(R.string.notice_room_visibility_invited)
|
||||
RoomHistoryVisibility.JOINED -> sp.getString(R.string.notice_room_visibility_joined)
|
||||
RoomHistoryVisibility.WORLD_READABLE -> sp.getString(R.string.notice_room_visibility_world_readable)
|
||||
}
|
||||
val formattedVisibility = roomHistoryVisibilityFormatter.format(historyVisibility)
|
||||
return if (event.isSentByCurrentUser()) {
|
||||
sp.getString(R.string.notice_made_future_room_visibility_by_you, formattedVisibility)
|
||||
} else {
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (c) 2020 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.riotx.features.home.room.detail.timeline.format
|
||||
|
||||
import im.vector.matrix.android.api.session.room.model.RoomHistoryVisibility
|
||||
import im.vector.riotx.R
|
||||
import im.vector.riotx.core.resources.StringProvider
|
||||
import javax.inject.Inject
|
||||
|
||||
class RoomHistoryVisibilityFormatter @Inject constructor(
|
||||
private val stringProvider: StringProvider
|
||||
) {
|
||||
|
||||
fun format(roomHistoryVisibility: RoomHistoryVisibility): String {
|
||||
return when (roomHistoryVisibility) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -23,7 +23,7 @@ sealed class RoomSettingsAction : VectorViewModelAction {
|
|||
data class SetRoomName(val newName: String) : RoomSettingsAction()
|
||||
data class SetRoomTopic(val newTopic: String) : RoomSettingsAction()
|
||||
data class SetRoomHistoryVisibility(val visibility: RoomHistoryVisibility) : RoomSettingsAction()
|
||||
data class SetRoomAlias(val alias: String) : RoomSettingsAction()
|
||||
data class SetRoomCanonicalAlias(val newCanonicalAlias: String) : RoomSettingsAction()
|
||||
object EnableEncryption : RoomSettingsAction()
|
||||
object Save : RoomSettingsAction()
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ 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.riotx.R
|
||||
import im.vector.riotx.core.epoxy.profiles.buildProfileAction
|
||||
|
@ -27,11 +26,12 @@ import im.vector.riotx.core.epoxy.profiles.buildProfileSection
|
|||
import im.vector.riotx.core.resources.ColorProvider
|
||||
import im.vector.riotx.core.resources.StringProvider
|
||||
import im.vector.riotx.features.form.formEditTextItem
|
||||
import im.vector.riotx.features.home.room.detail.timeline.format.RoomHistoryVisibilityFormatter
|
||||
import javax.inject.Inject
|
||||
|
||||
// TODO Add other feature here (waiting for design)
|
||||
class RoomSettingsController @Inject constructor(
|
||||
private val stringProvider: StringProvider,
|
||||
private val roomHistoryVisibilityFormatter: RoomHistoryVisibilityFormatter,
|
||||
colorProvider: ColorProvider
|
||||
) : TypedEpoxyController<RoomSettingsViewState>() {
|
||||
|
||||
|
@ -55,7 +55,7 @@ class RoomSettingsController @Inject constructor(
|
|||
val roomSummary = data?.roomSummary?.invoke() ?: return
|
||||
|
||||
val historyVisibility = data.historyVisibilityEvent?.let { formatRoomHistoryVisibilityEvent(it) } ?: ""
|
||||
val newHistoryVisibility = data.newHistoryVisibility?.let { formatRoomHistoryVisibility(it) }
|
||||
val newHistoryVisibility = data.newHistoryVisibility?.let { roomHistoryVisibilityFormatter.format(it) }
|
||||
|
||||
buildProfileSection(
|
||||
stringProvider.getString(R.string.settings)
|
||||
|
@ -127,17 +127,6 @@ class RoomSettingsController @Inject constructor(
|
|||
|
||||
private fun formatRoomHistoryVisibilityEvent(event: Event): String? {
|
||||
val historyVisibility = event.getClearContent().toModel<RoomHistoryVisibilityContent>()?.historyVisibility ?: return null
|
||||
|
||||
return formatRoomHistoryVisibility(historyVisibility)
|
||||
}
|
||||
|
||||
private fun formatRoomHistoryVisibility(historyVisibility: RoomHistoryVisibility): String {
|
||||
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
|
||||
return roomHistoryVisibilityFormatter.format(historyVisibility)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ import im.vector.riotx.core.extensions.exhaustive
|
|||
import im.vector.riotx.core.platform.VectorBaseFragment
|
||||
import im.vector.riotx.core.utils.toast
|
||||
import im.vector.riotx.features.home.AvatarRenderer
|
||||
import im.vector.riotx.features.home.room.detail.timeline.format.RoomHistoryVisibilityFormatter
|
||||
import im.vector.riotx.features.roomprofile.RoomProfileArgs
|
||||
import kotlinx.android.synthetic.main.fragment_room_setting_generic.*
|
||||
import kotlinx.android.synthetic.main.merge_overlay_waiting_view.*
|
||||
|
@ -44,6 +45,7 @@ import javax.inject.Inject
|
|||
class RoomSettingsFragment @Inject constructor(
|
||||
val viewModelFactory: RoomSettingsViewModel.Factory,
|
||||
private val controller: RoomSettingsController,
|
||||
private val roomHistoryVisibilityFormatter: RoomHistoryVisibilityFormatter,
|
||||
private val avatarRenderer: AvatarRenderer
|
||||
) : VectorBaseFragment(), RoomSettingsController.Callback {
|
||||
|
||||
|
@ -141,7 +143,11 @@ class RoomSettingsFragment @Inject constructor(
|
|||
|
||||
AlertDialog.Builder(requireContext()).apply {
|
||||
setTitle(R.string.room_settings_room_read_history_rules_pref_title)
|
||||
setSingleChoiceItems(historyVisibilities.map { formatHistoryVisibility(it) }.toTypedArray(), currentHistoryVisibilityIndex) { dialog, which ->
|
||||
setSingleChoiceItems(
|
||||
historyVisibilities
|
||||
.map { roomHistoryVisibilityFormatter.format(it) }
|
||||
.toTypedArray(),
|
||||
currentHistoryVisibilityIndex) { dialog, which ->
|
||||
if (which != currentHistoryVisibilityIndex) {
|
||||
viewModel.handle(RoomSettingsAction.SetRoomHistoryVisibility(historyVisibilities[which]))
|
||||
}
|
||||
|
@ -152,17 +158,7 @@ class RoomSettingsFragment @Inject constructor(
|
|||
return@withState
|
||||
}
|
||||
|
||||
// TODO Create a formatter for this enum, it's done 3 times in the project
|
||||
private fun formatHistoryVisibility(historyVisibility: RoomHistoryVisibility): String {
|
||||
return when (historyVisibility) {
|
||||
RoomHistoryVisibility.SHARED -> getString(R.string.notice_room_visibility_shared)
|
||||
RoomHistoryVisibility.INVITED -> getString(R.string.notice_room_visibility_invited)
|
||||
RoomHistoryVisibility.JOINED -> getString(R.string.notice_room_visibility_joined)
|
||||
RoomHistoryVisibility.WORLD_READABLE -> getString(R.string.notice_room_visibility_world_readable)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAliasChanged(alias: String) {
|
||||
viewModel.handle(RoomSettingsAction.SetRoomAlias(alias))
|
||||
viewModel.handle(RoomSettingsAction.SetRoomCanonicalAlias(alias))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,7 +117,7 @@ class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState:
|
|||
is RoomSettingsAction.SetRoomName -> setState { copy(newName = action.newName) }
|
||||
is RoomSettingsAction.SetRoomTopic -> setState { copy(newTopic = action.newTopic) }
|
||||
is RoomSettingsAction.SetRoomHistoryVisibility -> setState { copy(newHistoryVisibility = action.visibility) }
|
||||
is RoomSettingsAction.SetRoomAlias -> setState { copy(newCanonicalAlias = action.alias) }
|
||||
is RoomSettingsAction.SetRoomCanonicalAlias -> setState { copy(newCanonicalAlias = action.newCanonicalAlias) }
|
||||
is RoomSettingsAction.Save -> saveSettings()
|
||||
}.exhaustive
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue