Code review update

This commit is contained in:
Valere 2020-11-25 15:47:27 +01:00
parent d9757cc660
commit a8b5a5227f
7 changed files with 21 additions and 19 deletions

View File

@ -71,8 +71,8 @@ class CreateDirectRoomActivity : SimpleFragmentActivity(), UserListViewModel.Fac
injector.inject(this)
}
override fun create(initialState: UserListViewState, args: UserListFragmentArgs): UserListViewModel {
return userListViewModelFactory.create(initialState, args)
override fun create(initialState: UserListViewState): UserListViewModel {
return userListViewModelFactory.create(initialState)
}
override fun onCreate(savedInstanceState: Bundle?) {

View File

@ -68,8 +68,8 @@ class InviteUsersToRoomActivity : SimpleFragmentActivity(), UserListViewModel.Fa
injector.inject(this)
}
override fun create(initialState: UserListViewState, args: UserListFragmentArgs): UserListViewModel {
return userListViewModelFactory.create(initialState, args)
override fun create(initialState: UserListViewState): UserListViewModel {
return userListViewModelFactory.create(initialState)
}
override fun onCreate(savedInstanceState: Bundle?) {

View File

@ -116,8 +116,8 @@ class UserCodeActivity
}.exhaustive
}
override fun create(initialState: UserCodeState, args: Args) =
viewModelFactory.create(initialState, args)
override fun create(initialState: UserCodeState) =
viewModelFactory.create(initialState)
companion object {
fun newIntent(context: Context, userId: String): Intent {

View File

@ -41,7 +41,6 @@ import org.matrix.android.sdk.internal.util.awaitCallback
class UserCodeSharedViewModel @AssistedInject constructor(
@Assisted val initialState: UserCodeState,
@Assisted val args: UserCodeActivity.Args,
private val session: Session,
private val stringProvider: StringProvider,
private val rawService: RawService) : VectorViewModel<UserCodeState, UserCodeActions, UserCodeShareViewEvents>(initialState) {
@ -53,27 +52,23 @@ class UserCodeSharedViewModel @AssistedInject constructor(
is FragmentViewModelContext -> viewModelContext.fragment as? Factory
is ActivityViewModelContext -> viewModelContext.activity as? Factory
}
return factory?.create(state, args) ?: error("You should let your activity/fragment implements Factory interface")
}
override fun initialState(viewModelContext: ViewModelContext): UserCodeState? {
return UserCodeState(viewModelContext.args<UserCodeActivity.Args>().userId)
return factory?.create(state) ?: error("You should let your activity/fragment implements Factory interface")
}
}
init {
val user = session.getUser(args.userId)
val user = session.getUser(initialState.userId)
setState {
copy(
matrixItem = user?.toMatrixItem(),
shareLink = session.permalinkService().createPermalink(args.userId)
shareLink = session.permalinkService().createPermalink(initialState.userId)
)
}
}
@AssistedInject.Factory
interface Factory {
fun create(initialState: UserCodeState, args: UserCodeActivity.Args): UserCodeSharedViewModel
fun create(initialState: UserCodeState): UserCodeSharedViewModel
}
override fun handle(action: UserCodeActions) {

View File

@ -30,4 +30,8 @@ data class UserCodeState(
object SCAN : Mode()
data class RESULT(val matrixItem: MatrixItem) : Mode()
}
constructor(args: UserCodeActivity.Args) : this(
userId = args.userId
)
}

View File

@ -43,7 +43,6 @@ private typealias KnownUsersSearch = String
private typealias DirectoryUsersSearch = String
class UserListViewModel @AssistedInject constructor(@Assisted initialState: UserListViewState,
@Assisted args: UserListFragmentArgs,
private val session: Session)
: VectorViewModel<UserListViewState, UserListAction, UserListViewEvents>(initialState) {
@ -54,7 +53,7 @@ class UserListViewModel @AssistedInject constructor(@Assisted initialState: User
@AssistedInject.Factory
interface Factory {
fun create(initialState: UserListViewState, args: UserListFragmentArgs): UserListViewModel
fun create(initialState: UserListViewState): UserListViewModel
}
companion object : MvRxViewModelFactory<UserListViewModel, UserListViewState> {
@ -65,7 +64,7 @@ class UserListViewModel @AssistedInject constructor(@Assisted initialState: User
is ActivityViewModelContext -> viewModelContext.activity as? Factory
}
val args = viewModelContext.args<UserListFragmentArgs>()
return factory?.create(state, args) ?: error("You should let your activity/fragment implements Factory interface")
return factory?.create(state) ?: error("You should let your activity/fragment implements Factory interface")
}
}
@ -73,7 +72,7 @@ class UserListViewModel @AssistedInject constructor(@Assisted initialState: User
setState {
copy(
myUserId = session.myUserId,
existingRoomId = args.existingRoomId
existingRoomId = initialState.existingRoomId
)
}
observeUsers()

View File

@ -35,6 +35,10 @@ data class UserListViewState(
val existingRoomId: String? = null
) : MvRxState {
constructor(args: UserListFragmentArgs) : this(
existingRoomId = args.existingRoomId
)
fun getSelectedMatrixId(): List<String> {
return pendingInvitees
.mapNotNull {