Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigation in mvvm #21

Open
steven274 opened this issue Sep 30, 2016 · 3 comments
Open

Navigation in mvvm #21

steven274 opened this issue Sep 30, 2016 · 3 comments

Comments

@steven274
Copy link

steven274 commented Sep 30, 2016

  1. I want startactivityforresult or setresult and finish activity, how can handle it in view model of activity ?
  2. Same question with view model of recyclerview.viewholder
@deno028
Copy link

deno028 commented Oct 1, 2016

  1. In ViewModel you can cast context to Activity(this context should be instance of Activity) :((Activity) context).startActivityForResult().
  2. In adapter:
    RecyclerView.ViewHolder

itemView.getContext() then do the same as case 1.

@steven274
Copy link
Author

I think View Model shouldn't know anything about View, right ?

@jasminsuljic
Copy link

@steven274 i share your opinion about view model not knowing anything about view, even about platform specific stuff. What i tend to do when dealing with use cases you described (startactivityforresult) is to create interface: <view_model>Delegate with implementation from activity. Then you can invoke: delegate.doSomethingWhatRequiresStartActivityForResult() and from onActivityResult (in host activity) invoke viewModel.success(response).

With this approach you can mock <view_model>Delegate implementation and test viewModel with local tests, its just plan old platform independent java code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants