mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-29 06:28:45 +03:00
Clean code after Benoit's review
This commit is contained in:
parent
d6e6092eea
commit
52de14b1b5
14 changed files with 41 additions and 29 deletions
|
@ -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.events.model.Event
|
||||||
import im.vector.matrix.android.api.session.room.model.PowerLevelsContent
|
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) {
|
class SenderNotificationPermissionCondition(val key: String) : Condition(Kind.sender_notification_permission) {
|
||||||
|
|
||||||
|
|
|
@ -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.JsonDict
|
||||||
import im.vector.matrix.android.api.util.Optional
|
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 {
|
interface ProfileService {
|
||||||
|
|
||||||
companion object Constants {
|
companion object Constants {
|
||||||
|
@ -29,9 +32,25 @@ interface ProfileService {
|
||||||
const val AVATAR_URL_KEY = "avatar_url"
|
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<Optional<String>>): Cancelable
|
fun getDisplayName(userId: String, matrixCallback: MatrixCallback<Optional<String>>): Cancelable
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the current avatarUrl for this user.
|
||||||
|
* @param userId the userId param to look for
|
||||||
|
*
|
||||||
|
*/
|
||||||
fun getAvatarUrl(userId: String, matrixCallback: MatrixCallback<Optional<String>>): Cancelable
|
fun getAvatarUrl(userId: String, matrixCallback: MatrixCallback<Optional<String>>): 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<JsonDict>): Cancelable
|
fun getProfile(userId: String, matrixCallback: MatrixCallback<JsonDict>): Cancelable
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ package im.vector.matrix.android.api.session.room.model
|
||||||
|
|
||||||
import com.squareup.moshi.Json
|
import com.squareup.moshi.Json
|
||||||
import com.squareup.moshi.JsonClass
|
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.
|
* Class representing the EventType.EVENT_TYPE_STATE_ROOM_POWER_LEVELS state event content.
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package im.vector.matrix.android.api.session.room.powerlevers
|
package im.vector.matrix.android.api.session.room.powerlevels
|
||||||
|
|
||||||
object PowerLevelsConstants {
|
object PowerLevelsConstants {
|
||||||
|
|
|
@ -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.events.model.EventType
|
||||||
import im.vector.matrix.android.api.session.room.model.PowerLevelsContent
|
import im.vector.matrix.android.api.session.room.model.PowerLevelsContent
|
||||||
|
@ -64,9 +64,7 @@ class PowerLevelsHelper(private val powerLevelsContent: PowerLevelsContent) {
|
||||||
* @return the level
|
* @return the level
|
||||||
*/
|
*/
|
||||||
fun notificationLevel(key: String): Int {
|
fun notificationLevel(key: String): Int {
|
||||||
val value = powerLevelsContent.notifications[key]
|
return when (val value = powerLevelsContent.notifications[key]) {
|
||||||
?: return PowerLevelsConstants.DEFAULT_ROOM_MODERATOR_LEVEL
|
|
||||||
return when (value) {
|
|
||||||
// the first implementation was a string value
|
// the first implementation was a string value
|
||||||
is String -> value.toInt()
|
is String -> value.toInt()
|
||||||
is Int -> value
|
is Int -> value
|
|
@ -32,5 +32,5 @@ interface ProfileAPI {
|
||||||
* @param userId the user id to fetch profile info
|
* @param userId the user id to fetch profile info
|
||||||
*/
|
*/
|
||||||
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "profile/{userId}")
|
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "profile/{userId}")
|
||||||
fun getProfile(@Path("userId") roomId: String): Call<JsonDict>
|
fun getProfile(@Path("userId") userId: String): Call<JsonDict>
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
package im.vector.riotx.features.roommemberprofile
|
package im.vector.riotx.features.roommemberprofile
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transient events for RoomProfile
|
* Transient events for RoomMemberProfile
|
||||||
*/
|
*/
|
||||||
sealed class RoomMemberProfileViewEvents {
|
sealed class RoomMemberProfileViewEvents {
|
||||||
data class Loading(val message: CharSequence) : RoomMemberProfileViewEvents()
|
data class Loading(val message: CharSequence) : RoomMemberProfileViewEvents()
|
||||||
|
|
|
@ -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.members.roomMemberQueryParams
|
||||||
import im.vector.matrix.android.api.session.room.model.PowerLevelsContent
|
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.model.RoomSummary
|
||||||
import im.vector.matrix.android.api.session.room.powerlevers.PowerLevelsConstants
|
import im.vector.matrix.android.api.session.room.powerlevels.PowerLevelsConstants
|
||||||
import im.vector.matrix.android.api.session.room.powerlevers.PowerLevelsHelper
|
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.MatrixItem
|
||||||
import im.vector.matrix.android.api.util.toMatrixItem
|
import im.vector.matrix.android.api.util.toMatrixItem
|
||||||
import im.vector.matrix.android.api.util.toOptional
|
import im.vector.matrix.android.api.util.toOptional
|
||||||
|
@ -196,7 +196,7 @@ class RoomMemberProfileViewModel @AssistedInject constructor(@Assisted private v
|
||||||
if (isIgnored) {
|
if (isIgnored) {
|
||||||
session.unIgnoreUserIds(listOf(state.userId), ignoreActionCallback)
|
session.unIgnoreUserIds(listOf(state.userId), ignoreActionCallback)
|
||||||
} else {
|
} else {
|
||||||
session.ignoreUserIds(listOf(initialState.userId), ignoreActionCallback)
|
session.ignoreUserIds(listOf(state.userId), ignoreActionCallback)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,12 +42,10 @@ class RoomProfileController @Inject constructor(private val stringProvider: Stri
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
val roomSummary = data.roomSummary() ?: return
|
||||||
val roomSummary = data.roomSummary()
|
|
||||||
|
|
||||||
// Security
|
// Security
|
||||||
buildProfileSection(stringProvider.getString(R.string.room_profile_section_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
|
R.string.room_profile_encrypted_subtitle
|
||||||
} else {
|
} else {
|
||||||
R.string.room_profile_not_encrypted_subtitle
|
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,
|
icon = R.drawable.ic_room_profile_notification,
|
||||||
action = { callback?.onNotificationsClicked() }
|
action = { callback?.onNotificationsClicked() }
|
||||||
)
|
)
|
||||||
val numberOfMembers = roomSummary?.joinedMembersCount?.toString() ?: "-"
|
val numberOfMembers = roomSummary.joinedMembersCount ?: 0
|
||||||
buildProfileAction(
|
buildProfileAction(
|
||||||
id = "member_list",
|
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,
|
icon = R.drawable.ic_room_profile_member_list,
|
||||||
action = { callback?.onMemberListClicked() }
|
action = { callback?.onMemberListClicked() }
|
||||||
)
|
)
|
||||||
|
|
|
@ -15,8 +15,6 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@file:Suppress("DEPRECATION")
|
|
||||||
|
|
||||||
package im.vector.riotx.features.roomprofile
|
package im.vector.riotx.features.roomprofile
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
|
|
@ -64,10 +64,7 @@ class RoomProfileViewModel @AssistedInject constructor(@Assisted initialState: R
|
||||||
room.rx().liveRoomSummary()
|
room.rx().liveRoomSummary()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.execute {
|
.execute {
|
||||||
copy(
|
copy(roomSummary = it)
|
||||||
roomSummary = it,
|
|
||||||
isEncrypted = room.isEncrypted()
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,7 @@ import im.vector.matrix.android.api.session.room.model.RoomSummary
|
||||||
|
|
||||||
data class RoomProfileViewState(
|
data class RoomProfileViewState(
|
||||||
val roomId: String,
|
val roomId: String,
|
||||||
val roomSummary: Async<RoomSummary> = Uninitialized,
|
val roomSummary: Async<RoomSummary> = Uninitialized
|
||||||
val isEncrypted: Boolean = false
|
|
||||||
) : MvRxState {
|
) : MvRxState {
|
||||||
|
|
||||||
constructor(args: RoomProfileArgs) : this(roomId = args.roomId)
|
constructor(args: RoomProfileArgs) : this(roomId = args.roomId)
|
||||||
|
|
|
@ -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.Membership
|
||||||
import im.vector.matrix.android.api.session.room.model.PowerLevelsContent
|
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.model.RoomMemberSummary
|
||||||
import im.vector.matrix.android.api.session.room.powerlevers.PowerLevelsConstants
|
import im.vector.matrix.android.api.session.room.powerlevels.PowerLevelsConstants
|
||||||
import im.vector.matrix.android.api.session.room.powerlevers.PowerLevelsHelper
|
import im.vector.matrix.android.api.session.room.powerlevels.PowerLevelsHelper
|
||||||
import im.vector.matrix.rx.mapOptional
|
import im.vector.matrix.rx.mapOptional
|
||||||
import im.vector.matrix.rx.rx
|
import im.vector.matrix.rx.rx
|
||||||
import im.vector.matrix.rx.unwrap
|
import im.vector.matrix.rx.unwrap
|
||||||
|
|
|
@ -12,7 +12,10 @@
|
||||||
<string name="room_profile_section_more">More</string>
|
<string name="room_profile_section_more">More</string>
|
||||||
<string name="room_profile_section_more_settings">Room settings</string>
|
<string name="room_profile_section_more_settings">Room settings</string>
|
||||||
<string name="room_profile_section_more_notifications">Notifications</string>
|
<string name="room_profile_section_more_notifications">Notifications</string>
|
||||||
<string name="room_profile_section_more_member_list">"%1$s people"</string>
|
<plurals name="room_profile_section_more_member_list">
|
||||||
|
<item quantity="one">"One person"</item>
|
||||||
|
<item quantity="other">"%1$d people"</item>
|
||||||
|
</plurals>
|
||||||
<string name="room_profile_section_more_uploads">Uploads</string>
|
<string name="room_profile_section_more_uploads">Uploads</string>
|
||||||
<string name="room_profile_section_more_leave">Leave Room</string>
|
<string name="room_profile_section_more_leave">Leave Room</string>
|
||||||
<string name="room_profile_leaving_room">"Leaving the room..."</string>
|
<string name="room_profile_leaving_room">"Leaving the room..."</string>
|
||||||
|
|
Loading…
Reference in a new issue