mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-17 04:20:00 +03:00
Remove string usage from SDK - step 1 - Role
Lint will also be able to detect more possible errors with this change
This commit is contained in:
parent
898c2d514c
commit
c42b42cb61
4 changed files with 46 additions and 20 deletions
|
@ -17,14 +17,11 @@
|
||||||
|
|
||||||
package org.matrix.android.sdk.api.session.room.powerlevels
|
package org.matrix.android.sdk.api.session.room.powerlevels
|
||||||
|
|
||||||
import androidx.annotation.StringRes
|
sealed class Role(open val value: Int) : Comparable<Role> {
|
||||||
import org.matrix.android.sdk.R
|
object Admin : Role(100)
|
||||||
|
object Moderator : Role(50)
|
||||||
sealed class Role(open val value: Int, @StringRes val res: Int) : Comparable<Role> {
|
object Default : Role(0)
|
||||||
object Admin : Role(100, R.string.power_level_admin)
|
data class Custom(override val value: Int) : Role(value)
|
||||||
object Moderator : Role(50, R.string.power_level_moderator)
|
|
||||||
object Default : Role(0, R.string.power_level_default)
|
|
||||||
data class Custom(override val value: Int) : Role(value, R.string.power_level_custom)
|
|
||||||
|
|
||||||
override fun compareTo(other: Role): Int {
|
override fun compareTo(other: Role): Int {
|
||||||
return value.compareTo(other.value)
|
return value.compareTo(other.value)
|
||||||
|
|
|
@ -20,6 +20,7 @@ import im.vector.app.ActiveSessionDataSource
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
import im.vector.app.core.resources.StringProvider
|
import im.vector.app.core.resources.StringProvider
|
||||||
import im.vector.app.features.home.room.detail.timeline.helper.RoomSummariesHolder
|
import im.vector.app.features.home.room.detail.timeline.helper.RoomSummariesHolder
|
||||||
|
import im.vector.app.features.roomprofile.permissions.RoleFormatter
|
||||||
import im.vector.app.features.settings.VectorPreferences
|
import im.vector.app.features.settings.VectorPreferences
|
||||||
import org.matrix.android.sdk.api.extensions.appendNl
|
import org.matrix.android.sdk.api.extensions.appendNl
|
||||||
import org.matrix.android.sdk.api.extensions.orFalse
|
import org.matrix.android.sdk.api.extensions.orFalse
|
||||||
|
@ -55,6 +56,7 @@ import javax.inject.Inject
|
||||||
class NoticeEventFormatter @Inject constructor(
|
class NoticeEventFormatter @Inject constructor(
|
||||||
private val activeSessionDataSource: ActiveSessionDataSource,
|
private val activeSessionDataSource: ActiveSessionDataSource,
|
||||||
private val roomHistoryVisibilityFormatter: RoomHistoryVisibilityFormatter,
|
private val roomHistoryVisibilityFormatter: RoomHistoryVisibilityFormatter,
|
||||||
|
private val roleFormatter: RoleFormatter,
|
||||||
private val vectorPreferences: VectorPreferences,
|
private val vectorPreferences: VectorPreferences,
|
||||||
private val roomSummariesHolder: RoomSummariesHolder,
|
private val roomSummariesHolder: RoomSummariesHolder,
|
||||||
private val sp: StringProvider
|
private val sp: StringProvider
|
||||||
|
@ -124,8 +126,8 @@ class NoticeEventFormatter @Inject constructor(
|
||||||
val from = PowerLevelsHelper(previousPowerLevelsContent).getUserRole(userId)
|
val from = PowerLevelsHelper(previousPowerLevelsContent).getUserRole(userId)
|
||||||
val to = PowerLevelsHelper(powerLevelsContent).getUserRole(userId)
|
val to = PowerLevelsHelper(powerLevelsContent).getUserRole(userId)
|
||||||
if (from != to) {
|
if (from != to) {
|
||||||
val fromStr = sp.getString(from.res, from.value)
|
val fromStr = roleFormatter.format(from)
|
||||||
val toStr = sp.getString(to.res, to.value)
|
val toStr = roleFormatter.format(to)
|
||||||
val diff = sp.getString(R.string.notice_power_level_diff, userId, fromStr, toStr)
|
val diff = sp.getString(R.string.notice_power_level_diff, userId, fromStr, toStr)
|
||||||
diffs.add(diff)
|
diffs.add(diff)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021 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.app.features.roomprofile.permissions
|
||||||
|
|
||||||
|
import im.vector.app.R
|
||||||
|
import im.vector.app.core.resources.StringProvider
|
||||||
|
import org.matrix.android.sdk.api.session.room.powerlevels.Role
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class RoleFormatter @Inject constructor(
|
||||||
|
private val stringProvider: StringProvider
|
||||||
|
) {
|
||||||
|
fun format(role: Role): String {
|
||||||
|
return when (role) {
|
||||||
|
Role.Admin -> stringProvider.getString(R.string.power_level_admin)
|
||||||
|
Role.Moderator -> stringProvider.getString(R.string.power_level_moderator)
|
||||||
|
Role.Default -> stringProvider.getString(R.string.power_level_default)
|
||||||
|
is Role.Custom -> stringProvider.getString(R.string.power_level_custom, role.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -32,6 +32,7 @@ import javax.inject.Inject
|
||||||
|
|
||||||
class RoomPermissionsController @Inject constructor(
|
class RoomPermissionsController @Inject constructor(
|
||||||
private val stringProvider: StringProvider,
|
private val stringProvider: StringProvider,
|
||||||
|
private val roleFormatter: RoleFormatter,
|
||||||
colorProvider: ColorProvider
|
colorProvider: ColorProvider
|
||||||
) : TypedEpoxyController<RoomPermissionsViewState>() {
|
) : TypedEpoxyController<RoomPermissionsViewState>() {
|
||||||
|
|
||||||
|
@ -124,7 +125,7 @@ class RoomPermissionsController @Inject constructor(
|
||||||
buildProfileAction(
|
buildProfileAction(
|
||||||
id = editablePermission.labelResId.toString(),
|
id = editablePermission.labelResId.toString(),
|
||||||
title = stringProvider.getString(editablePermission.labelResId),
|
title = stringProvider.getString(editablePermission.labelResId),
|
||||||
subtitle = getSubtitle(currentRole),
|
subtitle = roleFormatter.format(currentRole),
|
||||||
dividerColor = dividerColor,
|
dividerColor = dividerColor,
|
||||||
divider = true,
|
divider = true,
|
||||||
editable = editable,
|
editable = editable,
|
||||||
|
@ -136,15 +137,6 @@ class RoomPermissionsController @Inject constructor(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getSubtitle(currentRole: Role): String {
|
|
||||||
return when (currentRole) {
|
|
||||||
Role.Admin,
|
|
||||||
Role.Moderator,
|
|
||||||
Role.Default -> stringProvider.getString(currentRole.res)
|
|
||||||
is Role.Custom -> stringProvider.getString(currentRole.res, currentRole.value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getCurrentRole(editablePermission: EditablePermission, content: PowerLevelsContent): Role {
|
private fun getCurrentRole(editablePermission: EditablePermission, content: PowerLevelsContent): Role {
|
||||||
val value = when (editablePermission) {
|
val value = when (editablePermission) {
|
||||||
is EditablePermission.EventTypeEditablePermission -> content.events[editablePermission.eventType] ?: content.stateDefault
|
is EditablePermission.EventTypeEditablePermission -> content.events[editablePermission.eventType] ?: content.stateDefault
|
||||||
|
|
Loading…
Add table
Reference in a new issue