2

我想使用 ViewModelProvider Factory 从意图(即:俱乐部)注入自定义可打包数据。

val teamModule = Kodein.Module {
  bind<ViewModelProvider.Factory>("team-factory") with factory { club: Club -> TeamListViewModelFactory(club, instance()) }
  bind<GetTeams>() with provider { GetTeams(instance()) }
  bind<TeamRepository>() with provider { TeamDataRepository(instance()) }
  bind<TeamListViewModel>() with factory { context: FragmentActivity -> ViewModelProviders.of(context, instance("team-factory")).get(TeamListViewModel::class.java) }
}

在我的活动中,我想获得一个带有内置意图数据的视图模型。这里是我的活动:

class TeamActivity : AppCompatActivity(), KodeinInjected {
  override val injector = KodeinInjector()
  private val viewModel: TeamListViewModel by injector.with(this).instance() // and intent.getParcelable<Club>(CLUB) but no idea how
}

任何想法?

4

0 回答 0