I need some advice to properly implement MVVM with what I'm trying to do.
1) I have a WebView control in a View because I need user to manually login to a website.
2) Once login, it will set a flag to indicate that user has logged in. It will then go to another link in the website and periodically read a html element value.
3) The values read will then be displayed in a table in another View.
4) In the scenario when the user is logged off from the website, it will show the website login page again. And then it will continue to Step 2 and Step 3.
5) The View that has the WebView control only need to be shown for the user to log in to the website. After logging in, the View can be hidden, and only showing the table which contains the values read, which are periodically updated.
I have few ideas on how to implement it but I am not sure if my idea is correct or not.
Have 2 View/ViewModel pair. 1 View/ViewModel (VM1) to display out the readings read. Another View/ViewModel (VM2) which contains WebView control for the user to login. VM1 will periodically trigger VM2 (by using mediator pattern) to read from the website. As VW2 tries to read from the website, if the user is not logged in to the website, it will go to the log in page. Once the user has logged in, it will go to the webpage that contains the html element and read the value. It will stay in that webpage so that the next time VW1 triggers VM2 to read the value, it can readily do so without user intervention.
Eventhough user may close the VM2's View, the View is not really closed. It is just hidden and the program is still able to read from the webpage in the background.
Have View/ViewModel (VM1) to display out the value in the table. VM1 calls a service that does the reading of webpage. The service has a WebView control. If the user is not logged in, the service will instantiate a View/ViewModel (VM2) and passing in the WebView control which the user can use to log in. Once the user has logged in, the WebView control is passed back to the service so that the service can continue to read the html element. The service then triggers the ViewModel (VM2) to close the View.
Please advice on what is the correct MVVM way to do what I'm trying to do.
modified 10-May-17 18:00pm.