From 52de14b1b516cd54b47de10de994c9c5bd2a4adf Mon Sep 17 00:00:00 2001 From: ganfra Date: Wed, 15 Jan 2020 11:46:33 +0100 Subject: [PATCH] Clean code after Benoit's review --- .../SenderNotificationPermissionCondition.kt | 2 +- .../api/session/profile/ProfileService.kt | 19 +++++++++++++++++++ .../session/room/model/PowerLevelsContent.kt | 2 +- .../PowerLevelsConstants.kt | 2 +- .../PowerLevelsHelper.kt | 6 ++---- .../internal/session/profile/ProfileAPI.kt | 2 +- .../RoomMemberProfileViewEvents.kt | 2 +- .../RoomMemberProfileViewModel.kt | 6 +++--- .../roomprofile/RoomProfileController.kt | 10 ++++------ .../roomprofile/RoomProfileFragment.kt | 2 -- .../roomprofile/RoomProfileViewModel.kt | 5 +---- .../roomprofile/RoomProfileViewState.kt | 3 +-- .../members/RoomMemberListViewModel.kt | 4 ++-- vector/src/main/res/values/strings_riotX.xml | 5 ++++- 14 files changed, 41 insertions(+), 29 deletions(-) rename matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/{powerlevers => powerlevels}/PowerLevelsConstants.kt (92%) rename matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/{powerlevers => powerlevels}/PowerLevelsHelper.kt (91%) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/pushrules/SenderNotificationPermissionCondition.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/pushrules/SenderNotificationPermissionCondition.kt index 657ad29c87..e0d4034082 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/pushrules/SenderNotificationPermissionCondition.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/pushrules/SenderNotificationPermissionCondition.kt @@ -17,7 +17,7 @@ package im.vector.matrix.android.api.pushrules import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.room.model.PowerLevelsContent -import im.vector.matrix.android.api.session.room.powerlevers.PowerLevelsHelper +import im.vector.matrix.android.api.session.room.powerlevels.PowerLevelsHelper class SenderNotificationPermissionCondition(val key: String) : Condition(Kind.sender_notification_permission) { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/profile/ProfileService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/profile/ProfileService.kt index 2718ff742a..c1dc9a8afa 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/profile/ProfileService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/profile/ProfileService.kt @@ -22,6 +22,9 @@ import im.vector.matrix.android.api.util.Cancelable import im.vector.matrix.android.api.util.JsonDict import im.vector.matrix.android.api.util.Optional +/** + * This interface defines methods to handling profile information. It's implemented at the session level. + */ interface ProfileService { companion object Constants { @@ -29,9 +32,25 @@ interface ProfileService { const val AVATAR_URL_KEY = "avatar_url" } + /** + * Return the current dispayname for this user + * @param userId the userId param to look for + * + */ fun getDisplayName(userId: String, matrixCallback: MatrixCallback>): Cancelable + /** + * Return the current avatarUrl for this user. + * @param userId the userId param to look for + * + */ fun getAvatarUrl(userId: String, matrixCallback: MatrixCallback>): Cancelable + /** + * Get the combined profile information for this user. + * This may return keys which are not limited to displayname or avatar_url. + * @param userId the userId param to look for + * + */ fun getProfile(userId: String, matrixCallback: MatrixCallback): Cancelable } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/PowerLevelsContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/PowerLevelsContent.kt index 9b4a1f23d9..2f81965d0a 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/PowerLevelsContent.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/PowerLevelsContent.kt @@ -18,7 +18,7 @@ package im.vector.matrix.android.api.session.room.model import com.squareup.moshi.Json import com.squareup.moshi.JsonClass -import im.vector.matrix.android.api.session.room.powerlevers.PowerLevelsConstants +import im.vector.matrix.android.api.session.room.powerlevels.PowerLevelsConstants /** * Class representing the EventType.EVENT_TYPE_STATE_ROOM_POWER_LEVELS state event content. diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/powerlevers/PowerLevelsConstants.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/powerlevels/PowerLevelsConstants.kt similarity index 92% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/powerlevers/PowerLevelsConstants.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/powerlevels/PowerLevelsConstants.kt index a039626d6e..16af3d216e 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/powerlevers/PowerLevelsConstants.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/powerlevels/PowerLevelsConstants.kt @@ -15,7 +15,7 @@ * */ -package im.vector.matrix.android.api.session.room.powerlevers +package im.vector.matrix.android.api.session.room.powerlevels object PowerLevelsConstants { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/powerlevers/PowerLevelsHelper.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/powerlevels/PowerLevelsHelper.kt similarity index 91% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/powerlevers/PowerLevelsHelper.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/powerlevels/PowerLevelsHelper.kt index ec285f0e1f..b18a7dd97b 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/powerlevers/PowerLevelsHelper.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/powerlevels/PowerLevelsHelper.kt @@ -15,7 +15,7 @@ * */ -package im.vector.matrix.android.api.session.room.powerlevers +package im.vector.matrix.android.api.session.room.powerlevels import im.vector.matrix.android.api.session.events.model.EventType import im.vector.matrix.android.api.session.room.model.PowerLevelsContent @@ -64,9 +64,7 @@ class PowerLevelsHelper(private val powerLevelsContent: PowerLevelsContent) { * @return the level */ fun notificationLevel(key: String): Int { - val value = powerLevelsContent.notifications[key] - ?: return PowerLevelsConstants.DEFAULT_ROOM_MODERATOR_LEVEL - return when (value) { + return when (val value = powerLevelsContent.notifications[key]) { // the first implementation was a string value is String -> value.toInt() is Int -> value diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/profile/ProfileAPI.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/profile/ProfileAPI.kt index eb016280d8..197d85f879 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/profile/ProfileAPI.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/profile/ProfileAPI.kt @@ -32,5 +32,5 @@ interface ProfileAPI { * @param userId the user id to fetch profile info */ @GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "profile/{userId}") - fun getProfile(@Path("userId") roomId: String): Call + fun getProfile(@Path("userId") userId: String): Call } diff --git a/vector/src/main/java/im/vector/riotx/features/roommemberprofile/RoomMemberProfileViewEvents.kt b/vector/src/main/java/im/vector/riotx/features/roommemberprofile/RoomMemberProfileViewEvents.kt index 2a72051491..093e54989b 100644 --- a/vector/src/main/java/im/vector/riotx/features/roommemberprofile/RoomMemberProfileViewEvents.kt +++ b/vector/src/main/java/im/vector/riotx/features/roommemberprofile/RoomMemberProfileViewEvents.kt @@ -17,7 +17,7 @@ package im.vector.riotx.features.roommemberprofile /** - * Transient events for RoomProfile + * Transient events for RoomMemberProfile */ sealed class RoomMemberProfileViewEvents { data class Loading(val message: CharSequence) : RoomMemberProfileViewEvents() diff --git a/vector/src/main/java/im/vector/riotx/features/roommemberprofile/RoomMemberProfileViewModel.kt b/vector/src/main/java/im/vector/riotx/features/roommemberprofile/RoomMemberProfileViewModel.kt index 737539937b..88f394e865 100644 --- a/vector/src/main/java/im/vector/riotx/features/roommemberprofile/RoomMemberProfileViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/roommemberprofile/RoomMemberProfileViewModel.kt @@ -33,8 +33,8 @@ import im.vector.matrix.android.api.session.room.Room import im.vector.matrix.android.api.session.room.members.roomMemberQueryParams import im.vector.matrix.android.api.session.room.model.PowerLevelsContent import im.vector.matrix.android.api.session.room.model.RoomSummary -import im.vector.matrix.android.api.session.room.powerlevers.PowerLevelsConstants -import im.vector.matrix.android.api.session.room.powerlevers.PowerLevelsHelper +import im.vector.matrix.android.api.session.room.powerlevels.PowerLevelsConstants +import im.vector.matrix.android.api.session.room.powerlevels.PowerLevelsHelper import im.vector.matrix.android.api.util.MatrixItem import im.vector.matrix.android.api.util.toMatrixItem import im.vector.matrix.android.api.util.toOptional @@ -196,7 +196,7 @@ class RoomMemberProfileViewModel @AssistedInject constructor(@Assisted private v if (isIgnored) { session.unIgnoreUserIds(listOf(state.userId), ignoreActionCallback) } else { - session.ignoreUserIds(listOf(initialState.userId), ignoreActionCallback) + session.ignoreUserIds(listOf(state.userId), ignoreActionCallback) } } } diff --git a/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileController.kt b/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileController.kt index dfd534badd..37a36fbcf1 100644 --- a/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileController.kt +++ b/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileController.kt @@ -42,12 +42,10 @@ class RoomProfileController @Inject constructor(private val stringProvider: Stri if (data == null) { return } - - val roomSummary = data.roomSummary() - + val roomSummary = data.roomSummary() ?: return // Security buildProfileSection(stringProvider.getString(R.string.room_profile_section_security)) - val learnMoreSubtitle = if (data.isEncrypted) { + val learnMoreSubtitle = if (roomSummary.isEncrypted) { R.string.room_profile_encrypted_subtitle } else { R.string.room_profile_not_encrypted_subtitle @@ -73,10 +71,10 @@ class RoomProfileController @Inject constructor(private val stringProvider: Stri icon = R.drawable.ic_room_profile_notification, action = { callback?.onNotificationsClicked() } ) - val numberOfMembers = roomSummary?.joinedMembersCount?.toString() ?: "-" + val numberOfMembers = roomSummary.joinedMembersCount ?: 0 buildProfileAction( id = "member_list", - title = stringProvider.getString(R.string.room_profile_section_more_member_list, numberOfMembers), + title = stringProvider.getQuantityString(R.plurals.room_profile_section_more_member_list, numberOfMembers, numberOfMembers), icon = R.drawable.ic_room_profile_member_list, action = { callback?.onMemberListClicked() } ) diff --git a/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileFragment.kt b/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileFragment.kt index f8994b895b..da161efd6a 100644 --- a/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileFragment.kt @@ -15,8 +15,6 @@ * */ -@file:Suppress("DEPRECATION") - package im.vector.riotx.features.roomprofile import android.os.Bundle diff --git a/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileViewModel.kt b/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileViewModel.kt index d7e86130f9..8134c93b4f 100644 --- a/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileViewModel.kt @@ -64,10 +64,7 @@ class RoomProfileViewModel @AssistedInject constructor(@Assisted initialState: R room.rx().liveRoomSummary() .unwrap() .execute { - copy( - roomSummary = it, - isEncrypted = room.isEncrypted() - ) + copy(roomSummary = it) } } diff --git a/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileViewState.kt b/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileViewState.kt index 7a5e74b10e..aed1488b07 100644 --- a/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileViewState.kt +++ b/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileViewState.kt @@ -24,8 +24,7 @@ import im.vector.matrix.android.api.session.room.model.RoomSummary data class RoomProfileViewState( val roomId: String, - val roomSummary: Async = Uninitialized, - val isEncrypted: Boolean = false + val roomSummary: Async = Uninitialized ) : MvRxState { constructor(args: RoomProfileArgs) : this(roomId = args.roomId) diff --git a/vector/src/main/java/im/vector/riotx/features/roomprofile/members/RoomMemberListViewModel.kt b/vector/src/main/java/im/vector/riotx/features/roomprofile/members/RoomMemberListViewModel.kt index 3ba457bfb8..c3db239047 100644 --- a/vector/src/main/java/im/vector/riotx/features/roomprofile/members/RoomMemberListViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/roomprofile/members/RoomMemberListViewModel.kt @@ -29,8 +29,8 @@ import im.vector.matrix.android.api.session.room.members.roomMemberQueryParams import im.vector.matrix.android.api.session.room.model.Membership import im.vector.matrix.android.api.session.room.model.PowerLevelsContent import im.vector.matrix.android.api.session.room.model.RoomMemberSummary -import im.vector.matrix.android.api.session.room.powerlevers.PowerLevelsConstants -import im.vector.matrix.android.api.session.room.powerlevers.PowerLevelsHelper +import im.vector.matrix.android.api.session.room.powerlevels.PowerLevelsConstants +import im.vector.matrix.android.api.session.room.powerlevels.PowerLevelsHelper import im.vector.matrix.rx.mapOptional import im.vector.matrix.rx.rx import im.vector.matrix.rx.unwrap diff --git a/vector/src/main/res/values/strings_riotX.xml b/vector/src/main/res/values/strings_riotX.xml index 8c544a3dbf..c57145d10e 100644 --- a/vector/src/main/res/values/strings_riotX.xml +++ b/vector/src/main/res/values/strings_riotX.xml @@ -12,7 +12,10 @@ More Room settings Notifications - "%1$s people" + + "One person" + "%1$d people" + Uploads Leave Room "Leaving the room..."