Toast message formatting of invited users.

This commit is contained in:
onurays 2020-05-12 12:10:45 +03:00
parent fe013f803e
commit 700fd47f22
4 changed files with 22 additions and 8 deletions

View File

@ -24,7 +24,6 @@ import android.view.View
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import com.airbnb.mvrx.MvRx import com.airbnb.mvrx.MvRx
import com.airbnb.mvrx.viewModel import com.airbnb.mvrx.viewModel
import com.airbnb.mvrx.withState
import im.vector.matrix.android.api.failure.Failure import im.vector.matrix.android.api.failure.Failure
import im.vector.riotx.R import im.vector.riotx.R
import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.di.ScreenComponent
@ -102,7 +101,7 @@ class InviteUsersToRoomActivity : SimpleFragmentActivity() {
private fun renderInviteEvents(viewEvent: InviteUsersToRoomViewEvents) { private fun renderInviteEvents(viewEvent: InviteUsersToRoomViewEvents) {
when (viewEvent) { when (viewEvent) {
is InviteUsersToRoomViewEvents.Loading -> renderInviteLoading() is InviteUsersToRoomViewEvents.Loading -> renderInviteLoading()
is InviteUsersToRoomViewEvents.Success -> renderInvitationSuccess() is InviteUsersToRoomViewEvents.Success -> renderInvitationSuccess(viewEvent.successMessage)
is InviteUsersToRoomViewEvents.Failure -> renderInviteFailure(viewEvent.throwable) is InviteUsersToRoomViewEvents.Failure -> renderInviteFailure(viewEvent.throwable)
} }
} }
@ -125,8 +124,8 @@ class InviteUsersToRoomActivity : SimpleFragmentActivity() {
.show() .show()
} }
private fun renderInvitationSuccess() = withState(viewModel) { private fun renderInvitationSuccess(successMessage: String) {
toast(R.string.invitations_sent_successfully) toast(successMessage)
finish() finish()
} }

View File

@ -21,5 +21,5 @@ import im.vector.riotx.core.platform.VectorViewEvents
sealed class InviteUsersToRoomViewEvents : VectorViewEvents { sealed class InviteUsersToRoomViewEvents : VectorViewEvents {
object Loading : InviteUsersToRoomViewEvents() object Loading : InviteUsersToRoomViewEvents()
data class Failure(val throwable: Throwable) : InviteUsersToRoomViewEvents() data class Failure(val throwable: Throwable) : InviteUsersToRoomViewEvents()
object Success : InviteUsersToRoomViewEvents() data class Success(val successMessage: String) : InviteUsersToRoomViewEvents()
} }

View File

@ -24,12 +24,15 @@ import com.squareup.inject.assisted.AssistedInject
import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.Session
import im.vector.matrix.android.api.session.user.model.User import im.vector.matrix.android.api.session.user.model.User
import im.vector.matrix.rx.rx import im.vector.matrix.rx.rx
import im.vector.riotx.R
import im.vector.riotx.core.platform.VectorViewModel import im.vector.riotx.core.platform.VectorViewModel
import im.vector.riotx.core.resources.StringProvider
import io.reactivex.Observable import io.reactivex.Observable
class InviteUsersToRoomViewModel @AssistedInject constructor(@Assisted class InviteUsersToRoomViewModel @AssistedInject constructor(@Assisted
initialState: InviteUsersToRoomViewState, initialState: InviteUsersToRoomViewState,
session: Session) session: Session,
val stringProvider: StringProvider)
: VectorViewModel<InviteUsersToRoomViewState, InviteUsersToRoomAction, InviteUsersToRoomViewEvents>(initialState) { : VectorViewModel<InviteUsersToRoomViewState, InviteUsersToRoomAction, InviteUsersToRoomViewEvents>(initialState) {
private val room = session.getRoom(initialState.roomId)!! private val room = session.getRoom(initialState.roomId)!!
@ -61,7 +64,17 @@ class InviteUsersToRoomViewModel @AssistedInject constructor(@Assisted
room.rx().invite(user.userId, null) room.rx().invite(user.userId, null)
}.subscribe( }.subscribe(
{ {
_viewEvents.post(InviteUsersToRoomViewEvents.Success) val successMessage = when (selectedUsers.size) {
1 -> stringProvider.getString(R.string.invitation_sent_to_one_user,
selectedUsers.first().displayName)
2 -> stringProvider.getString(R.string.invitations_sent_to_two_users,
selectedUsers.first().displayName,
selectedUsers.last().displayName)
else -> stringProvider.getString(R.string.invitations_sent_to_three_and_more_users,
selectedUsers.first().displayName,
selectedUsers.size - 1)
}
_viewEvents.post(InviteUsersToRoomViewEvents.Success(successMessage))
}, },
{ {
_viewEvents.post(InviteUsersToRoomViewEvents.Failure(it)) _viewEvents.post(InviteUsersToRoomViewEvents.Failure(it))

View File

@ -2372,7 +2372,9 @@ Not all features in Riot are implemented in RiotX yet. Main missing (and coming
<string name="invite_users_to_room_action_invite">INVITE</string> <string name="invite_users_to_room_action_invite">INVITE</string>
<string name="inviting_users_to_room">Inviting users…</string> <string name="inviting_users_to_room">Inviting users…</string>
<string name="invite_users_to_room_title">Invite Users</string> <string name="invite_users_to_room_title">Invite Users</string>
<string name="invitations_sent_successfully">Invitation sent successfully</string> <string name="invitation_sent_to_one_user">Invitation sent to %1$s</string>
<string name="invitations_sent_to_two_users">Invitations sent to %1$s and %2$s</string>
<string name="invitations_sent_to_three_and_more_users">Invitations sent to %1$s and %2$d more</string>
<string name="invite_users_to_room_failure">We could not invite users. Please check the users you want to invite and try again.</string> <string name="invite_users_to_room_failure">We could not invite users. Please check the users you want to invite and try again.</string>
</resources> </resources>